Nagios – Monitor VMware vSphere Hypervisor 5.5
Proviamo a monitare tramite nagios un server su cui è installato un VMWare vSphere Hypervisor (ESXi) 5.5; installiamo prima di tutto i prerequisiti:
# yum -y install openssl-devel perl-Archive-Zip perl-Class-MethodMaker \ uuid-perl perl-SOAP-Lite perl-XML-SAX perl-XML-NamespaceSupport \ perl-XML-LibXML perl-MIME-Lite perl-MIME-Types perl-MailTools perl-TimeDate \ uuid libuuid perl-Data-Dump perl-UUID cpan perl-Crypt-SSLeay \ perl-Params-Validate perl-YAML perl-Config-Tiny # cpan Test::More # cpan Nagios::Plugin
È necessario installare il vSphere SDK for Perl 5.5 versione 64 bit; una volta scaricato dal sito della VMWare e messo il package nella directory /usr/src, provvediamo ad installarlo:
# cd /usr/src # tar xvfz VMware-vSphere-Perl-SDK-5.5.0-1384587.x86_64.tar.gz # cd vmware-vsphere-cli-distrib/ # ./vmware-install.pl
Copiamo il seguente script nella directory dei plugins (/usr/local/nagios/libexec); questo è il comando principale che viene usato per effettuare i check del nostro sistema; cambiamogli i diritti con 755:
# chmod 755 /usr/local/nagios/libexec/check_vmware_api.pl
Definiamo il nostro host; editiamo il nuovo file /usr/local/nagios/etc/objects/esxi.cfg
############################################################################### # HOST DEFINITION ############################################################################### define host{ use linux-server host_name esxi-01 address 192.168.44.44 } ############################################################################### # HOST GROUP DEFINITION ############################################################################### define hostgroup{ hostgroup_name vmware-servers alias VMWare Servers members esxi-01 } ############################################################################### # SERVICESGROUP DEFINITIONS ############################################################################### define servicegroup{ servicegroup_name esxiservice alias ESX/ESXi Services } ############################################################################### # SERVICE DEFINITIONS ############################################################################### define service{ use local-service host_name esxi-01 service_description PING check_command check_ping!100.0,20%!500.0,60% } #============== VMWare Service check # check cpu define service{ use generic-service host_name esxi-01 service_description ESXi CPU Load check_command check_esx_cpu!80!90 servicegroups esxiservice } # check memory usage define service{ use generic-service host_name esxi-01 service_description ESXi Memory usage check_command check_esx_mem!80!90 servicegroups esxiservice } # check net define service{ use generic-service host_name esxi-01 service_description ESXi Network usage check_command check_esx_net!102400!204800 servicegroups esxiservice } # check runtime status define service{ use generic-service host_name esxi-01 service_description ESXi Runtime status check_command check_esx_runtime servicegroups esxiservice } # check io read define service{ use generic-service host_name esxi-01 service_description ESXi IO read check_command check_esx_ioread!40!90 servicegroups esxiservice } # check io write define service{ use generic-service host_name esxi-01 service_description ESXi IO write check_command check_esx_iowrite!40!90 servicegroups esxiservice }
Facciamo in modo che nagios carichi la nuova configurazione, inserendo nel file /usr/local/nagios/etc/nagios.cfg la seguente riga:
cfg_file=/usr/local/nagios/etc/objects/esxi.cfg
Modifichiamo il file /usr/local/nagios/etc/resource.cfg per inserire all’interno le credenziali di accesso al server esxi, affinchè possano essere usate al momento del check (USER11 è la username e USER12 è la password):
$USER11$=root $USER12$=123456
Aggiungiamo al file dei comandi (/usr/local/nagios/etc/objects/commands.cfg) le seguenti sezioni:
# ESXi 5.5 TEST COMMAND # check cpu define command{ command_name check_esx_cpu command_line $USER1$/check_vmware_api.pl -H $HOSTADDRESS$ -u $USER11$ -p $USER12$ -l cpu -s usage -w $ARG1$ -c $ARG2$ } # check memory usage define command{ command_name check_esx_mem command_line $USER1$/check_vmware_api.pl -H $HOSTADDRESS$ -u $USER11$ -p $USER12$ -l mem -s usage -w $ARG1$ -c $ARG2$ } # check net usage define command{ command_name check_esx_net command_line $USER1$/check_vmware_api.pl -H $HOSTADDRESS$ -u $USER11$ -p $USER12$ -l net -s usage -w $ARG1$ -c $ARG2$ } # check runtime status define command{ command_name check_esx_runtime command_line $USER1$/check_vmware_api.pl -H $HOSTADDRESS$ -u $USER11$ -p $USER12$ -l runtime -s status } # check io read define command{ command_name check_esx_ioread command_line $USER1$/check_vmware_api.pl -H $HOSTADDRESS$ -u $USER11$ -p $USER12$ -l io -s read -w $ARG1$ -c $ARG2$ } # check io write define command{ command_name check_esx_iowrite command_line $USER1$/check_vmware_api.pl -H $HOSTADDRESS$ -u $USER11$ -p $USER12$ -l io -s write -w $ARG1$ -c $ARG2$ }
Testiamo se la configurazione appena creata abbia dei problemi, ed in caso negativo, ricarichiamo la configurazione del nagios:
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg # service nagios reload
La soluzione finale sarà la seguente: