Friday, February 19, 2010

Get VMware configuration info from SNMP (quick and easy)

Here are the steps I use to get SNMP working for ESX 3.5 and 4.0 so I can get some basic configuration information about the running virtual machines. I'm working on a script to auto-create parent rules for Nagios monitoring and it would be helpful for Nagios to know which VMs were on which ESX host.

First, you need to tell the firewall to allow SNMP traffic, if it's not already allowed.

Is SNMP enabled?
[root@esxserver root]# iptables -L |grep snmp

To enable SNMP:
[root@esxserver root]# esxcfg-firewall -e snmpd

v 3.5
In 3.5, you need to load a module to get at the VMware specific information.
Just edit /etc/snmp/snmpd.conf and add:

dlmod SNMPESX /usr/lib/vmware/snmp/libSNMPESX.so

And then all you need to do is restart SNMP
[root@esxserver root]# service snmpd restart

v 4.0
In v4.0, you have to proxy the SNMP request to the VMware snmp agent.

First configure the net-snmp. In /etc/snmp/snmpd.conf add this line

proxy -v 1 -c public udp:127.0.0.1:171 .1.3.6.1.4.1.6876

Then we have to configure vmware. For some reason I was unable to use the command line which is the preferred method. All the command line does is edit this XML file, /etc/vmware/snmp.xml.

<config>
<snmpSettings>
<communities>public</communities>
<enable>true</enable>
<port>171</port>
<targets>127.0.0.1</targets>
</snmpSettings>
</config>


We are telling the VMware agent to listen on port 171 so it doesn't conflict with regular SNMP, and since we proxy this through Net-SNMP, we only need to listen to localhost.

Now restart the vmware and snmp services.

[root@esxserver root]# service mgmt-vmware restart
[root@esxserver root]# service snmpd restart

Test your setup
I just want a list of what servers are running on what hosts so I run this command

snmpwalk -v2c -c public esxserver .1.3.6.1.4.1.6876.2.1.1.2

If you want to see everything this has to offer, here is the top level.

snmpwalk -v2c -c public esxserver .1.3.6.1.4.1.6876

If you don't like seeing the cryptic numbers and want what you are seeing translated to something you might be able to understand, you need to copy the VMware mibs to /usr/share/snmp/mibs and add the -m switch.

snmpwalk -v2c -c public -m ALL esxserver .1.3.6.1.4.1.6876

I include all mibs just to make it easy, but you can specify specific MIBs to translate.

0 comments: