Skip to content

Instantly share code, notes, and snippets.

@miebach
Last active December 20, 2015 18:08
Show Gist options
  • Save miebach/6173385 to your computer and use it in GitHub Desktop.
Save miebach/6173385 to your computer and use it in GitHub Desktop.
#!/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