Automation
Automation

Scripting How-To: Library for snmp-example script

by Cordelia on ‎08-11-2015 02:32 AM - edited on ‎09-15-2017 04:03 PM by Administrator Administrator (931 Views)

Overview

An example script uses the snmp.slax library. This library makes it as easy to get a value as it does set a value. This applies to SLAX version 1.0 and higher.

 

Description

 

This script demonstrates setting a given utility MIB to the value 100.

Source Code


GitHub Links

 

The source code below is also available from GitHub at the following locations:

Example Output


01	user@cli> op snmp-example string wibble Utility MIB wibble has value 100
02	 
03	user@cli> show snmp mib walk jnxUtil
04	jnxUtilIntegerValue.119.105.98.98.108.101 = 100
05	 
06	system {
07	     scripts {
08	         op {
09	             file snmp-example.slax;
10	         }
11	     }
12	}

SLAX Script Contents


01	version 1.0;
02	 
03	/*
04	 * CVS details
05	 * $Id$
06	 *
07	 * the change log can be found at the bottom of this file
08	 */
09	 
10	/*
11	 * This script uses the snmp.slax library. This library makes it as easy
12	 * to get a value as it does set a value.
13	 * This script demontrates this by setting a given utility MIB to the value 100
14	 */
15	 
16	ns junos = "http://xml.juniper.net/junos/*/junos";
17	ns xnm = "http://xml.juniper.net/xnm/1.1/xnm";
18	ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0";
19	ns ext = "http://xmlsoft.org/XSLT/namespace";
20	 
21	import "../import/junos.xsl";
22	import "snmp.slax";
23	 
24	param $string;
25	 
26	var $arguments = {
27	    <argument> {
28	        <name> string;
29	        <description> "a string";
30	    }
31	}
32	 
33	match / {
34	    <op-script-results> {
35	        /* set the utility MIB to the value of 100 */
36	        call snmp_set($instance = $string, $value = "100");
37	         
38	        /* now here's the magic. get the value without having to convert
39	         * the string into an OID format
40	         */
41	        var $mib = "jnxUtilIntegerValue." _ $string;
42	        var $value = {
43	            call snmp_get($instance = $mib);
44	        }
45	         
46	        <output> "Utility MIB " _ $string _ " has value " _ $value;
47	    }
48	}

XML Script Contents


01	<?xml version="1.0"?>
02	<script>
03	<title>snmp-example.slax</title>
04	<author>dgethings</author>
05	<synopsis>
06	An example script uses the snmp.slax library. This library makes it as easy to get a value as it does set a value.
07	</synopsis>
08	<coe>op</coe>
09	<type>snmp</type>
10	 
11	<description>
12	This script demonstrates this be setting a given utility MIB to the value 100
13	</description>
14	 
15	 <example>
16	 <title>Sample output</title>
17	 <output>example-1.output</output>
18	 </example>
19	 
20	<xhtml:script xmlns:xhtml="http://www.w3.org/1999/xhtml"
21	src="../../../../../web/leaf.js"
22	type="text/javascript"/>
23	</script>