Differences

This shows you the differences between two versions of the page.

Link to this comparison view

sdk:scripts:snmp-cmd [2015/05/05 15:04] (current)
Line 1: Line 1:
 +====== SDK Script snmp-cmd.are ======
 +<code c snmp-cmd.are>​
 +/* DESC: This script issues SNMP set/get commands
 + * Copyright (C) 2014 NetModule AG, Switzerland
 + */
 +
 +HOST = "​192.168.1.1";​
 +PORT = 161;
 +VERSION = 3;
 +USER = "​admin";​
 +PASS = "​admin01admin01";​
 +AUTH = "​MD5";​
 +PRIV = "​DES";​
 +
 +if (nb_snmp_host(HOST,​ PORT, VERSION, USER, PASS, AUTH, PRIV) != 0) {
 +    nb_syslog("​unable to set SNMP host"​);​
 +    exit(1);
 +}
 +
 +
 +/* query sysDescr */
 +OID = "​.1.3.6.1.2.1.1.1.0";​
 +
 +ret = nb_snmp_get(OID);​
 +
 +if (is_void(ret)) {
 +    nb_syslog("​unable to query OID %s", OID);
 +    exit(1);
 +} else if (is_int(ret)) {
 +    nb_syslog("​OID %s returns integer %d", OID, ret);
 +} else if (is_string(ret)) {
 +    nb_syslog("​OID %s returns string '​%s'",​ OID, ret);
 +}
 +
 +
 +/* set an arbitrary entity */
 +OID = "​.1.2.3.4.5";​
 +
 +if (nb_snmp_set(OID,​ "​i",​ 1) != 0) {
 +    nb_syslog("​unable to set OID %s", OID);
 +    exit(1);
 +}
 +
 +exit(0);
 +</​code>​