MQTT on Juniper devices with Junos 16.1R1
For decades, syslog and snmp traps have been extensively used to receive event notifications from devices. It typically required an operator to configure the event category and severity level on the devices and where to send the events to.
Fast forward to today and thanks to a generic need for highly scalable and lightweight instant messaging needs, there is now MQTT (MQ Telemetry Transport), defined in an ISO standard (ISO/IEC PRF 20922): A client server publish/subscribe messaging transport protocol, run over TCP/IP.
Juniper introduced MQTT to Junos 16.1R1 as an integral part of the Juniper Extension Toolkit (JET). Chapter 2 in Juniper Extension Toolkit API Guide describes the notification API in detail, but where is the fun in reading when you can simply take a router for a spin!
First, make sure you run Junos 16.1R1 or higher, then enable MQTT with the following configuration:
$ ssh admin@vmx4
Last login: Sun Aug 28 09:21:41 2016 from 172.17.0.1
--- JUNOS 16.1R1.7 Kernel 64-bit JNPR-10.1-20160624.329953_builder_stable_10
admin@vmx4> show configuration system services extension-service notification
port 1883;
allow-clients {
address 0.0.0.0/0;
}
This pretty much opens up the router for worldwide attack. Access can be limited to IPv4/IPv6 networks/prefixes.
Second, install a suitable MQTT client on your host system. I opted here for one of the most basic, CLI based, clients there is on Linux: mosquitto-clients. Install it on Ubuntu with
sudo apt-get install mosquitto-clients
Third, launch mosquitto_sub against the router, either via IP address or hostname and wait for messages to trickle in. Instead of subscribing to specific event topics, we simply want everything (and in JSON format). This can be done using the wildcard ‘#’. See the man page for mqtt(7) for more details how to subscribe to specific events. Subscribing to everything via mosquitto_sub against a Junos device with notification extension-service turned on, will print all messages that it receives:
$ mosquitto_sub -h vmx4 -t \#
{
"jet-event": {
"event-id": "SYSTEM",
"hostname": "vmx4",
"time": "2016-08-28-09:21:41",
"severity": "notice",
"facility": "auth",
"process-id": 80148,
"process-name":"sshd",
"message": "(pam_sm_acct_mgmt): DEBUG: PAM_USER: mwiget",
"attributes": {
"message": "(pam_sm_acct_mgmt): DEBUG: PAM_USER: mwiget"
}
}
}
{
"jet-event": {
"event-id": "SYSTEM",
"hostname": "vmx4",
"time": "2016-08-28-09:21:41",
"severity": "info",
"facility": "auth",
"process-id": 80148,
"process-name":"sshd",
"message": "Accepted publickey for mwiget from 172.17.0.1 port 47968 ssh2: RSA 60:46:50:7b:d5:b7:6b:75:ba:a6:86:48:6d:44:63:e0",
"attributes": {
"message": "Accepted publickey for mwiget from 172.17.0.1 port 47968 ssh2: RSA 60:46:50:7b:d5:b7:6b:75:ba:a6:86:48:6d:44:63:e0"
}
}
}
{
"jet-event": {
"event-id": "UI_COMMIT_PROGRESS",
"hostname": "vmx4",
"time": "2016-08-28-09:30:51",
"severity": "info",
"facility": "interact",
"process-id": 80151,
"process-name":"mgd",
"message": "UI_COMMIT_PROGRESS: Commit operation in progress: commit complete",
"attributes": {
"message": "commit complete"
}
}
}
{
"jet-event": {
"event-id": "UI_COMMIT_COMPLETED",
"hostname": "vmx4",
"time": "2016-08-28-09:30:51",
"severity": "warn",
"facility": "interact",
"process-id": 80151,
"process-name":"mgd",
"message": "UI_COMMIT_COMPLETED: commit complete",
"attributes": {
}
}
}
{
"jet-event": {
"event-id": "UI_COMMIT_PROGRESS",
"hostname": "vmx4",
"time": "2016-08-28-09:30:51",
"severity": "info",
"facility": "interact",
"process-id": 80151,
"process-name":"mgd",
"message": "UI_COMMIT_PROGRESS: Commit operation in progress: signaling 'Alarm control process', pid 4180, signal 30, status 0 with notification errors enabled",
"attributes": {
"message": "signaling 'Alarm control process', pid 4180, signal 30, status 0 with notification errors enabled"
}
}
}
{
"jet-event": {
"event-id": "PIC",
"hostname": "vmx4",
"time": "2016-08-28-09:30:51",
"severity": "debug",
"facility": "pfe",
"process-id": 0,
"process-name":"UNKNOWN",
"message": "fpc0 FPC slot: 0, DISABLE Delay: 5, Frequency: 60\n",
"attributes": {
"message": "fpc0 FPC slot: 0, DISABLE Delay: 5, Frequency: 60\n"
}
}
}
{
"jet-event": {
"event-id": "SNMP_TRAP_LINK_DOWN",
"hostname": "vmx4",
"time": "2016-08-28-09:30:51",
"severity": "warn",
"facility": "daemon",
"process-id": 4086,
"process-name":"mib2d",
"message": "SNMP_TRAP_LINK_DOWN: ifIndex 529, ifAdminStatus down(2), ifOperStatus down(2), ifName ge-0\/0\/1.0",
"attributes": {
"snmp-interface-index": "529",
"admin-status": "down(2)",
"operational-status": "down(2)",
"interface-name": "ge-0\/0\/1.0"
}
}
}
Physical Interface (IFD), Logical Interface (IFL), Family (IFF), Address, Firwall, Route, Route-table and Syslog are Event Topics one can subscribe to. See JET Notification API Overview from http://www.juniper.net/techpubs/ for details about these Junos Event Topics.
https://marcelwiget.wordpress.com/2016/08/28/mqtt-on-juniper-devices-with-junos-16-1r1/#more-61
https://www.youtube.com/watch?v=EIxdz-2rhLs
No comments:
Post a Comment