SysMan Mall

« Sun Management Cente... | Main | SNMPv3 in Sun MC... »

http://blogs.sun.com/adikhit/date/20060926 Tuesday September 26, 2006

Getting the OS version using SNMP

Having information about the operating system a server is running comes in handy,  specially if a quick job requires one to test/ build something on a specific version of an OS. It is very easy to correlate with such a situation in our day to day life.

Most of the OSs run some flavor of SNMP agent which can be leveraged to our advantage in figuring out what Operating System is running on a particular server. (There are other cool things one can go figure about the server but that's a different thread). Once we know the Object Identifiers (SNMP way of accessing a variable) to go after, it is very easy to convert the basic semantic into a script. The script in turn can be consumed by a management application like Sun Management Center to program and automate the whole process.

In addition to Object Identifier one also needs security credentials to perform gets on these agents from remote. On servers running Solaris  9 and below where the SunMC agent is not running, the way to get information is using SNMP get operation on sunMIB.sunSystem.motd Object Identifier.  Something as shown below using net-snmp utilities under /usr/sfw/bin directory on a Solaris 10 system can be used for querying OS type and version.

$ snmpget -v1 -c public <hostName>:<portNo>  1.3.6.1.4.1.42.3.1.3.0
SNMPv2-SMI::enterprises.42.3.1.3.0 = STRING: "Sun Microsystems Inc..SunOS 5.9.Generic.May 2002."
Solaris 10 comes with Solaris Management Agent which stores OS information in sysDescr OID that can be queried as shown below
$  snmpget -v1 -c public <hostName>:<portNo> 1.3.6.1.2.1.1.1.0
SNMPv2-MIB::sysDescr.0 = STRING: SunOS rm1-rack10-v880 5.10 Generic sun4u
In case one is running Sun Management Center agents on any of Solaris 7 through Solaris 10 system or one of the supported Linux flavor you can simply query the following Object identifier to get the running OS information
$  snmpget -v1 -c public <hostName>:<portNo> 1.3.6.1.4.1.42.2.12.2.1.2.1.3.0
..
and you'll see response as shown below depending upon the OS type
SNMPv2-SMI::enterprises.42.2.12.2.1.2.1.3.0 = STRING: "SunOS 5.10, Generic"
or
SNMPv2-SMI::enterprises.42.2.12.2.1.2.1.3.0 = STRING: "SunOS 5.9, Generic"
or
SNMPv2-SMI::enterprises.42.2.12.2.1.2.1.3.0 = STRING: "Linux 2.4.21-4.ELsmp, #1 SMP Fri Oct 3 17:52:56 EDT 2003"
Its possible that in some of the environment SNMP v1 access is restricted/ disabled in which case SNMPv3 options of the net-snmp utility can be used. Use of SNMPv3 will require knowledge of users configured to access the above mentioned Object Identifiers along with their passphrases or keys. An example of a get using SNMPv3 is as shown below when the query is directed to a  Sun Management Center agent.
$ snmpget -v3 -a MD5 -A <digestPassPhrase> -x DES -X <privacyPassPhrase> -l authPriv -u <userName> <hostName>:<portNo>  1.3.6.1.4.1.42.2.12.2.1.2.1.3.0

The SNMPv3 operations will work for OIDs of SunMC agent and SMA on Solaris 10 only.

To convert all this into a script, will require logic to try non SunMC OIDs first, and if those fail to evoke a response, then send queries using SunMC OIDs.

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed

Valid HTML! Valid CSS!

This is a personal weblog, I do not speak for my employer.