All metrics are not show in influxdb from Telegraf - influxdb

I have followed multiple documentation but I couldn't receive all the metrics from my JSON file to Influxdb.
My Input json file
{
"apBuildNumber": "04.04.01.0003.1f7fd3ce8896",
"version": "1.0.0",
"sentTimeMs": "1661678671000",
"sciSystemId": "scis1",
"apMac": "54:ec:2f:18:78:4d",
"apSerial": "281915001731",
"apVenue": "test",
"apName": "281915001731",
"apTenantId": "tenant",
"apReport": {},
"apNonCumulativeReport": {},
"apCumulativeReport": {
"cumulativeReportBins": [
{
"binStartTime": 123131232,
"binSampleDurationSec": "10",
"apCumulativeBinNetworksViews": [
{
"pci": [
123,
333
]
}
]
},
{
"binStartTime": 567567577,
"binSampleDurationSec": "10",
"apCumulativeBinNetworksViews": [
{
"pci": [
252,
124
]
}
]
}
]
},
"apAlarmsReport": {}
}
what I have tried :
My telegraf.conf is like this
data_format = "json_v2"
[[inputs.file.json_v2]]
[[inputs.file.json_v2.object]]
path = "apCumulativeReport"
disable_prepend_keys = true
tags = ["cumulativeReportBins_binStartTime"]
[[inputs.file.json_v2.object.field]]
path = "cumulativeReportBins_apCumulativeBinNetworksViews_pci"
type = "int"
Ideally I have to receive all the PCI values from the array but I can see only second element in each PCI array in InfluxDB.
Can someone identify what mistake I'm doing here.

Related

Using data from the first response in the body of the second

I'm trying to combine requests from two services in one endpoint.
The first returns the list of users, like this:
{
"data": [
{ "id": 1, "name": "first", "photo": "employee_photos/key1.png" },
{ "id": 2, "name": "second", "photo": null },
{ "id": 3, "name": "third", "photo": "employee_photos/key3.png" }
]
}
The second is supposed to receive the POST request with the JSON listing photo keys to get the required version URLs.
Request:
{
"keys": [ "employee_photos/key1.png", "employee_photos/key3.png" ],
"versions": [ "small", "large" ]
}
I created a small Lua script to process the response of the first request and collect the list of keys. It looks like this:
function post_employees(request, employeesResponse)
local resp = employeesResponse.load()
local data = resp:data():get("data")
local photo_keys = {}
for i = 0, data:len() - 1, 1 do
local rec = data:get(i)
local id = rec:get("id")
local photo = rec:get("photo")
if photo then
table.insert(photo_keys, photo)
end
end
resp:data():set("photos", table.concat(photo_keys, ","))
end
But then... I can't find a way to use this list of keys in the second request. Is it even possible?

Using Json Slurper + Groovy + Azure answer

So I am trying to write a Jenkins job using groovy to fetch me some data
The data inside the variable answer after the 3rd line would be some like
[
{
"endIpAddress": "11.21.115.9",
"id": "blabla1",
"name": "blabla",
"resourceGroup": "stg",
"startIpAddress": "11.12.115.9",
"type": "blablafirewallRules"
},
{
"endIpAddress": "1.2.15.9",
"id": "blabla2",
"name": "function1-blabla",
"resourceGroup": "stg",
"startIpAddress": "1.2.15.9",
"type": "blablafirewallRules"
},
{
"endIpAddress": "7.7.7.7",
"id": "blabla2",
"name": "function2-blabla",
"resourceGroup": "stg",
"startIpAddress": "7.7.7.7",
"type": "blablafirewallRules"
},
.
.
.
.
]
What id like to do is to build a list or a 2-dimentions-array that would parse this json and the it will hold all the startipaddress of all the items where name contains "function", so based on this JSON, the data should be
desiredData[0] = [function1-blabla, 1.2.15.9]
desiredData[1] = [function2-blabla, 7.7.7.7]
Up until now I wasn't using JsonSlurper and I was manipulating the text and building the array which is pretty stupid thing to do since this is kind of what JSON is all about I guess.
import groovy.json.JsonSlurper
command = "az mysql server firewall-rule list --resource-group ${rgNameSrvr} --server-name ${BLA} --output json"
answer = azure.executeAzureCliCommand(command, "BLA")
def jsonSlurper = new JsonSlurper()
def json = new JsonSlurper().parseText(answer)
def data = json.findAll{ it.name =~ /^function/ }.collectEntries{ [it.name, it.startIpAddress] }
Code above returns map where key=name and value=ip
If you want 2dim array:
def data = json.findAll{ it.name =~ /^function/ }.collect{ [it.name, it.startIpAddress] }

Complex Dictionary blocked Xcode compile operation in swift

xCode 7.1 + swift2.1 + iOS 9.0
Code below block the Xcode compile operation.
let dic_1:Dictionary<String,Int> = ["key":200]
print("dic_1---->\(dic_1)")
Has this happened to anyone ?How does this happen?
Thanks for correcting grammer.
I found that it's not the reason the code above.
My origin code is below:
let dic_1 = [
"status": 200,
"info": "1234",
"data":[
"st_id":"st_id",
"st_name":"radiant",
"address":"dire",
"longitude":"122.111",
"latitude":"123.000000",
"is_favorite":"0",
"score":"5",
"thumbnail":"www.baidu.com",
"comment_count":"45612",
"cert_img_url":"www.baidu.com",
"has_inspay":"1",
"has_car_discount":"1",
"has_groupon":"1",
"score_environment":"4.5",
"score_service":"5.0",
"score_oil":"5.0",
"type":"98",
"city":"SHENZHEN",
"show_price_discount":"1",
"is_support_invoice":"1",
"price":[
[
"oil_name":"95#",
"market_price":"6.23",
"sell_price":"6.00",
"wecar_price":"-100.00"
],
[
"oil_name":"95#",
"market_price":"6.23",
"sell_price":"6.00",
"wecar_price":"-100.00"
],
[
"oil_name":"95#",
"market_price":"6.23",
"sell_price":"6.00",
"wecar_price":"-100.00"
],
],
"promotions": [
"promotion1",
"promotion1",
"promotion1",
"promotion1"
],
"gpns":[
[
"gpn_id":"75642",
"gpn_name":"gpn_name",
"oil_type":"95",
"price":"180",
"sell_amount":"20000000",
"old_price":"200"
]
],
"discount_items":[
[
"desc":"It's a descrition.",
"disc_type":"1"
]
]
]
]
print("dic_1---->\(dic_1)")
Playground is running running,never figure out anything.So does this happen in iOS project.No error,just running.
You've got a complex nested structure for the data key so Swift's type inference system failed. In my Xcode 7.1.1, it gives a "Type is ambiguous without more context" error.
Give the compiler a hint as to the data type:
let data: [String: Any] = [
"st_id":"st_id",
"st_name":"radiant",
"address":"dire",
"longitude":"122.111",
"latitude":"123.000000",
"is_favorite":"0",
"score":"5",
"thumbnail":"www.baidu.com",
"comment_count":"45612",
"cert_img_url":"www.baidu.com",
"has_inspay":"1",
"has_car_discount":"1",
"has_groupon":"1",
"score_environment":"4.5",
"score_service":"5.0",
"score_oil":"5.0",
"type":"98",
"city":"SHENZHEN",
"show_price_discount":"1",
"is_support_invoice":"1",
"price":[
[
"oil_name":"95#",
"market_price":"6.23",
"sell_price":"6.00",
"wecar_price":"-100.00"
],
[
"oil_name":"95#",
"market_price":"6.23",
"sell_price":"6.00",
"wecar_price":"-100.00"
],
[
"oil_name":"95#",
"market_price":"6.23",
"sell_price":"6.00",
"wecar_price":"-100.00"
],
],
"promotions": [
"promotion1",
"promotion1",
"promotion1",
"promotion1"
],
"gpns":[
[
"gpn_id":"75642",
"gpn_name":"gpn_name",
"oil_type":"95",
"price":"180",
"sell_amount":"20000000",
"old_price":"200"
]
],
"discount_items":[
[
"desc":"It's a descrition.",
"disc_type":"1"
]
]
]
let dic_1: [String: Any] = [
"status": 200,
"info": "1234",
"data": data
]

Search a JSON Response using Ruby

I'm using a Ruby script to interface with an application API and the results being returned are in a JSON format. For example:
{
"incidents": [
{
"number": 1,
"status": "open",
"key": "abc123"
}
{
"number": 2,
"status": "open",
"key": "xyz098"
}
{
"number": 3,
"status": "closed",
"key": "lmn456"
}
]
}
I'm looking to search each block for a particular "key" value (yzx098 in this example) and return the associated "number" value.
Now, I'm very new to Ruby and I'm not sure if there's already a function to help accomplish this. However, a couple days of scouring the Googles and Ruby resource books hasn't yielded anything that works.
Any suggestions?
First of all, the JSON should be as below: (note the commas)
{
"incidents": [
{
"number": 1,
"status": "open",
"key": "abc123"
},
{
"number": 2,
"status": "open",
"key": "xyz098"
},
{
"number": 3,
"status": "closed",
"key": "lmn456"
}
]
}
Strore the above json in a variable
s = '{"incidents": [{"number": 1,"status": "open","key": "abc123"},{"number": 2,"status": "open","key": "xyz098"},{"number": 3,"status": "closed","key": "lmn456"}]}'
Parse the JSON
h = JSON.parse(s)
Find the required number using map
h["incidents"].map {|h1| h1['number'] if h1['key']=='xyz098'}.compact.first
Or you could also use find as below
h["incidents"].find {|h1| h1['key']=='xyz098'}['number']
Or you could also use select as below
h["incidents"].select {|h1| h1['key']=='xyz098'}.first['number']
Do as below
# to get numbers from `'key'`.
json_hash["incidents"].map { |h| h['key'][/\d+/].to_i }
json_hash["incidents"] - will give you the value of the key "incidents", which is nothing but an array of hash.
map to iterate thorough each hash and collect the value of 'key'. Then applying Hash#[] to each inner hash of the array, to get the value of "key". Then calling str[regexp], to get only the number strings like '098' from "xyz098", finally applying to_i to get the actual integer from it.
If the given hash actually a json string, then first parse it using JSON::parse to convert it to a hash.Then do iterate as I said above.
require 'json'
json_hash = JSON.parse(json_string)
# to get values from the key `"number"`.
json_hash["incidents"].map { |h| h['number'] } # => [1, 2, 3]
# to search and get all the numbers for a particular key match and take the first
json_hash["incidents"].select { |h| h['key'] == 'abc123' }.first['number'] # => 1
# or to search and get only the first number for a particular key match
json_hash["incidents"].find { |h| h['key'] == 'abc123' }['number'] # => 1

Rails Mongoid select where key/value pair in array

so I have a collection Groups that looks like this
[
{
\"_id\": \"51bdff3968c7c4dd30000003\",
\"members\": [
{
\"id\": \"51bdedef68c7c4bc7c000001\",
\"role\": \"admin\"
},
{
\"id\": \"51be0d4568c7c473ef000007\",
\"role\": \"user\"
}
],
\"name\": \"tetsing2\"
},
{
\"_id\": \"51bdf97868c7c46604000002\",
\"members\": [
{
\"id\": \"51be12ae68c7c4dcce000001\",
\"role\": \"user\"
},
{
\"id\": \"51be12db68c7c45e08000002\",
\"role\": \"user\"
}
],
\"name\": \"ds\"
}
]"
I just what to get the object that in the members array has an id equal to 51be12db68c7c45e08000002
I can do it in the console mongo client with this command
db.groups.find({ "members.id": ObjectId("51be12db68c7c45e08000002") })
and it gives back just the one appropriate object named 'ds'
However with Mongoid in rails, when I try similar command like this:
#groups = Group.where(' { "members.id": "'+current_user.id+'"}')
I get back both objects.
I've looked through the docs, but does anyone know to how achieve this through Mongoid or can I run a console command through Monogoid or moped or something?
Thank you
Group.where( :"members.id" => current_user.id )

Resources