/[nagios-plugins-perl]/trunk/plugins/check_url.pl
ViewVC logotype

Contents of /trunk/plugins/check_url.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 121 - (show annotations) (download)
Thu Nov 12 13:29:04 2009 UTC (11 years ago) by racvision
File MIME type: text/plain
File size: 2676 byte(s)
convert source structure from autotools to rpm-build.sh
1 #!/usr/bin/perl -w
2 #
3 #
4 # check_url.pl <urlname>
5 #
6 # 9/2002 Stéphane Urbanovski <stephane.urbanovski@ac-nancy-metz.fr>
7 #
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License
10 # as published by the Free Software Foundation; either version 2
11 # of the License, or (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty
15 # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # you should have received a copy of the GNU General Public License
19 # along with this program (or with Netsaint); if not, write to the
20 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 # Boston, MA 02111-1307, USA
22 #
23 #
24
25 use strict;
26 use Digest::MD5 qw(md5 md5_hex md5_base64);
27
28 # Fichier de configuration des urls :
29 my $URLS_FILE = "/etc/racvision/check_url.conf";
30
31 # Predefined exit codes for Nagios/NetSaint
32 my %EXIT_CODES = (
33 'UNKNOWN' => -1,
34 'OK' => 0,
35 'WARNING' => 1,
36 'CRITICAL' => 2
37 );
38
39
40 my $url = undef;
41 my $goodmd5 = undef ;
42
43 # Get the options :
44 my $urlname = shift || &usage();
45
46 open (URLFILE,"<$URLS_FILE");
47 while (<URLFILE>) {
48 if (/^$urlname\s+(.*)/) {
49 $url=$1;
50 if ( $url =~ /^(.*)\s+([\w\d]+)$/ ) {
51 $url=$1;
52 $goodmd5=$2;
53 last;
54 }
55 }
56 }
57 close (URLFILE);
58
59
60 my $state = "UNKNOWN";
61 my $answer ;
62
63
64 if (!$url) {
65 $answer = "Pas d'URL pour $urlname !\n";
66 } else {
67
68 # wget -q -O - $url 2>&1
69 my $html = `wget -q -C off -O - $url 2>&1`;
70
71 if (!$?) {
72 $answer = "Url OK\n";
73
74 # Vérifier la conformitée de la page
75 my $digest = md5_hex($html);
76
77 if ( $goodmd5 && ($goodmd5 eq $digest)) {
78 $state = "OK";
79 $answer = "Url OK (MD5=$digest)\n";
80 } elsif ( $goodmd5) {
81 $state = "WARNING";
82 $answer = "Mauvaise signature :<br />- MD5 relevé=$digest<br />- MD5 recherché=$goodmd5\n";
83 } else {
84 $state = "OK";
85 $answer = "Url OK (Pas de signature MD5)\n";
86 }
87
88 } else {
89 $state = "CRITICAL";
90 chop($html);
91 if ($html =~ /(ERREUR .*)$/) {
92 $answer = "Erreur http : ".$1."\n";
93 } else {
94 $answer = "Erreur Inconnue ou serveur non joignable : ".$html." !\n";
95 }
96 }
97
98 }
99 print $answer;
100
101 exit $EXIT_CODES{$state};
102
103 sub usage {
104 print "Minimum arguments not supplied!\n";
105 print "\n";
106 print "Perl Check URL plugin for Nagios/NetSaint\n";
107 print " (c) 2002 Stéphane Urbanovski <stephane.urbanovski\@ac-nancy-metz.fr>\n";
108 print "\n";
109 print "Usage: $0 <urlname>\n";
110 print "\n";
111 print "<url> = Short name of the URL to test.\n";
112 print " (see $URLS_FILE for configuration).\n";
113 exit $EXIT_CODES{"UNKNOWN"};
114 }

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.8