Last active
December 20, 2015 18:08
-
-
Save miebach/6173385 to your computer and use it in GitHub Desktop.
VMWare ESXi 4 LSI Raid nagios script http://vmware-forum.de/viewtopic.php?t=21886 https://mail.google.com/mail/u/0/#apps/krenn/140584e0a5e60892
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use VMware::VIRuntime; | |
# Default Variablen | |
my $exit_code = 0; | |
my $error_message = ''; | |
# Argumente parsen | |
Opts::parse(); | |
Opts::validate(); | |
my $esx_host = Opts::get_option('server'); | |
# Host Objekt rausfiltern | |
eval{ | |
Util::connect(); | |
}; | |
if ( $@ ) { | |
print 'CRITICAL. Could no connect to ' . $esx_host . ' : ' . $@ . "n"; | |
Util::disconnect(); | |
exit 2; | |
} | |
my $host_views = Vim::find_entity_views( | |
view_type => 'HostSystem', | |
); | |
foreach my $host (@{$host_views}) { | |
my $storageStatusInfo = $host->runtime->healthSystemRuntime->hardwareStatusInfo->storageStatusInfo; | |
if (! defined($storageStatusInfo) ) { | |
print 'CRITICAL. No Storage-Hardware Status on ' . $esx_host . ' available!' . "n"; | |
Util::disconnect(); | |
exit 2 | |
} | |
foreach my $storageInfo ( @{$storageStatusInfo}) { | |
my $status_label = $storageInfo->status->label; | |
if ($status_label ne 'Green') { | |
if ($status_label eq "Red") { | |
$exit_code = 2; | |
$error_message = $error_message . $storageInfo->name; | |
} | |
if ( ($status_label eq "Yellow") && ($exit_code != 2 ) ){ | |
$exit_code = 1; | |
$error_message = $error_message . ' '. $storageInfo->name; | |
} | |
if ( ($status_label eq "Unknown") && ( ($exit_code != 2 ) || ( $exit_code != 1 ) ) ) { | |
$exit_code = 3; | |
} | |
} | |
} | |
} | |
Util::disconnect(); | |
if ( $exit_code == 2 ) { | |
print 'CRITICAL. Storage-Hardware on ' . $esx_host . ' has an critical Error! ' . $error_message . "n"; | |
exit 2; | |
} | |
if ( $exit_code == 1 ) { | |
print 'WARNING. Storage-Hardware on ' . $esx_host . ' has an Error! ' . $error_message . "n"; | |
exit 1; | |
} | |
if ( $exit_code == 3 ) { | |
print 'UNKNOWN. Storage-Hardware on ' . $esx_host . ' has an unknwown State!'. "n"; | |
exit 3; | |
} | |
print 'OK. Storage-Hardware on ' . $esx_host . ' is OK.' . "n"; | |
exit 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment