check_release.pl
changeset 10 0b560168af46
parent 9 25921fa4d40f
child 20 464fb46c0b7d
equal deleted inserted replaced
9:25921fa4d40f 10:0b560168af46
     1 #!/usr/bin/perl -w
     1 #!/usr/bin/perl -w
     2 
     2 
     3 #    Copyright (C) 2011  Christian Arnold
     3 #    Copyright (C) 2011  Christian Arnold
       
     4 #    Copyright (C) 2015  Heiko Schlittermann
     4 #
     5 #
     5 #    This program is free software: you can redistribute it and/or modify
     6 #    This program is free software: you can redistribute it and/or modify
     6 #    it under the terms of the GNU General Public License as published by
     7 #    it under the terms of the GNU General Public License as published by
     7 #    the Free Software Foundation, either version 3 of the License, or
     8 #    the Free Software Foundation, either version 3 of the License, or
     8 #    (at your option) any later version.
     9 #    (at your option) any later version.
    35 sub get_stable_release($$);
    36 sub get_stable_release($$);
    36 sub report($$);
    37 sub report($$);
    37 sub version($$);
    38 sub version($$);
    38 
    39 
    39 my $ME      = basename $0;
    40 my $ME      = basename $0;
    40 my $VERSION = "2.3";
    41 my $VERSION = "2.5";
    41 
    42 
    42 my %opt = (
    43 my %opt = (
    43     url    => "http://www.debian.org/releases/stable/index.html",
    44     url    => "http://www.debian.org/releases/stable/index.html",
    44     search => "<p>Debian",
    45     search => "<p>Debian",
    45     file   => "/etc/debian_version",
    46     file   => "/etc/debian_version",
   114 }
   115 }
   115 
   116 
   116 sub report($$) {
   117 sub report($$) {
   117     my ($current_release, $stable_release) = @_;
   118     my ($current_release, $stable_release) = @_;
   118 
   119 
       
   120 
       
   121     if ($opt{ok} or $current_release eq $stable_release) {
       
   122         print "RELEASE OK: $current_release/$stable_release\n";
       
   123         exit $ERRORS{OK};
       
   124     }
       
   125 
   119     $stable_release =~ /^(\d+)/ and my $stable_major = int($1);
   126     $stable_release =~ /^(\d+)/ and my $stable_major = int($1);
   120     $current_release =~ /^(\d+)/ and my $current_major = int($1);
   127     $current_release =~ /^(\d+)/ and my $current_major = int($1);
   121 
   128 
   122     if ($current_major < $stable_major) {
   129 
   123 		if ($opt{ok}) {
   130     if ($current_major - $stable_major < -1) {
   124 			print "RELEASE OK: $current_release/$stable_release\n";
       
   125 			exit $ERRORS{OK};
       
   126 		}
       
   127         print "RELEASE CRITICAL: $current_release / $stable_release\n";
   131         print "RELEASE CRITICAL: $current_release / $stable_release\n";
   128         exit $ERRORS{CRITICAL};
   132         exit $ERRORS{CRITICAL};
   129     }
   133     }
   130 
   134 
   131     if ($current_release ne $stable_release) {
       
   132 		if ($opt{ok}) {
       
   133 			print "RELEASE OK: $current_release/$stable_release\n";
       
   134 			exit $ERRORS{OK};
       
   135 		}
       
   136         print "RELEASE WARNING: $current_release / $stable_release\n";
   135         print "RELEASE WARNING: $current_release / $stable_release\n";
   137         exit $ERRORS{"WARNING"};
   136         exit $ERRORS{"WARNING"};
   138     }
   137 
   139 
       
   140     print "RELEASE OK: $current_release/$stable_release\n";
       
   141     exit $ERRORS{"OK"};
       
   142 }
   138 }
   143 
   139 
   144 sub version($$) {
   140 sub version($$) {
   145     my ($progname, $version) = @_;
   141     my ($progname, $version) = @_;
   146 
   142 
   147     print <<_VERSION;
   143     print <<_VERSION;
   148 $progname version $version
   144 $progname version $version
   149 Copyright (C) 2011 by Christian Arnold and Schlittermann internet & unix support.
   145 Copyright (C) 2011-2013 by Christian Arnold and Schlittermann internet & unix support.
       
   146 Copyright (C) 2015 by Schlittermann internet & unix support.
   150 
   147 
   151 $ME comes with ABSOLUTELY NO WARRANTY. This is free software,
   148 $ME comes with ABSOLUTELY NO WARRANTY. This is free software,
   152 and you are welcome to redistribute it under certain conditions.
   149 and you are welcome to redistribute it under certain conditions.
   153 See the GNU General Public Licence for details.
   150 See the GNU General Public Licence for details.
   154 _VERSION
   151 _VERSION