Grafana import API will not return a proper dashboard ID (in response)after importing a new dashboard using API - grafana-api

While importing the dashboard, API is not returning proper dashboard ID.
For all the dashboard ID it provides id as 0
If I check the dashboard using Chrome Devtools > Network tab, I'm able to get some id (in increment order).
What Grafana version are you using?
5.2.0-beta3 (previously using 5.1.4)
What datasource are you using?
InfluxDB
What OS are you running grafana on?
Windows 10 Pro
What did you do?
Imported the dashboard using Grafana API
What was the expected result?
Should be able to import the dashboard and as response it should return a dashboard ID
What happened instead?
Able to import the dashboard but not getting proper dashboard ID. For all dashboard it gives ID=0
import requests
url='http://admin:admin#localhost:3000/api/dashboards/import'
data='''{
"dashboard": {}
"folderId": 8,
"overwrite": false
}'''
headers={"Content-Type": 'application/json'}
response = requests.post(url, data=data,headers=headers)
print(response)
print(response.status_code)
print (response.text)
Response
Response [200]
200
{
"pluginId": "",
"title": "Template dfsad",
"imported": true,
"importedUri": "db/template-dfsad",
"importedUrl": "/d/uid1098/template-dfsad",
"slug": "",
"dashboardId": 0,
"folderId": 8,
"importedRevision": 1,
"revision": 1,
"description": "",
"path": "",
"removed": false
}

Related

Teams is not displaying my unfurl response

I have a Teams integration with link unfurling set up. I have the messaging endpoint pointed to a public ngrok URL and ngrok proxying a local node.js server that returns the example payload Microsoft has in it's documentation.
This is my endpoint (express.js):
app.post('/bot-test', (req, res) => {
res.send({
"composeExtension": {
"type": "result",
"attachmentLayout": "list",
"attachments": [
{
"contentType": "application/vnd.microsoft.teams.card.o365connector",
"content": {
"sections": [
{
"activityTitle": "[85069]: Create a cool app",
"activityImage": "https://placekitten.com/200/200"
},
{
"title": "Details",
"facts": [
{
"name": "Assigned to:",
"value": "[Larry Brown](mailto:larryb#example.com)"
},
{
"name": "State:",
"value": "Active"
}
]
}
]
}
}
]
}
});
});
When I post a URL in a message in Teams, I see it POST to that endpoint and it responds without errors, but nothing shows up in Teams. What's going wrong? I can't find any logs on Microsoft's side either. I would expect that Teams renders a card with the response payload.
Office 365 Connector cards are not supported for link unfurls ("Message extension previews" in MS parlance). Changing the response to a supported card type worked. Unfortunately, MS doesn't surface this problem anywhere and it just silently discards the response. I was able to find a somewhat useful error description by inspecting the network request that went out from the Teams web client, however.
See this for supported card types: https://learn.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/cards-reference

Slack Dialog for search on external data source

I have couple of question on slack dialog. I developed a form to complete and submit. One field is using external data source and I am able to see the options in the drop down.
Further to enhance this, I would like to know if we can use a search functionality, like if the user types "abc", it show up on those options matching "abc".
Another question which I have is, in the same form, having multiple fields, can we configure the dialog in such a way that, based on one value the other option set has to query and change.
Please help on this part. Thank you.
Dialog json using currently:
{
"label": "ProjectName",
"type": "select",
"name": "prjname",
"data_source": "external",
"min_query_length":3
},
Concept
Search function
Every select menu with external source to designed to provide a search function. Once the user enters at least min_query_length chars its supposed to automatically start matching against your input. However, the actual matching has to be done by your app. Slack will be sending your app the characters the user entered and your app need to respond with the list of matches. If implemented correctly this will result in a search function.
Updating elements before submit
The user has to click on "Submit" before his input is registered and send to your app. It is not possible to get the intermediate state of elements or update them before the user submits.
Example code
Here is an example showing how to supply the data for a dynamic menu with external data. The example is in Python using Flask and the standard Slackclient.
This example will show a dynamic select element "City". Once the user enters text in the search field the list of cities is dynamically filtered based on the user input. e.g. "Li" will only show "London" and "Lisabon".
import os
import slack
from flask import Flask, json, request
app = Flask(__name__) #create the Flask app
#app.route('/slash', methods=['POST'])
def dialog_show():
"""shows the dialog"""
# define dialog
dialog = {
"callback_id": "ryde-46e2b0",
"title": "Request a Ride",
"submit_label": "Request",
"notify_on_cancel": True,
"state": "Limo",
"elements": [
{
"type": "text",
"label": "Pickup Location",
"name": "loc_origin"
},
{
"type": "text",
"label": "Dropoff Location",
"name": "loc_destination"
},
{
"label": "City",
"name": "city",
"type": "select",
"data_source": "external"
}
]
}
# open the dialog
client = slack.WebClient(token=os.environ['SLACK_TOKEN'])
response = client.dialog_open(
trigger_id=request.form.get('trigger_id'),
dialog=json.dumps(dialog)
)
assert response["ok"]
return ""
#app.route('/interactive', methods=['POST'])
def dialog_submit():
"""handle dialog submission"""
payload_json = request.form["payload"]
payload = json.loads(payload_json)
print(payload)
return ""
#app.route('/options_load', methods=['POST'])
def dialog_options_load():
"""provide filtered list of options based on input for dialog"""
payload_json = request.form["payload"]
payload = json.loads(payload_json)
# example list of all options
cities = {
"Berlin": 1,
"Copenhagen": 2,
"Lisabon": 3,
"London": 4,
"Madrid": 5,
"Oslo": 6,
"Paris": 7,
"Rom": 8,
"Stockholm": 9
}
# find matching options
# will match if user input string is in name
options = list()
for name, value in cities.items():
if payload["value"] in name:
options.append({
"label": name,
"value": value
})
# build response structure
response = {
"options": options
}
return json.jsonify(response)
if __name__ == '__main__':
app.run(debug=True, port=8000) #run app in debug mode on port 8000

Google Geolocation API returns IP location even if considerIp:false

I wanted to test the Google Geolocation API but I figured something strange.
I have run a basic request script on my machine and on repl.it, the results are correlated to the IP location of the machine. (even tried through VPN, same results)
It seems that Google is not taking the considerIp:false into account.
Even with a fake mac address, I got a 200 response (not a 404 as described in the end of the doc page).
Any positive experience on your side?
My script:
import requests
url='https://www.googleapis.com/geolocation/v1/geolocate?key=xxx'
response = requests.post(url, data="""{
"considerIp": "false",
"wifiAccessPoints": [
{
"macAddress": "00:25:9c:cf:1c:ac",
"signalStrength": -43,
"signalToNoiseRatio": 0
}
]
}""")
print(response.text)
try sending a JSON in order to specify the content-application type, worked for me. Also you need to have at least 2 wifi access points to avoid fallbacking to IP geolocation.
response = requests.post(url, json={
"considerIp": "false",
"wifiAccessPoints": [
{
"macAddress": "00:25:9c:cf:1c:ac",
"signalStrength": -43,
"signalToNoiseRatio": 0
},
{
"macAddress": "bb:aa:bb:aa:bb:aa",
"signalStrength": -43,
"signalToNoiseRatio": 0
}
]
})

SonarQube 6.7 LTS group permissions API doesn't working

I'm migrating SonarQube from 5.6 version to 6.7. I'm using SonarQube API with my Jenkins jobs and the problem is the API for groups permissions isn't working with 6.7 version...
I've tried manually with Postman (POST raw JSON) this :
{
"groupName": "project-name-admin",
"permission": "admin",
"projectKey": "project-name"
}
The result returned is :
{
"errors": [
{
"msg": "Group name or group id must be provided"
}
]
}
And it's the same if I use :
{
"groupId": 53,
"permission": "admin",
"projectKey": "project-name"
}
or
{
"groupId": 53,
"groupName": "project-name-admin",
"permission": "admin",
"projectKey": "project-name"
}
It's working with 6.5 verison and I've no idea where this problem may come from :(
#SonarQube developers team : can you fix thaaaat please ?
Send data as application/x-www-form-urlencoded or form-data.
SonarQube Web API doesn't handle POST body in raw JSON format. See this question about Java ServletRequest to know more (Tomcat is used under the hood).
This is a piece of code to assign a project to a gate, using authentication and post. Mind the body and content-type!
// format post, sonarqube only knows form encoded
def body = sprintf("gateId=%s&projectKey=%s", ["${gateId}", "${projectKey}"])
// post to associate project with gate
result = httpRequest (
consoleLogResponseBody: true,
authentication: '<My Jenkins Credential>',
contentType: 'APPLICATION_FORM',
httpMode: 'POST',
ignoreSslErrors: true,
requestBody: "${body}",
url: "http://<sonarqube.url>/api/qualitygates/select"
)

Google Logging API - What service name to use when writing entries from non-Google application?

I am trying to use Google Cloud Logging API to write log entries from a web application I'm developing (happens to be .net).
To do this, I must use the logging.projects.logs.entries.write request. This request dictates that I provide a serviceName argument:
{
"entries": [
{
"textPayload": "test",
"metadata":
{
"serviceName": "compute.googleapis.com"
"projectId": "...",
"region": "us-central1",
"zone": "us-central1-a",
"severity": "DEFAULT",
"timestamp": "2015-01-13T19:17:01Z",
"userId": "",
}
}]
}
Unless I specify "compute.googleapis.com" as the serviceName I get an error 400 response:
{
"error":
{
"code": 400,
"message": "Unsupported service specified",
"status": "INVALID_ARGUMENT"
}
}
For now using "compute.googleapis.com" seems to work but I'm asking - what service name should I give, given that I'm not using Google Compute Engine or Google App Engine here?
The Cloud Logging API currently only officially supports Google resources, so the best course of action is to continue to use "compute.googleapis.com" as the service and supply the labels "compute.googleapis.com/resource_type" and "compute.googleapis.com/resource_id", which are used for indexing and visible in the UI drop-downs.
We also currently permit the service name "custom.googleapis.com" with index labels "custom.googleapis.com/primary_key" and "custom.googleapis.com/secondary_key" but that is not officially supported and subject to change in a future release.

Resources