Since 1.2.3i1 version, check_mk include a very interesting plugin to check vSphere ESXi servers. We can read documentation about this fantastic plugin in official check_mk page.
Check_mk vSphere plugin allow to access ESXi data directly from ESXi servers or via vCenter.
Let’s see how to do the configuration of the vSphere ESXi, and vCenter servers check_mk plugin.
Create user and profile in ESXi server and/or vCenter.
Fist of all we must create a user and a role with appropriate permissions. It is very important to use the necessary permissions only. We will explain the steps necessary to create users in vCenter and / or ESXi servers.
You must create a local user on the ESXi. This is done by connecting directly with viClient against ESXi (this can probably also be done with scripts). This step is only for ESXi servers. Vcenter use users from local system or a directory as Active Directory.
We will create the local user (tab “Local Users & Groups”), e.g., “nagios”:
We must create e.g. the Role “Monitoring” from Menu / Home / Roles / Add Role (mark only within Section “Host” the “CIM” option. This step is identical for both the ESXi server and the vCenter.
We assign the Monitor role to Nagios user. In the “Permissions” tab, right-click “Add permission”, select “nagios” user and “Monitoring” role. This step is identical for both the ESXi host to the vCenter.
In this way we have created our user with access only to the properties of servers accessible by CIM.
Prerequisites in Nagios / check_mk server to run vSphere CMK plugin.
To work CMK vSphere specific plugin only demands a prerequisite. You need to first install “pysphere-0.1.7” (Python API for interaction With the vSphere Web Services SDK). º
It seems necessary only to connect with vCenter but not to connect directly with ESXi servers. In a Centos with EPEL repositories configured would be as simple as:
yum install python-pip.noarch easy_install -U pysphere
Of course.Yo need a running install of Nagios + Check_mk. This post can be interesting about this.
Before configuring checks in CMK we can test the plugin in command line to verify that it works and return data. Normally, the binary “agent_vsphere” will be in the location: /usr/share/ check_mk/agents/special. Examples for our “nagios” user password “PASSWORD”:
Against vCenter (if we created the user in vCenter)
./agent_vsphere -u 'nagios' -s 'PASSWORD' -i hostsystem --hostname 'esxi-0005.midominio.es' --timeout 5 vcenter5.midominio.es
Against a Esxi server (user having previously created on ESXi as indicated)
./agent_vsphere -u 'nagios' -s 'PASSWORD' -i hostsystem,datastore,counters --direct --timeout 5 esxi-0005.midominio.es
With -i option we define the options to inventory different information (hostsystem, virtualmachine, datastore, counters). We can get info about virtual machines too.
Objects configuration in Check_mk.
The configuration can be done in CMK graphical interface WATO or directly in configuration files as in our case. CMK use special agents config for this plugin.
The following definition applies to to hosts that have the tag “esxi”. It use user “nagios” and the password “PASSWORD” and get next information (hostsystems, datastore, counters, …)
datasource_programs.append(( "/usr/share/check_mk/agents/special/agent_vsphere -u 'nagios' -s 'PASSWORD' " "-i hostsystem,datastore,counters --direct " "--hostname '<HOST>' --timeout 5 <IP>", ["esxi"], ALL_HOSTS ))
Esxi Hosts defined objects must have an identification tag “esxi” in the form:
all_hosts += [ 'esx-0001.midominio.es|esxi|cpd2', 'esx-0002.midominio.es|esxi|cpd2', 'esx-0005.midominio.es|esxi|cpd2', ]
Finally you only need to scan your ESXi hosts from CMK and restart it. As always with:
cmk -I hostname
This article is a translation of the original in spanish: