summaryrefslogtreecommitdiffstats
path: root/check_load
diff options
context:
space:
mode:
Diffstat (limited to 'check_load')
-rwxr-xr-xcheck_load61
1 files changed, 35 insertions, 26 deletions
diff --git a/check_load b/check_load
index 8a3b2c8..6f068d7 100755
--- a/check_load
+++ b/check_load
@@ -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');