#!/usr/bin/perl -w #check_3i_cpu v1.5 # # Created Feb 2008 by Carlos R. Tronco (cars@lostroncos.org) # # Last Modified: DD/MM/YY by FML # 06/03/08 by CRT - Cleaned up code. Getting view # just for host not for datacenter since this is # targeted at reporting on hosts for Nagios. # ##OBJECTIVE #--------- # This script connects to a specified ESX 3i server and checks on the status of the # storage subsystem. It reports the status in a format suitable for use with Nagios. # Usage: # check_3i_storage --username --password --server # # # * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # * COLLABORATIVE FUSION, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, # * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; # * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, # * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR # * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # use strict; use warnings; use VMware::VIRuntime; #Set the version # for this script so it can be queried from command line $Util::script_version = "1.5"; # my %ERRORS=('GREEN'=>0, 'YELLOW'=>1, 'RED'=>2, 'UNKNOWN'=>3, 'DEPENDENT'=>4); my $verbose = 0; # read/validate command line options and connect to the server Opts::add_options(); Opts::parse(); Opts::validate(); # Connect to the server Util::connect(); # get all hosts under this datacenter my $host = Vim::find_entity_view(view_type => 'HostSystem', filter =>{}); if (!$host) { die "Host '" . get_option('server'). "' not found\n"; } #storage element holder. my $element; # Array Index my $idx; # Status Red/Green/Yellow my $hoststatus; # Descriptive Text for status my $hoststatusdesc; # if ($verbose) {print "Hosts found:\n";} # Assume everything is green to start with $hoststatus = "Green" ; # Empty our descriptive text $hoststatusdesc = ""; #Just so we know we're getting a valid connection if ($verbose) {print "Boot time " . $host->runtime->bootTime . "\n";} $idx = 0; # Get Array of StorageStatusInfo elements (relate to each component) my $ary = $host->runtime->healthSystemRuntime->hardwareStatusInfo->cpuStatusInfo; #Get upper bound of our element array my $ub = $#$ary; # Set worst element status to Green my $worst_ele = "GREEN"; # Iterate over our array of storageStatusInfo elements for ( $idx = 0; $idx <= $ub; $idx++){ #use elemenet to save a whole bunch of typing $element = $host->runtime->healthSystemRuntime->hardwareStatusInfo->cpuStatusInfo->[$idx]; # my ($ele_name,$ele_status_summary, $ele_status_key, $ele_status_label, $ele_opinfo_prop, $ele_opinfo_val); #Name of the element -ex: 'Controller 0 (PERC 6/i Integrated)' $ele_name = $element->name; #Status Summary Descriptive text for this element. # Empty if it's okay $ele_status_summary = $element->status->summary; # Red/green/yellow status $ele_status_label = $element->status->label; #if this element is not green then set the worst element status and # hoststatus descriptive text for output to Nagios if ($ele_status_label ne "Green") { if ($ele_status_label eq "Red") { $worst_ele = uc($ele_status_label); } elsif ( ($worst_ele ne "RED") && ($ele_status_label eq "Yellow")){ $worst_ele = uc($ele_status_label); } elsif (( $worst_ele ne "YELLOW") && ($ele_status_label eq "Unknown")) { $worst_ele = uc($ele_status_label); } #$hoststatusdesc .= "$ele_name has status of $ele_status_label: [$ele_status_summary]\n"; $hoststatusdesc .= "$ele_name has status of $ele_status_label\n"; }; if ($verbose) { print "$ele_name Has status of $ele_status_label\n";} } if ($worst_ele ne "GREEN") { print $hoststatusdesc; }else { print "CPU status is GREEN \n"; } #Disconnect from the server before we exit script Util::disconnect(); # exit $ERRORS{$worst_ele};