New XIV plugin
Esteban Monge
esteban at nuevaeralatam.com
Mon Mar 11 19:44:59 CET 2013
Hello:
I am writing one plugin for check XIV API, at the moment I can check:
CF
DIMM
Ethernet Cable
FAN
MODULES
PSU
UPS
I am using Perl with Nagios::Plugins, also I am using IBM::XCLI(1)
I add to original IBM::XCLI module the possibility of obtain only modules
in raw format. But you can try with other checks.
But I have problems with output, when I run the plugin in bash I get OK,
CRITICAL and UNKNOW results, but when Nagios run the check I get "Return
code of 9 is out of bounds."
I am not a Perl writers, it's my first plugin, I paste the code:
#!/usr/bin/perl
# Copyright: Ton Voon, 2006
# Modified by Esteban Monge, 2013
#
# This is the script used in the Nagios Plugin lightning talk
# given by Ton Voon at FOSDEM 2007.
# See http://www.nagioscommunity.org for more details
#
# This script is available under GPLv2, though the ideas are
# public domain :)
#
# You will need to set the permissions of the script so it is executable
# Get these plugins from CPAN
use Nagios::Plugin;
use Nagios::Plugin::Functions;
use IBM::XCLI;
use warnings;
use Switch;
#Function for evaluate if any component isn't OK
sub print_array {
$end_code = 0;
local (@array) = @_;
foreach (@array) {
s/^"\|"$//g;
my(@array) = split /","/;
substr($array[0], 0, 1, '');
if ( $array[1] ne "Status" ) {
print
"Component:\t$array[0]\tStatus:\t$array[1]\n";
if ($array[1] ne "OK" ) {
$end_code = 2;
}
}
}
if ( $end_code eq 0 ) {
nagios_exit( 'OK', 'Full, full, perfect' );
}
if ( $end_code eq 2 ) {
nagios_exit( 'CRITICAL', 'Something is Wrong' );
}
}
#Define xcli path usually /opt/XIVGUI/xcli
$xcli_path = "/opt/XIVGUI/xcli";
$np = Nagios::Plugin->new(
shortname => "Check_XIV.pl",
usage => "Usage: %s [-m] [-u] [-p] [-c]",
);
$np->add_arg(
spec => "machine|m=s",
help => "-m, --machine=IP. IP of XIV machine",
required => 1,
);
$np->add_arg(
spec => "username|u=s",
help => "-u, --username=someuser. User account with read
permissions in XIVGUI",
required => 1,
);
$np->add_arg(
spec => "password|p=s",
help => "-p, --password=somepassword. Valid password for the user
of XIVGUI",
required => 1,
);
$np->add_arg(
spec => "command|c=s",
help => "-c, --command=somecommand. One command from list_dimm",
required => 1,
);
$np->getopts;
my $xiv = IBM::XCLI->new(
ip_address => $np->opts->machine,
username => $np->opts->username,
password => $np->opts->password,
xcli => $xcli_path,
);
switch ($np->opts->command) {
case cf_list {
my @cf = $xiv->cf_list_raw();
print_array(@cf);
}
case dimm_list {
my @dimms = $xiv->dimm_list_raw();
print_array(@dimms);
}
case ethernet_cable_list {
my @ethernet_cable = $xiv->ethernet_cable_list_raw();
print_array(@ethernet_cable);
}
case fan_list {
my @fan = $xiv->fan_list_raw();
print_array(@fan);
}
case module_list {
my @module = $xiv->module_list_raw();
print_array(@module);
}
case psu_list {
my @psu = $xiv->psu_list_raw();
print_array(@psu);
}
case ups_list {
my @ups = $xiv->ups_list_raw();
print_array(@ups);
}
else {
print "Invalid command\n";
nagios_exit( UNKNOWN, 'Verify XIV command' );
}
}
(1) http://search.cpan.org/~ltp/IBM-XCLI-0.5/lib/IBM/XCLI.pm
------------------------------------------------------------------------------
Symantec Endpoint Protection 12 positioned as A LEADER in The Forrester
Wave(TM): Endpoint Security, Q1 2013 and "remains a good choice" in the
endpoint security space. For insight on selecting the right partner to
tackle endpoint security challenges, access the full report.
http://p.sf.net/sfu/symantec-dev2dev
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue.
::: Messages without supporting info will risk being sent to /dev/null
More information about the Users
mailing list