Skip to content

Commit

Permalink
Fixed Aggregate Check
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Krogloth committed Feb 26, 2015
1 parent eec3990 commit aaacf6d
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 31 deletions.
104 changes: 74 additions & 30 deletions check_cdot_aggr.pl
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
use NaServer;
use NaElement;
use Getopt::Long;
use Data::Dumper;

GetOptions(
'hostname=s' => \my $Hostname,
'username=s' => \my $Username,
'password=s' => \my $Password,
'warning=i' => \my $Warning,
'critical=i' => \my $Critical,
'aggr=s' => \my $Aggr,
'perf' => \my $perf,
'help|?' => sub { exec perldoc => -F => $0 or die "Cannot execute perldoc: $!\n"; },
) or Error("$0: Error in command line arguments\n");
Expand All @@ -37,49 +39,85 @@ sub Error {
Error('Option --warning needed!') unless $Warning;
Error('Option --critical needed!') unless $Critical;

my $perfmsg;
my $message;
my $critical = 0;
my $warning = 0;

my $s = NaServer->new( $Hostname, 1, 3 );
$s->set_transport_type("HTTPS");
$s->set_style("LOGIN");
$s->set_admin_user( $Username, $Password );

my $output = $s->invoke("aggr-get-iter");

if ($output->results_errno != 0) {
my $r = $output->results_reason();
print "UNKNOWN: $r\n";
exit 3;
my $iterator = NaElement->new("aggr-get-iter");
my $tag_elem = NaElement->new("tag");
$iterator->child_add($tag_elem);

my $xi = new NaElement('desired-attributes');
$iterator->child_add($xi);
my $xi1 = new NaElement('aggr-attributes');
$xi->child_add($xi1);
$xi1->child_add_string('aggregate-name','<aggregate-name>');
my $xi2 = new NaElement('aggr-space-attributes');
$xi1->child_add($xi2);
$xi2->child_add_string('percent-used-capacity','<percent-used-capacity>');
$xi2->child_add_string('size-available','<size-available>');
$xi2->child_add_string('size-total','<size-total>');
$xi2->child_add_string('size-used','<size-used>');
my $xi3 = new NaElement('query');
$iterator->child_add($xi3);
my $xi4 = new NaElement('aggr-attributes');
$xi3->child_add($xi4);
if($Aggr){
$xi4->child_add_string('aggregate-name',$Aggr);
}
my $xi5 = new NaElement('query');
$iterator->child_add($xi5);

my $perfmsg;
my $message;
my $critical = 0;
my $warning = 0;
my $next = "";

my $aggrs = $output->child_get("attributes-list");
my @result = $aggrs->children_get();
while(defined($next)){
unless($next eq ""){
$tag_elem->set_content($next);
}

foreach my $aggr (@result){
$iterator->child_add_string("max-records", 100);
my $output = $s->invoke_elem($iterator);

my $aggr_name = $aggr->child_get_string("aggregate-name");
my $space = $aggr->child_get("aggr-space-attributes");
my $percent = $space->child_get_int("percent-used-capacity");
if ($output->results_errno != 0) {
my $r = $output->results_reason();
print "UNKNOWN: $r\n";
exit 3;
}

$critical++ if $percent >= $Critical;
$warning++ if $percent >= $Warning;
my $aggrs = $output->child_get("attributes-list");
my @result = $aggrs->children_get();

if ($message) {
$message .= ", " . $aggr_name . " (" . $percent . "%)";
}
else {
$message .= $aggr_name . " (" . $percent . "%)";
}
foreach my $aggr (@result){

my $aggr_name = $aggr->child_get_string("aggregate-name");
my $space = $aggr->child_get("aggr-space-attributes");
my $percent = $space->child_get_int("percent-used-capacity");

$critical++ if $percent >= $Critical;
$warning++ if $percent >= $Warning;

if ($perf) {
$perfmsg .= " $aggr_name=$percent%;$Warning;$Critical";
if ($message) {
$message .= ", " . $aggr_name . " (" . $percent . "%)";
}
else {
$message .= $aggr_name . " (" . $percent . "%)";
}

if ($perf) {
$perfmsg .= " $aggr_name=$percent%;$Warning;$Critical";
}
else {
$perfmsg .= "$aggr_name=$percent%;$Warning;$Critical";
}
}
else {
$perfmsg .= "$aggr_name=$percent%;$Warning;$Critical";
}

$next = $output->child_get_string("next-tag");
}

if($critical > 0){
Expand Down Expand Up @@ -111,7 +149,7 @@ =head1 SYNOPSIS
check_cdot_aggr.pl --hostname HOSTNAME --username USERNAME \
--password PASSWORD --warning PERCENT_WARNING \
--critical PERCENT_CRITICAL --perf
--critical PERCENT_CRITICAL (--perf) (--aggr AGGR)
=head1 DESCRIPTION
Expand Down Expand Up @@ -146,6 +184,10 @@ =head1 OPTIONS
Flag for performance data output
=item --aggr
Check only specific aggregate
=item -help
=item -?
Expand All @@ -166,3 +208,5 @@ =head1 AUTHORS
Alexander Krogloth <git at krogloth.de>
Stelios Gikas <sgikas at demokrit.de>
Stefan Grosser <sgr at firstframe.net>
Stephan Lang <stephan.lang at acp.at>
2 changes: 1 addition & 1 deletion check_cdot_clusterconfig.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ USERNAME=$2
NODES=$(ssh $USERNAME@$HOSTNAME "node show" | awk '$0 ~ "entries were displayed" { print $1 }')

VLAN_DIFF=$(ssh $USERNAME@$HOSTNAME "network port vlan show -fields vlan-name" | awk '{ print $2 }' | grep ^a0a | sort | uniq -u)
FAILOVER_DIFF=$(ssh $USERNAME@$HOSTNAME "network interface failover-groups show -fields targets" | awk -F ',' 'NF != '$NODES' && $1 ~ "(failover_|([0-9]{1,3}.){4})" { print $0}')
FAILOVER_DIFF=$(ssh $USERNAME@$HOSTNAME "network interface failover-groups show -fields targets" | awk -F ',' 'NF != '$NODES' && $1 !~ "[0-9]_[0-9]" && $1 ~ "(failover_|([0-9]{1,3}.){4})" { print $0}')

if [ -n "$VLAN_DIFF" ] || [ -n "$FAILOVER_DIFF" ]; then {

Expand Down

0 comments on commit aaacf6d

Please sign in to comment.