mosquitto with PAHO publishing and subscribing - mqtt

I want to send a command line by MQTT from raspberry pi to my laptop. After search i found MQTT launcher 1 ,i want to send python simple_stream.py to run simple_stream script in windows ,but i don't know how to put the program and arguments of my command line ( python simple_stream.py) in launcher.conf file instead of the examples of author , this is launcher.conf file of author
logfile = 'logfile'
mqtt_broker = 'localhost' # default: 'localhost'
mqtt_port = 1883 # default: 1883
mqtt_clientid = 'mqtt-launcher-1'
# mqtt_username = 'jane'
# mqtt_password = 'secret'
topiclist = {
# topic payload value program & arguments
"sys/file" : {
'create' : [ '/usr/bin/touch', '/tmp/file.one' ],
'false' : [ '/bin/rm', '-f', '/tmp/file.one' ],
'info' : [ '/bin/ls', '-l', '/tmp/file.one' ],
},
"prog/pwd" : {
None : [ 'pwd' ],
},
"dev/1" : {
None : [ 'ls', '-l', '/' ],
},
"dev/2" : {
None : [ "/bin/echo", "111", "*", "#!#", "222", "#!#", "333" ],
},
}
can you please help me

Add a line to the sys/file, right after info, that says the following:
'launch' : [ '/usr/bin/python', 'simple_stream.py' ],
This way, when you send the payload 'launch' (without quotes) to the topic sys/file, it will execute the desired python script. Please adjust with the path of your python executable (in linux: 'which python' will tell you the path).
Hope this helps.

Related

All metrics are not show in influxdb from Telegraf

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.

Bazel convert tar to zip

Is there a way to convert a tar target (created using rules_pkg) and turn it into a zip target in Bazel?
pkg_tar(
name = "bundle-tar",
srcs = [
":aws-lambda",
],
include_runfiles = True,
package_dir = "/",
)
pkg_zip(
name = "bundle-zip",
srcs = [
":bundle-tar", # ???
],
)
I imagine this could be accomplished using #bazel_tools//tools/zip:zipper?
This kind of works, but it is not deterministic:
genrule(
name = "bundle-zip",
srcs = [ ':bundle-tar' ],
outs = [ "bundle.zip" ],
cmd = " && ".join([
"tar xf $(location :bundle-tar)",
"zip $# $$(tar tf $(location :bundle-tar))",
]),
)
load("#bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "rules_pkg",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.7.0/rules_pkg-0.7.0.tar.gz",
"https://github.com/bazelbuild/rules_pkg/releases/download/0.7.0/rules_pkg-0.7.0.tar.gz",
],
sha256 = "8a298e832762eda1830597d64fe7db58178aa84cd5926d76d5b744d6558941c2",
)
load("#rules_pkg//:deps.bzl", "rules_pkg_dependencies")
rules_pkg_dependencies()
Please refer to this issue for a detailed explanation on how to convert tar to zip files. Thank you.

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] }

Groovy: Implementing JsonSlurper is giving a JsonException --- Usually works

I am trying to build a json request in SoapUI and trying to post to a test step. For building the request, I have below code. When I execute it, it is throwing a JsonException (text provided below.) Any advise would be greatly appreciated. I have done this for over 60 services (so I've done this a 1001 times) and all of them have passed/worked. I am unable to pinpoint as to what the issue here is. Thanks!
import groovy.json.JsonSlurper
import groovy.json.JsonOutput
def setReqPayload ( pArrKeyValues ) {//[objId, dirInd, selActId, actDt, coType, secId]
def jsonPayload = '''
{
"objectId" : "",
"actDate": "",
"dirIndicator" : "",
"selectActId" : "",
"coInfo" : {"secId" : "","coType" : ""}
}
'''
// parse the request
def jsonReq = new JsonSlurper ( ).parseText ( jsonPayload )
jsonReq.objectId = pArrKeyValues [ 0 ] )
jsonReq.dirIndicator = pArrKeyValues [ 1 ]
jsonReq.selectActId = pArrKeyValues [ 2 ]
jsonReq.actDate = pArrKeyValues [ 3 ]
jsonReq.coInfo.coType = pArrKeyValues [ 4 ]
jsonReq.coInfo.secId = pArrKeyValues [ 5 ]
log.info "REQUEST JSON SLURP: " + jsonReq
return jsonReq
}
Exception:
ERROR:groovy.json.JsonException: expecting '}' or ',' but got current char ' ' with an int value of 160 The current character read is ' ' with an int value of 160
I have used below code as well to parse but that is throwing different kind of exception (Not that kind of map) and not allowing me to set the values to the keys.
// parse the request
def parser = new JsonSlurper ( ).setType ( JsonParserType.LAX )
def jsonReq = JsonOutput.toJson ( parser.parseText ( jsonPayload ) )
You have non-breaking space character(s) in your JSON, it's unfortunately invalid, it should be the usual space character.
Using LAX mode was a good idea but it does not seem to handle non-breaking spaces:
Use LAX if you want to enable relaxed JSON parsing, i.e., allow
comments, no quote strings, etc.
So if you cannot clean up your data at the source, you can filter it like this:
jsonPayload = jsonPayload.replace('\u00a0', '\u0020')
Looks like you have some trivial issue in the script.
Below script:
import groovy.json.JsonSlurper
import groovy.json.JsonOutput
def setReqPayload ( pArrKeyValues ) {//[objId, dirInd, selActId, actDt, coType, secId]
def jsonPayload = '''
{
"objectId" : "",
"actDate": "",
"dirIndicator" : "",
"selectActId" : "",
"coInfo" : {"secId" : "","coType" : ""}
}
'''
// parse the request
def jsonReq = new JsonSlurper ( ).parseText ( jsonPayload )
jsonReq.objectId = pArrKeyValues [ 0 ]
jsonReq.dirIndicator = pArrKeyValues [ 1 ]
jsonReq.selectActId = pArrKeyValues [ 2 ]
jsonReq.actDate = pArrKeyValues [ 3 ]
jsonReq.coInfo.coType = pArrKeyValues [ 4 ]
jsonReq.coInfo.secId = pArrKeyValues [ 5 ]
println "REQUEST JSON SLURP: " + jsonReq
return jsonReq
}
​setReqPayload([1,2,3,4,5,6])​
Produces below output:
{actDate=4, coInfo={coType=5, secId=6}, dirIndicator=2, objectId=1, selectActId=3}

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