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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2817 - (show annotations) (download)
Thu Dec 17 16:53:45 2015 UTC (6 years, 5 months ago) by dennisvd
File size: 3643 byte(s)
Summary: new nagios sensor for freshness of stratum-1 repositories

1 #!/usr/bin/perl -w
2 #
3 # Copyright 2015 Stichting Fundamenteel Onderzoek der Materie (FOM-Nikhef)
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 # This Nagios check is meant for CVMFS stratum 1 servers, and checks which
18 # repositories for a given domain are becoming 'stale'.
19 #
20 # It does this by checking the .cvmfswhitelist and checking the 'E' field.
21
22 use strict;
23 use Getopt::Long;
24 use Time::Local;
25 use Time::localtime;
26 use POSIX qw{strftime};
27
28 my $verbose = 0; # whether to be loud
29 my $debug = 0; # whether to be even louder
30 my $domain = ""; # which domain to check (e.g. egi.eu), default is all.
31 my $thresholddays = 7; # minimal freshness in days
32
33 GetOptions("domain:s" => \$domain,
34 "debug" => \$debug,
35 "verbose" => \$verbose,
36 "threshold:i" => \$thresholddays);
37
38 # turn days into seconds
39 my $threshold = $thresholddays * 24 * 60 * 60;
40
41 # START nagios check boilerplate
42
43 my $TIMEOUT = 10;
44
45 my %ERRORS=(OK=>0,
46 WARNING=>1,
47 CRITICAL=>2,
48 UNKNOWN=>3,
49 DEPENDENT=>4);
50
51 my $message = "";
52 my @msgok;
53 my @msgwarn;
54 my @msgcrit;
55
56 my $result = $ERRORS{"UNKNOWN"};
57
58 # Just in case of problems, let's not hang Nagios
59 $SIG{'ALRM'} = sub {
60 print ("ERROR: No timely response (alarm timeout)\n");
61 exit $ERRORS{"UNKNOWN"};
62 };
63
64 alarm($TIMEOUT);
65
66 # END nagios check boilerplate
67
68 # match each repository configuration directory with the domain given
69 # wildcards!
70
71 my @repos = glob "/etc/cvmfs/repositories.d/*${domain}";
72
73 # Format of a .whitelist file:
74 # 20151215091203
75 # E20160115091203
76 # Nsoftdrive.nl
77 # AA:63:17:0A:82:41:0A:0A:91:9D:E5:33:17:C9:41:BF:8D:BC:D8:10
78 # --
79 # 9cb13f4bda5e4613cb7619e35f53dbd0da473d92
80 # <garbage follows>
81
82 # Take the current time only once, we don't need
83 # high resolution
84 my $currenttime = time;
85
86 for my $r (@repos) {
87
88 $r =~ s,.*repositories\.d/,,; # just the repository name
89
90 # open /srv/cvmfs/$r/.cvmfswhitelist
91 open my $fh, "<", "/srv/cvmfs/$r/.cvmfswhitelist" or do {
92 push @msgwarn, "WARNING: Could not find .cvmfswhitelist for $r;";
93 next;
94 };
95
96 while(<$fh>) {
97 # match the EYYYYMMDDhhmmss pattern for expiration
98 # compare date with something 14 days from now.
99 if (m/^E
100 (\d{4}) # 1 year
101 (\d{2}) # 2 month
102 (\d{2}) # 3 day
103 (\d{2}) # 4 hours
104 (\d{2}) # 5 minutes
105 (\d{2}) # 6 seconds
106 /x) {
107 my $expiration = timegm($6,$5,$4,$3,$2-1,$1);
108 # compare the expiration with the current time
109 my $remaining = $expiration - $currenttime;
110
111 if ($remaining < 0) {
112 push @msgcrit, "CRITICAL: whitelist for $r has expired on " . ctime($expiration);
113 } elsif ($remaining < $threshold) {
114 push @msgwarn, "WARNING: whitelist for $r will expire within $thresholddays days on " . ctime($expiration);
115 } else {
116 push @msgok, "OK (whitelist for $r expires on " . ctime($expiration) . ")";
117 }
118 last;
119 }
120 }
121 close $fh;
122 }
123
124
125
126 alarm(0);
127
128 $, = ";"; # field separator
129 $\ = "\n"; # record separator
130 print @msgcrit,@msgwarn,@msgok;
131
132 if ($msgcrit[0]) {
133 $result = $ERRORS{CRITICAL};
134 } elsif ($msgwarn[0]) {
135 $result = $ERRORS{WARNING};
136 } else {
137 $result = $ERRORS{OK};
138 }
139
140 exit $result;

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