Monitoring Scripts
Differences between revisions 1 and 2
⇤ ← Revision 1 as of 2009-09-21 10:27:46
Size: 3128
Comment:
|
Size: 3134
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 14: | Line 14: |
command_line /etc/nagios-plugins/custom/check_ubuntu $HOSTNAME$ $ARG1$ | command_line /etc/nagios-plugins/custom/check_ubuntu $HOSTNAME$ $ARG1$ $ARG2$ |
Line 22: | Line 22: |
host_name .*\.archive\.ubuntu\.com | host_name <your mirrors hostname> |
Contents |
Contents |
If you have scripts to monitor the status of your mirror, please post them here.
Nagios
This check is suitable for Nagios installations. It will do a HEAD-request on the requested file on both your webserver and the main webserver and calculate the time-difference between the two last-modified headers.
Call this script as follows:
define command { command_name check_ubuntu command_line /etc/nagios-plugins/custom/check_ubuntu $HOSTNAME$ $ARG1$ $ARG2$ }
And:
define service{ use generic-service host_name <your mirrors hostname> service_description Mirror status check_command check_ubuntu!<hostname of main mirror>!<file to check> }
Good files to check are:
- ubuntu/ls-lR.gz for archive mirrors
- .pool/MD5SUMS for releases mirrors
# Create a user agent object use LWP::UserAgent; use Net::DNS; use Date::Parse; use strict; use lib "/usr/lib/nagios/plugins"; use utils qw($TIMEOUT %ERRORS &print_revision &support); my ($yourhost, $mainhost, $file) = @ARGV; my $ua = LWP::UserAgent->new; $ua->agent("UbuntuMirrorCheck/0.1 "); # Create a request my $canonical = HTTP::Request->new(HEAD => 'http://'.$mainhost.'/'.$file); my $mirror = HTTP::Request->new(HEAD => 'http://'.$yourhost.'/'.$file); # Pass request to the user agent and get a response back my $canonical_res = $ua->request($canonical); my $mirror_res = $ua->request($mirror); # Check the outcome of the response if ($mirror_res->is_success) { my $canonical_time = str2time($canonical_res->header('last-modified')); my $mirror_time = str2time($mirror_res->header('last-modified')); if ($mirror_time > $canonical_time) { print "WARNING - Mirror seems to live in the future"; exit $ERRORS{"WARNING"}; } else { my $diff = $canonical_time - $mirror_time; my ($rest, $days, $hours, $minutes, $seconds) = (0, 0, 0, 0, 0); $days = int($diff/86400); $rest = $diff-($days*86400); $hours = int($rest/3600); $rest = $rest-($hours*3600); $minutes = int($rest/60); $rest = $rest-($minutes*60); $seconds = $rest; if ($diff > 43200) { print "CRITICAL - Mirror is $days days, $hours hours, $minutes minutes and $seconds seconds behind"; exit $ERRORS{"CRITICAL"}; } else { print "OK - Mirror is $days days, $hours hours, $minutes minutes and $seconds seconds behind"; exit $ERRORS{"OK"}; } } } else { print "CRITICAL - Mirror is unavailable"; exit $ERRORS{"CRITICAL"}; }
Mirrors/Monitoring Scripts (last edited 2022-07-25 23:59:19 by tcuthbert)