Retrieve Grafana dashboard query using the API - grafana

I would like to get the query used in each of my dashboards using the Grafana API.
The expr field in the JSON model menu of the UI seems to contain the query. Is there a way of querying this using the API?

You can't do that. There is no official API which will return all "dashboard queries". It isn't possible, because frontend in the browser generate that and exact query depends on the user input (e.g. time range, dashboard variables, used macros, ....) and also used datasource.

Related

how to copy a dashboard in a different azure devops instance?

I have a requirement to copy an existing dashboard dashboard in an org(source org) to a different org(target org) under a different ado instance by any means possible. Dashboard can have widgets and widgets can be linked to
pipeline
Query - A query can be referencing to a user, team, project, custom values of a standard field, custom fields
some other things that i have not encountered so far
So far my steps are as follows
get dashboard details using get dashboard rest api
identify widgets in dashboard details api response
get any pipeline if there is no pipeline create a dummy one and use its details for a widget that is using pipeline
identify distinct queries present in all widgets
create its equivalent query in target org and save its id
replace queryid in widget settings to its equivalent created queryid in targetorg
create dashboard in target org
I am facing issue in step 5
There are lot of moving variables in a query. Query might be referencing to things that does not exist in target org like a particular user, team, custom values of a standard field, custom fields. In order to create a query successfully i need to know possible values of a field in target org. While creating a new query from ui it shows possible values for a field in dropdown so i am wondering is there any rest api that gives possible values of a field and if no such field exist in target org then it should throw error.
Looking forward to suggestions for a simpler or alternative approach to replicate a dashboard across different ado instance and/or better approach for step 5
If you are looking for a rest api the query the fields in your target process of the organization, you could refer to this doc. Field-list.
GET https://dev.azure.com/{organization}/_apis/work/processes/{processId}/workItemTypes/{witRefName}/fields?api-version=6.0-preview.2
After that, you could create the fields in your target process, you could refer to this rest api. Fields-Create
POST https://dev.azure.com/{organization}/_apis/work/processdefinitions/{processId}/fields?api-version=4.1-preview.1
Or could you share more details of your requirement, like screenshots and widget definition or dashboards configuration for update.

Multi-tenant Algolia index

I would like to offer full-text search to my users through their data - and make sure that they can only access the data they own. Are there any patterns allowing to do that on Algolia ? None of the solutions I've considered seem a good fit, so i was wondering if I had overlooked some other options.
We could host each user's data in a separate Algolia app, so that each API key would give access to only the relevant data, but that would quickly become unaffordable, as many would hit the 10000 records limit.
We could host each user's data in a separate index and use team index restrictions, but there does not seem to be an API to manage those, and that would anyway require an Algolia account for each customer, which seems like a misuse of the service (we could e.g. generate email addresses at our domain name).
Finally we could filter queries with some userId to retrieve only the relevant data, but that wouldn't be secure, as someone could use the apikey to query algolia without the filter.
We could proxy algolia calls to inject the filter and the api key - but the perf penalty would probably be high.
Any other suggestions ? Thanks!
I got a great answer from rayrutjes at Algolia, so I'm pasting it here in case :
The best approach for your use case is to use what we call generated API keys. Here is the documentation for the JavaScript client: https://www.algolia.com/doc/api-client/javascript/api-keys/#generate-key
The usage is fairly simple, you generate an API key on the fly based on your search API key + some additional query params.
The resulting API key can be used like a standard search API key, with the difference that it can be scoped on a given set of parameters.
Note that the generation of such a scoped API key does not require an actual call to the API.
Also be sure to generate those scoped API keys in the backend as in that case you don't want to expose the search API key you use for their generation.

Link with context from Grafana to Kibana (retain time frame and lucene query)

I have Grafana setup with an Elasticsearch datasource and I am graphing 404 http status codes from my webserver.
I want to implement a drill down link to the Kibana associated with my Elasticsearch instance. The required URL is of this form:
https://my.elasticsearch.com/_plugin/kibana/#/discover?_g=(refreshInterval:(display:Off,section:0,value:0),time:(from:now-12h,mode:quick,to:now))&_a=(columns:!(_source),filters:!(),index:'cwl-*',interval:auto,query:(query_string:(analyze_wildcard:!t,query:'status:404')),sort:!('#timestamp',desc))
For the from: and to: fields, I want to use the current "from" and "to" values that Grafana is using. And for the query: field, I want to use the value from the "Lucene query" of the associated metric.
Does Grafana expose some context object from which I can pull these values, and thus generate the necessary URL?
Or is there some other way?
It's now possible, starting Grafana 7.1.2:
complete working example:
https://kibana/app/kibana#/discover/my-search?_g=(time:(from:'${__from:date}',to:'${__to:date}'))&_a=(query:(language:lucene,query:'host:${host:lucene}'))
https://github.com/grafana/grafana/issues/25396

Grafana - Graph with metrics on demand

I am using Grafana for my application, where I have metrics being exposed from my data source on demand, and I want to monitor such on-demand metrics in Grafana in a user-friendly graph. For example, until an exception has been hit by my application, the data source does NOT expose the metric named 'Exception'. However, I want to create a graph before hand where I should be able to specify the metric 'Exception' and it should log it in the graph whenever my data source exposes the 'Exception' metric.
When I try to create a graph on Grafana using the web GUI, I'm unable to see these 'on-demand metrics' since they've not yet been exposed by my data source. However, I should be able to configure the graph such that in case these metrics are exposed then show them. If I go ahead and type out the non-exposed metric name in the metrics field, I get an error "Timeseries data request error".
Does Grafana provide a method to do this? If so, what am I missing?
It depends on what data source you are using (Graphite, InfluxDB, OpenTSDB?).
For graphite you can enter raw query mode (pen button). To specify what ever query you want, it does not need to exist. Same is true InfluxDB, you find the raw query mode in the hamburger menu drop down to the right of eacy query.
You can also use wildcards in a graphite query (or regex in InfluxDB) to create generic graphs that will add series to the graph as they come in.

how can I use active Record queries with salesforce as the data-store?

I am connecting to Salesforce.com as a data-store and accessing their REST API's.
Currently, to do a query, have to use SOQL, which is a query language.
How can I use ActiveRecord type 'where' queries instead?
You don't have to use SOQL to retrieve records via the Salesforce.com REST API, if you are retrieving by the Id of the record. To do this, you can just use the following syntax:
/vXX.X/sobjects/SObjectName/id/
To retrieve records that meet a specific clause other than ID, I don't believe there is an alternative to SOQL at this point directly in the REST API.
However, if you are using Ruby, there is a Ruby Toolkit for salesforce that does support using active record style syntax. This is an open source project and you can find out more about it here:
http://quintonwall.com/wp-content/uploads/2011/02/RubyToolkit-gettingstarted.pdf
Here are a couple of examples from the above document:
There are toolkits for other languages, but I am not sure of their support for Active Record style record access.