/[pdpsoft]/trunk/nl.nikhef.ndpf.tools/nagios-ndpf-sensors/scripts/check_wms_active_jobs
ViewVC logotype

Contents of /trunk/nl.nikhef.ndpf.tools/nagios-ndpf-sensors/scripts/check_wms_active_jobs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2614 - (show annotations) (download)
Tue Mar 19 15:26:59 2013 UTC (9 years, 3 months ago) by ronalds
File size: 1484 byte(s)
fixed WMS job states
1 #!/usr/bin/perl -w
2
3 use strict;
4 use Getopt::Long;
5
6 my $verbose=0;
7 my $help;
8
9
10 my $TIMEOUT = 10;
11
12 GetOptions("help" => \$help,
13 "verbose|v+" => \$verbose );
14
15 my %ERRORS=(OK=>0,
16 WARNING=>1,
17 CRITICAL=>2,
18 UNKNOWN=>3,
19 DEPENDENT=>4);
20
21 my $QUERY_DB = "/usr/bin/queryDb";
22 if ( ! -x $QUERY_DB ) {
23 print "ERROR: cannot execute $QUERY_DB: $!\n";
24 exit $ERRORS{"UNKNOWN"};
25 }
26
27 # queryDB requires env var
28 $ENV{"WMS_LOCATION_VAR"} ||= "/var";
29
30 my $result = $ERRORS{"UNKNOWN"};
31 my $message = "";
32
33 # Just in case of problems, let's not hang Nagios
34 $SIG{'ALRM'} = sub {
35 print "ERROR: alarm timeout\n";
36 exit $ERRORS{"UNKNOWN"};
37 };
38
39 alarm($TIMEOUT);
40
41 ##############################################################################
42 #
43 # output of queryDb
44 #
45
46 my @job_states = ( "REGISTERED", "PENDING", "IDLE", "RUNNING", "REALLY-RUNNING", "UNKNOWN" );
47
48 my $cmd = "$QUERY_DB -vS -s " . join( ",", @job_states );
49 if ( ! open QRY, "$cmd | " ) {
50 print "ERROR: cannot read from command $cmd\n";
51 exit $ERRORS{"UNKNOWN"};
52 }
53
54 my %state_count;
55 while ( <QRY> ) {
56 if ( /^[\[](.+)[\]]$/ ) {
57 $state_count{$1}++;
58 }
59 }
60
61 close QRY;
62
63
64 alarm(0);
65
66 $message = "OK";
67 $result = $ERRORS{"OK"};
68
69 # performance data
70 my $perf = "";
71 foreach my $js ( @job_states ) {
72 $state_count{$js} |= 0;
73 $perf .= sprintf "%s=%d;;;; ", $js, $state_count{$js};
74 }
75
76 # Write output and return exit code;
77 print "$message|$perf\n";
78 exit($result);
79

Properties

Name Value
svn:executable *

grid.support@nikhef.nl
ViewVC Help
Powered by ViewVC 1.1.28