Doc/Monitoring/NagiosProbes: check_ncd.NIKHEF

File check_ncd.NIKHEF, 1.8 KB (added by /C=GR/O=HellasGrid/OU=auth.gr/CN=Christos Triantafyllidis, 13 years ago)

check_ncd by NIKHEF

Line 
1#!/usr/bin/perl -w
2
3use strict;
4use Getopt::Long;
5
6my $verbose=0;
7my $help;
8my $hostname;
9my $metric;
10my $state;
11my $debug;
12
13my $TIMEOUT = 10;
14
15GetOptions("help" => \$help,
16           "host:s" => \$hostname,
17           "metric:s" => \$metric,
18           "state:s" => \$state,
19           "debug" => \$debug,
20           "verbose" => \$verbose );
21
22my %ERRORS=(OK=>0,
23            WARNING=>1,
24            CRITICAL=>2,
25            UNKNOWN=>3,
26            DEPENDENT=>4);
27
28my $ZGREP = "/usr/bin/zgrep";
29my $SORT = "/bin/sort";
30my $TAIL = "/usr/bin/tail";
31
32my $result = $ERRORS{"UNKNOWN"};
33
34# Just in case of problems, let's not hang Nagios
35$SIG{'ALRM'} = sub {
36     print ("ERROR: No response from $hostname (alarm timeout)\n");
37     exit $ERRORS{"UNKNOWN"};
38};
39
40alarm($TIMEOUT);
41
42##############################################################################
43# output of ncm-ncd
44#
45my $timestamp = 'NOT FOUND';
46my $errors    = 0;
47my $warnings  = 0;
48
49my $message;
50
51my $cmd = "$ZGREP -h 'warnings executing configure' /var/log/ncm/ncd.log* | $SORT | $TAIL -1";
52
53$_ = `$cmd`;
54
55if (/^(.+)\s+\[\w+\]\s+(\d+) errors, (\d+) warnings executing configure$/) {
56    $timestamp = $1;
57    $errors    = $2;
58    $warnings  = $3;
59
60    if ( $errors > 0 ) {
61        $message = "ERROR: $errors error(s)";
62        $message .= ", $warnings warning(s)" if ( $warnings > 0 );
63        $message .= " [$timestamp]";
64        $result = $ERRORS{"CRITICAL"};
65    }
66    elsif ( $warnings > 0 ) { 
67        $message = "WARNING: $warnings warning(s) [$timestamp]";
68        $result = $ERRORS{"WARNING"};
69    }
70    else {
71        $message = "OK: [$timestamp]";
72        $result = $ERRORS{"OK"};
73    }
74}
75else {
76    $message = "UNKNOWN: could not determine result of last ncm-ncd run";
77    $result = $ERRORS{"UNKNOWN"};
78}
79
80alarm(0);
81
82print "$message\n";
83exit($result);