Azure Event Hubs - REST API Authentication - azure

I have a Python program that generates streaming data. Each piece of data is stored as a variable called message.
Since Event Hubs does not offer a Python SDK, I've opted to use their REST API. I've attempted to push the data to my Event Hub instance as a part of my Python program that generates data as follows:
r = requests.post("https://{Instance name}.servicebus.windows.net/{Path}/messages", message)
print(r.status_code, r.reason)
Upon executing this code, I receive a 401 Unauthorized response.
After running into this issue, I used this tutorial to try and create a shared access signature. Upon using curl to confirm that my generated token worked, I received a HTTP/1.1 401 40103: Invalid authorization token signature response.
Is there a better way to send the data while still generating it in Python? A better way to create a shared access signature?

Azure SDK for Python supports sending messages to Event Hubs: https://github.com/Azure/azure-sdk-for-python/tree/master/azure-servicebus#event-hub.
I'd suggest using the SDK but if you really want to call the REST API directly, take a look at the Event Hubs methods implementation in the SDK source: https://github.com/Azure/azure-sdk-for-python/blob/master/azure-servicebus/azure/servicebus/servicebusservice.py.

Related

HTTPS endpoint of Azure event hub

I am using service that can only send messages using webhook. The only thing I can set up in that webhook are HTTP endpoint, user name and password (you can see it on the screenshot below). I would like to send messages to my event hub, but I don't know how to find its HTTP endpoint. The only thing I could find was SAS Endpoint.
Event Hubs offers a REST API that allows you to perform a subset of the operations supported by its AMQP API. Publishing basic events via REST is possible and would use the endpoint: https://{servicebusNamespace}.servicebus.windows.net/{eventHubPath}/messages.
The full set of documentation for the REST API can be found here, and the specifics for sending events here.

How to use a Trapper Item without Zabbix S

How do I send a JSON payload to a Zabbix Trapper Item without using Zabbix Sender?
I see the documentation on how to format the sender request and I see the documentation related to the header, but I haven't found how to use the header with a JSON payload.
My goal is to send Azure Activity Logs to Zabbix a Trapper Item using Azure Alerts.
I don't want to setup a Script Item or equivalent that would pull the information from the Azure API, as I would then have to worry about hitting the query limit for the Azure Management APIs and being throttled by the Azure platform.
How is the header incorporated into the request payload?
You need to use an implementation of the same protocol, for example:
in go: https://github.com/adubkov/go-zabbix
in python: https://github.com/adubkov/py-zabbix
and put that in a cloud function to send the payload to Zabbix.

How to call event Analytics DialogFlow by nodejs

I'm using dialogflow v2 using npm https://github.com/googleapis/nodejs-dialogflow.
Then I have a task to call API to get the number of messages in analytics.
https://dialogflow.cloud.google.com/#/agent//analytics
use this API
https://api.dialogflow.com/api/interactions/analytics/messages?timeInterval=1.
So anyone can suggest to me how to call that API in dialogflow npm. I can not get
x-goog-access-token
x-goog-id-token
See https://developers.google.com/identity/protocols/oauth2 for more about generating the auth token for a REST request using a service account. But that isn't the problem.
The real issue is that you're trying to access an internal API, and your project likely isn't permitted to this API.
The library itself doesn't have access to that portion of the API as well, so even if you were permitted (and, I should emphasize, you're probably not), you would need to make the REST calls directly without a library.

Peek and Complete Message using different Receiver Instances - Azure Service Bus

Scenario
When business transactions are performed, we're supposed to make that data available to end clients.
Current Design
Our web app publishes transaction messages are added to a topic on the Azure Service Bus.
We expose APIs to clients through which they can consume the data from those transactions.
Upon calling these APIs, we read the messages from the Subscription and return it to the client.
Problem
We want a guaranteed delivery - we want to make sure the client acknowledges the delivery of the data. So we don't want to remove the message from the subscription immediately. We want to keep it until the client acknowledges it.
So we only want to do a "Peek" instead of "Receive".
So the client calls the first API, to get the data, where we do a Peek.
And once the client has received the packets, the client would call a second API, to acknowledge.
At this point, we want to remove the message from the Subscription, making it Complete.
The current design of the Service Bus Message Receiver is that, a Complete can be performed only using the same Receiver instance that performed the Peek, as per the documentation, and we also observed the same when we tried it out.
Both the APIs, are two separate APIs and we cannot do the Peek and Complete using the same instance of the Receiver.
Thinking about options to somehow make the Receiver as a Singleton, across APIs within that App Service.
However this will be a problem when the App Service scales out.
Is there a different way to achieve what we're trying to do here ?
There is an option available in Azure Service Bus to defer messages. Once a message is deferred, it can be received with the help of it's sequence number.
The first client should receive the message and instead of completing it, it should defer it and return it.
The second client (which has sequence number) can receive the message from the Subscription. Refer here for more details.
Another option would be to not use a Service Bus Client on your backend and instead your clients could directly work with Service Bus using its Service REST API (assuming they can't use the AMQP client if I am understanding your scenario correctly).
There are APIs to
Peek-Lock
Renew Lock
Unlock
Delete (Complete)
You could also proxy these requests if you'd like using your backend itself or a service like APIM if you are already using it.
PS: Cross posting the answer for the same query on the MSDN forum

Send IoT Message to Azure Event Hub by URL

I am now using a Beacon Reveiver to get the iBeacon Information.
Here is the problem:
the receiver platform server only allow me to type a url.
How should I do to send the information to azure eventhub??
I found this API:
https://NAMESPACE.servicebus.windows.net/EVENTHUB-NAME/publishers/PUBLISHER-NAME/messages
I tried it ,but it seems doesn't work.
Do i miss anything?? or Can anyone teach me how to add the authentication in url? What should I do now?
Thanks
You must set an authentication HTTP header in order to send events to Event Hubs. You can't include authentication information in the request URL.
Even though you can't send messages directly to Event Hubs, you can develop a custom Web API that uses your own URL-based authentication mechanism and forwards the requests to Event Hubs (or another service). That defeats the purpose of using Event Hubs to some degree but gives you more flexibility.

Resources