#!/usr/bin/perl -w # Copyright 2006 VMware, Inc. All rights reserved. # This script prints all VM's and hosts under a datacenter ############################################################################# # modified version of datacenterlisting.pl from the VMware VI-Perl toolkit # samples. It queries a host(s) to get storage info status. I believe it will # only work with ESX 3i not the full blown 3.5 version. This is a simple crude # version that I'll use as a basis to create another one for use within Nagios # sample cmdline for checking one host: # check_3i_storage_simple --username --password --server # --datacenter ha-datacenter # CRT 2/22/08 cars@lostroncos.org # # use strict; use warnings; use VMware::VIRuntime; $Util::script_version = "1.0"; my %opts = ( datacenter => { type => "=s", help => "Datacenter name", required => 1, }, ); # read/validate options and connect to the server Opts::add_options(%opts); Opts::parse(); Opts::validate(); Util::connect(); # find datacenter my $datacenter = Opts::get_option('datacenter'); print "Datacenter = $datacenter\n"; my $datacenter_view = Vim::find_entity_view(view_type => 'Datacenter', filter => { name => $datacenter }); if (!$datacenter_view) { die "Datacenter '" . $datacenter . "' not found\n"; } # get all hosts under this datacenter my $host_views = Vim::find_entity_views(view_type => 'HostSystem', begin_entity => $datacenter_view); # print hosts my $counter = 1; #host object holder my $crthost; # storage element temp placeholder my $element; #array index my $idx; print "Hosts found:\n"; foreach (@$host_views) { print "$counter: " . $_->name . "\n"; $counter++; $host = $_; print "Boot time " . $_->runtime->bootTime . "\n"; #Reset array index $idx = 0; # Let's figure out how many elements are in the storageStatusInfo array my $ary = $host->runtime->healthSystemRuntime->hardwareStatusInfo->storageStatusInfo; my $ub = $#$ary; # for ( $idx = 0; $idx <= $ub; $idx++){ $element = $crthost->runtime->healthSystemRuntime->hardwareStatusInfo->storageStatusInfo->[$idx]; my ($ele_name,$ele_status_summary, $ele_status_key, $ele_status_label, $ele_opinfo_prop, $ele_opinfo_val); $ele_name = $element->name; $ele_status_summary = $element->status->summary; $ele_status_label = $element->status->label; print "$ele_name Has status of $ele_status_label\n"; }; }; # disconnect from the server Util::disconnect(); exit 0;