InfluxDB templating query - referring to measuerments? - templating

I'm trying to make templates for my dahboards, and I have problems when it comes to referring to measuerment names.
My variables:
$space = SHOW MEASUREMENTS
Then I would like a variable that contains only values from a specific $space, which is actually a MEASUREMENT:
$app = SHOW TAG VALUES WITH KEY = "Application" WHERE MEASUREMENT =~ /^$space$/
Here I get a message: Template variables could not be initialized: error parsing query: found MEASUREMENT, expected identifier, string, number, bool at line 1, char 48
In the official example it is like this, though it refers to another tag:
$datacenter = SHOW TAG VALUES WITH KEY = "datacenter"
$host = SHOW TAG VALUES WITH KEY = "hostname" WHERE "datacenter" =~ /^$datacenter$/
I cannot find any info how to refer to MEASUREMENTS which would work. WHERE, WITH, etc.. Maybe is it not possible at all?
I found only this in the official tutorial, but this is for keys, not values.
SHOW TAG KEYS [FROM <measurement_name>]

I actually figured it out:
SHOW TAG VALUES FROM /^$space$/ WITH KEY = "Application"

Related

Custom wireshark disector shows value but fieldname is not visible using lua

I am testing some network packets of my Organisation's product. We already have custom plugins. I am trying to add some some more fields into those existing plugins (like conversion of 2 byte code to a string and assign it to a field)
Thankyou in advance for reading my query.
--edit
Wireshark version : 2.4.5 (organization's plugins dont work on latest wireshark application)
--edit
Problem statement:
I am able to add field and show value, but fieldname is not displayed as defined.
I cannot share the entire .lua file but i will try to explain What i did:
Below is the image where I have a field aprint.type. this is a two byte field. In .lua file, for display purpose it is appended with corresponding description using a custom function int_to_enum.
I want to add one more proto field aprint.typetext which will show the text.
What I did:
Added a protofield f_apr_msg_type_txt = ProtoField.string("aprint.typetxt","aprint_type_text") (Tried f_apr_msg_type_txt = ProtoField.string("aprint.typetxt","aprint_type_text",FT_STRING) also)
Below the code where subtree aprint.type is shown, added my required field as subtree:add(f_apr_msg_type_txt, msg_type_string) (Below is image of code extract)
I am able to see the text but field Name is shown as Wireshark Lua text (_ws.lua.text)
Normally displaying strings based on numeric values is accomplished by a value string lookup, so you'd have something like so:
local aprint_type_vals = {
[1] = "Foo",
[2] = "Bar",
[9] = "State alarm"
}
f_apr_msg_type = ProtoField.uint16("aprint.type", "Type", base.DEC, aprint_type_vals)
f_apr_msg_type_txt = ProtoField.string("aprint.typetxt","aprint_type_text", base.ASCII)
... then
local msg_type = tvb(offset, 2):le_uint()
subtree:add_le(f_apr_msg_type, tvb(offset, 2))
subtree:add(f_apr_msg_type_txt, tvb(offset, 2), (aprint_type_vals[msg_type] or "Unknown"))
--[[
Alternatively:
subtree:add(f_apr_msg_type_txt, tvb(offset, 2)):set_text("aprint_type_text: " .. (aprint_type_vals[msg_type] or "Unknown"))
--]]
I'm also not sure why you need the extra field with only the text when the text is already displayed with the existing field, but that's basically how you'd do it.

dynamic template variables values based on other template variables in influxdb - chronograf

I have two template variables and I want that after selecting first template variable from dropdown, second template variable should be dynamic based on first variable value.
let me clear this scenario with an example:
assume I have this data:
data=> System=10
tags=> appName="a", appVersion="1.1"
data=> System=12
tags=> appName="b", appVersion="2.1"
I have defined two template variables :appName: and :appVersion:
and Im getting their values using this meta query
SHOW TAG VALUES ON "db_name" FROM "measurement_name" WITH KEY = appName
SHOW TAG VALUES ON "db_name" FROM "measurement_name" WITH KEY = appVersion
now whenever I select :appName: = 'a', I want that :appVersion: should show only "1.1" value in dropdown. But :appVersion: shows both values "1.1" and "2.1". We know "2.1" value is useless when we have selected appName=a.
I thought I can use this for defining :appVersion:
SHOW TAG VALUES ON "db_name" FROM "measurement_name" WITH KEY = appVersion WHERE appName = :appName:
but this is not working
Please help me to achieve this kind of dynamic/codependent variables in chronograf
solved this with this:
show tag values on "db_name" from "measurement_name" with key = "appVersion" where appName = ':app_name:'
I had to use single quote after where clause. Seems I cant use " here

After converting field to tag, no query result

I am using Telegraf with Telemetry, I want to see traffic level on interface based on their description, "/interfaces/interface/subinterfaces/subinterface/state/description". Unfortunately the interface description was as field key, which I converted using the processors.converter. Since I needed to rewrite the data after this, I just dropped the whole measurement so the new tag can take place.
I do see the descriptions as tag fields and I do see the interface description as a tag key.
Unfortunately I am still getting blank results on any query when I try with querying by interface description.
### Relevant telegraf.conf:
# Convert values to another metric value type
[[processors.converter]]
# Fields to convert
[processors.converter.fields]
tag = ["/interfaces/interface/subinterfaces/subinterface/state/description"]
System info:
Telegraf 1.14.5
Debian
Steps to reproduce:
> select "/interfaces/interface/subinterfaces/subinterface/state/description" from "/interfaces/"
(empty result) this is expected since now its a tag
> show tag keys
name: /interfaces/
tagKey
------
/interfaces/interface/subinterfaces/subinterface/state/description
we can see here that now it's as a tag key
> show tag values with key = "/interfaces/interface/subinterfaces/subinterface/state/description"
(gives all descriptions)
> SELECT "/interfaces/interface/subinterfaces/subinterface/state/counters/out-pkts" from /interfaces/ where "/interfaces/interface/subinterfaces/subinterface/state/description" = 'some_description'
(empty result) Where I would like to have some result based on the interface description
Expected behavior:
SELECT "/interfaces/interface/subinterfaces/subinterface/state/counters/out-pkts" from /interfaces/ where "/interfaces/interface/subinterfaces/subinterface/state/description" = 'some_description'
to give some a result for the interface with that description
Actual behavior:
SELECT "/interfaces/interface/subinterfaces/subinterface/state/counters/out-pkts" from /interfaces/ where "/interfaces/interface/subinterfaces/subinterface/state/description" = 'some_description'
(is not returning any result)
Additional information
I am also using Chronograph which gives no results too.
You cannot just select just a tag from a measurement. For influx to return results it needs atleast one field in the select clause.

Correct way to update map data type with cqerl

I am having hard time coming with the syntax of updating map using cqerl. I have tried the following till now and it doesn't work
statement = "UPDATE keyspace SET data[?] = :data_value WHERE scope = ?;",
values = [{data,"Key Value"},{data_value, "Data Value",{scope, "Scope Value"}]
What am I doing wrong here?
Also setting ttl does not work
statement = "INSERT INTO data(scope)
VALUES(?) USING ttl ?",
values = [{scope, "Scope Value"},{[ttl], 3650}]
Anyone, any idea?
Please note that you are using single quotes around the values, which in Erlang syntax indicates you are using atoms. Based on the documentation cqerl, it doesn't expect atoms there. cqerl data types
For example try:
statement = "INSERT INTO data(scope)
VALUES(?) USING ttl ?",
values = [{scope, "Scope Value"},{[ttl], 3650}]
Based on reply from the contributor on github, it takes an atom, so '[ttl]' is the right way
https://github.com/matehat/cqerl/issues/122
For updating a map correct way is with atom in the values part
statement = "UPDATE keyspace SET data[?] = ? WHERE scope = ?;",
values = [{'key(data)',"Key Value"},{'value(data)', "Data Value",{scope, "Scope Value"}]

Cleaning scraped <a href> rails

I have scraped data from a website and entered it into an array using the code below:
def process_course_details(course_details)
details_array =[]
details_link = true
entry_link = true
details_info = {}
# Sets all data in hash
details_info[:url] = clean_link(course_details.search('div.coursedetails_programmeurl a'))
details_array.push(details_info)
print_details_info(details_info)
entry_link = course_details.search('ul.details_tabs').first
end
The code above stores the element being pulled as such:
View course details on provider's website
But I'd like to clean the above to the below:
http://www.abdn.ac.uk/study/courses/undergraduate/C8R1/
or failing that remove the apostrophe and have this:
View course details on providers website`
You can extract the href with Nokogiri like this:
html = Nokogiri::HTML('View course details on provider\'s website')
html.xpath("//a/#href").to_s # => "http://www.abdn.ac.uk/study/courses/undergraduate/C8R1/"
Based on your comment:
When storing other data I've scraped into the database the apostrophe
provided errors and stopped it. Once I had cleaned the apostrophe and
it no longer was part of the array the code worked and the table was
created.
db = SQLite3::Database.open('ahhh.sqlite3')
db.execute "INSERT INTO aahah (uname, cname, duration, qualification, url, entry) VALUES ('#{#uni_name}', #{#course_name}', '#{#course_duration}', '#{#course_qual}', '#{#details_entry}', '#{#requirements}')"
You are inserting the values via string interpolation:
db.execute("INSERT INTO table_name (foo, bar) VALUES ('#{#foo}', '#{#bar}')")
Apparently, if the interpolated strings contain an apostrophe, your SQL string likely becomes invalid. Even worse, this code is prone to SQL injection.
Instead you should use parameter markers and let the SQLite gem handle the escaping:
db.execute("INSERT INTO table_name (foo, bar) VALUES (?, ?)", [#foo, #bar])
This allows you to safely insert apostrophe and other special characters.

Resources