From 4f63b93a9b58e1c958233315683450092dc3d2df Mon Sep 17 00:00:00 2001 From: Martin Fuerstenau Date: Fri, 5 Aug 2022 23:50:32 +0200 Subject: [PATCH] Version 1.2.5 - some bugfixes and changes. See HISTORY --- HISTORY | 11 +++++ check_vmware_esx.pl | 89 +++++++++++++++++++++++++++++------- command_reference | 71 ++++++++++++++++++++++++++-- modules/help.pm | 72 ++++++++++++++++++++++++++++- modules/host_runtime_info.pm | 38 +++++++++++++-- modules/host_volumes_info.pm | 29 ++++++++++++ modules/vm_storage_path.pm | 38 +++++++++++++++ 7 files changed, 323 insertions(+), 25 deletions(-) create mode 100644 modules/host_volumes_info.pm create mode 100644 modules/vm_storage_path.pm diff --git a/HISTORY b/HISTORY index 7e85985..02a24e7 100644 --- a/HISTORY +++ b/HISTORY @@ -1332,3 +1332,14 @@ was done is printed - Remove output of guestToolsUnmanaged if --open_vm_tools_ok - Fully ignore unknown states for hardware + +- 04 Auf 2022 M.Fuerstenau version 1.2.5 + - Renamed module host_list_vm_volumes_info to host_volumes_info + because name was misleading + - Minor corrections in help.pm + - New option --show-storage for runtime->listvms via host ore DC + - Fixed bug in blacklist/whitelist. Was casesensitve by default. This leads + to problems if for example a VM is defined in ESX with uppercase letters + and check is with lowercase (MYSERVER vs. myserver). So for example + checking for snapshots may result in no old snapshots found while + there are some. Fixed by adding option --ignore_casesensitive. diff --git a/check_vmware_esx.pl b/check_vmware_esx.pl index 30d558c..fb44b3c 100755 --- a/check_vmware_esx.pl +++ b/check_vmware_esx.pl @@ -488,7 +488,7 @@ # - host_net_info.pm -> host_net_info() # - host_disk_io_info.pm -> host_disk_io_info() # - datastore_volumes_info.pm -> datastore_volumes_info() -# - host_list_vm_volumes_info.pm -> host_list_vm_volumes_info() +# - host_volumes_info.pm -> host_volumes_info() # - host_runtime_info.pm -> host_runtime_info() # - host_service_info.pm -> host_service_info() # - host_storage_info.pm -> host_storage_info() @@ -1395,7 +1395,7 @@ # - 26 Nov 2019 M.Fuerstenau version 1.2.3 # - Fixed duplicate definition in datastore_volumes_info.pm # -# - 9 Jun 2022 M.Fuerstenau version 1.2.4 +# - 3 Jun 2022 M.Fuerstenau version 1.2.4 # - Added several patches (pull requests) from Github: # - new command line option "--moref" that allows for selecting virtual # machines by their Managed Object Reference name (e.g. "vm-193") @@ -1414,7 +1414,18 @@ # is printed # - Remove output of guestToolsUnmanaged if --open_vm_tools_ok # - Fully ignore unknown states for hardware - +# +# - 04 Auf 2022 M.Fuerstenau version 1.2.5 +# - Renamed module host_list_vm_volumes_info to host_volumes_info +# because name was misleading +# - Minor corrections in help.pm +# - New option --show-storage for runtime->listvms via host ore DC +# - Fixed bug in blacklist/whitelist. Was casesensitve by default. This leads +# to problems if for example a VM is defined in ESX with uppercase letters +# and check is with lowercase (MYSERVER vs. myserver). So for example +# checking for snapshots may result in no old snapshots found while +# there are some. Fixed by adding option --ignore_casesensitive. +# use strict; @@ -1466,7 +1477,7 @@ BEGIN # General stuff our $version; # Only for showing the version -our $prog_version = '1.2.4'; # Contains the program version number +our $prog_version = '1.2.5'; # Contains the program version number our $ProgName = basename($0); my $PID = $$; # Stores the process identifier of the actual run. This will be @@ -1557,6 +1568,7 @@ BEGIN our $blacklist; # Contains the blacklist our $whitelist; # Contains the whitelist +our $ignore_casesensitive; # Option to handle blacklist/whitelist case insensitive our $isregexp; # treat names, blacklist and whitelists as regexp @@ -1599,9 +1611,9 @@ BEGIN # set this default to "n". my $statelabels; # To overwrite $statelabels_def via commandline. our $openvmtools; # Signalize that you use Open VM Tools instead of the servers one. -our $no_vmtools; # Signalize that not having VMware tools is ok +our $no_vmtools; # Signalize that not having VMware tools is ok our $hidekey; # Hide licenses key when requesting license informations - +our $show_storage; # Show storage shows storage used bei VM. Used in conjunction with listvms my $trace; @@ -1646,11 +1658,13 @@ BEGIN "nosession" => \$nosession, "B=s" => \$blacklist, "exclude=s" => \$blacklist, "W=s" => \$whitelist, "include=s" => \$whitelist, + "ignore_casesensitive" => \$ignore_casesensitive, "t=s" => \$timeout, "timeout=s" => \$timeout, "V" => \$version, "version" => \$version, "d" => \$debug, "debug" => \$debug, "ignore_unknown" => \$ignoreunknown, "ignore_warning" => \$ignorewarning, + "show-storage" => \$show_storage, "trace=s" => \$trace, "listsensors" => \$listsensors, "ignore_health" => \$ignorehealth, @@ -2291,7 +2305,7 @@ sub main_select if (defined($host)) { - # The following if black is only needed if we check a ESX server via the + # The following if block is only needed if we check a ESX server via the # the datacenten (vsphere server) instead of doing it directly. # Directly is better @@ -2300,6 +2314,13 @@ sub main_select { $esx_server = {name => $host}; } + + if (defined $show_storage) + { + require vm_storage_path; + import vm_storage_path; + } + if ($select eq "cpu") { require host_cpu_info; @@ -2330,9 +2351,9 @@ sub main_select } if ($select eq "volumes") { - require host_list_vm_volumes_info; - import host_list_vm_volumes_info; - ($result, $output) = host_list_vm_volumes_info($esx_server, $maintenance_mode_state); + require host_volumes_info; + import host_volumes_info; + ($result, $output) = host_volumes_info($esx_server, $maintenance_mode_state); return($result, $output); } if ($select eq "runtime") @@ -2702,9 +2723,18 @@ sub isblacklisted return 0; } +#our $ignore_casesensitive; # Option to handle blacklist/whitelist case insensitive + if ($regexpflag == 0) { - $ret = grep(/$candidate/, $$blacklist_ref); + if (defined($ignore_casesensitive)) + { + $ret = grep(/$candidate/i, $$blacklist_ref); + } + else + { + $ret = grep(/$candidate/, $$blacklist_ref); + } } else { @@ -2712,9 +2742,19 @@ sub isblacklisted foreach $blacklist (@blacklist) { - if ($candidate =~ m/$blacklist/) + if (defined($ignore_casesensitive)) { - $hitcount++; + if ($candidate =~ m/$blacklist/i) + { + $hitcount++; + } + } + else + { + if ($candidate =~ m/$blacklist/) + { + $hitcount++; + } } } @@ -2741,7 +2781,14 @@ sub isnotwhitelisted if ($regexpflag == 0) { - $ret = ! grep(/$candidate/, $$whitelist_ref); + if (defined($ignore_casesensitive)) + { + $ret = ! grep(/$candidate/i, $$whitelist_ref); + } + else + { + $ret = ! grep(/$candidate/, $$whitelist_ref); + } } else { @@ -2749,9 +2796,19 @@ sub isnotwhitelisted foreach $whitelist (@whitelist) { - if ($candidate =~ m/$whitelist/) + if (defined($ignore_casesensitive)) + { + if ($candidate =~ m/$whitelist/i) + { + $hitcount++; + } + } + else { - $hitcount++; + if ($candidate =~ m/$whitelist/) + { + $hitcount++; + } } } diff --git a/command_reference b/command_reference index b2b0333..8f1fdf8 100644 --- a/command_reference +++ b/command_reference @@ -1,5 +1,5 @@ -check_vmware_esx.pl,Version 1.2.1 +check_vmware_esx.pl,Version 1.2.5 This vmware Infrastructure monitoring 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 @@ -95,6 +95,9 @@ or with Use blacklist OR(!) whitelist. Using both in one statement is not allowed. + --ignore_casesensitive Black-/whitlist is normally case sensitive. So for example + if check is for VM myserver and the name in ESX is MYSERVER + it would not match. --isregexp Whether to treat name, blacklist and whitelist as regexp -w, --warning= Warning threshold. -c, --critical= Critical threshold. @@ -112,7 +115,7 @@ Runtime Info: -S, --select=runtime Shows all runtime info for the datacenter/Vcenter. No thresholds are allowed here or with --s, --subselect=listvms List of vmware machines and their power state.. +-s, --subselect=listvms List of virtual machines and their power state. BEWARE!! In larger environments systems can cause trouble displaying the informations needed due to the mass of data. @@ -124,6 +127,9 @@ or with Use blacklist OR(!) whitelist. Using both in one statement is not allowed. + --ignore_casesensitive Black-/whitlist is normally case sensitive. So for example + if check is for VM myserver and the name in ESX is MYSERVER + it would not match. --isregexp Whether to treat blacklist and whitelist as regexp --multiline Multiline output in overview. This mean technically that a multiline output uses a HTML
for the GUI instead of @@ -160,6 +166,9 @@ or Use blacklist OR(!) whitelist. Using both in one statement is not allowed. + --ignore_casesensitive Black-/whitlist is normally case sensitive. So for example + if check is for VM myserver and the name in ESX is MYSERVER + it would not match. --isregexp Whether to treat blacklist and whitelist as regexp --multiline Multiline output in overview. This mean technically that a multiline output uses a HTML
for the GUI instead of @@ -180,6 +189,9 @@ or Use blacklist OR(!) whitelist. Using both in one statement is not allowed. + --ignore_casesensitive Black-/whitlist is normally case sensitive. So for example + if check is for VM myserver and the name in ESX is MYSERVER + it would not match. --isregexp Whether to treat blacklist and whitelist as regexp --multiline Multiline output in overview. This mean technically that a multiline output uses a HTML
for the GUI instead of @@ -195,6 +207,9 @@ or Use blacklist OR(!) whitelist. Using both in one statement is not allowed. + --ignore_casesensitive Black-/whitlist is normally case sensitive. So for example + if check is for VM myserver and the name in ESX is MYSERVER + it would not match. --isregexp Whether to treat blacklist and whitelist as regexp --multiline Multiline output in overview. This mean technically that a multiline output uses a HTML
for the GUI instead of @@ -229,6 +244,9 @@ or Use blacklist OR(!) whitelist. Using both in one statement is not allowed. + --ignore_casesensitive Black-/whitlist is normally case sensitive. So for example + if check is for VM myserver and the name in ESX is MYSERVER + it would not match. --isregexp Whether to treat blacklist and whitelist as regexp --multiline Multiline output in overview. This mean technically that a multiline output uses a HTML
for the GUI instead of @@ -256,6 +274,9 @@ Snapshots Use blacklist OR(!) whitelist. Using both in one statement is not allowed. + --ignore_casesensitive Black-/whitlist is normally case sensitive. So for example + if check is for VM myserver and the name in ESX is MYSERVER + it would not match. --isregexp Whether to treat blacklist and whitelist as regexp --listall List all VMs with all snapshots. --poweredonly List only VMs which are powered on. @@ -417,6 +438,9 @@ or with Use blacklist OR(!) whitelist. Using both in one statement is not allowed. + --ignore_casesensitive Black-/whitlist is normally case sensitive. So for example + if check is for VM myserver and the name in ESX is MYSERVER + it would not match. --isregexp Whether to treat name, blacklist and whitelist as regexp -w, --warning= Warning threshold. -c, --critical= Critical threshold. @@ -482,6 +506,9 @@ Host mounted media: Use blacklist OR(!) whitelist. Using both in one statement is not allowed. + --ignore_casesensitive Black-/whitlist is normally case sensitive. So for example + if check is for VM myserver and the name in ESX is MYSERVER + it would not match. --isregexp Whether to treat blacklist and whitelist as regexp --listall List all VMs with all mounted media. --multiline Multiline output in overview. This mean technically that @@ -499,6 +526,9 @@ Service info: Use blacklist OR(!) whitelist. Using both in one statement is not allowed. + --ignore_casesensitive Black-/whitlist is normally case sensitive. So for example + if check is for VM myserver and the name in ESX is MYSERVER + it would not match. --isregexp Whether to treat blacklist and whitelist as regexp --multiline Multiline output in overview. This mean technically that a multiline output uses a HTML
for the GUI instead of @@ -517,13 +547,18 @@ Runtime info: or with -s, --subselect=con Shows connection state. or --s, --subselect=listvms List of vmware machines and their statuses. +-s, --subselect=listvms List of virtual machines and their power state. + --show-storage Shows storage used by the VM. + -B, --exclude= Blacklist VMs. -W, --include= Whitelist VMs. Use blacklist OR(!) whitelist. Using both in one statement is not allowed. + --ignore_casesensitive Black-/whitlist is normally case sensitive. So for example + if check is for VM myserver and the name in ESX is MYSERVER + it would not match. --isregexp Whether to treat blacklist and whitelist as regexp --multiline Multiline output in overview. This mean technically that a multiline output uses a HTML
for the GUI instead of @@ -550,6 +585,9 @@ or Use blacklist OR(!) whitelist. Using both in one statement is not allowed. + --ignore_casesensitive Black-/whitlist is normally case sensitive. So for example + if check is for VM myserver and the name in ESX is MYSERVER + it would not match. --isregexp Whether to treat blacklist and whitelist as regexp or -s, --subselect=storagehealth Local(!) storage status check. @@ -559,6 +597,9 @@ or Use blacklist OR(!) whitelist. Using both in one statement is not allowed. + --ignore_casesensitive Black-/whitlist is normally case sensitive. So for example + if check is for VM myserver and the name in ESX is MYSERVER + it would not match. --isregexp Whether to treat blacklist and whitelist as regexp --multiline Multiline output in overview. This mean technically that a multiline output uses a HTML
for the GUI instead of @@ -573,6 +614,9 @@ or Use blacklist OR(!) whitelist. Using both in one statement is not allowed. + --ignore_casesensitive Black-/whitlist is normally case sensitive. So for example + if check is for VM myserver and the name in ESX is MYSERVER + it would not match. --isregexp Whether to treat blacklist and whitelist as regexp --multiline Multiline output in overview. This mean technically that a multiline output uses a HTML
for the GUI instead of @@ -587,6 +631,9 @@ or Use blacklist OR(!) whitelist. Using both in one statement is not allowed. + --ignore_casesensitive Black-/whitlist is normally case sensitive. So for example + if check is for VM myserver and the name in ESX is MYSERVER + it would not match. --isregexp Whether to treat blacklist and whitelist as regexp --multiline Multiline output in overview. This mean technically that a multiline output uses a HTML
for the GUI instead of @@ -616,6 +663,9 @@ Storage info: Use blacklist OR(!) whitelist. Using both in one statement is not allowed. + --ignore_casesensitive Black-/whitlist is normally case sensitive. So for example + if check is for VM myserver and the name in ESX is MYSERVER + it would not match. --isregexp Whether to treat blacklist and whitelist as regexp or with -s, --subselect=adapter List host bus adapters. @@ -625,6 +675,9 @@ or with Use blacklist OR(!) whitelist. Using both in one statement is not allowed. + --ignore_casesensitive Black-/whitlist is normally case sensitive. So for example + if check is for VM myserver and the name in ESX is MYSERVER + it would not match. --isregexp Whether to treat blacklist and whitelist as regexp --multiline Multiline output in overview. This mean technically that a multiline output uses a HTML
for the GUI instead of @@ -645,6 +698,9 @@ or with Use blacklist OR(!) whitelist. Using both in one statement is not allowed. + --ignore_casesensitive Black-/whitlist is normally case sensitive. So for example + if check is for VM myserver and the name in ESX is MYSERVER + it would not match. --isregexp Whether to treat blacklist and whitelist as regexp --alertonly List only alerting units. Important here to avoid masses of data. --multiline Multiline output in overview. This mean technically that @@ -664,6 +720,9 @@ or with Use blacklist OR(!) whitelist. Using both in one statement is not allowed. + --ignore_casesensitive Black-/whitlist is normally case sensitive. So for example + if check is for VM myserver and the name in ESX is MYSERVER + it would not match. --isregexp Whether to treat blacklist and whitelist as regexp --alertonly List only alerting units. Important here to avoid masses of data. --multiline Multiline output in overview. This mean technically that @@ -689,6 +748,9 @@ Snapshots Use blacklist OR(!) whitelist. Using both in one statement is not allowed. + --ignore_casesensitive Black-/whitlist is normally case sensitive. So for example + if check is for VM myserver and the name in ESX is MYSERVER + it would not match. --isregexp Whether to treat blacklist and whitelist as regexp --listall List all VMs with all snapshots. --poweredonly List only VMs which are powered on. @@ -957,6 +1019,9 @@ or with Use blacklist OR(!) whitelist. Using both in one statement is not allowed. + --ignore_casesensitive Black-/whitlist is normally case sensitive. So for example + if check is for VM myserver and the name in ESX is MYSERVER + it would not match. --isregexp Whether to treat name, blacklist and whitelist as regexp -w, --warning= Warning threshold. -c, --critical= Critical threshold. diff --git a/modules/help.pm b/modules/help.pm index 379ca2b..bbe9388 100644 --- a/modules/help.pm +++ b/modules/help.pm @@ -35,6 +35,9 @@ sub hint print " -S, --select=service shows host service info.\n"; print " -B, --exclude= blacklist services.\n"; print " -W, --include= whitelist services.\n"; + print " --ignore_casesensitive Black-/whitlist is normally case sensitive. So for example\n"; + print " if check is for VM myserver and the name in ESX is MYSERVER\n"; + print " it would not match.\n"; print " --isregexp whether to treat blacklist and whitelist as regexp\n"; print " --multiline Multiline output in overview. This mean technically that\n"; print " a multiline output uses a HTML
for the GUI instead of\n"; @@ -180,6 +183,9 @@ sub print_help print " Use blacklist OR(!) whitelist. Using both in one statement\n"; print " is not allowed.\n"; print "\n"; + print " --ignore_casesensitive Black-/whitlist is normally case sensitive. So for example\n"; + print " if check is for VM myserver and the name in ESX is MYSERVER\n"; + print " it would not match.\n"; print " --isregexp Whether to treat name, blacklist and whitelist as regexp\n"; print "-w, --warning= Warning threshold.\n"; print "-c, --critical= Critical threshold.\n"; @@ -197,7 +203,7 @@ sub print_help print "-S, --select=runtime Shows all runtime info for the datacenter/Vcenter.\n"; print " No thresholds are allowed here\n"; print "or with\n"; - print "-s, --subselect=listvms List of vmware machines and their power state..\n"; + print "-s, --subselect=listvms List of virtual machines and their power state.\n"; print "\n"; print " BEWARE!! In larger environments systems can cause trouble displaying\n"; print " the informations needed due to the mass of data.\n"; @@ -209,6 +215,9 @@ sub print_help print " Use blacklist OR(!) whitelist. Using both in one statement\n"; print " is not allowed.\n"; print "\n"; + print " --ignore_casesensitive Black-/whitlist is normally case sensitive. So for example\n"; + print " if check is for VM myserver and the name in ESX is MYSERVER\n"; + print " it would not match.\n"; print " --isregexp Whether to treat blacklist and whitelist as regexp\n"; print " --multiline Multiline output in overview. This mean technically that\n"; print " a multiline output uses a HTML
for the GUI instead of\n"; @@ -245,6 +254,9 @@ sub print_help print " Use blacklist OR(!) whitelist. Using both in one statement\n"; print " is not allowed.\n"; print "\n"; + print " --ignore_casesensitive Black-/whitlist is normally case sensitive. So for example\n"; + print " if check is for VM myserver and the name in ESX is MYSERVER\n"; + print " it would not match.\n"; print " --isregexp Whether to treat blacklist and whitelist as regexp\n"; print " --multiline Multiline output in overview. This mean technically that\n"; print " a multiline output uses a HTML
for the GUI instead of\n"; @@ -265,6 +277,9 @@ sub print_help print " Use blacklist OR(!) whitelist. Using both in one statement\n"; print " is not allowed.\n"; print "\n"; + print " --ignore_casesensitive Black-/whitlist is normally case sensitive. So for example\n"; + print " if check is for VM myserver and the name in ESX is MYSERVER\n"; + print " it would not match.\n"; print " --isregexp Whether to treat blacklist and whitelist as regexp\n"; print " --multiline Multiline output in overview. This mean technically that\n"; print " a multiline output uses a HTML
for the GUI instead of\n"; @@ -280,6 +295,9 @@ sub print_help print " Use blacklist OR(!) whitelist. Using both in one statement\n"; print " is not allowed.\n"; print "\n"; + print " --ignore_casesensitive Black-/whitlist is normally case sensitive. So for example\n"; + print " if check is for VM myserver and the name in ESX is MYSERVER\n"; + print " it would not match.\n"; print " --isregexp Whether to treat blacklist and whitelist as regexp\n"; print " --multiline Multiline output in overview. This mean technically that\n"; print " a multiline output uses a HTML
for the GUI instead of\n"; @@ -314,6 +332,9 @@ sub print_help print " Use blacklist OR(!) whitelist. Using both in one statement\n"; print " is not allowed.\n"; print "\n"; + print " --ignore_casesensitive Black-/whitlist is normally case sensitive. So for example\n"; + print " if check is for VM myserver and the name in ESX is MYSERVER\n"; + print " it would not match.\n"; print " --isregexp Whether to treat blacklist and whitelist as regexp\n"; print " --multiline Multiline output in overview. This mean technically that\n"; print " a multiline output uses a HTML
for the GUI instead of\n"; @@ -341,6 +362,9 @@ sub print_help print " Use blacklist OR(!) whitelist. Using both in one statement\n"; print " is not allowed.\n"; print "\n"; + print " --ignore_casesensitive Black-/whitlist is normally case sensitive. So for example\n"; + print " if check is for VM myserver and the name in ESX is MYSERVER\n"; + print " it would not match.\n"; print " --isregexp Whether to treat blacklist and whitelist as regexp\n"; print " --listall List all VMs with all snapshots.\n"; print " --poweredonly List only VMs which are powered on.\n"; @@ -507,6 +531,9 @@ sub print_help print " Use blacklist OR(!) whitelist. Using both in one statement\n"; print " is not allowed.\n"; print "\n"; + print " --ignore_casesensitive Black-/whitlist is normally case sensitive. So for example\n"; + print " if check is for VM myserver and the name in ESX is MYSERVER\n"; + print " it would not match.\n"; print " --isregexp Whether to treat name, blacklist and whitelist as regexp\n"; print "-w, --warning= Warning threshold.\n"; print "-c, --critical= Critical threshold.\n"; @@ -572,6 +599,9 @@ sub print_help print " Use blacklist OR(!) whitelist. Using both in one statement\n"; print " is not allowed.\n"; print "\n"; + print " --ignore_casesensitive Black-/whitlist is normally case sensitive. So for example\n"; + print " if check is for VM myserver and the name in ESX is MYSERVER\n"; + print " it would not match.\n"; print " --isregexp Whether to treat blacklist and whitelist as regexp\n"; print " --listall List all VMs with all mounted media.\n"; print " --multiline Multiline output in overview. This mean technically that\n"; @@ -589,6 +619,9 @@ sub print_help print " Use blacklist OR(!) whitelist. Using both in one statement\n"; print " is not allowed.\n"; print "\n"; + print " --ignore_casesensitive Black-/whitlist is normally case sensitive. So for example\n"; + print " if check is for VM myserver and the name in ESX is MYSERVER\n"; + print " it would not match.\n"; print " --isregexp Whether to treat blacklist and whitelist as regexp\n"; print " --multiline Multiline output in overview. This mean technically that\n"; print " a multiline output uses a HTML
for the GUI instead of\n"; @@ -607,13 +640,18 @@ sub print_help print "or with\n"; print "-s, --subselect=con Shows connection state.\n"; print "or\n"; - print "-s, --subselect=listvms List of vmware machines and their statuses.\n"; + print "-s, --subselect=listvms List of virtual machines and their power state.\n"; + print " --show-storage Shows storage used by the VM.\n"; + print "\n"; print "-B, --exclude= Blacklist VMs.\n"; print "-W, --include= Whitelist VMs.\n"; print "\n"; print " Use blacklist OR(!) whitelist. Using both in one statement\n"; print " is not allowed.\n"; print "\n"; + print " --ignore_casesensitive Black-/whitlist is normally case sensitive. So for example\n"; + print " if check is for VM myserver and the name in ESX is MYSERVER\n"; + print " it would not match.\n"; print " --isregexp Whether to treat blacklist and whitelist as regexp\n"; print " --multiline Multiline output in overview. This mean technically that\n"; print " a multiline output uses a HTML
for the GUI instead of\n"; @@ -640,6 +678,9 @@ sub print_help print " Use blacklist OR(!) whitelist. Using both in one statement\n"; print " is not allowed.\n"; print "\n"; + print " --ignore_casesensitive Black-/whitlist is normally case sensitive. So for example\n"; + print " if check is for VM myserver and the name in ESX is MYSERVER\n"; + print " it would not match.\n"; print " --isregexp Whether to treat blacklist and whitelist as regexp\n"; print "or\n"; print "-s, --subselect=storagehealth Local(!) storage status check.\n"; @@ -649,6 +690,9 @@ sub print_help print " Use blacklist OR(!) whitelist. Using both in one statement\n"; print " is not allowed.\n"; print "\n"; + print " --ignore_casesensitive Black-/whitlist is normally case sensitive. So for example\n"; + print " if check is for VM myserver and the name in ESX is MYSERVER\n"; + print " it would not match.\n"; print " --isregexp Whether to treat blacklist and whitelist as regexp\n"; print " --multiline Multiline output in overview. This mean technically that\n"; print " a multiline output uses a HTML
for the GUI instead of\n"; @@ -663,6 +707,9 @@ sub print_help print " Use blacklist OR(!) whitelist. Using both in one statement\n"; print " is not allowed.\n"; print "\n"; + print " --ignore_casesensitive Black-/whitlist is normally case sensitive. So for example\n"; + print " if check is for VM myserver and the name in ESX is MYSERVER\n"; + print " it would not match.\n"; print " --isregexp Whether to treat blacklist and whitelist as regexp\n"; print " --multiline Multiline output in overview. This mean technically that\n"; print " a multiline output uses a HTML
for the GUI instead of\n"; @@ -677,6 +724,9 @@ sub print_help print " Use blacklist OR(!) whitelist. Using both in one statement\n"; print " is not allowed.\n"; print "\n"; + print " --ignore_casesensitive Black-/whitlist is normally case sensitive. So for example\n"; + print " if check is for VM myserver and the name in ESX is MYSERVER\n"; + print " it would not match.\n"; print " --isregexp Whether to treat blacklist and whitelist as regexp\n"; print " --multiline Multiline output in overview. This mean technically that\n"; print " a multiline output uses a HTML
for the GUI instead of\n"; @@ -706,6 +756,9 @@ sub print_help print " Use blacklist OR(!) whitelist. Using both in one statement\n"; print " is not allowed.\n"; print "\n"; + print " --ignore_casesensitive Black-/whitlist is normally case sensitive. So for example\n"; + print " if check is for VM myserver and the name in ESX is MYSERVER\n"; + print " it would not match.\n"; print " --isregexp Whether to treat blacklist and whitelist as regexp\n"; print "or with\n"; print "-s, --subselect=adapter List host bus adapters.\n"; @@ -715,6 +768,9 @@ sub print_help print " Use blacklist OR(!) whitelist. Using both in one statement\n"; print " is not allowed.\n"; print "\n"; + print " --ignore_casesensitive Black-/whitlist is normally case sensitive. So for example\n"; + print " if check is for VM myserver and the name in ESX is MYSERVER\n"; + print " it would not match.\n"; print " --isregexp Whether to treat blacklist and whitelist as regexp\n"; print " --multiline Multiline output in overview. This mean technically that\n"; print " a multiline output uses a HTML
for the GUI instead of\n"; @@ -735,6 +791,9 @@ sub print_help print " Use blacklist OR(!) whitelist. Using both in one statement\n"; print " is not allowed.\n"; print "\n"; + print " --ignore_casesensitive Black-/whitlist is normally case sensitive. So for example\n"; + print " if check is for VM myserver and the name in ESX is MYSERVER\n"; + print " it would not match.\n"; print " --isregexp Whether to treat blacklist and whitelist as regexp\n"; print " --alertonly List only alerting units. Important here to avoid masses of data.\n"; print " --multiline Multiline output in overview. This mean technically that\n"; @@ -754,6 +813,9 @@ sub print_help print " Use blacklist OR(!) whitelist. Using both in one statement\n"; print " is not allowed.\n"; print "\n"; + print " --ignore_casesensitive Black-/whitlist is normally case sensitive. So for example\n"; + print " if check is for VM myserver and the name in ESX is MYSERVER\n"; + print " it would not match.\n"; print " --isregexp Whether to treat blacklist and whitelist as regexp\n"; print " --alertonly List only alerting units. Important here to avoid masses of data.\n"; print " --multiline Multiline output in overview. This mean technically that\n"; @@ -779,6 +841,9 @@ sub print_help print " Use blacklist OR(!) whitelist. Using both in one statement\n"; print " is not allowed.\n"; print "\n"; + print " --ignore_casesensitive Black-/whitlist is normally case sensitive. So for example\n"; + print " if check is for VM myserver and the name in ESX is MYSERVER\n"; + print " it would not match.\n"; print " --isregexp Whether to treat blacklist and whitelist as regexp\n"; print " --listall List all VMs with all snapshots.\n"; print " --poweredonly List only VMs which are powered on.\n"; @@ -1060,6 +1125,9 @@ sub print_help print " Use blacklist OR(!) whitelist. Using both in one statement\n"; print " is not allowed.\n"; print "\n"; + print " --ignore_casesensitive Black-/whitlist is normally case sensitive. So for example\n"; + print " if check is for VM myserver and the name in ESX is MYSERVER\n"; + print " it would not match.\n"; print " --isregexp Whether to treat name, blacklist and whitelist as regexp\n"; print "-w, --warning= Warning threshold.\n"; print "-c, --critical= Critical threshold.\n"; diff --git a/modules/host_runtime_info.pm b/modules/host_runtime_info.pm index f36fa7e..e2718f8 100644 --- a/modules/host_runtime_info.pm +++ b/modules/host_runtime_info.pm @@ -46,6 +46,7 @@ sub host_runtime_info my $poweredoff_out = ''; # Virtual machine powerstate temporary output my $suspended_out = ''; # Virtual machine powerstate temporary output my $value; + my $stor_path; my $vm; my $vm_state; my $vm_views; @@ -154,21 +155,50 @@ sub host_runtime_info } $vm_state = $vm->runtime->powerState->val; - + + if (defined $show_storage) + { + $stor_path = vm_storage_path($vm->name); + } + if ($vm_state eq "poweredOn") { $poweredon++; - $poweredon_out = $poweredon_out . $vm->name . " (" . $vm_state . ")" . $multiline; + if (!$alertonly) + { + if (defined $show_storage) + { + $poweredon_out = $poweredon_out . $vm->name . " (" . $vm_state . ") - Storage: " .$stor_path . $multiline; + } + else + { + $poweredon_out = $poweredon_out . $vm->name . " (" . $vm_state . ")" . $multiline; + } + } } if ($vm_state eq "poweredOff") { $poweredoff++; - $poweredoff_out = $poweredoff_out . $vm->name . " (" . $vm_state . ")" . $multiline; + if (defined $show_storage) + { + $poweredon_out = $poweredoff_out . $vm->name . " (" . $vm_state . ") - Storage: " .$stor_path . $multiline; + } + else + { + $poweredon_out = $poweredoff_out . $vm->name . " (" . $vm_state . ")" . $multiline; + } } if ($vm_state eq "suspended") { $suspended++; - $suspended_out = $suspended_out . $vm->name . " (" . $vm_state . ")" . $multiline; + if (defined $show_storage) + { + $suspended_out = $suspended_out . $vm->name . " (" . $vm_state . ") - Storage: " .$stor_path . $multiline; + } + else + { + $suspended_out = $suspended_out . $vm->name . " (" . $vm_state . ")" . $multiline; + } } } diff --git a/modules/host_volumes_info.pm b/modules/host_volumes_info.pm new file mode 100644 index 0000000..50144bd --- /dev/null +++ b/modules/host_volumes_info.pm @@ -0,0 +1,29 @@ +sub host_volumes_info + { + my ($host, $maintenance_mode_state) = @_; + my $host_view = Vim::find_entity_view(view_type => 'HostSystem', filter => $host, properties => ['name', 'datastore', 'runtime.inMaintenanceMode']); + + if (!defined($host_view)) + { + print "Host " . $$host{"name"} . " does not exist\n"; + exit 2; + } + + if (($host_view->get_property('runtime.inMaintenanceMode')) eq "true") + { + print "Notice: " . $host_view->name . " is in maintenance mode, check skipped\n"; + exit $maintenance_mode_state; + } + + if (!defined($host_view->datastore)) + { + print "Insufficient rights to access Datastores on the Host\n"; + exit 2; + } + + return datastore_volumes_info($host_view->datastore); + } + +# A module always must end with a returncode of 1. So placing 1 at the end of a module +# is a common method to ensure this. +1; diff --git a/modules/vm_storage_path.pm b/modules/vm_storage_path.pm new file mode 100644 index 0000000..8e8e38f --- /dev/null +++ b/modules/vm_storage_path.pm @@ -0,0 +1,38 @@ +sub vm_storage_path + { + my ($vmname) = @_; + my $output; + my $storage; + my $storage_array; + my $storage_path=" "; + + my $vm_view = Vim::find_entity_view(view_type => 'VirtualMachine', filter => {name => $vmname}, properties => ['name', 'storage']); + + if (defined($vm_view)) + { + $storage_array = $vm_view->storage->perDatastoreUsage; + + if (defined $storage_array) + { + foreach $storage (@{$storage_array}) + { + $storage_path = $storage->datastore->value; + } + + $storage_path =~ s/^.*://; + } + + $output = $storage_path; + } + else + { + $output = "No storage information available"; + } + + return ($output); + } + +# A module always must end with a returncode of 1. So placing 1 at the end of a module +# is a common method to ensure this. +1; +