|
1 #!/usr/bin/perl -w |
|
2 |
|
3 use strict; |
|
4 use File::Basename; |
|
5 use Getopt::Long; |
|
6 use LWP::Simple; |
|
7 |
|
8 use lib "/usr/lib/nagios/plugins"; |
|
9 use utils qw (%ERRORS &print_revision &support); |
|
10 |
|
11 my $ME = basename $0; |
|
12 my $VERSION = "1.1"; |
|
13 my $USAGE = <<EOF; |
|
14 Usage: $ME [-u | --url] |
|
15 $ME [-s | --search] |
|
16 $ME [-f | --file] |
|
17 $ME [-h | --help] |
|
18 $ME [-V | --version] |
|
19 EOF |
|
20 |
|
21 my $opt_url = "http://www.debian.org/releases/stable/index.html"; |
|
22 my $opt_search = "<p>Debian GNU/Linux"; |
|
23 my $opt_file = "/etc/debian_version"; |
|
24 my ($found, $current_release, $current_majornr, $stable_release, $stable_majornr, @website); |
|
25 |
|
26 sub check_status(); |
|
27 sub print_help(); |
|
28 sub print_usage(); |
|
29 |
|
30 MAIN: { |
|
31 Getopt::Long::Configure('bundling'); |
|
32 GetOptions( |
|
33 "u|url" => \$opt_url, |
|
34 "s|search" => \$opt_search, |
|
35 "f|file" => \$opt_file, |
|
36 "h|help" => sub { print_help(); exit $ERRORS{OK}; }, |
|
37 "V|version" => |
|
38 sub { print_revision( $ME, $VERSION ); exit $ERRORS{OK}; }, |
|
39 ); |
|
40 |
|
41 # get current release number |
|
42 unless ( -r $opt_file ) { |
|
43 print "RELEASE CRITICAL: $opt_file not exists or not read permission is granted\n"; |
|
44 exit $ERRORS{"CRITICAL"}; |
|
45 } |
|
46 |
|
47 open(CR, "<$opt_file"); |
|
48 while(<CR>) { |
|
49 chomp; |
|
50 $current_release = $_; |
|
51 $current_release =~ /^(\d)+.*/; |
|
52 $current_majornr = $1; |
|
53 } |
|
54 close(CR); |
|
55 |
|
56 # download the website |
|
57 push @website, split("\n", get($opt_url)); |
|
58 |
|
59 foreach (@website) { |
|
60 unless ($found) { |
|
61 /$opt_search/ or next; |
|
62 $found = $_; |
|
63 next; |
|
64 } |
|
65 } |
|
66 |
|
67 # get stable release number |
|
68 if ($found =~ /$opt_search\s+([\d\.]+).*/) { |
|
69 $stable_release = $1; |
|
70 $stable_release =~ /^(\d)+.*/; |
|
71 $stable_majornr = $1; |
|
72 } |
|
73 |
|
74 check_status(); |
|
75 |
|
76 } |
|
77 |
|
78 sub check_status() { |
|
79 if ($stable_release eq $current_release) { |
|
80 print "RELEASE OK: current release number $current_release\n"; |
|
81 exit $ERRORS{"OK"}; |
|
82 } elsif ($current_majornr < $stable_majornr) { |
|
83 print "RELEASE CRITICAL: current release number $current_release / stable release number $stable_release\n"; |
|
84 exit $ERRORS{"CRITICAL"}; |
|
85 } else { |
|
86 print "RELEASE WARNING: current release number $current_release / stable release number $stable_release\n"; |
|
87 exit $ERRORS{"WARNING"}; |
|
88 } |
|
89 } |
|
90 |
|
91 |
|
92 sub print_usage() { print $USAGE } |
|
93 |
|
94 sub print_help() { |
|
95 print_revision( $ME, $VERSION ); |
|
96 print <<EOF; |
|
97 Copyright (c) 2010 Christian Arnold |
|
98 |
|
99 This plugin checks the current debian release number. |
|
100 |
|
101 $USAGE |
|
102 -u, --url |
|
103 URL where to search for the search string (default: http://www.debian.org/releases/stable/index.html) |
|
104 -s, --search |
|
105 search string on the url (default: '<p>Debian GNU/Linux') |
|
106 -f, --file |
|
107 file with current release informations (default: /etc/debian_version) |
|
108 -h, --help |
|
109 print detailed help screen |
|
110 -V, --version |
|
111 print version information |
|
112 EOF |
|
113 support(); |
|
114 } |