3 # nagios check for debian security sync checks
5 # Copyright (c) 2008 Alexander Wirt <formorer@debian.org>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
32 $ENV{'PATH'} = '/bin:/sbin:/usr/bin:/usr/sbin';
33 delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
36 my $PROGRAM_NAME = 'check_securitymirror';
39 $params->{'host'} = 'security.debian.org'; #which host to check
40 $params->{'path'} = 'project/trace/security-master.debian.org';
48 '--help' => \$params->{'help'},
49 '--verbose' => \$params->{'verbose'},
50 '--version' => \$params->{'version'},
51 '--host=s' => \$params->{'host'},
52 '--path=s' => \$params->{'path'},
54 die ("Usage: $PROGRAM_NAME [--help|--version] [--verbose]\n");
57 if ($params->{'help'}) {
58 print "$PROGRAM_NAME $VERSION\n";
59 print "Usage: $PROGRAM_NAME [--help|--version] [--verbose]\n";
61 print " --help Print this short help.\n";
62 print " --version Report version number.\n";
63 print " --verbose Be a little verbose.\n";
64 print " --host hostname to check.\n";
65 print " --path path to tracefile.\n";
70 my $host = $params->{'host'};
71 my $path = $params->{'path'};
77 @slaves = gethostbyname($params->{'host'}) or die "Can't resolve " . $params->{'host'} .": $!\n";
78 @slaves = map { inet_ntoa($_) } @slaves[4 .. $#slaves];
79 print "Checking the following hosts:\n" . join("\n", @slaves) . "\n" if $params->{'verbose'};
83 foreach my $slave (@slaves) {
84 my $ua = LWP::UserAgent->new;
85 $ua->proxy('http', "http://$slave");
86 print "Requesting http://$host/$path from $slave\n" if $params->{'verbose'};
87 my $response = $ua->get("http://$host/$path");
90 if ($response->is_success) {
91 my $content = $response->content; # or whatever
92 my ($date, $foo, $bar) = split("\n", $content);
93 my $synctime = str2time($date);;
94 print "$slave last synced $synctime\n" if $params->{'verbose'};
95 $status->{$slave}->{'synced'} = $synctime;
98 push @exitstatus, "$slave broken: " . $response->status_line;
99 $status->{$slave}->{'error'} = $response->status_line;
100 $exitcode = $CRITICAL;
101 push @critical, $slave;
107 my $o_sync = scalar(grep !$seen{$_}++, map{$status->{$_}->{'synced'}} keys(%{$status}));
109 $exitcode = $CRITICAL;
111 my @mirrors = sort { $status->{$a}->{'synced'} <=> $status->{$b}->{'synced'} } keys %{$status};
112 push @exitstatus, "$o_sync mirror(s) not in sync (from oldest to newest): ".
113 join(",", splice(@mirrors,0,$o_sync));
115 print "All mirrors unique\n" if $params->{'verbose'};
118 if ($exitcode == $CRITICAL) {
119 print "CRITICAL: " . join(',',@exitstatus) . "\n";
120 } elsif ($exitcode == $OK) {
121 print "OK: all mirrors up2date\n";
124 foreach my $mirror (keys(%{$status})) {
125 if ($status->{$mirror}->{'error'}) {
126 print "$mirror broken: " . $status->{$mirror}->{'error'} . "\n";
128 print "$mirror last synced: " . localtime($status->{$mirror}->{'synced'}) ."\n";