MQTT with json format
-
Hello, i did agent config as following:
MasterServers = x.x.x.x ConfigIncludeDir = C:\NetXMS\etc\nxagentd.conf.d LogFile = {syslog} FileStore = C:\NetXMS\var SubAgent = mqtt SubAgent = winperf [MQTT/Brokers/Test] Hostname = y.y.y.y Port = 1883 [MQTT/Brokers/Test/Metrics] Volt = "metrics/grid/voltage/L1"the output looks like this:
{ "timestamp": "2024-10-30T09:42:12.145495", "type": "float", "value": 236.21934509277344 }how can i extract the value ?
Currently in netxms i just get unsuported.
-
This is interesting, seems that json payload is a popular thing these days.
Unsupported could be in case if agent subscribed to topic, but there is no new value on the broker. I've used similar config as what you have and once I've pushed a new value with mosquitto_pub, I can get value of "Volt" from the agent - whole contents of the json appears in last values on the server.
Max length of DCI value is 255 chars, so if you payload is within that, you are lucky. Ideally agent could parse the payload, I've added ticker for that: https://track.radensolutions.com/issue/NX-2626
Now, in transformation script you can parse the json and extract your value:
j = JsonParse($1);
if (j == null) return null;
value = j.get("value");
return value;P.S. It's not necessary to specify metrics in agent config - you can use MQTT origin, in this case agent automatically subscribes to topics. I've updated the documentation on this.
-
So i need only following in agent config ?
[MQTT/Brokers/Test] Hostname = y.y.y.y Port = 1883I made new DCI:
Origin: mqtt
Metric: Test:metrics/grid/voltage/L1
Data type: FloatBtw the Broker is in same server as agent itself, if it makes difference. With mqtt explorer i see that value changes every few seconds. Yet dci remains in not supported status.
-
Or just
[MQTT/Brokers/Test] Hostname = y.y.y.yif using default port number.
First thing to check if mqtt subagent actually loads during agent start. This is visible in agent log, e.g.:
2024.11.04 11:43:11.911 *I* [subagents ] Subagent "MQTT" (/opt/netxms-master/lib/netxms/mqtt.nsm) loaded successfully (version 5.1.0-rc326)On Linux you might need to install netxms-agent-mqtt package as mqtt subagent is in it.
Then a bit tricky part is if using MQTT origin, server tries to get the value from agent which runs along with your server (or agent which is zone proxy, if node where DCI is configured is in some zone). This is the same logic as for ssh monitoring. The idea is that you might have a node (or sensor) object which corresponds to your mqtt device and you have DCIs on it, but data collection happens through agent on another node. You can explicitly specify MQTT proxy in node or sensor properties.
You can enable DebugLevel=6 in agent config, the you should see lines like this:
2024.11.04 09:53:27.692 *D* [comm.cs.2 ] Requesting metric "MQTT.TopicData("test:metrics/grid/voltage/L2")" 2024.11.04 09:53:27.693 *D* [mqtt ] Subscribed to topic metrics/grid/voltage/L2 on MQTT broker 127.0.0.1:1883 ... 2024.11.04 09:54:26.671 *D* [mqtt ] MQTT message received: metrics/grid/voltage/L2="456" -
Can it be version problem, i currently run V5.0.5?
In agent logs i get following:
config
2024.11.04 12:23:22.778 *I* [config ] +- CORE 2024.11.04 12:23:22.778 *I* [config ] | +- DebugLevel 2024.11.04 12:23:22.778 *I* [config ] | | value: 6 2024.11.04 12:23:22.778 *I* [config ] | +- MasterServers 2024.11.04 12:23:22.778 *I* [config ] | | value: 192.168.3.73 2024.11.04 12:23:22.778 *I* [config ] | +- ConfigIncludeDir 2024.11.04 12:23:22.778 *I* [config ] | | value: C:\NetXMS\etc\nxagentd.conf.d 2024.11.04 12:23:22.778 *I* [config ] | +- LogFile 2024.11.04 12:23:22.778 *I* [config ] | | value: C:\NetXMS\log\log.txt 2024.11.04 12:23:22.778 *I* [config ] | +- FileStore 2024.11.04 12:23:22.778 *I* [config ] | | value: C:\NetXMS\var 2024.11.04 12:23:22.778 *I* [config ] | +- SubAgent 2024.11.04 12:23:22.778 *I* [config ] | value: winperf 2024.11.04 12:23:22.778 *I* [config ] | value: mqtt 2024.11.04 12:23:22.778 *I* [config ] +- MQTT 2024.11.04 12:23:22.778 *I* [config ] +- Brokers 2024.11.04 12:23:22.778 *I* [config ] +- Local 2024.11.04 12:23:22.778 *I* [config ] +- Hostname 2024.11.04 12:23:22.778 *I* [config ] value: 127.0.0.1 ... 2024.11.04 12:23:23.214 *D* [mqtt ] 0 MQTT parameters added from configuration 2024.11.04 12:23:23.214 *D* [mqtt ] Using libmosquitto 2.0.15 2024.11.04 12:23:23.214 *D* [mqtt ] Automatic registration of MQTT topics is enabled 2024.11.04 12:23:23.214 *I* [subagents ] Subagent "MQTT" (mqtt.nsm) loaded successfully (version 5.0.1) 2024.11.04 12:23:23.214 *D* [mqtt ] Connected to MQTT broker 127.0.0.1:1883 as anonymous -
Version is fine, last changes in mqtt were somewhere in 4.x, so any 5.x version has the latest and greatest code.
If you node where you have this agent is not your netxms server and not zone's proxy, try setting the node itself as MQTT proxy in it's properties.
-
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login