| Server IP : 216.92.14.13 / Your IP : 216.73.216.171 Web Server : Apache System : Linux vps4089.pairvps.com 5.15.0-190-generic #200-Ubuntu SMP Fri Aug 7 15:06:04 UTC 2026 x86_64 User : rmlac2fmr ( 1040637) PHP Version : 8.2.32 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /lib/nagios/plugins/ |
Upload File : |
#!/usr/local/bin/perl
use strict;
use warnings;
use JSON;
use Data::Dumper;
my $METRIC_FILE = '/var/lib/nagios/.sc2k';
# Lets exit cleanly for now if there is no metric file
unless(-f $METRIC_FILE) {
print "OK: Could not find sc2k file";
exit 0;
}
local $/;
open(my $fh, "<", $METRIC_FILE);
my $METRICS = eval { decode_json(<$fh>) };
unless($METRICS) {
print "UNKNOWN: Could not parse sc2k file";
exit 3;
}
close $fh;
my @PERFDATA = process_perfdata();
detect_warnings();
exit;
# detect nrpe warn key, print warning message and exit in nagios format
sub detect_warnings {
my ($warn, $crit, $unknown);
foreach my $key (keys %{$METRICS->{nrpe}}) {
if (my $status = $METRICS->{nrpe}{$key}{status}) {
if($status eq 'warn') {
$warn++;
} elsif ($status eq 'crit') {
$crit++;
} else {
$unknown++;
}
}
}
if ($crit) {
nagios_print(status=>'CRITICAL', msg => $METRICS->{msg_events});
exit 2;
} elsif ($warn) {
nagios_print(status=>'WARNING', msg => $METRICS->{msg_events});
exit 1;
} elsif ($unknown) {
nagios_print(status=>'UNKNOWN', msg => $METRICS->{msg_events});
exit 3;
} else {
nagios_print(status=>'OK', msg => $METRICS->{msg_events});
exit 0;
}
}
sub nagios_print {
my %args = @_;
print "$args{status}: ";
print "$_ " foreach @{$args{msg}};
if(@PERFDATA) {
print "|";
print "$_ " foreach @PERFDATA;
}
}
# Import key values into nagios performance data format
sub process_perfdata {
my @perfdata;
foreach my $key (keys %{$METRICS->{nrpe}}) {
my $check = $METRICS->{nrpe}{$key};
next unless defined $check->{value};
my $value = $check->{uom} ? $check->{value}.$check->{uom} : $check->{value};
push @perfdata, "\'$check->{name}\'=$value";
}
return @perfdata;
}