Monitor oVirt or libvirt with SNMP and Zabbix

Somehow, I expected to have little to no work when I wanted to monitor an oVirt host over SNMP. One would expect this since oVirt is the upstream project for Red Hat’s Enterprise Virtualization (RHEV) which seems to be quite strong in the market. While it isn’t that hard to get information about using SNMP for oVirt or libvirt the outcome can be disappointing. There is some documentation about it but here you can find a more hands-on explanation.

Personally, I have a love-hate relationship with SNMP. While most products support SNMP and it gives you an quick way to monitor something, it can be a real pain in the ass the get the information which you want and how you want out of something. Especially in combination with non-existing Zabbix templates…

It’s clear that an oVirt (or libvirt) host needs some monitoring. By monitoring the underlying Linux OS, as you would do with any other Linux installation, you can already get a lot of useful information but there is just that little bit of hypervisor specific information that’s missing. Unfortunately, the possibilities to monitor libvirt over SNMP are rather poor but let’s stay positive and take what we can get.

Official documentation for libvirt-SNMP can be found here: http://wiki.libvirt.org/page/Libvirt-snmp

Access to libvirt on an oVirt host

By default, users do not have access to libvirt, for example with virsh, on an oVirt machine. This is a good thing since you want to control your VM’s and everything around it in a single, consistent, place. In order for us to get the correct information over SNMP, the SNMP subagent for libvirt will require access.

As you can see, by default, libvirt is asking us to authenticate before we can get some information via virsh. Even when we run the command as root.

The SNMP subagent which we will install later, will run as root, that’s a requirement for it to correctly communicate with the “normal” snmpd. Logically, the subagent will require access to libvirt to get information and entering a username and password each time we start the subagent isn’t really an option.

To allow access, edit /etc/libvirt/libvirtd.conf, don’t forget to take a backup before you do so :)

Uncomment the the auth_unix_rw = “none” parameter in the file.

After saving the changes, restart libvirtd (it seems that a reload is not working). In my experience this didn’t cause my virtual machines to stop or pause so it could be used (with care) in a production environment.

After restarting, let’s test to see if root has proper access to libvirt:

The communication with libvirt will be done using unix-sockets, which is basically a file. As we can see, root will have access after our changes. If we would like to give access to other users, we can add them to the group-owner (qemu).

To test this with group ownership, let’s add the current non-superuser to the group:

In order for the group membership to become active, we need to reloging or just su to ourselves:

As you can see, the user jensd has access to libvirt now too.

Install and configure SNMPd

Since we want to monitor libvirt over SNMP, we need to install a basic SNMP agent on our host in order to have SNMP working.

Install the required packages from the repositories:

Configure the SNMP daemon for read-only access to our system: edit  /etc/snmp/snmpd.conf to look like this:

As you can see, I’ve chosen to use the communitystring “public” for read-only access. The rest of the snmpd.conf is rather basic except for the last line. Since we want to monitor libvirt via an SNMP subagent, we need AgentX master support in the “normal” snmpd daemon.

After saving the config, let’s start snmpd:

As you can see in the syslog, AgentX master support was turned on.

To get information over SNMP from another machine, we need to open UDP port 161 in our firewall:

Install and configure libvirt-snmp

There are two options to install libvirt-snmp. Libvirt-snmp can be found in the Base repository of CentOS and RHEL but there is a newer version which claims to fix some bugs available.

I’ll continue with the version from the repositories but added a walk trough on how to use the newer version in the end of this post. So if you feel like you would like to use the newer version, execute the steps listed in the end and come back to this point to continue.

Let’s start by installing the libvirt-snmp package from the repositories (skip this if you want the newer version):

The package is rather basic and doesn’t provide an init-script so we’ll create one ourselves. Since oVirt is still recommending to run on CentOS 6, I didn’t choose to create a systemd-service file.

Create /etc/init.d/ovirt-snmp with the following contents:

After saving the script, which is quite basic (and dirty), let’s install and activate the service:

Test libvirt-snmp

No that we got all components installed and running, we can test getting libvirt or ovirt information over SNMP using snmpwalk:

To get a more nice output for the above, we van use snmptable:

In case you want to get the information from another host that doesn’t have the libvirtMIB installed, you can download it here: http://jensd.be/download/LIBVIRT-MIB.txt or use the OID .1.3.6.1.4.1.12345

Monitor oVirt or libvirt with Zabbix

To monitor this information from within Zabbix, I created a Zabbix-template. You can download it from the Zabbix templates website or directly from: http://jensd.be/download/Zabbix_ovirt_template.zip Don’t forget to read the readme and create the value mapping before importing the template.

Compile and install the latest version of libvirt-snmp

As mentioned earlier in the post, there is a newer version of libvirt-snmp available that isn’t in the official repositories yet. You can follow these steps to download, build and install it. The build-script generates an RPM together with the binaries so it’s recommended to build the RPM on another system to keep your oVirt-host clean.

Install the required packages in order to build libvirt-snmp:

Then, download the latest version, either from the GIT-repository of libvirt of from here: http://jensd.be/download/libvirt-snmp-latest.tar.gz. After downloading, untar the file:

Now, cd into the directory which was untarred and execute the autobuild.sh script:

When the build finishes successfully, you can find the binary files in build/srv:

The autobuild.sh-script also create an RPM in ~/rpmbuild which is easier to install (and remove) on RHEL-based systems:

To install the RPM on this or another system:

9 thoughts on “Monitor oVirt or libvirt with SNMP and Zabbix

    • Seems like a good idea, I’ve worked on an ESX template in the past too, I’ll see if I can find some time to put both of them there.

    • By default there is no information supplied over SNMP by oVirt. libvirt-snmp is a service/daemon that will pass that infor over SNMP.

  1. Hi
    How does one correlate the traps from underlying physical host and the VM in problem? Does the template provide that info?

    • The template only looks after information provided by libvirt-snmp. In Zabbix, you can add the oVirt template together with another that is responsible for information about the physical system.

  2. Hi,
    I’ve tried to use your template on Zabbix 3.0 but I just don’t get any informations. I’ve setup libvirt-snmp correctly since using snmpwalk from the zabbix works perfectly.
    The OIDs seems correct but I think there must be something wrong with the discovery rules.

    Rgds

    • Probably it is because macro {$SNMP_COMMUNITY}=servers attach to the template, I had wasted some time before noticed this )

Leave a Reply

Your email address will not be published. Required fields are marked *