--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/check_release.pl Wed Jul 28 16:24:58 2010 +0200
@@ -0,0 +1,114 @@
+#!/usr/bin/perl -w
+
+use strict;
+use File::Basename;
+use Getopt::Long;
+use LWP::Simple;
+
+use lib "/usr/lib/nagios/plugins";
+use utils qw (%ERRORS &print_revision &support);
+
+my $ME = basename $0;
+my $VERSION = "1.1";
+my $USAGE = <<EOF;
+Usage: $ME [-u | --url]
+ $ME [-s | --search]
+ $ME [-f | --file]
+ $ME [-h | --help]
+ $ME [-V | --version]
+EOF
+
+my $opt_url = "http://www.debian.org/releases/stable/index.html";
+my $opt_search = "<p>Debian GNU/Linux";
+my $opt_file = "/etc/debian_version";
+my ($found, $current_release, $current_majornr, $stable_release, $stable_majornr, @website);
+
+sub check_status();
+sub print_help();
+sub print_usage();
+
+MAIN: {
+ Getopt::Long::Configure('bundling');
+ GetOptions(
+ "u|url" => \$opt_url,
+ "s|search" => \$opt_search,
+ "f|file" => \$opt_file,
+ "h|help" => sub { print_help(); exit $ERRORS{OK}; },
+ "V|version" =>
+ sub { print_revision( $ME, $VERSION ); exit $ERRORS{OK}; },
+ );
+
+ # get current release number
+ unless ( -r $opt_file ) {
+ print "RELEASE CRITICAL: $opt_file not exists or not read permission is granted\n";
+ exit $ERRORS{"CRITICAL"};
+ }
+
+ open(CR, "<$opt_file");
+ while(<CR>) {
+ chomp;
+ $current_release = $_;
+ $current_release =~ /^(\d)+.*/;
+ $current_majornr = $1;
+ }
+ close(CR);
+
+ # download the website
+ push @website, split("\n", get($opt_url));
+
+ foreach (@website) {
+ unless ($found) {
+ /$opt_search/ or next;
+ $found = $_;
+ next;
+ }
+ }
+
+ # get stable release number
+ if ($found =~ /$opt_search\s+([\d\.]+).*/) {
+ $stable_release = $1;
+ $stable_release =~ /^(\d)+.*/;
+ $stable_majornr = $1;
+ }
+
+ check_status();
+
+}
+
+sub check_status() {
+ if ($stable_release eq $current_release) {
+ print "RELEASE OK: current release number $current_release\n";
+ exit $ERRORS{"OK"};
+ } elsif ($current_majornr < $stable_majornr) {
+ print "RELEASE CRITICAL: current release number $current_release / stable release number $stable_release\n";
+ exit $ERRORS{"CRITICAL"};
+ } else {
+ print "RELEASE WARNING: current release number $current_release / stable release number $stable_release\n";
+ exit $ERRORS{"WARNING"};
+ }
+}
+
+
+sub print_usage() { print $USAGE }
+
+sub print_help() {
+ print_revision( $ME, $VERSION );
+ print <<EOF;
+Copyright (c) 2010 Christian Arnold
+
+This plugin checks the current debian release number.
+
+$USAGE
+ -u, --url
+ URL where to search for the search string (default: http://www.debian.org/releases/stable/index.html)
+ -s, --search
+ search string on the url (default: '<p>Debian GNU/Linux')
+ -f, --file
+ file with current release informations (default: /etc/debian_version)
+ -h, --help
+ print detailed help screen
+ -V, --version
+ print version information
+EOF
+ support();
+}