How to make Simple-JSON variable template query in grafana? - json

I am trying to create a dynamic variable for a graph using a kdb+ database, which requires the Simple-JSON plug in. However, I am struggling to figure out how to write the query in the Query search bar under Variables on my Dashboard.
I have looked into the documentation found here but there is only a few mentions of the templating feature for variables in grafana, but nothing on how to do it.
https://github.com/grafana/simple-json-datasource/blob/master/README.md

You can write arbitrary text in the timeserie query, it doesn't need to be one of the hardcoded metrics that /search returns.
There is also the simpod json datasource plugin.
https://grafana.com/grafana/plugins/simpod-json-datasource
built on top of the Simple JSON Datasource. It has refactored code, additional features and active development.
One of the "additional features" is an "Additional JSON Data" tab where you can use variables. {"key": $variableValue}

It actually turns out that the adaptor for kdb+/grafana needs it's search function overloaded to be able to accept variables and return a string (or something that grafana can understand).

Related

PoI filter Data WireCloud

I'm using WireCloud, I'm trying to connect the output of a Map Viewer (PoI selected) to the input of a WebBrowser Widget (filter the PoI and get the URL of the image field). I saw some examples on the web doing it, but I'm not able to find the operator. Does anybody knows where can I get it?
Thanks a lot
We had custom operators for that tasks, and I've been cleaning and updating code to publish it as a new operator.
Such operator is called Value Filter, and you can find it on: https://github.com/Wirecloud/value-filter-operator
It does require a preference in dot-sepparated syntax as the path to the data you want to filter. It does receive a JSON object, extracts the path-addressed data and outputs it, so it can be instantiated in-line. In case original data is a POI, the path should be something like poi.data.something.
Best regards

Groovy to generate dynamic parameters based on JSON of job values?

I just found that Jenkins jobs via a JSON URL each job has using this format: https://jenkinsurl.net/job/_test/lastBuild/api/json provides info like below.
{"_class":"hudson.model.FreeStyleBuild","actions":[{"_class":"hudson.model.ParametersAction","parameters":[{"_class":"hudson.model.StringParameterValue","name":"build_num","value":""}]},{"_class":"hudson.model.CauseAction","causes":[{"_class":"hudson.model.Cause$UserIdCause","shortDescription":"Started by user anonymous","userId":"anonymous","userName":"anonymous"}]},{},{},{},{},{},{"_class":"org.jenkinsci.plugins.buildenvironment.actions.BuildEnvironmentBuildAction"},{}],"artifacts":[],"building":false,"description":null,"displayName":"#1","duration":1850,"estimatedDuration":1850,"executor":null,"fullDisplayName":"_test #1","id":"1","keepLog":false,"number":1,"queueId":5753,"result":"SUCCESS","timestamp":1479700053274,"url":"http://jenkinsserver.net/job/_test/1/","builtOn":"node_name","changeSet":{"_class":"hudson.scm.EmptyChangeLogSet","items":[],"kind":null},"culprits":[]}
I'd like to know how I can query those fields with a Groovy script to help me build Dynamic parameters when selecting "Build with Parameters". I already have the Groovy and Dynamic parameter plugins and use them for some simple queries I've been using to generate some parameters, like timestamps not overwritten by Jenkins jobs downstream.
How do I query for these and return their values? For example, if I wanted to return the value of the user that started the build from this segment:
[{"_class":"hudson.model.Cause$UserIdCause","shortDescription":"Started by user anonymous","userId":"anonymous","userName":"anonymous"}]
This isn't a question about getting the person that triggered the build. Sorry if that's not such a great example, but this one appears to be a bit nested, so presumably a good one to learn with.
I know how to reference the value of parameters and get some info to return to generate them, but not how to use that URL and extract specific info from it to help create a parameter's value before the build begins. Is this possible? If not, what other mechanism could I use?
You can do something similar to this one:
How do I discover the additional causes of my Jenkins build?
job = hudson.model.Hudson.instance.getItem("demo-job")
build = job.getLastBuild()
// get action first
def action = build.getAction(hudson.model.CauseAction.class)
cause = action.findCause(hudson.model.Cause.UserIdCause)
println cause.userId
http://javadoc.jenkins-ci.org/hudson/model/Cause.UserIdCause.html
The question is abit confusing so not sure if this helps at all. Anyway, you should be able to extract all the information you need from build returned by getLastBuild().
It not possible to extra parameters before the build begins. If that is what you mean.

PAW app: Filtering JSON in the response panel

I recently discovered a nice little feature in the PAW app, that allows me to filter json in the response panel.
Unfortunately, it seems only to be able to select base on the key names. Is there some documentation somewhere that would explain the syntax of this filter (if any).
I was hoping actually, that it would be backed by something as powerful as jq's query language.
For the KeyPath in the filter you can see the example in the screenshot, it takes the format address.geocode.latitude for example (keys separated with dots).

Returning MarkLogic EVAL REST service output as JSON

I am working on a demo using MarkLogic to store emails exported from Outlook as XML, so that they stay searchable and accessible when I move away from Outlook.
I am using an AngularJS front-end calling either the native MarkLogic REST services of own REST services written in JAVA using Jersey.
MarkLogic SEARCH REST service works very well to get back a list of references to documents based on various search criteria, but I also want to display information stored inside the found documents.
I would like to avoid multiple REST calls and to get back only the needed information, so I am trying to use the EVAL REST service to run an xQuery.
It works well to get XML back (inside a multipart/mixed message) but I don't seem to be able to get JSON instead which would be much more convenient and is very easy with most other MarkLogic REST services.
I could use "json:transform-to-json()" in my xQuery or transform the XML to JSON in my JAVA code, but that does not look very elegant to me.
Is there a more efficient method to get where I am trying to go ?
First, json:transform-to-json seems plenty elegant to me. But of course it's not always the right answer.
I see three options you haven't mentioned.
server-side transforms - REST search supports server-side transforms which transform each document when you perform a bulk read by query. Those server-side transforms could generate any json you need.
search extract-document-data - this the simplest way to extract portions of documents. But it seems best if your documents are json to match your json response. Otherwise you get xml in your json response . . . unless you're ok with that.
custom search snippets - another very powerful way to customize what search returns
All of these options don't require the privileges that eval requires, which is a very good thing. Since eval allows execution of arbitrary code on your server, it requires special privileges and should be used with great care. Two other options before you use eval are (1) custom xquery installed in an http server, and (2) REST extensions.
The answers from Sam are what I would suggest. Specifically I would set a search option for search-extract-document-data (This is a search API option. If you are posting the request, then you can add the option in the XML you post back. If you are using GET, then you need to register the option ahead of time and call it. Relevant URLs to assist:
https://docs.marklogic.com/guide/rest-dev/search#id_48838
https://docs.marklogic.com/guide/search-dev/appendixa#id_44222
As for json.. ML8 will transform content. Use the accept-header or just add format=json to your results...
Example - xml which is what my content is stored as:
http://localhost:8000/v1/search?q=watermellon
...
<search:result index="1" uri="/sample/collections/1.xml" path="fn:doc("/sample/collections/1.xml")" score="34816" confidence="0.5982239" fitness="0.6966695" href="/v1/documents?uri=%2Fsample%2Fcollections%2F1.xml" mimetype="application/xml" format="xml">
<search:snippet>
<search:match path="fn:doc("/sample/collections/1.xml")/x">
<search:highlight>watermellon</search:highlight>
</search:match>
</search:snippet>
</search:result>
...
Example - json which is what my content is stored as:
http://localhost:8000/v1/search?q=watermellon&format=json
...
"index":1,
"uri":"/sample/collections/1.xml",
"path":"fn:doc(\"/sample/collections/1.xml\")",
"score":34816,
"confidence":0.5982239,
"fitness":0.6966695,
"href":"/v1/documents?uri=%2Fsample%2Fcollections%2F1.xml",
"mimetype":"application/xml",
"format":"xml",
"matches":[
{
"path":"fn:doc(\"/sample/collections/1.xml\")/x",
"match-text":[
{
"highlight":"watermellon"
}
]
}
]
}
...
For real heavy-lifting, you can use server-side transforms as in Sam's description. One note about this. Server-side transformations are not part of the search API, but part of the REST API. Just mentioning it so you have some idea of which tool you are using in each case..

JBPM rest calls with JSON

We want to start a process in JBPM6 using the rest API. We need to pass an object as a process variable.
We know how to do it JAXB and the execute call. But we want to do it with JSON and /runtime/{deploymentId}/process/{processDefId}/start
Is it possible? we try and have no success.
I am not sure whether my answer exactly addresses the question. But for someones use in future I place couple of lines here.
If you want to set a process variable when starting a process using the RESTful API, you can do it like this.
If your variable name is myVar just add the value as a URL parameter by appending the phrase "map_" to the parameter name. It means the parameter name should now be map_myVar. For an example see below request.
http://<host>:<port>/jbpm-console/rest/runtime/{deploymentId}/process/{processDefId}/start?map_myVar=myValue
You can confirm whether the value is set by writing below code in a script task.
Object var = kcontext.getVariable("myVar");
System.out.println("myVar : " + var);
See the 17.1.1.3. Map query parameters section of JBPM6 documentation.
After talking to the dev that is responsible for the REST API. I was able to confirm how it works.
The
/runtime/{deploymentId}/process/{processDefId}/start
Is a POST request where all the contents in the payload are ignored. The variables are written as key=value in the GET string.
With deployment id: com.web:work:1.0
With processDefId: work.worload
2 variables: var1 and var2
For example:
/runtime/com.web:work:1.0/process/work.worload/start?var1=a&var2=b
I'm still after trying to understand how to define objects with the remote API.
Meanwhile, I also confirmed that it is impossible to define objects using this way. The only way to define objects is only by using the JaxB. This uses the "/execute" path