JET Notification API Overview
The JET Notification API includes interfaces in the JETHandler
Python package that allow you to subscribe
to events and designate a callback function to receive events when
they occur. These Python interfaces provide an interface to the MQTT
notification system that for languages other than Python must be handled
outside of JET (see Programming JET Notification for Non-Python Languages). For
details about MQTT and Python, see http://mosquitto.org/ .
JSON Format of JET Notification Messages
JET notification is delivered in JSON format. The JSON message has two parts, one the header, and other the event-information portion, called attributes. The header is common for all events. It contains the event ID, hostname, time, severity, and facility of the event. The attributes vary depending event’s topic name.
All kernel rtsock events will have info as the severity and KERNEL as the facility. For syslog events, the severity and facility will be same as that of the Junos OS syslog messages.
The following is an example event JSON file.
Subscribing to Events
Applications developed using JET can subscribe to the events listed in Table 1. A topic is an endpoint to which the clients connect. A topic acts as the central distribution hub for publishing and subscribing messages. Topics are simple, hierarchical strings, encoded in UTF-8, delimited by a forward slash.
Table 1: Junos Event Topics
Events | Topic | Event Information Returned |
---|---|---|
Physical Interface (IFD) |
| name, snmp-id, flags |
Logical Inteface (IFL) |
| name, subunit, snmp-id, flags |
Family (IFF) |
| name, subunit, family, table-name, flags |
Address |
| name, subunit, family, local-address, destination-address, broadcast-address, flags |
Firewall |
| name, version, client-id, filter-type, protocol, interface-name, flags |
Route |
| table-name, logical-router-name, address-family, route-type, route-prefix, arrayof(nexthop-address), flags |
Route-table |
| name, logical-router-name, address-family, flags |
Syslog | /junos/events/syslog/event-id | arrayof(attribute-value pairs) |
Understanding the JET Notification API
The JET Notification APIs are as follows:
OpenNotificationSession() | — | Creates a request-response session with the JET server. Raises an exception in the case of invalid arguments or when JET notification server is not accessible. The user is required to configure allow-clients IP addresses using CLI. By default the behavior is to disallow all clients to connect to broker unless user has configured to allow them. The bind_address argument passed in the OpenNotificationSession() call needs to be configured for the allow-clients configuration statement in device to authorize the connection at mosquitto broker side. Arguments
|
CloseNotificationSession() | — | Closes the notification connection with the broker. After this method is executed successfully, further calls over this session will fail. |
Subscribe() | — | Subscribes to a specific topic the client application is interested in. |
Unsubscribe() | — | Takes the topic as argument and unsubscribes to the given topic. If topic name is not given as argument (no arguments), this method unsubscribes to all the topics that the application is already subscribed for. |
CreateIFDTopic() | — | Creates physical interface topic. Arguments
|
CreateIFLTopic() | — | Creates logical interface topic. Arguments
|
CreateIFFTopic() | — | Creates family topic. Arguments
|
CreateIFATopic() | — | Creates address topic. Arguments
|
CreateFirewallTopic() | — | Creates firewall topic. Arguments
|
CreateRouteTopic() | — | Creates route topic. Arguments
|
CreateRouteTableTopic() | — | Creates route table topic. Arguments
|
Programming JET Notification for Non-Python Languages
Many of the high-level languages have an MQTT library available. A JET application can use the corresponding library to connect to MQTT broker running on Junos OS and subscribe for events. For example, please refer the following link for a sample JAVA program connecting to an MQTT broker and subscribing for events: Example MQTT Messaging in Java.
For details on example MQTT libraries for different languages, see Table 2.
Table 2: MQTT Libraries by Language
Language Name | License Link |
---|---|
C, Mosquitto | |
C++, Mosquitto | |
Python, Mosquitto | |
Ruby, Ruby-mqtt | |
Java, Eclipse paho Java | |
Go, Eclipse Paho Go | |
C#, MqttDotNet |