diff options
author | Alexander Sulfrian <alexander@sulfrian.net> | 2014-02-14 04:03:38 +0100 |
---|---|---|
committer | Alexander Sulfrian <alexander@sulfrian.net> | 2014-02-14 04:36:57 +0100 |
commit | 2816f34bc6b18ee7bf2832966f9534c5c198eec3 (patch) | |
tree | ce9408a35be4c97603ddd78677632f87b35e4854 /check_load | |
parent | 2388161afa4fed244b7333c7edab62c68ad7ec6c (diff) | |
download | vserver-monitoring-2816f34bc6b18ee7bf2832966f9534c5c198eec3.tar.gz vserver-monitoring-2816f34bc6b18ee7bf2832966f9534c5c198eec3.tar.bz2 vserver-monitoring-2816f34bc6b18ee7bf2832966f9534c5c198eec3.zip |
refactor code to have a sub to handle a single vserver
Diffstat (limited to 'check_load')
-rwxr-xr-x | check_load | 61 |
1 files changed, 35 insertions, 26 deletions
@@ -58,6 +58,40 @@ sub parse_thresholds($) { return undef; } +sub handle_vserver($$$$) { + my $id = shift; + my $warn = shift; + my $crit = shift; + my $name = shift; + + my $n = init_nagios_plugin(); + my $load = VServer::get_loadavg($id); + if ($load) { + my @status = [ UNKNOWN ]; + my $output = ""; + + for my $key (qw( load1 load5 load15 )) { + $n->add_perfdata(label => $key, + value => $load->{$key}, + warning => $warn->{$key}, + critical => $crit->{$key}, + min => 0, + ); + + push(@status, + $n->check_threshold(check => $load->{$key}, + warning => $warn->{$key}, + critical => $crit->{$key} + ) + ); + + $output .= " $load->{$key}"; + } + + $n->nagios_exit($n->max_state(@status), "load average:$output"); + } +} + # fix taint mode if ($0 =~ m/(\w[\w\/]*\w)/) { @@ -94,30 +128,5 @@ unless ($context) { $n->nagios_exit(UNKNOWN, "vserver '$vserver' not found"); } -my $load = VServer::get_loadavg($id); -if (@load) { - my @status = [ UNKNOWN ]; - my $output = ""; - - for my $key (qw( load1 load5 load15 )) { - $n->add_perfdata(label => $key, - value => $load->{$key}, - warning => $warn{$key}, - critical => $crit{$key}, - min => 0, - ); - - push(@status, - $n->check_threshold(check => $load->{$key}, - warning => $warn{$key}, - critical => $crit{$key} - ) - ); - - $output .= " $load->{$key}"; - } - - $n->nagios_exit($n->max_state(@status), "load average:$output"); -} - +handle_vserver($context, \%warn, \%crit, $vserver); $n->nagios_exit(UNKNOWN, 'unable to parse loadavg'); |