Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 
 

Understanding Supported Data Types in SNMP Scripts

Understand the data types supported by SNMP scripts, which return information for custom OIDs on Junos devices.

Data Types Overview

SNMP scripts are triggered automatically when an SNMP manager requests information from the SNMP agent for an object identifier (OID) that is mapped to the SNMP script. SLAX and XSLT scripts return the information for the requested object in the <snmp-script-results> element. Python scripts return the information by executing the jcs.emit_snmp_attributes() function.

When the SNMP script returns the requested object, it provides the OID, a type, and a value. SNMP scripts support standard SNMP data types. Table 1 outlines the supported data types.

Table 1: SNMP Script Supported Data Types
Data Type Description Example

Counter32

32-bit unsigned integer.

Range: 0 through 4,294,967,295

4294967295

Counter64

64-bit unsigned integer.

Range: 0 through 18,446,744,073,709,551,615

18446744073709551615

INTEGER
or
Integer32

32-bit signed integer.

Range: -2,147,483,647 through 2,147,483,647

-1000

OCTET STRING

A sequence of bytes that can represent text or binary data.

Specify the hexadecimal representation of each ASCII character in the output string. Use spaces to separate each hex value.

64 65 76 69 63 65 20 72 65 62 6f 6f 74 65 64

Translates to "device rebooted"

Unsigned32

32-bit unsigned integer.

Range: 0 through 4,294,967,295

896

Example: Emitting Objects with Different Data Types in SNMP Scripts

This example shows an SNMP script that emits information for objects with different data types.

Requirements

  • Device running Junos OS or device running Junos OS Evolved.

  • SNMP is configured on the device.

Overview and SNMP Script

This example presents an SNMP script that matches and processes several OIDs. The script returns the information for the requested object, which includes its OID, data type, and value. The script processes OIDs for objects that use different data types.

The example provides the SNMP script in SLAX and Python. The SLAX SNMP script returns the information for the requested object by using the <snmp-script-results> element. The Python SNMP script returns the information for the requested object by executing the jcs.emit_snmp_attributes() function.

SLAX Syntax

Python Syntax

Configuration

Procedure

To download and enable the script:

  1. Copy the script into a text file and name the file snmp-script-data-types.slax or snmp-script-data-types.py, as appropriate.

  2. Download the script 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.

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

  4. Configure the SNMP script with the appropriate filename and extension for your script language at the [edit system scripts snmp] hierarchy level.

  5. Under the SNMP script's hierarchy, configure the OIDs for which the script is returning information.

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

    For example:

    Note:

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

  7. Issue the commit command to commit the configuration.

Results

From configuration mode, confirm your configuration by entering the show system scripts command. The configuration statements will vary depending on your script language.

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.