JET Notification API Overview

 

The JET Notification API allows 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 https://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)

  • /junos/events/kernel/interfaces/ifd/add/ifdname

  • /junos/events/kernel/interfaces/ifd/change/ifdname

  • /junos/events/kernel/interfaces/ifd/delete/ifdname

name, snmp-id, flags

Logical Inteface (IFL)

  • /junos/events/kernel/interfaces/ifl/add/iflname

  • /junos/events/kernel/interfaces/ifl/change/iflname

  • /junos/events/kernel/interfaces/ifl/delete/iflname

name, subunit, snmp-id, flags

Family (IFF)

  • /junos/events/kernel/interfaces/iff/add/iflname/family-type

  • /junos/events/kernel/interfaces/iff/change/iflname/family-type

  • /junos/events/kernel/interfaces/iff/delete/iflname/family-type

name, subunit, family, table-name, flags

Address

  • /junos/events/kernel/interfaces/ifa/add/iflname/family-type/address

  • /junos/events/kernel/interfaces/ifa/change/iflname/family-type/address

  • /junos/events/kernel/interfaces/ifa/delete/iflname/family-type/address

name, subunit, family, local-address, destination-address, broadcast-address, flags

Firewall

  • /junos/events/kernel/firewall/filter/add/filtername

  • /junos/events/kernel/firewall/filter/change/filtername

  • /junos/events/kernel/firewall/filter/delete/filtername

name, version, client-id, filter-type, protocol, interface-name, flags

Route

  • /junos/events/kernel/route/add/family/prefix-with-length

  • /junos/events/kernel/route/change/family/prefix-with-length

  • /junos/events/kernel/route/delete/family/prefix-with-length

table-name, logical-router-name, address-family, route-type, route-prefix, arrayof(nexthop-address), flags

Route-table

  • /junos/events/kernel/route-table/add/tablename/lrname

  • /junos/events/kernel/route-table/change/tablename/lrname

  • /junos/events/kernel/route-table/delete/tablename/lrname

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

  • device—JET Server IP address. Default is localhost.

  • port—JET Notification port number. Default is 1883.

  • user—Username on the JET server, used for authentication and authorization.

  • password—Password to access the JET server, used for authentication and authorization.

  • keepalive—Maximum period in seconds between communications with the broker.

  • bind_address—Client address to bind. Can be used to control access at broker side.

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

  • op—Operation (ADD, DELETE, CHANGE, ALL). Default is ALL.

  • ifd_name—The physical interface name to subscribe to. Default is all physical interface names.

CreateIFLTopic()Creates logical interface topic.

Arguments

  • op—Operation (ADD, DELETE, CHANGE, ALL). Default is ALL.

  • ifd_name—The physical interface name to subscribe to. Default is all physical interface names.

  • sub_unit—This argument is mandatory when an interface name is passed.

  • family_type—Default is all family types.

CreateIFFTopic()Creates family topic.

Arguments

  • op—Operation (ADD, DELETE, CHANGE, ALL). Default is ALL.

  • ifd_name—The physical interface name to subscribe to. Default is all physical interface names.

CreateIFATopic()Creates address topic.

Arguments

  • op—Operation (ADD, DELETE, CHANGE, ALL). Default is ALL.

  • ifd_name—The physical interface name to subscribe to. Default is all physical interface names.

  • sub_unit—This argument is mandatory when an interface name is passed.

  • family_type—Default is all family types.

  • address—Default is all addresses.

CreateFirewallTopic()Creates firewall topic.

Arguments

  • op—Operation (ADD, DELETE, CHANGE, ALL). Default is ALL.

  • filter_name—Filter name to subscribe to. Default is all filters.

CreateRouteTopic()Creates route topic.

Arguments

  • op—Operation (ADD, DELETE, CHANGE, ALL). Default is ALL.

  • family—Family to subscribe to. Default is all families.

  • prefix_length—Default is all prefix lengths.

CreateRouteTableTopic()Creates route table topic.

Arguments

  • op—Operation (ADD, DELETE, CHANGE, ALL). Default is ALL.

  • table_name—Table name to subscribe to. Default is all table names.

  • lr_name—LR name to subscribe to. Default is all LR names.

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

FreeBSD

C++, Mosquitto

FreeBSD

Python, Mosquitto

FreeBSD

Ruby, Ruby-mqtt

MIT License

Java, Eclipse paho Java

Eclipse Public License

Go, Eclipse Paho Go

Eclipse Public License

C#, MqttDotNet

Custom License

Related Documentation