VMWare

check_vmware_api

Description:

check_vmware_api (former check_esx3) is a Nagios plugin made by op5 AB to monitor vmware’s products.

The plugin uses the VMWare API (via HTTPS) to do a wide variety of checks. You can check out the latest version with GIT at git://git.op5.org/nagios/op5plugins.git Requires the Nagios::Plugin CPAN module as well as the “VMware Infrastructure (VI) Perl Toolkit Packages” available from http://www.vmware.com/download/sdk/ See http://www.op5.com/support/documentation/how-to/400-monitoring-vmware-esx-3x-and-vmware-esxi for Nagios Command definitions, although the latest version of the script supports additional checks which aren’t listed on that webpage yet, so you’ll probably need to make a few more up.

Current Version

Last Release Date

June 12, 2009

Compatible With

Owner

op5


Project Notes
./check_vmware_api --help check_vmware_api 0.6.0 This nagios plugin is free software, and comes with ABSOLUTELY NO WARRANTY. It may be used, redistributed and/or modified under the terms of the GNU General Public Licence (see http://www.fsf.org/licensing/licenses/gpl.txt). VMWare Infrastructure plugin Usage: check_vmware_api -D | -H [ -C ] [ -N ] -u -p | -f -l [ -s ] [ -T ] [ -i ] [ -x ] [ -o ] [ -t ] [ -w ] [ -c ] [ -V ] [ -h ] -?, --usage Print usage information -h, --help Print detailed help screen -V, --version Print version information --extra-opts=[
[@]] Section and/or config_file from which to load extra options (may repeat) -H, --host= ESX or ESXi hostname. -C, --cluster= ESX or ESXi clustername. -D, --datacenter= Datacenter hostname. -N, --name= Virtual machine name. -u, --username= Username to connect with. -p, --password= Password to use with the username. -f, --authfile= Authentication file with login and password. File syntax : username= password= -w, --warning=THRESHOLD Warning threshold. See http://nagiosplug.sourceforge.net/developer-guidelines.html#THRESHOLDFORMAT for the threshold format. -c, --critical=THRESHOLD Critical threshold. See http://nagiosplug.sourceforge.net/developer-guidelines.html#THRESHOLDFORMAT for the threshold format. -l, --command=COMMAND Specify command type (CPU, MEM, NET, IO, VMFS, RUNTIME, ...) -s, --subcommand=SUBCOMMAND Specify subcommand -S, --sessionfile=SESSIONFILE Specify a filename to store sessions for faster authentication -x, --exclude= Specify black list -o, --options= Specify additional command options (quickstats, ...) -T, --timestamp= Timeshift in seconds that could fix issues with "Unknown error". Use values like 5, 10, 20, etc -i, --interval= Sampling Period in seconds. Basic historic intervals: 300, 1800, 7200 or 86400. See config for any changes. Default value is 20 (realtime). Since cluster don't have realtime stats interval other than 20 is mandatory --trace= Set verbosity level of vSphere API request/respond trace -t, --timeout=INTEGER Seconds before plugin times out (default: 30) -v, --verbose Show details for command-line debugging (can repeat up to 3 times) Supported commands(^ means blank or not specified parameter) : Common options for VM, Host and DC : * cpu - shows cpu info + usage - CPU usage in percentage + usagemhz - CPU usage in MHz ^ all cpu info * mem - shows mem info + usage - mem usage in percentage + usagemb - mem usage in MB + swap - swap mem usage in MB + overhead - additional mem used by VM Server in MB + overall - overall mem used by VM Server in MB + memctl - mem used by VM memory control driver(vmmemctl) that controls ballooning ^ all mem info * net - shows net info + usage - overall network usage in KBps(Kilobytes per Second) + receive - receive in KBps(Kilobytes per Second) + send - send in KBps(Kilobytes per Second) ^ all net info * io - shows disk io info + read - read latency in ms (totalReadLatency.average) + write - write latency in ms (totalWriteLatency.average) ^ all disk io info * runtime - shows runtime info + status - overall host status (gray/green/red/yellow) + issues - all issues for the host ^ all runtime info VM specific : * cpu - shows cpu info + wait - CPU wait time in ms + ready - CPU ready time in ms * mem - shows mem info + swapin - swapin mem usage in MB + swapout - swapout mem usage in MB + active - active mem usage in MB * io - shows disk I/O info + usage - overall disk usage in MB/s * runtime - shows runtime info + con - connection state + cpu - allocated CPU in MHz + mem - allocated mem in MB + state - virtual machine state (UP, DOWN, SUSPENDED) + consoleconnections - console connections to VM + guest - guest OS status, needs VMware Tools + tools - VMWare Tools status Host specific : * net - shows net info + nic - makes sure all active NICs are plugged in * io - shows disk io info + aborted - aborted commands count + resets - bus resets count + kernel - kernel latency in ms + device - device latency in ms + queue - queue latency in ms * vmfs - shows Datastore info + (name) - free space info for datastore with name (name) ^ all datastore info * runtime - shows runtime info + con - connection state + health - checks cpu/storage/memory/sensor status + storagehealth - storage status check + temperature - temperature sensors + maintenance - shows whether host is in maintenance mode + list(vm) - list of VMWare machines and their statuses * service - shows Host service info + (names) - check the state of one or several services specified by (names), syntax for (names):,,..., ^ show all services * storage - shows Host storage info + adapter - list bus adapters + lun - list SCSI logical units + path - list logical unit paths * device - shows Host specific device info + cd/dvd - list vm's with attached cd/dvd drives * uptime - shows Host uptime DC specific : * io - shows disk io info + aborted - aborted commands count + resets - bus resets count + kernel - kernel latency in ms + device - device latency in ms + queue - queue latency in ms * vmfs - shows Datastore info + (name) - free space info for datastore with name (name) ^ all datastore info * runtime - shows runtime info + list(vm) - list of VMWare machines and their statuses + listhost - list of VMWare esx host servers and their statuses + listcluster - list of VMWare clusters and their statuses + tools - VMWare Tools status * recommendations - shows recommendations for cluster + (name) - recommendations for cluster with name (name) ^ all clusters recommendations Copyright (c) 2008 op5
Reviews (30) Add a Review
This is deprecated
by damned, September 30, 2021

please use this fork, very cool! https://github.com/BaldMansMojo/check_vmware_esx/



plugin does not exist
by Delg, March 31, 2021

plugin does not exist. op5.org not found.



check_vmware_api slow
by Jenkins, February 28, 2021

I found this api was timing out. My College Rod Zadeh fixed it for us. /dev/random was not returning results on my VM. Fix: " In a nutshell not enough entropy to create a client hash for an outbound SSL connection to the VMWare server. The Net::SSL library accesses /dev/random to get a random number to generate the hash. It should probably use /dev/urandom as this is running on a VM. To fix this I did: yum install rng-tools systemctl enable rngd.service systemctl start rngd.service ~Rod "



Used Reservation of CPU and Memory cluster level
by asharma1, October 31, 2018

Hi Please help me out to collect used reservation of CPU and Memory cluster specific... if possible.



Excelent plugin. I modified the script to monitor cluster nodes through the Datacenter
by Ozz, October 31, 2018

Hi I have modified the script to enable it to monitor cluster nodes using the Datacenter (vcenter) because it was restricted to access directly to each node. The new code is: #!/usr/bin/perl -w # # Nagios plugin to monitor VMware ESX and vSphere servers # # License: GPL # Copyright (c) 2008-2013 op5 AB # Author: Kostyantyn Hushchyn and op5 # # Contributors: # # Patrick Müller, Jeremy Martin, Eric Jonsson, stumpr, # John Cavanaugh, Libor Klepac, maikmayers, Steffen Poulsen, # Mark Elliott, simeg, sebastien.prudhomme, Raphael Schitz, # Mattias Bergsten # # For direct contact with any of the op5 developers, send an email to # op5-users@lists.op5.com # # Discussions are directed to the mailing list op5-users@lists.op5.com, # see http://lists.op5.com/mailman/listinfo/op5-users # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # package CheckVMwareAPI; use strict; use warnings; use vars qw($PROGNAME $VERSION $output $values $result $defperfargs); use Monitoring::Plugin::Functions qw(%STATUS_TEXT); use Monitoring::Plugin; use File::Basename; use HTTP::Date; use Data::Dumper qw(Dumper); use Net::SSL; my $perl_module_instructions=" Download the latest version of the vSphere SDK for Perl from VMware. In this example we use VMware-vSphere-Perl-SDK-5.1.0-780721.x86_64.tar.gz, but the instructions should apply to other versions as well. You may need to install additional packages and Perl modules on your server, see https://kb.op5.com/x/pYEK for more information and package names for op5 APS / CentOS 6 / RHEL 6. Upload the .tar.gz file to your op5 Monitor server's /root dir and execute: cd /root tar xvzf VMware-vSphere-Perl-SDK-5.1.0-780721.x86_64.tar.gz cd vmware-vsphere-cli-distrib/ ./vmware-install.pl Follow the on screen instructions, described below: "Creating a new vSphere CLI installer database using the tar4 format. Installing vSphere CLI 5.1.0 build-780721 for Linux. You must read and accept the vSphere CLI End User License Agreement to continue. Press enter to display it." "Read through the License Agreement" "Do you accept? (yes/no) yes "In which directory do you want to install the executable files? [/usr/bin]" "Please wait while copying vSphere CLI files... The installation of vSphere CLI 5.1.0 build-780721 for Linux completed successfully. You can decide to remove this software from your system at any time by invoking the following command: "/usr/bin/vmware-uninstall-vSphere-CLI.pl". This installer has successfully installed both vSphere CLI and the vSphere SDK for Perl. The following Perl modules were found on the system but may be too old to work with vSphere CLI: Compress::Zlib 2.037 or newer Compress::Raw::Zlib 2.037 or newer version 0.78 or newer IO::Compress::Base 2.037 or newer IO::Compress::Zlib::Constants 2.037 or newer LWP::Protocol::https 5.805 or newer Enjoy, --the VMware team" Note: None of the Perl modules mentioned as "may be too old" are needed for check_vmware_api to work. "; sub main { $PROGNAME = basename($0); $VERSION = '0.7.1'; my $np = Monitoring::Plugin->new( usage => "Usage: %s -D | -H [ -C ] [ -N ] [ -n ]n" . " -u -p | -f n" . " -l [ -s ] [ -T ] [ -i ]n" . " [ -x ] [ -o ]n" . " [ -t ] [ -w ] [ -c ]n" . ' [ -V ] [ -h ]', version => $VERSION, plugin => $PROGNAME, shortname => uc($PROGNAME), blurb => 'VMware ESX/vSphere plugin', extra => "Supported commands(^ - blank or not specified parameter, o - options, T - timeshift value, b - blacklist) :n" . " VM specific :n" . " * cpu - shows cpu infon" . " + usage - CPU usage in percentagen" . " + usagemhz - CPU usage in MHzn" . " + wait - CPU wait time in msn" . " + ready - CPU ready time in msn" . " ^ all cpu info(no thresholds)n" . " * mem - shows mem infon" . " + usage - mem usage in percentagen" . " + usagemb - mem usage in MBn" . " + swap - swap mem usage in MBn" . " + swapin - swapin mem usage in MBn" . " + swapout - swapout mem usage in MBn" . " + overhead - additional mem used by VM Server in MBn" . " + overall - overall mem used by VM Server in MBn" . " + active - active mem usage in MBn" . " + memctl - mem used by VM memory control driver(vmmemctl) that controls ballooningn" . " ^ all mem info(except overall and no thresholds)n" . " * net - shows net infon" . " + usage - overall network usage in KBps(Kilobytes per Second)n" . " + receive - receive in KBps(Kilobytes per Second)n" . " + send - send in KBps(Kilobytes per Second)n" . " ^ all net info(except usage and no thresholds)n" . " * io - shows disk I/O infon" . " + usage - overall disk usage in MB/sn" . " + read - read disk usage in MB/sn" . " + write - write disk usage in MB/sn" . " ^ all disk io info(no thresholds)n" . " * runtime - shows runtime infon" . " + con - connection staten" . " + cpu - allocated CPU in MHzn" . " + mem - allocated mem in MBn" . " + state - virtual machine state (UP, DOWN, SUSPENDED)n" . " + status - overall object status (gray/green/red/yellow)n" . " + consoleconnections - console connections to VMn" . " + guest - guest OS status, needs VMware Toolsn" . " + tools - VMware Tools statusn" . " + issues - all issues for the hostn" . " ^ all runtime info(except con and no thresholds)n" . " Host specific :n" . " * cpu - shows cpu infon" . " + usage - CPU usage in percentagen" . " o quickstats - switch for query either PerfCounter values or Runtime infon" . " + usagemhz - CPU usage in MHzn" . " o quickstats - switch for query either PerfCounter values or Runtime infon" . " ^ all cpu infon" . " o quickstats - switch for query either PerfCounter values or Runtime infon" . " * mem - shows mem infon" . " + usage - mem usage in percentagen" . " o quickstats - switch for query either PerfCounter values or Runtime infon" . " + usagemb - mem usage in MBn" . " o quickstats - switch for query either PerfCounter values or Runtime infon" . " + swap - swap mem usage in MBn" . " o listvm - turn on/off output list of swapping VM'sn" . " + overhead - additional mem used by VM Server in MBn" . " + overall - overall mem used by VM Server in MBn" . " + memctl - mem used by VM memory control driver(vmmemctl) that controls ballooningn" . " o listvm - turn on/off output list of ballooning VM'sn" . " ^ all mem info(except overall and no thresholds)n" . " * net - shows net infon" . " + usage - overall network usage in KBps(Kilobytes per Second)n" . " + receive - receive in KBps(Kilobytes per Second)n" . " + send - send in KBps(Kilobytes per Second)n" . " + nic - makes sure all active NICs are plugged inn" . " ^ all net info(except usage and no thresholds)n" . " * io - shows disk io infon" . " + aborted - aborted commands countn" . " + resets - bus resets countn" . " + read - read latency in ms (totalReadLatency.average)n" . " + write - write latency in ms (totalWriteLatency.average)n" . " + kernel - kernel latency in msn" . " + device - device latency in msn" . " + queue - queue latency in msn" . " ^ all disk io infon" . " * vmfs - shows Datastore infon" . " + (name) - free space info for datastore with name (name)n" . " o used - output used space instead of freen" . " o brief - list only alerting volumesn" . " o regexp - whether to treat name as regexpn" . " o blacklistregexp - whether to treat blacklist as regexpn" . " b - blacklist VMFS'sn" . " T (value) - timeshift to detemine if we need to refreshn" . " ^ all datastore infon" . " o used - output used space instead of freen" . " o brief - list only alerting volumesn" . " o blacklistregexp - whether to treat blacklist as regexpn" . " b - blacklist VMFS'sn" . " T (value) - timeshift to detemine if we need to refreshn" . " * runtime - shows runtime infon" . " + con - connection staten" . " + health - checks cpu/storage/memory/sensor status and propagates worst staten" . " o listitems - list all available sensors(use for listing purpose only)n" . " o blackregexpflag - whether to treat blacklist as regexpn" . " b - blacklist status objectsn" . " + storagehealth - storage status checkn" . " o blackregexpflag - whether to treat blacklist as regexpn" . " b - blacklist status objectsn" . " + temperature - temperature sensorsn" . " o blackregexpflag - whether to treat blacklist as regexpn" . " b - blacklist status objectsn" . " + sensor - threshold specified sensorn" . " + maintenance - shows whether host is in maintenance moden" . " o maintwarn - sets warning state when host is in maintenance moden" . " o maintcrit - sets critical state when host is in maintenance moden" . " + list(vm) - list of VMware machines and their statusesn" . " + status - overall object status (gray/green/red/yellow)n" . " + issues - all issues for the hostn" . " b - blacklist issuesn" . " ^ all runtime info(health, storagehealth, temperature and sensor are represented as one value and no thresholds)n" . " * service - shows Host service infon" . " + (names) - check the state of one or several services specified by (names), syntax for (names):,,...,n" . " ^ show all servicesn" . " * storage - shows Host storage infon" . " + adapter - list bus adaptersn" . " b - blacklist adaptersn" . " + lun - list SCSI logical unitsn" . " b - blacklist LUN'sn" . " + path - list logical unit pathsn" . " b - blacklist pathsn" . " ^ show all storage infon" . " * uptime - shows Host uptimen" . " o quickstats - switch for query either PerfCounter values or Runtime infon" . " * device - shows Host specific device infon" . " + cd/dvd - list vm's with attached cd/dvd drivesn" . " o listall - list all available devices(use for listing purpose only)n" . " DC specific :n" . " * cpu - shows cpu infon" . " + usage - CPU usage in percentagen" . " o quickstats - switch for query either PerfCounter values or Runtime infon" . " + usagemhz - CPU usage in MHzn" . " o quickstats - switch for query either PerfCounter values or Runtime infon" . " ^ all cpu infon" . " o quickstats - switch for query either PerfCounter values or Runtime infon" . " * mem - shows mem infon" . " + usage - mem usage in percentagen" . " o quickstats - switch for query either PerfCounter values or Runtime infon" . " + usagemb - mem usage in MBn" . " o quickstats - switch for query either PerfCounter values or Runtime infon" . " + swap - swap mem usage in MBn" . " + overhead - additional mem used by VM Server in MBn" . " + overall - overall mem used by VM Server in MBn" . " + memctl - mem used by VM memory control driver(vmmemctl) that controls ballooningn" . " ^ all mem info(except overall and no thresholds)n" . " * net - shows net infon" . " + usage - overall network usage in KBps(Kilobytes per Second)n" . " + receive - receive in KBps(Kilobytes per Second)n" . " + send - send in KBps(Kilobytes per Second)n" . " ^ all net info(except usage and no thresholds)n" . " * io - shows disk io infon" . " + aborted - aborted commands countn" . " + resets - bus resets countn" . " + read - read latency in ms (totalReadLatency.average)n" . " + write - write latency in ms (totalWriteLatency.average)n" . " + kernel - kernel latency in msn" . " + device - device latency in msn" . " + queue - queue latency in msn" . " ^ all disk io infon" . " * vmfs - shows Datastore infon" . " + (name) - free space info for datastore with name (name)n" . " o used - output used space instead of freen" . " o brief - list only alerting volumesn" . " o regexp - whether to treat name as regexpn" . " o blacklistregexp - whether to treat blacklist as regexpn" . " b - blacklist VMFS'sn" . " T (value) - timeshift to detemine if we need to refreshn" . " ^ all datastore infon" . " o used - output used space instead of freen" . " o brief - list only alerting volumesn" . " o blacklistregexp - whether to treat blacklist as regexpn" . " b - blacklist VMFS'sn" . " T (value) - timeshift to detemine if we need to refreshn" . " * runtime - shows runtime infon" . " + list(vm) - list of VMware machines and their statusesn" . " + listhost - list of VMware esx host servers and their statusesn" . " + listcluster - list of VMware clusters and their statusesn" . " + tools - VMware Tools statusn" . " b - blacklist VM'sn" . " + status - overall object status (gray/green/red/yellow)n" . " + issues - all issues for the hostn" . " b - blacklist issuesn" . " ^ all runtime info(except cluster and tools and no thresholds)n" . " * recommendations - shows recommendations for clustern" . " + (name) - recommendations for cluster with name (name)n" . " ^ all clusters recommendationsn" . " Cluster specific :n" . " * cpu - shows cpu infon" . " + usage - CPU usage in percentagen" . " + usagemhz - CPU usage in MHzn" . " ^ all cpu infon" . " * mem - shows mem infon" . " + usage - mem usage in percentagen" . " + usagemb - mem usage in MBn" . " + swap - swap mem usage in MBn" . " o listvm - turn on/off output list of swapping VM'sn" . " + memctl - mem used by VM memory control driver(vmmemctl) that controls ballooningn" . " o listvm - turn on/off output list of ballooning VM'sn" . " ^ all mem info(plus overhead and no thresholds)n" . " * cluster - shows cluster services infon" . " + effectivecpu - total available cpu resources of all hosts within clustern" . " + effectivemem - total amount of machine memory of all hosts in the clustern" . " + failover - VMware HA number of failures that can be toleratedn" . " + cpufairness - fairness of distributed cpu resource allocationn" . " + memfairness - fairness of distributed mem resource allocationn" . " ^ only effectivecpu and effectivemem values for cluster servicesn" . " * runtime - shows runtime infon" . " + list(vm) - list of VMware machines in cluster and their statusesn" . " + listhost - list of VMware esx host servers in cluster and their statusesn" . " + status - overall cluster status (gray/green/red/yellow)n" . " + issues - all issues for the clustern" . " b - blacklist issuesn" . " ^ all cluster runtime infon" . " * vmfs - shows Datastore infon" . " + (name) - free space info for datastore with name (name)n" . " o used - output used space instead of freen" . " o brief - list only alerting volumesn" . " o regexp - whether to treat name as regexpn" . " o blacklistregexp - whether to treat blacklist as regexpn" . " b - blacklist VMFS'sn" . " T (value) - timeshift to detemine if we need to refreshn" . " ^ all datastore infon" . " o used - output used space instead of freen" . " o brief - list only alerting volumesn" . " o blacklistregexp - whether to treat blacklist as regexpn" . " b - blacklist VMFS'sn" . " T (value) - timeshift to detemine if we need to refreshn" . "nnCopyright (c) 2008-2013 op5", timeout => 30, ); $np->add_arg( spec => 'host|H=s', help => "-H, --host=n" . ' ESX or ESXi hostname.', required => 0, ); $np->add_arg( spec => 'cluster|C=s', help => "-C, --cluster=n" . ' ESX or ESXi clustername.', required => 0, ); $np->add_arg( spec => 'datacenter|D=s', help => "-D, --datacenter=n" . ' Datacenter hostname.', required => 0, ); $np->add_arg( spec => 'name|N=s', help => "-N, --name=n" . ' Virtual machine name.', required => 0, ); $np->add_arg( spec => 'node|n=s', help => "-n, --name=n" . ' cluster Node.', required => 0, ); $np->add_arg( spec => 'username|u=s', help => "-u, --username=n" . ' Username to connect with.', required => 0, ); $np->add_arg( spec => 'password|p=s', help => "-p, --password=n" . ' Password to use with the username.', required => 0, ); $np->add_arg( spec => 'authfile|f=s', help => "-f, --authfile=n" . " Authentication file with login and password. File syntax :n" . " username=n" . ' password=', required => 0, ); $np->add_arg( spec => 'warning|w=s', help => "-w, --warning=THRESHOLDn" . " Warning threshold. Seen" . " http://nagiosplug.sourceforge.net/developer-guidelines.html#THRESHOLDFORMATn" . ' for the threshold format. By default, no threshold is set.', required => 0, ); $np->add_arg( spec => 'critical|c=s', help => "-c, --critical=THRESHOLDn" . " Critical threshold. Seen" . " http://nagiosplug.sourceforge.net/developer-guidelines.html#THRESHOLDFORMATn" . ' for the threshold format. By default, no threshold is set.', required => 0, ); $np->add_arg( spec => 'command|l=s', help => "-l, --command=COMMANDn" . ' Specify command type (CPU, MEM, NET, IO, VMFS, RUNTIME, ...)', required => 1, ); $np->add_arg( spec => 'subcommand|s=s', help => "-s, --subcommand=SUBCOMMANDn" . ' Specify subcommand', required => 0, ); $np->add_arg( spec => 'sessionfile|S=s', help => "-S, --sessionfile=SESSIONFILEn" . ' Specify a filename to store sessions for faster authentication', required => 0, ); $np->add_arg( spec => 'exclude|x=s', help => "-x, --exclude=n" . ' Specify black list', required => 0, ); $np->add_arg( spec => 'options|o=s', help => "-o, --options= n" . ' Specify additional command options (quickstats, ...)', required => 0, ); $np->add_arg( spec => 'timestamp|T=i', help => "-T, --timestamp= n" . ' Timeshift in seconds that could fix issues with "Unknown error". Use values like 5, 10, 20, etc', required => 0, ); $np->add_arg( spec => 'interval|i=s', help => "-i, --interval= n" . " Sampling Period in seconds. Basic historic intervals: 300, 1800, 7200 or 86400. See config for any changes.n" . " Supports literval values to autonegotiate interval value: r - realtime interval, h - historical interval specified by position.n" . ' Default value is 20 (realtime). Since cluster does not have realtime stats interval other than 20(default realtime) is mandatory.', required => 0, ); $np->add_arg( spec => 'maxsamples|M=s', help => "-M, --maxsamples= n" . " Maximum number of samples to retrieve. Max sample number is ignored for historic intervals.n" . ' Default value is 1 (latest available sample). ', required => 0, ); $np->add_arg( spec => 'trace=s', help => "--trace= n" . ' Set verbosity level of vSphere API request/respond trace', required => 0, ); $np->add_arg( spec => 'generate_test=s', help => "--generate_test= n" . ' Generate a test case script from the executed command/subcommand and write it to .' . ' If is "stdout", the test case script is written to stdout instead.', default => 0, required => 0, ); $np->getopts; my $host = $np->opts->host; my $cluster = $np->opts->cluster; my $datacenter = $np->opts->datacenter; my $vmname = $np->opts->name; my $cnode = $np->opts->node; my $username = $np->opts->username; my $password = $np->opts->password; my $authfile = $np->opts->authfile; my $warning = $np->opts->warning; my $critical = $np->opts->critical; my $command = $np->opts->command; my $subcommand = $np->opts->subcommand; my $sessionfile = $np->opts->sessionfile; my $blacklist = $np->opts->exclude; my $addopts = $np->opts->options; my $trace = $np->opts->trace; my $generate_test = $np->opts->generate_test; my $timeshift = $np->opts->timestamp; my $interval = $np->opts->interval; my $maxsamples = $np->opts->maxsamples; my $timeout = $np->opts->timeout; my $percw; my $percc; if ($generate_test) { if (uc($generate_test) ne "STDOUT") { -e $generate_test and die("cowardly refusing to write test case script to existing file ${generate_test}"); } use LWP::UserAgent; my $cref = *LWP::UserAgent::request{CODE}; { no warnings 'redefine'; *LWP::UserAgent::request = sub { my $r = &{$cref}(@_); #$r is (hopefully) a SOAP response as returned by the VMware WS if (uc($generate_test) ne "STDOUT") { open TEST_SCRIPT, ">>", $generate_test; print TEST_SCRIPT $r->content . "n!n"; #print the response content to the target script. separate messages by '!' for easy parsing } else { print $r->content . "n"; } $r #pass it on }; } } eval { require VMware::VIRuntime; } or Monitoring::Plugin::Functions::plugin_exit(UNKNOWN, "Missing perl module VMware::VIRuntime. Download and install 'VMware vSphere SDK for Perl', available at https://my.vmware.com/group/vmware/downloadsn $perl_module_instructions"); #This is, potentially, a lie. This might just as well fail if a dependency of VMware::VIRuntime is missing (i.e VIRuntime itself requires something which in turn fails). alarm($timeout) if $timeout; $output = "Unknown ERROR!"; $result = CRITICAL; if (defined($subcommand)) { $subcommand = undef if ($subcommand eq ''); } if (defined($critical)) { ($percc, $critical) = check_percantage($critical); $critical = undef if ($critical eq ''); } if (defined($warning)) { ($percw, $warning) = check_percantage($warning); $warning = undef if ($warning eq ''); } $np->set_thresholds(critical => $critical, warning => $warning); $defperfargs = {}; $defperfargs->{timeshift} = $timeshift if (defined($timeshift)); $defperfargs->{interval} = $interval if (defined($interval)); $defperfargs->{maxsamples} = $maxsamples if (defined($maxsamples)); eval { die "Provide either Password/Username or Auth file or Session filen" if ((!defined($password) || !defined($username) || defined($authfile)) && (defined($password) || defined($username) || !defined($authfile)) && (defined($password) || defined($username) || defined($authfile) || !defined($sessionfile))); die "Both threshold values must be the same unitsn" if (($percw && !$percc && defined($critical)) || (!$percw && $percc && defined($warning))); if (defined($authfile)) { open (AUTH_FILE, $authfile) || die "Unable to open auth file "$authfile"n"; while( ) { if(s/^[ t]*username[ t]*=//){ s/^s+//;s/s+$//; $username = $_; } if(s/^[ t]*password[ t]*=//){ s/^s+//;s/s+$//; $password = $_; } } die "Auth file must contain both username and passwordn" if (!(defined($username) && defined($password))); } my $host_address; if (defined($datacenter)) { $host_address = $datacenter; } elsif (defined($host)) { $host_address = $host; } else { $np->plugin_exit(CRITICAL, "No Host or Datacenter specified"); } $host_address .= ":443" if (index($host_address, ":") == -1); if (not $host_address =~ '^.*://.*$') { $host_address = "https://" . $host_address . "/sdk/webService"; } if (defined($sessionfile) and -e $sessionfile) { Opts::set_option("sessionfile", $sessionfile); eval { Util::connect($host_address, $username, $password); die "Connected host doesn't match reqested oncen" if (Opts::get_option("url") ne $host_address); }; if ($@) { Opts::set_option("sessionfile", undef); Util::connect($host_address, $username, $password); } } else { Util::connect($host_address, $username, $password); } if (defined($sessionfile)) { Vim::save_session(session_file => $sessionfile); } if (defined($trace)) { $Util::tracelevel = $Util::tracelevel; $Util::tracelevel = $trace if (($trace =~ m/^d$/) && ($trace >= 0) && ($trace $cnode} if (defined($datacenter)); if ($command eq "CPU") { ($result, $output) = host_cpu_info($esx, $np, local_uc($subcommand), $addopts); } elsif ($command eq "MEM") { ($result, $output) = host_mem_info($esx, $np, local_uc($subcommand), $addopts); } elsif ($command eq "NET") { ($result, $output) = host_net_info($esx, $np, local_uc($subcommand)); } elsif ($command eq "IO") { ($result, $output) = host_disk_io_info($esx, $np, local_uc($subcommand)); } elsif ($command eq "VMFS") { ($result, $output) = host_list_vm_volumes_info($esx, $np, $subcommand, $blacklist, $percc || $percw, $addopts); } elsif ($command eq "RUNTIME") { ($result, $output) = host_runtime_info($esx, $np, local_uc($subcommand), $blacklist, $addopts); } elsif ($command eq "SERVICE") { ($result, $output) = host_service_info($esx, $np, $subcommand); } elsif ($command eq "STORAGE") { ($result, $output) = host_storage_info($esx, $np, local_uc($subcommand), $blacklist); } elsif ($command eq "UPTIME") { ($result, $output) = host_uptime_info($esx, $np, $addopts); } elsif ($command eq "DEVICE") { ($result, $output) = host_device_info($esx, $np, $subcommand, $addopts); } else { $output = "Unknown HOST commandn" . $np->opts->_help; $result = CRITICAL; } } elsif (defined($vmname)) { if ($command eq "CPU") { ($result, $output) = vm_cpu_info($vmname, $np, local_uc($subcommand)); } elsif ($command eq "MEM") { ($result, $output) = vm_mem_info($vmname, $np, local_uc($subcommand)); } elsif ($command eq "NET") { ($result, $output) = vm_net_info($vmname, $np, local_uc($subcommand)); } elsif ($command eq "IO") { ($result, $output) = vm_disk_io_info($vmname, $np, local_uc($subcommand)); } elsif ($command eq "RUNTIME") { ($result, $output) = vm_runtime_info($vmname, $np, local_uc($subcommand)); } else { $output = "Unknown HOST-VM commandn" . $np->opts->_help; $result = CRITICAL; } } elsif (defined($host)) { my $esx; $esx = {name => $host} if (defined($datacenter)); if ($command eq "CPU") { ($result, $output) = host_cpu_info($esx, $np, local_uc($subcommand), $addopts); } elsif ($command eq "MEM") { ($result, $output) = host_mem_info($esx, $np, local_uc($subcommand), $addopts); } elsif ($command eq "NET") { ($result, $output) = host_net_info($esx, $np, local_uc($subcommand)); } elsif ($command eq "IO") { ($result, $output) = host_disk_io_info($esx, $np, local_uc($subcommand)); } elsif ($command eq "VMFS") { ($result, $output) = host_list_vm_volumes_info($esx, $np, $subcommand, $blacklist, $percc || $percw, $addopts); } elsif ($command eq "RUNTIME") { ($result, $output) = host_runtime_info($esx, $np, local_uc($subcommand), $blacklist, $addopts); } elsif ($command eq "SERVICE") { ($result, $output) = host_service_info($esx, $np, $subcommand); } elsif ($command eq "STORAGE") { ($result, $output) = host_storage_info($esx, $np, local_uc($subcommand), $blacklist); } elsif ($command eq "UPTIME") { ($result, $output) = host_uptime_info($esx, $np, $addopts); } elsif ($command eq "DEVICE") { ($result, $output) = host_device_info($esx, $np, $subcommand, $addopts); } else { $output = "Unknown HOST commandn" . $np->opts->_help; $result = CRITICAL; } } elsif (defined($cluster)) { if ($command eq "CPU") { ($result, $output) = cluster_cpu_info($cluster, $np, local_uc($subcommand)); } elsif ($command eq "MEM") { ($result, $output) = cluster_mem_info($cluster, $np, local_uc($subcommand), $addopts); } elsif ($command eq "CLUSTER") { ($result, $output) = cluster_cluster_info($cluster, $np, local_uc($subcommand)); } elsif ($command eq "VMFS") { ($result, $output) = cluster_list_vm_volumes_info($cluster, $np, $subcommand, $blacklist, $percc || $percw, $addopts); } elsif ($command eq "RUNTIME") { ($result, $output) = cluster_runtime_info($cluster, $np, local_uc($subcommand), $blacklist); } else { $output = "Unknown CLUSTER commandn" . $np->opts->_help; $result = CRITICAL; } } else { if ($command eq "RECOMMENDATIONS") { my $cluster_name; $cluster_name = {name => $subcommand} if (defined($subcommand)); ($result, $output) = return_cluster_DRS_recommendations($np, $cluster_name); } elsif ($command eq "CPU") { ($result, $output) = dc_cpu_info($np, local_uc($subcommand), $addopts); } elsif ($command eq "MEM") { ($result, $output) = dc_mem_info($np, local_uc($subcommand), $addopts); } elsif ($command eq "NET") { ($result, $output) = dc_net_info($np, local_uc($subcommand)); } elsif ($command eq "IO") { ($result, $output) = dc_disk_io_info($np, local_uc($subcommand)); } elsif ($command eq "VMFS") { ($result, $output) = dc_list_vm_volumes_info($np, $subcommand, $blacklist, $percc || $percw, $addopts); } elsif ($command eq "RUNTIME") { ($result, $output) = dc_runtime_info($np, local_uc($subcommand), $blacklist); } else { $output = "Unknown HOST commandn" . $np->opts->_help; $result = CRITICAL; } } }; if ($@) { if (uc(ref($@)) eq "HASH") { $output = $@->{msg}; $result = $@->{code}; } elsif ($@ =~ /^Error connecting to server at/) { $output = $@ . ""; $result = UNKNOWN; } elsif ($@ =~ /^Error: Cannot complete login/) { $output = $@ . ""; $result = UNKNOWN; } elsif ($@ =~ /^Error: Permission to perform/) { $output = $@ . ""; $result = UNKNOWN; } else { $output = $@ . ""; $result = CRITICAL; } } Util::disconnect(); if ($generate_test && uc($generate_test) ne 'STDOUT') { open TEST_SCRIPT, ">>", $generate_test; print TEST_SCRIPT "#" . $output . "n"; print TEST_SCRIPT "-" . $result; } $np->plugin_exit($result, $output); } main unless defined caller; ####################################################################################################################################################################### sub get_key_metrices { my ($perfmgr_view, $group, @names) = @_; my $perfCounterInfo = $perfmgr_view->perfCounter; my @counters; die "Insufficient rights to access perfcountersn" if (!defined($perfCounterInfo)); foreach (@$perfCounterInfo) { if ($_->groupInfo->key eq $group) { my $cur_name = $_->nameInfo->key . "." . $_->rollupType->val; foreach my $index (0..@names-1) { if ($names[$index] =~ /$cur_name/) { $names[$index] =~ /(w+).(w+):*(.*)/; $counters[$index] = PerfMetricId->new(counterId => $_->key, instance => $3); } } } } return @counters; } sub generic_performance_values { my ($views, $perfargs, $group, @list) = @_; my $counter = 0; my @values = (); my $amount = @list; my $perfMgr = $perfargs->{perfCounter}; if (!defined($perfMgr)) { $perfMgr = Vim::get_view(mo_ref => Vim::get_service_content()->perfManager, properties => [ 'perfCounter' ]); $perfargs->{perfCounter} = $perfMgr; } my $metrices = get_key_metrices($perfMgr, $group, @list); my $maxsamples = $perfargs->{maxsamples}; my $interval = defined($perfargs->{interval}) ? $perfargs->{interval} : 20; my $timestamp = $perfargs->{timestamp}; my @perf_query_spec = (); if (defined($timestamp)) { my $timeshift = $perfargs->{timeshift}; my ($sec,$min,$hour,$mday,$mon,$year) = gmtime($timestamp - $timeshift); my $startTime = sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ", $year + 1900, $mon + 1, $mday, $hour, $min, $sec); ($sec,$min,$hour,$mday,$mon,$year) = gmtime($timestamp); my $endTime = sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ", $year + 1900, $mon + 1, $mday, $hour, $min, $sec); if ($interval and $interval eq "r") { foreach (@$views) { my $summary = $perfMgr->QueryPerfProviderSummary(entity => $_); die "Realtime interval is not supported or not enabledn" unless ($summary && $summary->currentSupported); $interval = $summary->refreshRate; push(@perf_query_spec, PerfQuerySpec->new(entity => $_, metricId => $metrices, format => 'csv', intervalId => $interval, maxSample => $maxsamples, startTime => $startTime, endTime => $endTime)); } } elsif ($interval and substr($interval, 0, 1) eq "h") { my $index = substr($interval, 1, -1); foreach (@$views) { my $summary = $perfMgr->QueryPerfProviderSummary(entity => $_); die "Historical intervals are not supportedn" unless ($summary && $summary->summarySupported); my $historic_intervals = $perfMgr->historicalInterval; die "Historical interval [$index] is not present (max value " . @{$historic_intervals} . ")n" unless (($index >= 0) && ($index enabled); $interval = $perf_interval->key; push(@perf_query_spec, PerfQuerySpec->new(entity => $_, metricId => $metrices, format => 'csv', intervalId => $interval, maxSample => $maxsamples, startTime => $startTime, endTime => $endTime)); } } else { push(@perf_query_spec, PerfQuerySpec->new(entity => $_, metricId => $metrices, format => 'csv', intervalId => $interval, maxSample => $maxsamples, startTime => $startTime, endTime => $endTime)) foreach (@$views); } } else { if ($interval and $interval eq "r") { foreach (@$views) { my $summary = $perfMgr->QueryPerfProviderSummary(entity => $_); die "Realtime interval is not supported or not enabledn" unless ($summary && $summary->currentSupported); $interval = $summary->refreshRate; push(@perf_query_spec, PerfQuerySpec->new(entity => $_, metricId => $metrices, format => 'csv', intervalId => $interval, maxSample => $maxsamples)); } } elsif ($interval and substr($interval, 0, 1) eq "h") { my $index = substr($interval, 1, -1); foreach (@$views) { my $summary = $perfMgr->QueryPerfProviderSummary(entity => $_); die "Historical intervals are not supportedn" unless ($summary && $summary->summarySupported); my $historic_intervals = $perfMgr->historicalInterval; die "Historical interval [$index] is not present (max value " . @{$historic_intervals} . ")n" unless (($index >= 0) && ($index enabled); $interval = $perf_interval->key; push(@perf_query_spec, PerfQuerySpec->new(entity => $_, metricId => $metrices, format => 'csv', intervalId => $interval, maxSample => $maxsamples)); } } else { push(@perf_query_spec, PerfQuerySpec->new(entity => $_, metricId => $metrices, format => 'csv', intervalId => $interval, maxSample => $maxsamples)) foreach (@$views); } } my $perf_data = $perfMgr->QueryPerf(querySpec => @perf_query_spec); $amount *= @$perf_data; while (@$perf_data) { my $unsorted = shift(@$perf_data)->value; my @host_values = (); foreach my $id (@$unsorted) { foreach my $index (0..@$metrices-1) { if ($id->id->counterId == $$metrices[$index]->counterId) { $counter++ if (!defined($host_values[$index])); $host_values[$index] = $id; } } } push(@values, @host_values); } return undef if ($counter != $amount || $counter == 0); return @values; } sub return_host_performance_values { my $values; my $host_name = shift(@_); my $perfargs = shift(@_); my $timeshift = $perfargs->{timeshift}; my $host_view = Vim::find_entity_views(view_type => 'HostSystem', filter => $host_name, properties => (defined($timeshift) ? [ 'name', 'runtime.inMaintenanceMode', 'configManager.dateTimeSystem' ] : [ 'name', 'runtime.inMaintenanceMode']) ); # Added properties named argument. die "Runtime errorn" if (!defined($host_view)); die "Host "" . $$host_name{"name"} . "" does not existn" if (!@$host_view); die {msg => ("NOTICE: "" . $$host_view[0]->name . "" is in maintenance mode, check skippedn"), code => OK} if (uc($$host_view[0]->get_property('runtime.inMaintenanceMode')) eq "TRUE"); # Timestamp is required for some Hosts in vCenter(Datacenter), this could fix 'Unknown error' type of issues $perfargs->{timestamp} = str2time(Vim::get_view(mo_ref => $$host_view[0]->get_property('configManager.dateTimeSystem'))->QueryDateTime()) if (defined($timeshift)); $values = generic_performance_values($host_view, $perfargs, @_); return undef if ($@); return ($host_view, $values); } sub return_host_vmware_performance_values { my $values; my $vmname = shift(@_); my $vm_view = Vim::find_entity_views(view_type => 'VirtualMachine', filter => {name => "$vmname"}, properties => [ 'name', 'runtime.powerState' ]); die "Runtime errorn" if (!defined($vm_view)); die "VMware machine "" . $vmname . "" does not existn" if (!@$vm_view); die "VMware machine "" . $vmname . "" is not running. Current state is "" . $$vm_view[0]->get_property('runtime.powerState')->val . ""n" if ($$vm_view[0]->get_property('runtime.powerState')->val ne "poweredOn"); my $perfargs = shift(@_); $perfargs->{timestamp} = time() if (exists($perfargs->{timeshift})); $values = generic_performance_values($vm_view, $perfargs, @_); return $@ if ($@); return ($vm_view, $values); } sub return_dc_performance_values { my $values; my $host_views = Vim::find_entity_views(view_type => 'HostSystem', properties => [ 'name' ]); die "Runtime errorn" if (!defined($host_views)); die "Datacenter does not contain any hostsn" if (!@$host_views); my $perfargs = shift(@_); $perfargs->{timestamp} = time() if (exists($perfargs->{timeshift})); $values = generic_performance_values($host_views, $perfargs, @_); return undef if ($@); return ($host_views, $values); } sub return_cluster_performance_values { my $values; my $cluster_name = shift(@_); my $cluster_view = Vim::find_entity_views(view_type => 'ClusterComputeResource', filter => { name => "$cluster_name" }, properties => [ 'name' ]); # Added properties named argument. die "Runtime errorn" if (!defined($cluster_view)); die "Cluster "" . $cluster_name . "" does not existn" if (!@$cluster_view); my $perfargs = shift(@_); die "Since cluster does not have realtime stats interval other than 20(default value) is mandatoryn" if (!exists($perfargs->{interval})); $perfargs->{timestamp} = time() if (exists($perfargs->{timeshift})); $values = generic_performance_values($cluster_view, $perfargs, @_); return undef if ($@); return $values; } # Temporary solution to overcome zeros in network output sub return_host_temporary_vc_4_1_network_performance_values { my @values; my ($host_name, $perfargs, @list) = @_; my $host_view = Vim::find_entity_views(view_type => 'HostSystem', filter => $host_name, properties => [ 'name', 'runtime.inMaintenanceMode', 'summary.config.product.version', 'configManager.dateTimeSystem' ]); # Added properties named argument. die "Runtime errorn" if (!defined($host_view)); die "Host "" . $$host_name{"name"} . "" does not existn" if (!@$host_view); die {msg => ("NOTICE: "" . $$host_view[0]->name . "" is in maintenance mode, check skippedn"), code => OK} if (uc($$host_view[0]->get_property('runtime.inMaintenanceMode')) eq "TRUE"); my $software_version = $$host_view[0]->get_property('summary.config.product.version'); return undef if (substr($software_version, 0, 4) ne '4.1.'); my $timeshift = $perfargs->{timeshift}; my $interval = $perfargs->{interval}; my $maxsamples = $perfargs->{maxsamples}; my $timestamp = defined($timeshift) ? str2time(Vim::get_view(mo_ref => $$host_view[0]->get_property('configManager.dateTimeSystem'))->QueryDateTime()) : undef; my $perfMgr = Vim::get_view(mo_ref => Vim::get_service_content()->perfManager, properties => [ 'perfCounter' ]); my $metrices = get_key_metrices($perfMgr, 'net', @list); my $amount = @list; my @perf_query_spec = (); if (defined($timestamp)) { my ($sec,$min,$hour,$mday,$mon,$year) = gmtime($timestamp - $timeshift); my $endTime = sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ", $year + 1900, $mon + 1, $mday, $hour, $min, $sec); ($sec,$min,$hour,$mday,$mon,$year) = gmtime($timestamp - $timeshift); my $startTime = sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ", $year + 1900, $mon + 1, $mday, $hour, $min, $sec); push(@perf_query_spec, PerfQuerySpec->new(entity => $_, metricId => $metrices, format => 'csv', intervalId => $interval, startTime => $startTime, endtime => $endTime)) foreach (@$host_view); } else { push(@perf_query_spec, PerfQuerySpec->new(entity => $_, metricId => $metrices, format => 'csv', intervalId => $interval, maxSample => $maxsamples)) foreach (@$host_view); } my $perf_data = $perfMgr->QueryPerf(querySpec => @perf_query_spec); $amount *= @$perf_data; my $counter = 0; while (@$perf_data) { my $unsorted = shift(@$perf_data)->value; my @host_values = (); foreach my $id (@$unsorted) { foreach my $index (0..@$metrices-1) { if ($id->id->counterId == $$metrices[$index]->counterId) { if (!defined($host_values[$index])) { $counter++; $host_values[$index] = bless({ 'value' => '0' }, "PerfMetricSeriesCSV"); } $host_values[$index]{"value"} += convert_number($id->value) if ($id->id->instance ne ''); } } } push(@values, @host_values); } return undef if ($counter != $amount || $counter == 0 || $@); return ($host_view, @values); } # Remove as soon as possible sub local_uc { my ($val) = shift(@_); return defined($val)?uc($val):undef; } sub simplify_number { my ($number, $cnt) = @_; $cnt = 2 if (!defined($cnt)); return sprintf("%.${cnt}f", "$number"); } sub convert_number { my @vals = split(/,/, shift(@_)); my $res = 0; while (@vals) { my $value = pop(@vals); $value =~ s/^s+//; $value =~ s/s+$//; if (defined($value) && $value ne '') { return $value if ($value >= 0); $res = $value if ($res == 0); } } return $res; } sub check_percantage { my ($number) = shift(@_); my $perc = $number =~ s/%//; return ($perc, $number); } sub check_health_state { my ($state) = shift(@_); my $res = UNKNOWN; if (uc($state) eq "GREEN") { $res = OK } elsif (uc($state) eq "YELLOW") { $res = WARNING; } elsif (uc($state) eq "RED") { $res = CRITICAL; } return $res; } sub format_issue { my ($issue) = shift(@_); my $output = ''; if (defined($issue->datacenter)) { $output .= 'Datacenter "' . $issue->datacenter->name . '", '; } if (defined($issue->host)) { $output .= 'Host "' . $issue->host->name . '", '; } if (defined($issue->vm)) { $output .= 'VM "' . $issue->vm->name . '", '; } if (defined($issue->computeResource)) { $output .= 'Compute Resource "' . $issue->computeResource->name . '", '; } if (exists($issue->{dvs}) && defined($issue->dvs)) { # Since vSphere API 4.0 $output .= 'Virtual Switch "' . $issue->dvs->name . '", '; } if (exists($issue->{ds}) && defined($issue->ds)) { # Since vSphere API 4.0 $output .= 'Datastore "' . $issue->ds->name . '", '; } if (exists($issue->{net}) && defined($issue->net)) { # Since vSphere API 4.0 $output .= 'Network "' . $issue->net->name . '" '; } $output =~ s/, $/ /; $output .= ": " . $issue->fullFormattedMessage; $output .= "(caused by " . $issue->userName . ")" if ($issue->userName ne ""); return $output; } sub datastore_volumes_info { my ($datastore, $np, $subcommand, $blacklist, $perc, $addopts) = @_; my $res = OK; my $output = ''; my $usedflag; my $briefflag; my $regexpflag; my $blackregexpflag; $usedflag = $addopts =~ m/(^|s|t|,)QusedE($|s|t|,)/ if (defined($addopts)); $briefflag = $addopts =~ m/(^|s|t|,)QbriefE($|s|t|,)/ if (defined($addopts)); $regexpflag = $addopts =~ m/(^|s|t|,)QregexpE($|s|t|,)/ if (defined($addopts)); $blackregexpflag = $addopts =~ m/(^|s|t|,)QblacklistregexpE($|s|t|,)/ if (defined($addopts)); die "Blacklist is supported only in generic check or regexp subcheckn" if (defined($subcommand) && defined($blacklist) && !defined($regexpflag)); if (defined($regexpflag) && defined($subcommand)) { eval { qr{$subcommand}; }; if ($@) { $@ =~ s/ at.*line.*.//; die $@; } } my $state; foreach my $ref_store (@{$datastore}) { my $store = Vim::get_view(mo_ref => $ref_store, properties => ['summary', 'info']); my $name = $store->summary->name; if (!defined($subcommand) || ($name eq $subcommand) || (defined($regexpflag) && $name =~ /$subcommand/)) { if (defined($blacklist)) { next if ($blackregexpflag?$name =~ /$blacklist/:$blacklist =~ m/(^|s|t|,)Q$nameE($|s|t|,)/); } if ($store->summary->accessible) { $store->RefreshDatastoreStorageInfo() if ($store->can("RefreshDatastoreStorageInfo") && exists($store->info->{timestamp}) && $defperfargs->{timeshift} && (time() - str2time($store->info->timestamp) > $defperfargs->{timeshift})); my $value1 = simplify_number(convert_number($store->summary->freeSpace) / 1024 / 1024); my $value2 = convert_number($store->summary->capacity); $value2 = simplify_number(convert_number($store->info->freeSpace) / $value2 * 100) if ($value2 > 0); if ($usedflag) { $value1 = simplify_number(convert_number($store->summary->capacity) / 1024 / 1024) - $value1; $value2 = 100 - $value2; } $state = $np->check_threshold(check => $perc?$value2:$value1); $res = Monitoring::Plugin::Functions::max_state($res, $state); $np->add_perfdata(label => $name, value => $perc?$value2:$value1, uom => $perc?'%':'MB', threshold => $np->threshold); $output .= "'$name'" . ($usedflag ? "(used)" : "(free)") . "=". $value1 . " MB (" . $value2 . "%), " if (!$briefflag || $state != OK); } else { $res = CRITICAL; $output .= "'$name' is not accessible, "; } last if (!$regexpflag && defined($subcommand) && ($name eq $subcommand)); $blacklist .= $blackregexpflag?"|^$name$":",$name"; } } if ($output) { chop($output); chop($output); $output = "Storages : " . $output; } else { if ($briefflag) { $output = "There are no alerts"; } else { $res = WARNING; $output = defined($subcommand)?$regexpflag? "No matching volumes for regexp "$subcommand" found":"No volume named "$subcommand" found":"There are no volumes"; } } return ($res, $output); } #=====================================================================| HOST |============================================================================# sub host_cpu_info { my ($host, $np, $subcommand, $addopts) = @_; my $res = CRITICAL; my $output = 'HOST CPU Unknown error'; my $quickStats; $quickStats = $addopts =~ m/(^|s|t|,)QquickstatsE($|s|t|,)/ if (defined($addopts)); if (defined($subcommand)) { if ($subcommand eq "USAGE") { my $value; if (defined($quickStats)) { my $host_view = Vim::find_entity_view(view_type => 'HostSystem', filter => $host, properties => ['name', 'runtime.inMaintenanceMode', 'summary.hardware', 'summary.quickStats']); die "Host "" . $$host{"name"} . "" does not existn" if (!defined($host_view)); die {msg => ("NOTICE: "" . $host_view->name . "" is in maintenance mode, check skippedn"), code => OK} if (uc($host_view->get_property('runtime.inMaintenanceMode')) eq "TRUE"); $values = $host_view->get_property('summary.quickStats'); my $hardinfo = $host_view->get_property('summary.hardware'); $value = simplify_number($values->overallCpuUsage / ($hardinfo->numCpuCores * $hardinfo->cpuMhz) * 100) if exists($values->{overallCpuUsage}) && defined($hardinfo); } else { $values = return_host_performance_values($host, $defperfargs, 'cpu', ('usage.average')); $value = simplify_number(convert_number($$values[0][0]->value) * 0.01) if (defined($values)); } if (defined($value)) { $np->add_perfdata(label => "cpu_usage", value => $value, uom => '%', threshold => $np->threshold); $output = "cpu usage=" . $value . " %"; $res = $np->check_threshold(check => $value); } } elsif ($subcommand eq "USAGEMHZ") { my $value; if (defined($quickStats)) { my $host_view = Vim::find_entity_view(view_type => 'HostSystem', filter => $host, properties => ['name', 'runtime.inMaintenanceMode', 'summary.quickStats']); die "Host "" . $$host{"name"} . "" does not existn" if (!defined($host_view)); die {msg => ("NOTICE: "" . $host_view->name . "" is in maintenance mode, check skippedn"), code => OK} if (uc($host_view->get_property('runtime.inMaintenanceMode')) eq "TRUE"); $values = $host_view->get_property('summary.quickStats'); $value = simplify_number($values->overallCpuUsage) if exists($values->{overallCpuUsage}); } else { $values = return_host_performance_values($host, $defperfargs, 'cpu', ('usagemhz.average')); $value = simplify_number(convert_number($$values[0][0]->value)) if (defined($values)); } if (defined($value)) { $np->add_perfdata(label => "cpu_usagemhz", value => $value, uom => '', threshold => $np->threshold); $output = "cpu usagemhz=" . $value . " MHz"; $res = $np->check_threshold(check => $value); } } else { $res = CRITICAL; $output = "HOST CPU - unknown subcommandn" . $np->opts->_help; } } else { my $value1; my $value2; if (defined($quickStats)) { my $host_view = Vim::find_entity_view(view_type => 'HostSystem', filter => $host, properties => ['name', 'runtime.inMaintenanceMode', 'summary.hardware', 'summary.quickStats']); die "Host "" . $$host{"name"} . "" does not existn" if (!defined($host_view)); die {msg => ("NOTICE: "" . $host_view->name . "" is in maintenance mode, check skippedn"), code => OK} if (uc($host_view->get_property('runtime.inMaintenanceMode')) eq "TRUE"); $values = $host_view->get_property('summary.quickStats'); my $hardinfo = $host_view->get_property('summary.hardware'); if (exists($values->{overallCpuUsage}) && defined($hardinfo)) { $value1 = simplify_number($values->overallCpuUsage); $value2 = simplify_number($values->overallCpuUsage / ($hardinfo->numCpuCores * $hardinfo->cpuMhz) * 100); } } else { $values = return_host_performance_values($host, $defperfargs, 'cpu', ('usagemhz.average', 'usage.average')); if ($values) { $value1 = simplify_number(convert_number($$values[0][0]->value)); $value2 = simplify_number(convert_number($$values[0][1]->value) * 0.01); } } if (defined($value1) && defined($value2)) { $np->add_perfdata(label => "cpu_usagemhz", value => $value1, uom => '', threshold => $np->threshold); $np->add_perfdata(label => "cpu_usage", value => $value2, uom => '%', threshold => $np->threshold); $res = OK; $output = "cpu usage=" . $value1 . " MHz (" . $value2 . "%)"; } } return ($res, $output); } sub host_mem_info { my ($host, $np, $subcommand, $addopts) = @_; my $res = CRITICAL; my $output = 'HOST MEM Unknown error'; my $quickStats; my $outputlist; $quickStats = $addopts =~ m/(^|s|t|,)QquickstatsE($|s|t|,)/ if (defined($addopts)); $outputlist = $addopts =~ m/(^|s|t|,)QlistvmE($|s|t|,)/ if (defined($addopts)); if (defined($subcommand)) { if ($subcommand eq "USAGE") { my $value; if (defined($quickStats)) { my $host_view = Vim::find_entity_view(view_type => 'HostSystem', filter => $host, properties => ['name', 'runtime.inMaintenanceMode', 'summary.hardware', 'summary.quickStats']); die "Host "" . $$host{"name"} . "" does not existn" if (!defined($host_view)); die {msg => ("NOTICE: "" . $host_view->name . "" is in maintenance mode, check skippedn"), code => OK} if (uc($host_view->get_property('runtime.inMaintenanceMode')) eq "TRUE"); $values = $host_view->get_property('summary.quickStats'); my $hardinfo = $host_view->get_property('summary.hardware'); $value = simplify_number($values->overallMemoryUsage / ($hardinfo->memorySize / 1024 / 1024) * 100) if exists($values->{overallMemoryUsage}) && defined($hardinfo); } else { $values = return_host_performance_values($host, $defperfargs, 'mem', ('usage.average')); $value = simplify_number(convert_number($$values[0][0]->value) * 0.01) if (defined($values)); } if (defined($value)) { $np->add_perfdata(label => "mem_usage", value => $value, uom => '%', threshold => $np->threshold); $output = "mem usage=" . $value . " %"; $res = $np->check_threshold(check => $value); } } elsif ($subcommand eq "USAGEMB") { my $value; if (defined($quickStats)) { my $host_view = Vim::find_entity_view(view_type => 'HostSystem', filter => $host, properties => ['name', 'runtime.inMaintenanceMode', 'summary.quickStats']); die "Host "" . $$host{"name"} . "" does not existn" if (!defined($host_view)); die {msg => ("NOTICE: "" . $host_view->name . "" is in maintenance mode, check skippedn"), code => OK} if (uc($host_view->get_property('runtime.inMaintenanceMode')) eq "TRUE"); $values = $host_view->get_property('summary.quickStats'); $value = simplify_number($values->overallMemoryUsage) if exists($values->{overallMemoryUsage}); } else { $values = return_host_performance_values($host, $defperfargs, 'mem', ('consumed.average')); $value = simplify_number(convert_number($$values[0][0]->value) / 1024) if (defined($values)); } if (defined($value)) { $np->add_perfdata(label => "mem_usagemb", value => $value, uom => 'MB', threshold => $np->threshold); $output = "mem usage=" . $value . " MB"; $res = $np->check_threshold(check => $value); } } elsif ($subcommand eq "SWAP") { my $host_view; ($host_view, $values) = return_host_performance_values($host, $defperfargs, 'mem', ('swapused.average')); if (defined($values)) { my $value = simplify_number(convert_number($$values[0][0]->value) / 1024); $np->add_perfdata(label => "mem_swap", value => $value, uom => 'MB', threshold => $np->threshold); $output = "swap usage=" . $value . " MB: "; $res = $np->check_threshold(check => $value); if ($res != OK && $outputlist) { my $vm_views = Vim::find_entity_views(view_type => 'VirtualMachine', begin_entity => $$host_view[0], properties => ['name', 'runtime.powerState']); die "Runtime errorn" if (!defined($vm_views)); die "There are no VMs.n" if (!@$vm_views); my @vms = (); foreach my $vm (@$vm_views) { push(@vms, $vm) if ($vm->get_property('runtime.powerState')->val eq "poweredOn"); } $values = generic_performance_values(@vms, $defperfargs, 'mem', ('swapped.average')); if (defined($values)) { foreach my $index (0..@vms-1) { my $value = simplify_number(convert_number($$values[$index][0]->value) / 1024); $output .= $vms[$index]->name . " (" . $value . "MB), " if ($value > 0); } } } chop($output); chop($output); } } elsif ($subcommand eq "OVERHEAD") { $values = return_host_performance_values($host, $defperfargs, 'mem', ('overhead.average')); if (defined($values)) { my $value = simplify_number(convert_number($$values[0][0]->value) / 1024); $np->add_perfdata(label => "mem_overhead", value => $value, uom => 'MB', threshold => $np->threshold); $output = "overhead=" . $value . " MB"; $res = $np->check_threshold(check => $value); } } elsif ($subcommand eq "OVERALL") { $values = return_host_performance_values($host, $defperfargs, 'mem', ('consumed.average', 'overhead.average')); if (defined($values)) { my $value = simplify_number((convert_number($$values[0][0]->value) + convert_number($$values[0][1]->value)) / 1024); $np->add_perfdata(label => "mem_overhead", value => $value, uom => 'MB', threshold => $np->threshold); $output = "overall=" . $value . " MB"; $res = $np->check_threshold(check => $value); } } elsif ($subcommand eq "MEMCTL") { my $host_view; ($host_view, $values) = return_host_performance_values($host, $defperfargs, 'mem', ('vmmemctl.average')); if (defined($values)) { my $value = simplify_number(convert_number($$values[0][0]->value) / 1024); $np->add_perfdata(label => "mem_memctl", value => $value, uom => 'MB', threshold => $np->threshold); $output = "memctl=" . $value . " MB: "; $res = $np->check_threshold(check => $value); if ($res != OK && $outputlist) { my $vm_views = Vim::find_entity_views(view_type => 'VirtualMachine', begin_entity => $$host_view[0], properties => ['name', 'runtime.powerState']); die "Runtime errorn" if (!defined($vm_views)); die "There are no VMs.n" if (!@$vm_views); my @vms = (); foreach my $vm (@$vm_views) { push(@vms, $vm) if ($vm->get_property('runtime.powerState')->val eq "poweredOn"); } $values = generic_performance_values(@vms, $defperfargs, 'mem', ('vmmemctl.average')); if (defined($values)) { foreach my $index (0..@vms-1) { my $value = simplify_number(convert_number($$values[$index][0]->value) / 1024); $output .= $vms[$index]->name . " (" . $value . "MB), " if ($value > 0); } } } chop($output); chop($output); } } else { $res = CRITICAL; $output = "HOST MEM - unknown subcommandn" . $np->opts->_help; } } else { $values = return_host_performance_values($host, $defperfargs, 'mem', ('consumed.average', 'usage.average', 'overhead.average', 'swapused.average', 'vmmemctl.average')); if (defined($values)) { my $value1 = simplify_number(convert_number($$values[0][0]->value) / 1024); my $value2 = simplify_number(convert_number($$values[0][1]->value) * 0.01); my $value3 = simplify_number(convert_number($$values[0][2]->value) / 1024); my $value4 = simplify_number(convert_number($$values[0][3]->value) / 1024); my $value5 = simplify_number(convert_number($$values[0][4]->value) / 1024); $np->add_perfdata(label => "mem_usagemb", value => $value1, uom => 'MB', threshold => $np->threshold); $np->add_perfdata(label => "mem_usage", value => $value2, uom => '%', threshold => $np->threshold); $np->add_perfdata(label => "mem_overhead", value => $value3, uom => 'MB', threshold => $np->threshold); $np->add_perfdata(label => "mem_swap", value => $value4, uom => 'MB', threshold => $np->threshold); $np->add_perfdata(label => "mem_memctl", value => $value5, uom => 'MB', threshold => $np->threshold); $res = OK; $output = "mem usage=" . $value1 . " MB (" . $value2 . "%), overhead=" . $value3 . " MB, swapped=" . $value4 . " MB, memctl=" . $value5 . " MB"; } } return ($res, $output); } sub host_net_info { my ($host, $np, $subcommand) = @_; my $res = CRITICAL; my $output = 'HOST NET Unknown error'; if (defined($subcommand)) { if ($subcommand eq "USAGE") { $values = return_host_temporary_vc_4_1_network_performance_values($host, $defperfargs, ('received.average:*', 'transmitted.average:*')); if ($values) { $$values[0][0]{"value"} += $$values[0][1]{"value"}; } else { $values = return_host_performance_values($host, $defperfargs, 'net', ('usage.average')); } if (defined($values)) { my $value = simplify_number(convert_number($$values[0][0]->value)); $np->add_perfdata(label => "net_usage", value => $value, uom => '', threshold => $np->threshold); $output = "net usage=" . $value . " KBps"; $res = $np->check_threshold(check => $value); } } elsif ($subcommand eq "RECEIVE") { $values = return_host_temporary_vc_4_1_network_performance_values($host, $defperfargs, ('received.average:*')); $values = return_host_performance_values($host, $defperfargs, 'net', ('received.average')) if (!$values); if (defined($values)) { my $value = simplify_number(convert_number($$values[0][0]->value)); $np->add_perfdata(label => "net_receive", value => $value, uom => '', threshold => $np->threshold); $output



Information
by cmercier4, September 30, 2018

Thx for this plugin that works perfectly !! I have just one question, i try to change the return of value on my nagios core interface who always return the state of the plugin "CHECK_VMWARE_API.PL OK" "CHECK_VMWARE_API.PL WARNING" "CHECK_VMWARE_API.PL CRITICAL" It's possible not to display by modifying the code ? And if it's possible, where ? because i didn't found after research. thank you in advance



Works great, configuring it was much more challenging.
by KevinHerr, April 30, 2018

If you're using CentOS 7, you may need to install perl-Crypt-SSLeay and perl-Net-SSLeay.



ERROR
by hgomezg, August 31, 2017

[root@CCNAGIOS libexec]# ./check_vmware_api.pl -H 10.240.142.26 -u nagios -p N4g10s2017 -l mem -s usage -w 80 -c 90 Use of inherited AUTOLOAD for non-method XML::LibXML::Document::documentElement() is deprecated at /usr/share/perl5/VMware/VICommon.pm line 554. CHECK_VMWARE_API.PL CRITICAL - Undefined subroutine &XML::LibXML::Document::documentElement called at /usr/share/perl5/VMware/VICommon.pm line 554



problem with Maintenance Mode check
by ffuchs, May 31, 2016

The plugin works great. However, I found one bug. The check, if a machine is in maintenance mode, does not work. It will always return the value you use for querying. E.g. if you add the paramter "mainwarn", it will always return WARNING regardless of the state of the machine. The fix is quite easy. Just add "&& $runtime->inMaintenanceMode eq "1")" in the if-statements: 2280 if ($addopts eq "maintwarn" && $runtime->inMaintenanceMode eq "1") { 2281 $res = WARNING; 2282 } 2283 elsif ($addopts eq "maintcrit" && $runtime->inMaintenanceMode eq "1") { 2284 $res = CRITICAL; 2285 }



Fix SSL timeouts
by doro, December 31, 2015

Everything works with: Ubuntu 14.04 Nagios Core 3.5.1-1ubuntu1 Perl 5.18.2 VMware Perl SDK: VMware-vSphere-Perl-SDK-5.5.0-1384587.x86_64.tar.gz Path original VICommon.pm manually: root@st:~/check_vmware_api# diff /usr/share/perl/5.18/VMware/VICommon.pm /usr/share/perl/5.18/VMware/VICommon.pm_orig 448d447 ssl_opts( SSL_verify_mode => 0 ); 506c505 $ENV{PERL_NET_HTTPS_SSL_SOCKET_CLASS} = "Net::SSL"; 530d528 ssl_opts( SSL_verify_mode => 0 ); 2113d2110 ssl_opts( SSL_verify_mode => 0 ); root@st:~/check_vmware_api# TEST: Edit file generate_tests.pl: root@st:~/check_vmware_api# time perl generate_tests.pl CHECK_VMWARE_API.PL OK - Storages : 'local_datastore_1'(free)=907044.00 MB (95.86%), 'public_images'(free)=134284.75 MB (65.57%), 'vol258'(free)=281717.14 MB (62.34%) | local_datastore_1=907044.00MB;; public_images=134284.75MB;; vol258=281717.14MB;; CHECK_VMWARE_API.PL UNKNOWN - vmhba0 (unknown); vmhba32 (unknown); vmhba33 (unknown); vmhba34 (unknown); vmhba35 (unknown); vmhba36 (unknown); | adapters=0units;; CHECK_VMWARE_API.PL OK - Local ATA Disk (t10.ATA_____ST91000640NS________________________________________9XG4X7YW) ; | LUNs=1units;; CHECK_VMWARE_API.PL OK - sata.vmhba0-sata.0:0-t10.ATA_____ST91000640NS________________________________________9XG4X7YW ; | paths=1units;; CHECK_VMWARE_API.PL UNKNOWN - 0/6 adapters online, 1/1 LUNs ok, 1/1 paths active | adapters=0units;; LUNs=1units;; paths=1units;; CHECK_VMWARE_API.PL OK - cpu usage=8.99 % | cpu_usage=8.99%;; CHECK_VMWARE_API.PL OK - cpu usagemhz=2266.00 MHz | cpu_usagemhz=2266.00MHz;; CHECK_VMWARE_API.PL OK - cpu usage=2266.00 MHz (8.99%) | cpu_usagemhz=2266.00MHz;; cpu_usage=8.99%;; CHECK_VMWARE_API.PL OK - net usage=3352.00 KBps | net_usage=3352.00KBps;; CHECK_VMWARE_API.PL OK - net receive=199.00 KBps | net_receive=199.00KBps;; CHECK_VMWARE_API.PL OK - net send=3152.00 KBps | net_send=3152.00KBps;; CHECK_VMWARE_API.PL OK - All 2 NICs are connected | OK_NICs=2;; Bad_NICs=0;; CHECK_VMWARE_API.PL OK - net receive=199.00 KBps, send=3152.00 KBps, all 2 NICs are connected | net_receive=199.00KBps;; net_send=3152.00KBps;; OK_NICs=2;; Bad_NICs=0;; CHECK_VMWARE_API.PL OK - connection state=connected CHECK_VMWARE_API.PL OK - All 132 health checks are GREEN: Logging (3x); temperature (6x); fan (4x); Management Subsystem Health (4x); Memory (1x); CPU (2x); Software Components (87x); voltage (7x); power (6x); system (1x); Watchdog (4x); Battery (1x); Processors (6x); | Alerts=0;; CHECK_VMWARE_API.PL UNKNOWN - Storage health status unavailable - make sure you have the "Storage Health" tab in your vSphere client | Alerts=0;; CHECK_VMWARE_API.PL OK - All 6 temperature checks are GREEN: OK : [Device] Other 0 Inlet Temp --- Normal = 23 C, OK : Processor 1 PCH Temp --- Normal = 47 C, OK : Processor 1 DIMM ZONE 2 Temp --- Normal = 31 C, OK : Processor 1 DIMM ZONE 1 Temp --- Normal = 35 C, OK : Processor 1 CPU2 Temp --- Normal = 44 C, OK : Processor 1 CPU1 Temp --- Normal = 48 C | '[Device] Other 0 Inlet Temp --- Normal'=23C;; 'Processor 1 PCH Temp --- Normal'=47C;; 'Processor 1 DIMM ZONE 2 Temp --- Normal'=31C;; 'Processor 1 DIMM ZONE 1 Temp --- Normal'=35C;; 'Processor 1 CPU2 Temp --- Normal'=44C;; 'Processor 1 CPU1 Temp --- Normal'=48C;; CHECK_VMWARE_API.PL CRITICAL - Provide sensor name as -o argument Use of uninitialized value $addopts in string eq at ./check_vmware_api.pl line 2277. Use of uninitialized value $addopts in string eq at ./check_vmware_api.pl line 2280. CHECK_VMWARE_API.PL OK - maintenance=no CHECK_VMWARE_API.PL OK - 8/8 VMs up: vpn(OK), vcenter-88-2(OK), XXXXXXXX.com(OK), XXXXXXXX.com(OK), XXXXXXXX.com(OK), XXXXXXXX.com(OK), XXXXXXXX.com(OK), XXXXXXXX.com(OK) | vmcount=8units;; CHECK_VMWARE_API.PL OK - overall status=green CHECK_VMWARE_API.PL OK - No config issues Use of uninitialized value $subcommand in string ne at ./check_vmware_api.pl line 1898. CHECK_VMWARE_API.PL OK - 8/8 VMs up, overall status=green, connection state=connected, maintenance=no, All 132 health checks are Green, no config issues | vmcount=8units;; health_issues=0;; config_issues=0;; CHECK_VMWARE_API.PL OK - No VM's with cd/dvd devices | match=0;; CHECK_VMWARE_API.PL OK - services : DCUI (up), TSM (down), TSM-SSH (up), lbtd (up), lsassd (down), lwiod (down), netlogond (down), ntpd (up), sfcbd-watchdog (up), snmpd (up), vmware-fdm (down), vprobed (down), vpxa (up), xorg (down) CHECK_VMWARE_API.PL OK - io commands aborted=0 | io_aborted=0;; CHECK_VMWARE_API.PL OK - io bus resets=0 | io_busresets=0;; CHECK_VMWARE_API.PL OK - io read latency=0 ms | io_read=0ms;; CHECK_VMWARE_API.PL OK - io write latency=0 ms | io_write=0ms;; CHECK_VMWARE_API.PL OK - io kernel latency=0 ms | io_kernel=0ms;; CHECK_VMWARE_API.PL OK - io device latency=0 ms | io_device=0ms;; CHECK_VMWARE_API.PL OK - io queue latency=0 ms | io_queue=0ms;; CHECK_VMWARE_API.PL OK - io commands aborted=0, io bus resets=0, io read latency=0 ms, write latency=0 ms, kernel latency=0 ms, device latency=0 ms, queue latency=0 ms | io_aborted=0;; io_busresets=0;; io_read=0ms;; io_write=0ms;; io_kernel=0ms;; io_device=0ms;; io_queue=0ms;; CHECK_VMWARE_API.PL OK - mem usage=82.26 % | mem_usage=82.26%;; CHECK_VMWARE_API.PL OK - mem usage=107788.05 MB | mem_usagemb=107788.05MB;; CHECK_VMWARE_API.PL OK - swap usage=79.71 MB | mem_swap=79.71MB;; CHECK_VMWARE_API.PL OK - overhead=1502.64 MB | mem_overhead=1502.64MB;; CHECK_VMWARE_API.PL OK - overall=109290.69 MB | mem_overhead=109290.69MB;; CHECK_VMWARE_API.PL OK - memctl=129.01 MB | mem_memctl=129.01MB;; CHECK_VMWARE_API.PL OK - mem usage=107788.05 MB (82.26%), overhead=1502.64 MB, swapped=79.71 MB, memctl=129.01 MB | mem_usagemb=107788.05MB;; mem_usage=82.26%;; mem_overhead=1502.64MB;; mem_swap=79.71MB;; mem_memctl=129.01MB;; CHECK_VMWARE_API.PL OK - mem usage=82.25 % | mem_usage=82.25%;; CHECK_VMWARE_API.PL OK - mem usage=107773.45 MB | mem_usagemb=107773.45MB;; CHECK_VMWARE_API.PL OK - swap usage=79.71 MB | mem_swap=79.71MB;; CHECK_VMWARE_API.PL OK - overhead=1502.64 MB | mem_overhead=1502.64MB;; CHECK_VMWARE_API.PL OK - overall=109290.69 MB | mem_overall=109290.69MB;; CHECK_VMWARE_API.PL OK - memctl=129.01 MB | mem_memctl=129.01MB;; CHECK_VMWARE_API.PL OK - mem usage=107788.05 MB (82.26%), overhead=1502.64 MB, swapped=79.71 MB, memctl=129.01 MB | mem_usagemb=107788.05MB;; mem_usage=82.26%;; mem_overhead=1502.64MB;; mem_swap=79.71MB;; mem_memctl=129.01MB;; CHECK_VMWARE_API.PL OK - io commands aborted=0 | io_aborted=0;; CHECK_VMWARE_API.PL OK - io bus resets=0 | io_busresets=0;; CHECK_VMWARE_API.PL OK - io read latency=0 ms | io_read=0ms;; CHECK_VMWARE_API.PL OK - io write latency=0 ms | io_write=0ms;; CHECK_VMWARE_API.PL OK - io kernel latency=0 ms | io_kernel=0ms;; CHECK_VMWARE_API.PL OK - io device latency=0 ms | io_device=0ms;; CHECK_VMWARE_API.PL OK - io queue latency=0 ms | io_queue=0ms;; CHECK_VMWARE_API.PL OK - io commands aborted=0, io bus resets=0, io read latency=0 ms, write latency=0 ms, kernel latency=0 ms, device latency=0 ms, queue latency=0 ms | io_aborted=0;; io_busresets=0;; io_read=0ms;; io_write=0ms;; io_kernel=0ms;; io_device=0ms;; io_queue=0ms;; CHECK_VMWARE_API.PL OK - cpu usage=19.85 % | cpu_usage=19.85%;; CHECK_VMWARE_API.PL OK - cpu usagemhz=5002.00 MHz | cpu_usagemhz=5002.00MHz;; CHECK_VMWARE_API.PL OK - cpu usage=5002.00 MHz (19.85%) | cpu_usagemhz=5002.00MHz;; cpu_usage=19.85%;; CHECK_VMWARE_API.PL CRITICAL - Storages : 'public_images'(free)=134284.80 MB (65.57%), 'local_datastore_1'(free)=907044.00 MB (95.86%), 'local_datastore_2' is not accessible, 'vol258'(free)=281650.31 MB (62.34%) | public_images=134284.80MB;; local_datastore_1=907044.00MB;; vol258=281650.31MB;; CHECK_VMWARE_API.PL OK - 8/9 VMs up: debian8(DOWN), vcenter-88-2(UP), vpn(UP), XXXXXXXX.com(UP), XXXXXXXX.com(UP), XXXXXXXX.com(UP), XXXXXXXX.com(UP), XXXXXXXX.com(UP), XXXXXXXX.com(UP) | vmcount=8units;; CHECK_VMWARE_API.PL UNKNOWN - 1/2 Hosts up: XX.XX.XX.XX(UNKNOWN), XX.XX.XX.XX(UP) | hostcount=1units;; CHECK_VMWARE_API.PL OK - 1/1 Cluster green: cluster#1(GREEN) | clustercount=1units;; CHECK_VMWARE_API.PL OK - XXXXXXXX.com(Running-Unmanaged), XXXXXXXX.com(Running-Unmanaged), XXXXXXXX.com(Running-Unmanaged), XXXXXXXX.com(Running-Unmanaged), XXXXXXXX.com(Running-Unmanaged), XXXXXXXX.com(Running-Unmanaged), vpn(Not running-Not installed), vcenter-88-2(Running-Unmanaged) | toolsok=0%;; CHECK_VMWARE_API.PL UNKNOWN - Interxion MAD2 overall status=gray CHECK_VMWARE_API.PL OK - No config issues | issues=0;; CHECK_VMWARE_API.PL OK - 8/8 VMs up (1 templates), 1/2 Hosts up, Interxion MAD2 overall status=gray, no config issues | vmcount=8units;; hostcount=1units;; config_issues=0;; CHECK_VMWARE_API.PL OK - No recommendations | recommendations=0;; CHECK_VMWARE_API.PL OK - net usage=4352.00 KBps | net_usage=4352.00KBps;; CHECK_VMWARE_API.PL OK - net receive=111.00 KBps | net_receive=111.00KBps;; CHECK_VMWARE_API.PL OK - net send=3426.00 KBps | net_send=3426.00KBps;; CHECK_VMWARE_API.PL OK - net receive=111.00 KBps, send=3426.00 KBps | net_receive=111.00KBps;; net_send=3426.00KBps;; real 0m38.762s user 0m29.331s sys 0m2.007s root@st:~/check_vmware_api#



Server Version Unavilable
by campanel, May 31, 2015

# ./check_vmware_api.pl -D IP -u opuser -p ****** -l cpu -s usage -w 92 -c 98 CHECK_VMWARE_API.PL CRITICAL - Server version unavailable at 'https://IP:443/sdk/vimService.wsdl' at /usr/lib/perl5/site_perl/5.8.8/VMware/VICommon.pm line 545. ___ solution: # cpan -D LWP



Server Version Unavilable
by bkingx, February 28, 2015

I am also getting the Server version unavailable message when running the check but, being a n00b, I don't know how to apply the work around suggested by ginter. Can someone please tell me the steps to make this work correctly? I have: Ubuntu 14.04 Nagios Core 4.0.8 Perl 5.18.2 VMware Perl SDK 5.1



Work around for "Server version unavailable"
by giner, December 31, 2014

Here is a work around for everyone who can't make check_vmware_api work on recent OS with new perl and recent VMware Perl SDK. Prerequisites: - Ubuntu 14.04 Server (perl v5.18.2) - VMware-vSphere-Perl-SDK-5.5.0-2043780 - check_vmware_api.pl 0.7.1 Basic installation: apt-get install perl-doc libssl-dev libxml-libxml-perl libarchive-zip-perl libcrypt-ssleay-perl libclass-methodmaker-perl libuuid-perl libdata-dump-perl libsoap-lite-perl libio-compress-perl tar -xf VMware-vSphere-Perl-SDK-5.5.0-2043780.x86_64.tar.gz -C /tmp cd /tmp/vmware-vsphere-cli-distrib ./vmware-install.pl Work around for "Server version unavailable": patch -b /usr/share/perl/5.18/VMware/VICommon.pm new(agent => "VI Perl"); + $user_agent->ssl_opts( SSL_verify_mode => 0 ); my $cookie_jar = HTTP::Cookies->new(ignore_discard => 1); $user_agent->cookie_jar($cookie_jar); $user_agent->protocols_allowed(['http', 'https']); @@ -502,7 +503,7 @@ sub query_server_version { BEGIN { #To remove SSL Warning, switching from IO::Socket::SSL to Net::SSL - $ENV{PERL_NET_HTTPS_SSL_SOCKET_CLASS} = "Net::SSL"; + #$ENV{PERL_NET_HTTPS_SSL_SOCKET_CLASS} = "Net::SSL"; #To remove host verification $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0; } @@ -526,6 +527,7 @@ } } my $user_agent = LWP::UserAgent->new(agent => "VI Perl"); + $user_agent->ssl_opts( SSL_verify_mode => 0 ); my $cookie_jar = HTTP::Cookies->new(ignore_discard => 1); $user_agent->cookie_jar($cookie_jar); $user_agent->protocols_allowed(['http', 'https']); @@ -2108,6 +2110,7 @@ sub new { my ($class, $url) = @_; my $user_agent = LWP::UserAgent->new(agent => "VI Perl"); + $user_agent->ssl_opts( SSL_verify_mode => 0 ); my $cookie_jar = HTTP::Cookies->new(ignore_discard => 1); $user_agent->cookie_jar( $cookie_jar ); $user_agent->protocols_allowed( ['http', 'https'] ); *****************************************************************



IO vmhba
by 4l3x4ndr3, September 30, 2014

Hello From what I found, the script takes the standard IO latency vmhba (vmhba0):   /usr/local/nagios/libexec/check_esx3-0.5.pl D xxxx xxxx H -u nagiosvc p xxxx -l io CHECK_ESX3-0.5.PL OK - aborted commands io = 0, io bus resets = 0, io = 4 ms read latency, write latency = 0 ms, = 0 ms latency kernel, device = 0 ms latency, queue latency ms = 0 | io_aborted = 0 ;; io_busresets = 0 ;; io_read = 4ms;; io_write = 0ms;; io_kernel = 0ms;; io_device = 0ms;; io_queue = 0ms;; I have other vmhba, and what matters most is not the 0. You can customize the script to collect another? How can I do? Grateful!



Stopped working after update of liblwp-protocol-https-perl
by EdwinVanRee, July 31, 2014

Great plugin, we use it for years! Yesterday however I updated our Ubuntu server and the script does not work anymore. Error is: Server version unavailable at 'https://x.x.x.x:443/sdk/vimService.wsdl' at /usr/lib/perl5/5.18/VMware/VICommon.pm line 545 I narrowed down the offending update to: liblwp-protocol-https-perl, version 6.04-2ubuntu0.1. I reverted back to our backup and did not install this module, it is working fine again.



Percentage issue
by darkweaver87, March 31, 2014

Good plugin but the percentage is buggy. For host swap check for instance you have to check against the host total swap usable. For instance I got an alert because my ESX is using 20MB of swap on 1.5GB. This is not exactly 20%.



Excellent
by niriw, February 28, 2014

Does what it says. I was able to setup this plugin without lot of problems for ESXi host. I still cannot create configuration for VM monitoring though. Can anybody help with the configuration I need to perform for monitoring VM cpu and memory parameters?



Bug in script
by Pradyumna, February 28, 2014

Working fine but Esxi logs are growing every check create a Login event and a logout event in the event table of the Esxi. We get a lot of check (2 check per VM every 5min). That is generating millions of lines in the Esxi database which became very slow. We already reduce the event&task conservation time but not enough. Does anyone know a way to limit the number of login to Esxi done by the check ? Regards, Pradyumna



Great script - One problem installing
by speace, January 31, 2014

Great script does everything that I need. One note for people trying to install it. In my instance I am running Nagios on the latest Ubuntu server version. I experienced the "(Service Check Timed Out)" problem. I then tried installing the older Net-Http perl module (v 6.3): perl -MCPAN -e shell install GAAS/Net-HTTP-6.03.tar.gz After installing that the Service Check Timed Out error went away, but was replaced with: "Undefined subroutine &LWP::Protocol::https::Socket::can_read called at /usr/local/share/perl5/LWP/Protocol/http.pm line 22" A little research (thank you GOOGLE!) found the fix. You also need to re-install Bundle::LWP from an older version, not just Net-HTTP. perl -MCPAN -e shell install GAAS/libwww-perl-6.03.tar.gz. Now the sctipt is working great and does everything that I need.



Awesome plugin!
by dlawless, December 31, 2013

This plugin does everything you have stated, I was wondering if it was possible to pull disk statistics from this? I want to be able to pull the disk iops / read / write latency and I would want to do it at the datastore level. I can retrieve this information when i log into the vcenter and do stats show. Didn't know if this would be something that was relatively easy to add. Thanks for the plugin!



Nice Check!
by Vivawest, December 31, 2013

This is a very good Check for our environment. For those experiencing timeouts: Try to install libxml-libxml-perl ( sudo apt-get install libxml-libxml-perl on Ubuntu ) . The VMware vSphere SDK for Perl had a Output telling that it can't be found. After Installation the Checks via console were a lot faster (like 1 second) and i didn't get a timout on Icinga anymore.



Nice but big impact
by wadcyr8_197, November 30, 2013

Hi, this works fine on our infrastructure, but we get some issue donc vcenter database growing. every check create a Login event and a logout event in the event table of the vcenter. We get a lot of check (2 check per VM every 5min). That is generating millions of lines in the vcenter database which became very slow. We already reduce the event&task conservation time but not enough. Does anyone know a way to limite the number of login to vcenter done by the check ?



Nice plugin !
by NooJ, November 30, 2013

Good check here. Work like a charm when I launch this by command line (ie. ./check_vmware_api -H 192.168.2.25 -u supervision -p **** -l runtime -s status ) But when I launch this in NAGIOS I get : (Service Check Timed Out) I already tried to install older Net-Http perl module (v 6.3) perl -MCPAN -e shell install GAAS/Net-HTTP-6.03.tar.gz But nothing change. Any help here ?



timeout issues
by gardenik, May 31, 2013

Hi all, for timeout issues with this plugin like: /check_vmware_api -H xxxx -u root -p xxxx -l cpu CHECK_VMWARE_API UNKNOWN - plugin timed out (timeout 30s) the solution is to install older Net-Http perl module (v 6.3) perl -MCPAN -e shell install GAAS/Net-HTTP-6.03.tar.gz



DataStorage
by jarduini, April 30, 2013

There is a way to add a total datastorage usage and free space of the DC? BTW excelent check! Thanks a Lot Javier



using the plugin to monitor nfs datastore latency
by gg, January 31, 2013

Hello, is it possible to use it to monitor a NFS datastore latency ? which would be the syntax? thanks



got an issue
by jerry123je, November 30, 2012

Hi guys, I use this script on two of my nagios (different site) one is now in use and with a very good reply. another one has a big issue that after i installed basic component and vmware tool kit.this script can run with out error but only a time out output. ./check_vmware_api -H xxxx -u root -p xxxx -l cpu CHECK_VMWARE_API UNKNOWN - plugin timed out (timeout 30s) could anyone give some suggestion on this?



answer to rnygren
by vallsit, July 31, 2011

You're writing - h 10.2.2.1 but -h is for showing the script help In order to check that address you should type -H (in capital letters) host_address



great script - missing a few things
by binaryred, March 31, 2011

I have one complaint, in that the script defines a DataCenter as the vcenter, where a DataCenter should be a data center in vcenter. I have multiple sites with multiple machines at each site, organized into DataCenters at each site and clusters inside each DataCenter. This brings me to my only request. It would be great to be able to get the stats on the clusters themselves. Stats on the vcenter cpu as a whole For example), doesn't help me when I have machines in multiple locations that can't interact with each other. Stats for Clusters would help me tremendously to see if I am running low on resources at a particular site, and if I need to add another ESXi machine or just increase the phyical memory on an ESXi machine. Otherwise, after installing the VMware-vSphere-Perl-SDK modules, the script runs great and works very well. It could just be a bit better with my recommendations.



Failre to load nagios with this as a service
by rnygren, September 30, 2010

does anyone have an example of this script as a nagios service. I keep getting a config error. They dont seem to log the config errors in nagios. I can run from command line. I tried combining ars named pair separate and together but still get error. command line from libexec dir check_esx -h 10.2.2.1 -l CPU -u ss -p wer in config file define service{ use local-service ; Name of service template to use host_name frhg-vcenter service_description CPU check_command check_esx!- h 10.2.2.1!-u ss!-p wer!-l CPU notifications_enabled 0 } Any ideas or examples?



Add a Review

You must be logged in to submit a review.

Thank you for your review!

Your review has been submitted and is pending approval.

Recommend

To:


From:


Thank you for your recommendation!

Your recommendation has been sent.

Project Stats
Rating
4.1 (45)
Favorites
10
Views
289,511