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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2594 - (show annotations) (download)
Tue Jan 22 15:11:50 2013 UTC (9 years ago) by ronalds
File size: 4737 byte(s)
0.3.31: fixed load monitor script for UMD-2 CreamCE
1 #!/usr/bin/perl
2
3 use strict;
4 use Getopt::Long;
5
6 my $verbose = 0;
7 my $debug = 0;
8 my $mode;
9 my $conffile = '';
10
11 &GetOptions(
12 'verbose|v' => \$verbose,
13 'debug|d' => \$debug,
14 'wms' => sub { $mode = 'wms'; },
15 'cream' => sub { $mode = 'cream'; },
16 'conf:s' => \$conffile,
17 );
18
19 my %retcode = (
20 'OK' => 0,
21 'WARNING' => 1,
22 'CRITICAL' => 2,
23 'UNKNOWN' => 3
24 );
25
26 my $cmd = "";
27 if ( $mode eq "cream" ) {
28 $cmd = &get_path_for_file( "glite_cream_load_monitor", ( "/usr/bin", "/opt/glite/bin" ) );
29 if ( ! $cmd ) {
30 print "UNKNOWN: Could not find glite_cream_load_monitor\n";
31 exit $retcode{UNKNOWN};
32 }
33
34 # the configuration file MUST be the first argument
35 if ( $conffile ) {
36 # verify that $conffile is a normal path without malicious content
37 if ( $conffile =~/^([-\/\@\w.]+)$/ ) {
38 $cmd .= " $1";
39 }
40 else {
41 print "CRITICAL: Insecure argument: $conffile\n";
42 exit $retcode{CRITICAL};
43 }
44 }
45
46 # ... before options
47 $cmd .= " --test --show";
48 }
49 elsif ( $mode eq "wms" ) {
50 my $wmscfg = &get_path_for_file( "glite_wms.conf", ( "/etc/glite-wms", "/opt/glite/etc" ) );
51 my $par = "";
52 if ( $wmscfg ) {
53 ( $debug ) and print STDERR "WMS config file = $wmscfg\n";
54 $par = &get_wms_config_option( "${wmscfg}" );
55 }
56 else {
57 $par = '--oper jobSubmit '
58 . '--load1 10 --load5 10 --load15 10 '
59 . '--memusage 95 --swapusage 25 --diskusage 95 '
60 . '--fdnum 1000 --jdnum 1500 --ftpconn 300 ';
61 }
62 $cmd = &get_path_for_file( "glite_wms_wmproxy_load_monitor",
63 ( "/usr/sbin", "/opt/glite/sbin" ) );
64 if ( $cmd ) {
65 ( $debug ) and print STDERR "script = ${cmd}\n";
66 $cmd = "${cmd} $par ";
67 }
68 else {
69 print "UNKNOWN: Could not find glite_wms_wmproxy_load_monitor\n";
70 exit $retcode{UNKNOWN};
71 }
72 }
73 else {
74 print "UNKNOWN: mode ($mode) not defined or not recognized\n";
75 exit $retcode{UNKNOWN};
76 }
77
78 $debug and print STDERR "cmd: $cmd\n";
79
80
81 # locations for stdout/stderr of glite command
82 my $outfil = "/tmp/load-mon.$$.out";
83 my $errfil = "/tmp/load-mon.$$.err";
84
85 #
86 system( $cmd . "> $outfil 2> $errfil" );
87 my $ret = $? >> 8;
88
89 my $retval;
90 my $msg = "";
91 if ( $ret == 0 ) {
92 $msg = "OK";
93 $retval = $retcode{OK};
94 if ( $verbose ) {
95 open OUT, $outfil;
96 print STDERR ( <OUT> );
97 close OUT;
98 }
99 }
100 elsif ( $ret == 1 ) {
101 # read contents of stderr
102 open ERR, $errfil;
103 my @err = <ERR>;
104 close ERR;
105
106 # ... and make a short summary of trouble
107 my $errstr = '';
108 foreach my $error ( @err ) {
109 if ( $error =~ m/: ([0-9\.%]+).* for ([^:]+):\s*([0-9]+(\.[0-9]*)?)[%]?$/ ) {
110 $errstr .= "$2 = $3 (threshold $1); ";
111 }
112 }
113
114 $msg = "WARNING: $errstr";
115 $retval = $retcode{WARNING};
116 }
117 else {
118 $msg = "UNKNOWN: unexpected return value $ret";
119 $retval = $retcode{UNKNOWN};
120 }
121
122 # collect performance data
123 my $perfdata = "";
124 if ( $mode eq "cream" ) {
125 my ( $ftp_conn, $active_jobs );
126 foreach my $file ( $outfil, $errfil ) {
127 open PERF, $file;
128 while ( my $line = <PERF> ) {
129 if ( $line =~ /active jobs\: (\d+)$/ ) {
130 $active_jobs = $1;
131 # $perfdata .= sprintf " 'active jobs'=%d", $1;
132 }
133 elsif ( $line =~ /FTP Connection\: (\d+)$/ ) {
134 $ftp_conn = $1;
135 # $perfdata .= sprintf " FTP_conn=%d", $1;
136 }
137 }
138 close PERF;
139 $perfdata = sprintf "'active jobs'=%d FTP_conn=%d", $active_jobs, $ftp_conn;
140 }
141 }
142
143 ( ! $debug ) and unlink $outfil, $errfil;
144
145 print "$msg|$perfdata\n";
146 exit $retval;
147
148
149
150
151 sub get_wms_config_option {
152 my $cfgfile = $_[0];
153 my $wms_load_params = "";
154
155 if ( ! open WMSCFG, "$cfgfile" ) {
156 print STDERR "Cannot open $cfgfile: $!\n";
157 return $wms_load_params;
158 }
159
160 while ( <WMSCFG> ) {
161 if ( /^\s*jobSubmit.*(--oper jobSubmit.*)[\'\"];/ ) {
162 $wms_load_params = $1;
163 last;
164 }
165 }
166
167 close WMSCFG;
168
169 return $wms_load_params;
170 }
171
172
173 # find a file in a list of directories
174 # useful to deal with different locations of files for UMD and gLite 3.2
175 sub get_path_for_file($@) {
176 my ($file, @pathlist) = @_;
177
178 foreach my $dir ( @pathlist ) {
179 if ( -f "${dir}/$file" ) {
180 ( $debug ) and print STDERR "found file location: ${dir}/$file\n";
181 return "${dir}/$file";
182 }
183 }
184 ( $debug ) and print STDERR "could not find file location for $file\n";
185 return undef;
186 }

Properties

Name Value
svn:executable *

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