· 6 years ago · Feb 28, 2020, 05:20 PM
1<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2<mqtt-receiver xmlns="http://xmlns.opennms.org/xsd/config/mqtt-datacollection" xmlns:ns2="http://xmlns.opennms.org/xsd/config/xml-datacollection">
3 <!-- optional tuning parameters -->
4 <nodeCacheMaxSize>1000</nodeCacheMaxSize>
5 <nodeCacheMaxTtl>0</nodeCacheMaxTtl>
6 <maxMessageQueueLength>1000</maxMessageQueueLength>
7 <maxMessageQueueThreads>2</maxMessageQueueThreads>
8
9 <!-- if true new nodes will be created for messages referencing an unknown node -->
10 <createMissingNodes>true</createMissingNodes>
11 <!-- if true a dummy interface will also be created when the node is created -->
12 <createDummyInterfaces>true</createDummyInterfaces>
13 <!-- if true asset information will be copied to the node asset table when the node is created -->
14 <!-- this particularly applies to latitude and longitude if defined in the message -->
15 <createNodeAssetData>true</createNodeAssetData>
16
17 <!-- message data parsers define how data messages are converted into metrics to be stored in RRD's or Cassandra by OpenNMS -->
18 <!-- subscriptionTopics defines which topic messages will be passed to this parser. -->
19 <!-- many messageDataParsers can be defined but only one per topic although events can also be driven off the same topic) -->
20 <messageDataParsers>
21 <!-- payloadType determines how the payload is parsed; JSON, XML, PROTOBUF ot TEXT. Note only JSON is supported in present release -->
22 <!-- foreignSource defines the foreign source to be used when referencing or creating a new node -->
23 <!-- compression determines the processing of compressed messages GZIP, UNCOMPRESSED, AUTOMATIC_GZIP -->
24 <!-- (tries to guess if gzip compressed - small chance of false positives) -->
25 <messageDataParser foreignSource="mqtt" payloadType="JSON" compression="UNCOMPRESSED">
26 <subscriptionTopics>
27 <topic>mqtt-data</topic>
28 </subscriptionTopics>
29 <!-- xmlgroups configuration is very similar to XMLData collection configuration for JSON in OpenNMS -->
30 <!-- however multiple readings with different timestamps can be received. The timestamp-xpath is relative to the start of the message -->
31 <!-- the key-xpath defines the key which will give the node its foreignId. Thus the foreignSource defined above is combined with -->
32 <!-- the foreignId retrieved by the key-xpath to give a reference to the node for which the data is persisted. -->
33 <xml-groups>
34 <ns2:xml-group name="sniffy" resource-type="sniffy" resource-xpath="/" key-xpath="@id" timestamp-xpath="@time" timestamp-format="yyyy-MM-dd HH:mm:ss.SSSSSS">
35 <ns2:xml-object name="time" type="string" xpath="@time" />
36 <ns2:xml-object name="id" type="string" xpath="@id" />
37 <ns2:xml-object name="cityName" type="string" xpath="@cityName" />
38 <ns2:xml-object name="stationName" type="string" xpath="@stationName" />
39 <ns2:xml-object name="latitude" type="GAUGE" xpath="@latitude" />
40 <ns2:xml-object name="longitude" type="GAUGE" xpath="@longitude" />
41 <ns2:xml-object name="averaging" type="GAUGE" xpath="@averaging" />
42 <ns2:xml-object name="PM1" type="GAUGE" xpath="@PM1" />
43 <ns2:xml-object name="PM25" type="GAUGE" xpath="@PM25" />
44 <ns2:xml-object name="PM10" type="GAUGE" xpath="@PM10" />
45 </ns2:xml-group>
46 </xml-groups>
47 <!-- xmlRRD us set up exactly as it is for xml data collection. step (in seconds ) is the interval expected between data received from the same node -->
48 <xmlRrd step="300">
49 <ns2:rra>RRA:AVERAGE:0.5:1:2016</ns2:rra>
50 <ns2:rra>RRA:AVERAGE:0.5:12:1488</ns2:rra>
51 <ns2:rra>RRA:AVERAGE:0.5:288:366</ns2:rra>
52 <ns2:rra>RRA:MAX:0.5:288:366</ns2:rra>
53 <ns2:rra>RRA:MIN:0.5:288:366</ns2:rra>
54 </xmlRrd>
55 </messageDataParser>
56
57 <!-- *********************************** -->
58 <!-- message data parser for laurawan probes -->
59 <!-- *********************************** -->
60 </messageDataParsers>
61
62 <!-- message event parsers follow the same pattern as message data parsers. -->
63 <!-- however the Xpath defines which name value pairs are saved as params in the resulting opennms events -->
64
65 <messageEventParsers>
66 <messageEventParser foreignSource="mqtt" payloadType="JSON" compression="UNCOMPRESSED">
67 <subscriptionTopics>
68 <topic>mqtt-events/json</topic>
69 </subscriptionTopics>
70 <xml-groups>
71 <ns2:xml-group name="sniffy" resource-type="sniffy" resource-xpath="/" key-xpath="@id" timestamp-xpath="@time" timestamp-format="yyyy-MM-dd HH:mm:ss.SSSSSS">
72 <ns2:xml-object name="time" type="string" xpath="@time" />
73 <ns2:xml-object name="id" type="string" xpath="@id" />
74 <ns2:xml-object name="cityName" type="string" xpath="@cityName" />
75 <ns2:xml-object name="stationName" type="string" xpath="@stationName" />
76 <ns2:xml-object name="latitude" type="GAUGE" xpath="@latitude" />
77 <ns2:xml-object name="longitude" type="GAUGE" xpath="@longitude" />
78 <ns2:xml-object name="averaging" type="GAUGE" xpath="@averaging" />
79 <ns2:xml-object name="PM1" type="GAUGE" xpath="@PM1" />
80 <ns2:xml-object name="PM25" type="GAUGE" xpath="@PM25" />
81 <ns2:xml-object name="PM10" type="GAUGE" xpath="@PM10" />
82 </ns2:xml-group>
83 </xml-groups>
84 </messageEventParser>
85
86 <messageEventParser foreignSource="mqtt" payloadType="TEXT_CSV" compression="UNCOMPRESSED">
87 <!-- Site,Species,ReadingDateTime,Value,Units,Provisional or Ratified -->
88 <!-- 1, 2 3 4 5 6 Note jxpath numbers indexes from 1 -->
89 <!-- SH0,NO,01/01/2018 00:00,5.0,ug m-3,P -->
90 <subscriptionTopics>
91 <topic>mqtt-events/txt</topic>
92 </subscriptionTopics>
93 <xml-groups>
94 <ns2:xml-group name="textMeasure" resource-type="testMeasure" resource-xpath="." key-xpath=".[1]" timestamp-xpath=".[3]" timestamp-format="dd/mm/yyyy HH:mm"> <!-- empty string indicates simple timestamp from epoch (Date.toString()) -->
95 <ns2:xml-object name="name" type="string" xpath=".[1]" />
96 <ns2:xml-object name="timestamp" type="string" xpath=".[3]" />
97 <ns2:xml-object name="value" type="GAUGE" xpath=".[4]" />
98 </ns2:xml-group>
99 </xml-groups>
100 </messageEventParser>
101
102
103 </messageEventParsers>
104
105 <!-- mqttClients define connections to mqtt brokers. (This follows the paho client model). -->
106 <!-- each client must have a unique instanceId - this is used in OpenNMS logging. -->
107 <!-- the clienid must be unique for a given mqtt broker -->
108 <!-- the clientConnectionMaxWait tetermins the time the client will wait for the broker to respond before abandoning a connection attempt -->
109 <!-- the connectionRetryInterval is the interval before the client will try again to connect after failing to connect previously -->
110 <!-- the topic list determines which topics the client will subscribe to once it has established a connection -->
111 <!-- Note that the subscribed topic can also be a filter e.g. topic="/+/foo/# -->
112 <mqttClients>
113 <client clientInstanceId="client1">
114 <brokerUrl>tcp://localhost:1883</brokerUrl>
115 <clientId>opennms</clientId>
116 <connectionRetryInterval>3000</connectionRetryInterval>
117 <clientConnectionMaxWait>20000</clientConnectionMaxWait>
118 <topicList>
119 <topic qos="0" topic="mqtt-events/#" />
120 <topic qos="0" topic="mqtt-data" />
121 </topicList>
122 <userName>mqtt-user</userName>
123 <password>mqtt-password</password>
124
125 <!-- USING TLS -->
126 <!-- If you are using TLS you must provide both certificate and key files -->
127 <!-- If both are omitted from the configuration TLS will not be used -->
128
129 <!-- with AMAZON IoT, the certificate and key files can be generated for you -->
130 <!-- These are tied to a specific client id and IoT end point -->
131 <!-- <clientId>client id matching certificate</clientId> -->
132
133 <!-- <certificateFile>put absolute path to certificate.pem file here</certificateFile> -->
134 <!-- <privateKeyFile>put absolute path to private.key file here</privateKeyFile> -->
135 <!-- <brokerUrl>ssl://{iot end point}:8883</brokerUrl> -->
136 </client>
137 </mqttClients>
138
139 <!-- messageClients are alternative message sources defined within OpenNMS -->
140 <!-- In this case, the opennms-rest-client is an in built rest client which can receive messages on a particular topic and qos -->
141 <!-- determined by the url. The topicList determines which topics will be accepted by the ReST api and passed to the message queue for processing -->
142 <!-- the ReST url pattern is <opennms base url>/plugin/mqtt/v1-0/postmessage/<QOS>/TOPIC... -->
143 <!-- where the resource identifier is /postmessage/<QOS>/TOPIC... and TOPIC is a topic path e.g. /postmessage/0/foo/barr -->
144 <!-- Note that the subscribed topic can also be a filter e.g. topic="/+/foo/# -->
145 <!-- e.g. the following configuration allows json data to be POSTed to the mqtt-events topic with qos 0 at -->
146 <!-- http://localhost:8980/opennms/plugin/mqtt/v1-0/postmessage/0/mqtt-events -->
147 <messageClients>
148 <message-client clientInstanceId="opennms-rest-client" clientType="opennms-rest-client">
149 <configuration>
150 <client-configuration name="TBD" value="TBD" />
151 </configuration>
152 <topicList>
153 <topic qos="0" topic="mqtt-events" />
154 <topic qos="0" topic="mqtt-events/#" />
155 <topic qos="0" topic="mqtt-data" />
156 </topicList>
157 </message-client>
158 </messageClients>
159</mqtt-receiver>