Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 
 

Example: Process Unsupported OIDs with an SNMP Script

This sample SNMP script shows how to process object identifiers (OIDs) that are not supported on devices running Junos OS.

Requirements

Junos OS Release 15.1 or later when using SLAX SNMP scripts.

Junos OS Release 16.1R3 or later when using Python SNMP scripts on QFX Series switches or MX Series, PTX Series, or T Series routers.

Junos OS Release 17.1R1 or later when using Python SNMP scripts on EX Series switches.

Junos OS Release 17.3R1 or later when using Python SNMP scripts on SRX Series Firewalls.

SNMP is configured on the device.

Overview and SNMP Script

In this example, two equivalent SNMP scripts are presented in SLAX and Python that match and process several unsupported OIDs. The script returns the value for the requested object by using the <snmp-script-results> element in the SLAX script and the jcs.emit_snmp_attributes() function in the equivalent Python script. The syslog() extension function is called to log the requested SNMP action and OID in the system log file. For more information about the syslog() function, see syslog() Function (Python, SLAX, and XSLT).

SLAX Syntax

Python Syntax

Configuration

Procedure

Step-by-Step Procedure

To download and enable the script:

Note:

You can create SNMP scripts in Python, SLAX, or XSLT. You can use the request system scripts convert command to convert between SLAX and XSLT.

  1. Copy the script into a text file, name the file sample_snmp.slax or sample_snmp.py, as appropriate, and download it to the /var/db/scripts/snmp directory on the device.

    Note:

    Unsigned Python scripts must be owned by either root or a user in the Junos OS super-user login class, and only the file owner can have write permission for the file.

  2. Enable the SNMP script and configure the OID.

    In configuration mode, configure the file filename statement with the appropriate filename and extension for your script language at the [edit system scripts snmp] hierarchy level, and configure the OID that will trigger the script.

  3. If the script is written in Python, configure the language python or language python3 statement as appropriate.

  4. If the script is written in Python, configure the user under whose access privileges the script executes.

    Note:

    If you do not configure the python-script-user statement, then by default, Junos OS executes Python SNMP scripts under the access privileges of the user and group nobody.

  5. Issue the commit command to commit the configuration.

Results

From configuration mode, confirm your configuration by entering the show system scripts snmp command.

If the output does not display the intended configuration, repeat the configuration instructions in this example to correct it.

To ensure that the enabled files are on the device, list the contents of the /var/run/scripts/snmp directory using the file list /var/run/scripts/snmp operational mode command.

Verification

Verifying the Script Execution

Purpose

Verify that the SNMP script functions as expected.

Action

Issue the show snmp mib get, show snmp mib get-next, or show snmp mib walk command to generate an SNMP request.

The system log file contains the following messages after script execution: