Pulling PowerBI Gateway Status in to Splunk

Have you ever been asked to monitor PowerBI gateway status? They need to receive alert when the gateway is offline. Or it’s just simply a dashboard to show the gateway status with its data such as hostname, version?

The most common approach will be writing some scripts, pulling the data to logs and ingest it into Splunk.

Why not using Splunk? Splunk can’t not run curl command by default, but if you install the Webtools Addons then it will open a new world. Below is my query to get PowerBI gateway status directly from Splunk, then i ingest that result into Splunk index.

In order to make this work you will need:

  • Webtools Addons to support curl command
  • A principal id with admin privileges to pull gateway status
|makeresults
|eval client_secret="XXXXXXXXXXXXXXXXXXXXXXXXX"
|eval tenant_login_url="https://login.microsoftonline.com/YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY/oauth2/token"
|eval client_id="ZZZZZZZZZZZZZZZZZZZZZZZZ"
| eval data="grant_type=client_credentials&client_id="+client_id+"&client_secret="+eval+"&resource=https%3A%2F%2Fanalysis.windows.net%2Fpowerbi%2Fapi"
| curl method=post urifield=tenant_login_url datafield=data
| table curl*
 | table curl_message | spath input=curl_message output=access_token path=access_token 
|  table access_token
| eval token_status=if(isnull(access_token),"Bad","Good") 

| eval auth_header="{\"Authorization\":\"Bearer "+access_token+"\"}" 
| fields - access_token
 | curl method=get uri="https://api.powerbi.com/v1.0/myorg/gateways" debug=true headerfield=auth_header 
| table token_status,curl_message,auth_header | spath input=curl_message output=gateway_list path=value{}
|  table gateway_list,* ,auth_header
| mvexpand gateway_list
| spath input=gateway_list  path=id

```Getting the gateway detail ```
| eval gateway_detail_url="https://api.powerbi.com/v1.0/myorg/gateways/"+id
| curl method=get urifield=gateway_detail_url headerfield=auth_header
| table id,token_status,curl_message,auth_header | spath input=curl_message output=gatewayAnnotation path=gatewayAnnotation
| spath input=curl_message  path=name
| spath input=curl_message  path=gatewayStatus
| spath input=gatewayAnnotation  path=gatewayVersion output=gatewayVersion
| spath input=gatewayAnnotation  path=gatewayMachine output=gatewayMachine 

| fields - gatewayAnnotation 
| eval _time=now()
| table _time,name,id,gateway* ,token_status
|  collect index=yourindex addtime=true sourcetype="your_source_type" source="powerbi_gateway_status" marker="search_or_report_name=\"PowerBI status report\""

Leave a Reply

Your email address will not be published. Required fields are marked *