The -c public switch passes the community string public to the snmpget command.$ /opt/OV/bin/snmpget -c public orarouter1 .1.3.6.1.2.1.1.4.0 system.sysContact.0 : DISPLAY STRING- (ascii): ORA IT Group
TIP: Keep in mind that your devices shouldn't use the same (default) community strings that are used within this book. In addition, using the same string for the read-only (snmpget) and read-write (snmpset) communities is a poor idea.Now let's run the OpenView snmpsetcommand. This command takes the value specified in quotes on the command line and uses it to set the object indicated by the given OID. Use the same OID (system.sysContact.0). Since the new value for sysContact contains words and possibly numbers, we must also specify the variable type octetstring.[34] Run the OpenView snmpset command with the following parameters:
[34]If you read RFC 1213 (MIB-II) you will note that sysLocation has a SYNTAX of DisplayString. This is really a textual convention of type OCTET STRING with a size of 0..255 octets.
The result shows that snmpset successfully changed the router's contact person to Meg A. Byte 555-1212. If you don't see this result, the set was not successful. Table 8-2 shows some of the common error messages you might receive, and steps you can take to correct the problems. To confirm the value the device has stored in sysContact, we can repeat the snmpget command. If we use OpenView's GUI, things start to get a bit easier to see, set, and confirm. Use the GUI to getthe value of sysContact. Once you have confirmed that a value is there, type a description in the SNMP Set Value text box. Since there is only one instance for sysContact, you have to insert a 0 (zero) for the MIB Instance. After you have completed all the required input items, click on the "Set" button located to the right of the "SNMP Set Value" text box. You should see a pop-up window that reads "Set has completed successfully." To verify that the set actually occurred, click on "Start Query." (It should be apparent to you by now that using a GUI such as OpenView's MIB Browser program makes getting and setting MIB objects much easier.) To show how this can be done programmatically, we will write another small Perl script, named snmpset.pl:$ /opt/OV/bin/snmpset -c private orarouter1 .1.3.6.1.2.1.1.4.0 \ octetstring "Meg A. Byte 555-1212" system.sysContact.0 : DISPLAY STRING- (ascii): Meg A. Byte 555-1212
Let's run this script:#!/usr/local/bin/perl #filename: /opt/local/perl_scripts/snmpset.pl use SNMP_util; $MIB1 = ".1.3.6.1.2.1.1.6.0"; $HOST = "oraswitch2"; $LOC = "@ARGV"; ($value) = &snmpset("private\@$HOST","$MIB1",'string',"$LOC"); if ($value) { print "Results :$MIB1: :$value:\n"; } else { warn "No response from host :$HOST:\n"; }
Using the snmpget.pl script, we can verify that the set took place:$ /opt/local/perl_scripts/snmpset.pl A bld JM-10119 floor 7 Results :.1.3.6.1.2.1.1.6.0: :A bld JM-10119 floor 7:
Now we'll use the Net-SNMP snmpset utility to change the system contact:$ /opt/local/perl_scripts/snmpget.pl .1.3.6.1.2.1.1.6.0 public@oraswitch2 Results :.1.3.6.1.2.1.1.1.0: :A bld JM-10119 floor 7:
There's nothing really confusing here. We supplied a community string, a hostname, and an object ID, followed by a datatype (s for String) and the new value of sysContact. Just to convince ourselves that the set actually took place, we followed it with an snmpget. The only additional thing you need to know is the mechanism for specifying datatypes. Net-SNMP uses the single-character abbreviations shown in Table 8-1.$ snmpset oraswitch2 private sysContact.0 s myself system.sysContact.0 = myself $ snmpget oraswitch2 public sysContact.0 system.sysContact.0 = myself
Abbreviation | Meaning |
---|---|
a | IP address |
b[35] | Bits |
d | Decimal string |
D | Double |
F | Float |
i | Integer |
I | Signed int64 |
n | Null |
o | Object ID |
s | String |
t | Time ticks |
u | Unsigned integer |
U | Unsigned int64 |
x | Hexadecimal string |
[35]While the manpages show this as a valid datatype, the help output from the command does not.
Copyright © 2002 O'Reilly & Associates. All rights reserved.