Hi there,
I`m trying to implement a notification system via Telegram to show notifications from my Ubiquiti Unifi Platform. I've already set the API query to Unifi Controller to query what i want, but it gives me all alerts and not only the ones i need.
This is the output from the Unifi Controller:
{
"payload": {
"meta": {
"rc": "ok",
"count": 54
},
"data": [
{
"_id": "61269d6d66923f10392ead22",
"archived": false,
"key": "EVT_AP_Lost_Contact",
"ap": "xx:xx:c2:f9:xx:xx",
"ap_name": "Unifi Infantil",
"ap_model": "U7LT",
"ap_displayName": "Unifi Infantil",
"subsystem": "wlan",
"is_negative": true,
"site_id": "60e0ccc69be0f1039dde38fb",
"time": 1629920621661,
"datetime": "2021-08-25T19:43:41Z",
"msg": "AP[xx:xx:c2:f9:xx:xx] was disconnected"
},
{
"_id": "61269b5166923f10392ea8f4",
"archived": false,
"key": "EVT_AP_Lost_Contact",
"ap": "xx:xx:c2:f9:xx:xx",
"ap_name": "Unifi Infantil",
"ap_model": "U7LT",
"ap_displayName": "Unifi Infantil",
"subsystem": "wlan",
"is_negative": true,
"site_id": "60e0ccc69be0f1039dde38fb",
"time": 1629920081661,
"datetime": "2021-08-25T19:34:41Z",
"msg": "AP[xx:xx:c2:f9:xx:xx] was disconnected"
},
{
"_id": "6126777466923f10392e4ead",
"archived": false,
"gw": "xx:xx:bf:xx:7d:xx",
"iface": "eth9",
"state": "failover",
"key": "EVT_GW_WANTransition",
"dm": "xx:xx:bf:xx:7d:xx",
"dm_name": "UDM-Pro",
"dm_model": "UDMPRO",
"dm_displayName": "UDM-Pro",
"gw_displayName": "UDM-Pro",
"subsystem": "lan",
"is_negative": false,
"site_id": "60e0ccc69be0f1039dde38fb",
"time": 1629910900000,
"datetime": "2021-08-25T17:01:40Z",
"msg": "Gateway[xx:xx:bf:xx:7d:xx] WAN iface eth9 transition to state failover"
},
{
"_id": "6126777366923f10392e4eab",
"archived": false,
"gw": "xx:xx:bf:xx:7d:xx",
"iface": "ppp0",
"state": "active",
"key": "EVT_GW_WANTransition",
"dm": "xx:xx:bf:xx:7d:xx",
"dm_name": "UDM-Pro",
"dm_model": "UDMPRO",
"dm_displayName": "UDM-Pro",
"gw_displayName": "UDM-Pro",
"subsystem": "lan",
"is_negative": false,
"site_id": "60e0ccc69be0f1039dde38fb",
"time": 1629910899000,
"datetime": "2021-08-25T17:01:39Z",
"msg": "Gateway[xx:xx:bf:xx:7d:xx] WAN iface ppp0 transition to state active"
},
{
"_id": "6126776566923f10392e4e98",
"archived": false,
"gw": "xx:xx:bf:xx:7d:xx",
"iface": "ppp0",
"state": "inactive",
"key": "EVT_GW_WANTransition",
"dm": "xx:xx:bf:xx:7d:xx",
"dm_name": "UDM-Pro",
"dm_model": "UDMPRO",
"dm_displayName": "UDM-Pro",
"gw_displayName": "UDM-Pro",
"subsystem": "lan",
"is_negative": false,
"site_id": "60e0ccc69be0f1039dde38fb",
"time": 1629910885000,
"datetime": "2021-08-25T17:01:25Z",
"msg": "Gateway[xx:xx:bf:xx:7d:xx] WAN iface ppp0 transition to state inactive"
}
]
},
"inputMsg": {
"_msgid": "3f34798d5f650a0e",
"payload": 1629920720052,
"topic": ""
},
"_msgid": "4fc9e55d28ac33c2"
}
What i need is to filter only the messages (msg field) from all messages that have states like "state": "inactive", "state": "active", "state": "failover". I`ll the output the state and msg to a Telegram Sender node.
It would also be nice to correctly format the output, like :
"msg": "Gateway[xx:xx:bf:xx:7d:xx] WAN iface ppp0 transition to state inactive"
Become a message like "WAN interface ppp0 transition to state inactive"
Can you help me achieve this?