diff -r a03a6dab1176 -r 6a562a51e1d8 check_release.pl --- a/check_release.pl Fri Nov 03 11:18:53 2017 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,207 +0,0 @@ -#!/usr/bin/perl -w - -# Copyright (C) 2011 Christian Arnold -# Copyright (C) 2015 Heiko Schlittermann -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -# Christian Arnold - -use strict; -use File::Basename; -use Getopt::Long; -use LWP::Simple; -use Pod::Usage; - -my %ERRORS = ( - OK => 0, - WARNING => 1, - CRITICAL => 2, - UNKNOWN => 3, - DEPENDENT => 4 -); - -sub get_local_release; -sub get_stable_release($$); -sub report($$); -sub version($$); - -my $ME = basename $0; -my $VERSION = "2.9"; - -my %opt = ( - url => "https://www.debian.org/releases/stable/index.html", - search => qr/

Debian\b.*?([\d.]+)/, - file => "/etc/debian_version", - ok => 0 -); - -MAIN: { - Getopt::Long::Configure('bundling'); - GetOptions( - "u|url=s" => \$opt{url}, - "s|search=s" => \$opt{search}, - "f|file=s" => \$opt{file}, - "o|ok" => \$opt{ok}, - "h|help" => sub { pod2usage(-verbose => 1, -exitval => $ERRORS{OK}) }, - "m|man" => sub { pod2usage(-verbose => 2, -exitval => $ERRORS{OK}) }, - "V|version" => sub { version($ME, $VERSION); exit $ERRORS{OK}; } - ) or pod2usage(-verbose => 1, -exitval => $ERRORS{CRITICAL}); - - my ($local_release, $stable_release) = eval { - get_local_release($opt{file}), - get_stable_release($opt{url}, $opt{search}); - }; - if ($@) { - print "RELEASE CRITICAL: $@\n"; - exit $ERRORS{CRITICAL}; - } - report($local_release, $stable_release); -} - -sub get_local_release { - - my $local_release = do { - local @ARGV = grep { -r } @_ - or die "@_: $!\n"; - <>; - }; - - chomp $local_release; - return $local_release; -} - -sub get_stable_release($$) { - my ($url, $search) = @_; - my $website; - - $website = get($url) - or die "Failed to get $url\n"; - - $website =~ /$opt{search}/s - or die "an't parse $url\n"; - - return $1; -} - -sub compare_versions { - my ($left, $right) = @_; - my @left = split '.', $left; - my @right = split '.', $right; - -} - -sub report($$) { - my ($local_release, $stable_release) = @_; - my ($local_major, $stable_major) = map { int } $local_release, $stable_release; - - - if ($opt{ok} or $local_release eq $stable_release or $local_major > $stable_major) { - print "RELEASE OK: $local_release/$stable_release\n"; - exit $ERRORS{OK}; - } - - if ($local_major - $stable_major < -1) { - print "RELEASE CRITICAL: $local_release / $stable_release\n"; - exit $ERRORS{CRITICAL}; - } - - print "RELEASE WARNING: $local_release / $stable_release\n"; - exit $ERRORS{"WARNING"}; - -} - -sub version($$) { - my ($progname, $version) = @_; - - print <<_VERSION; -$progname version $version -Copyright (C) 2011-2013 by Christian Arnold and Schlittermann internet & unix support. -Copyright (C) 2015 by Schlittermann internet & unix support. - -$ME comes with ABSOLUTELY NO WARRANTY. This is free software, -and you are welcome to redistribute it under certain conditions. -See the GNU General Public Licence for details. -_VERSION -} - -__END__ - -=head1 NAME - -check_release - nagios plugin to checks the current debian release number - -=head1 SYNOPSIS - -check_release [-u|--url url] - [-s|--search string] - [-f|--file path] - [-o|--ok] - [-h|--help] - [-m|--man] - [-V|--version] - -=head1 OPTIONS - -=over - -=item B<-u>|B<--url> I - -URL where to search for the search string (default: https://www.debian.org/releases/stable/index.html) - -=item B<-s>|B<--search> I - -search string on the url (default: /

Debian\b.*?([\d.]+)/) - -=item B<-f>|B<--file> I - -file with current release informations (default: /etc/debian_version) - -=item B<-o>|B<--ok> - -Exit status always ok. - -=item B<-h>|B<--help> - -Print detailed help screen. - -=item B<-m>|B<--man> - -Print manual page. - -=item B<-V>|B<--version> - -Print version information. - -=back - -=head1 DESCRIPTION - -This plugin checks the current debian release number. - -=head1 VERSION - -This man page is current for version 2.3 of check_release. - -=head1 AUTHOR - -Written by Christian Arnold L - -=head1 COPYRIGHT - -Copyright (C) 2011 by Christian Arnold and Schlittermann internet & unix support. -This is free software, and you are welcome to redistribute it under certain conditions. -See the GNU General Public Licence for details. - -=cut