diff options
Diffstat (limited to 'contrib/check_frontpage')
-rw-r--r-- | contrib/check_frontpage | 151 |
1 files changed, 151 insertions, 0 deletions
diff --git a/contrib/check_frontpage b/contrib/check_frontpage new file mode 100644 index 00000000..ee958d30 --- /dev/null +++ b/contrib/check_frontpage | |||
@@ -0,0 +1,151 @@ | |||
1 | #! /usr/bin/perl -w | ||
2 | # | ||
3 | # $Id$ | ||
4 | # | ||
5 | # Check that FrontPage extensions appear to be working on a specified host. | ||
6 | # Currently only checks that the hit counter is not returning an error. | ||
7 | # | ||
8 | # Probably not a good idea to use this on a host that someone's counting | ||
9 | # the hits on, so create a separate vhost for frontpage extensions testing, | ||
10 | # or just install the extensions on the default/root host for your server, and | ||
11 | # point it against that hostname, running it against all vhosts on a server is | ||
12 | # probably rather wasteful. | ||
13 | # | ||
14 | # Kev Green, oRe Net (http://www.orenet.co.uk/). | ||
15 | |||
16 | |||
17 | use strict; | ||
18 | use lib "/usr/lib/nagios/plugins"; | ||
19 | use utils qw($TIMEOUT %ERRORS &print_revision &support); | ||
20 | use vars qw($PROGNAME); | ||
21 | use Getopt::Long; | ||
22 | use LWP; | ||
23 | use vars qw($opt_V $opt_h $verbose $opt_w $opt_c $opt_H); | ||
24 | my ($tt,$url,$response,$stime, $etime,$warning,$critical,$mimetype,$failtype,$temp,$message); | ||
25 | my $rt = 0; | ||
26 | |||
27 | $PROGNAME = "check_frontpage"; | ||
28 | sub print_help (); | ||
29 | sub print_usage (); | ||
30 | |||
31 | $ENV{'PATH'}=''; | ||
32 | $ENV{'BASH_ENV'}=''; | ||
33 | $ENV{'ENV'}=''; | ||
34 | |||
35 | Getopt::Long::Configure('bundling'); | ||
36 | GetOptions | ||
37 | ("V" => \$opt_V, "version" => \$opt_V, | ||
38 | "h" => \$opt_h, "help" => \$opt_h, | ||
39 | "v" => \$verbose, "verbose" => \$verbose, | ||
40 | "w=s" => \$opt_w, "warning=s" => \$opt_w, | ||
41 | "c=s" => \$opt_c, "critical=s" => \$opt_c, | ||
42 | "H=s" => \$opt_H, "hostname=s" => \$opt_H); | ||
43 | |||
44 | if ($opt_V) { | ||
45 | print_revision($PROGNAME,'$Revision$'); #' | ||
46 | exit $ERRORS{'OK'}; | ||
47 | } | ||
48 | |||
49 | if ($opt_h) { | ||
50 | print_help(); | ||
51 | exit $ERRORS{'OK'}; | ||
52 | } | ||
53 | |||
54 | $opt_H = shift unless ($opt_H); | ||
55 | print_usage() unless $opt_H; | ||
56 | my $host = $1 if ($opt_H =~ m/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|[a-zA-Z][-a-zA-Z0-9]+(\.[a-zA-Z0-9][-a-zA-Z0-9]+)*)$/); | ||
57 | print_usage() unless $host; | ||
58 | |||
59 | ($opt_c) || ($opt_c = shift) || ($opt_c = 120); | ||
60 | if ($opt_c =~ /([0-9]+)/) { | ||
61 | $critical = $1; | ||
62 | } else { | ||
63 | $critical = 10; | ||
64 | } | ||
65 | |||
66 | ($opt_w) || ($opt_w = shift) || ($opt_w = 60); | ||
67 | if ($opt_w =~ /([0-9]+)/) { | ||
68 | $warning = $1; | ||
69 | } else { | ||
70 | $warning = 5; | ||
71 | } | ||
72 | |||
73 | # Guts go here, once we're through argument parsing and have warning and | ||
74 | # critical thresholds. | ||
75 | my $browser = LWP::UserAgent->new; | ||
76 | |||
77 | my @urls = ( | ||
78 | # This is the "Hit Counter", which continues to work if frontpage extensions | ||
79 | # are 'uninstall'ed from the site, but not when they are 'fulluninstall'ed. | ||
80 | { | ||
81 | url => "_vti_bin/fpcount.exe?Page=_borders/right.htm|Image=4", | ||
82 | mimetype => "image/gif", | ||
83 | message => "None, or broken frontpage extensions on server, or virtual site 'fulluninstall'ed?", | ||
84 | failtype => "CRITICAL" | ||
85 | }, | ||
86 | # This is the "FrontPage Configuration Information" file, which is removed | ||
87 | # when you 'uninstall' the extensions from a site. | ||
88 | { | ||
89 | url => "_vti_inf.html", | ||
90 | mimetype => "text/html", | ||
91 | message => "Someone 'uninstall'ed extensions on virtual site?", | ||
92 | failtype => "WARNING" | ||
93 | } | ||
94 | ); | ||
95 | |||
96 | print "FRONTPAGE: "; | ||
97 | |||
98 | foreach $temp (@urls) { | ||
99 | $url = $temp->{'url'}; | ||
100 | $mimetype = $temp->{'mimetype'}; | ||
101 | $failtype = $temp->{'failtype'}; | ||
102 | $message = $temp->{'message'}; | ||
103 | $stime = time(); | ||
104 | $response=$browser->get("http://".$host."/".$url); | ||
105 | $etime = time(); | ||
106 | $tt = $etime - $stime; | ||
107 | |||
108 | # If we got a server error, or unknown output type, report back as critical. | ||
109 | if ($response->status_line !~ "^200") { | ||
110 | print $message." (".$response->status_line.")\r\n"; | ||
111 | exit $ERRORS{$failtype}; | ||
112 | } elsif ($response->content_type !~ $mimetype) { | ||
113 | print $message." (Wrong Content-type: ".$response->content_type.")\r\n"; | ||
114 | exit $ERRORS{$failtype}; | ||
115 | } else { | ||
116 | # Because we're dealing with multiple URL's | ||
117 | $rt += $tt; | ||
118 | } | ||
119 | |||
120 | # Decide if the response time was critical or not. | ||
121 | # | ||
122 | if ($rt > $critical) { | ||
123 | print "Response time ".$rt." over critical threshold ".$critical."\r\n"; | ||
124 | exit($ERRORS{'CRITICAL'}); | ||
125 | } elsif ($rt > $warning) { | ||
126 | print "Response time ".$rt." over warning threshold ".$warning."\r\n"; | ||
127 | exit($ERRORS{'WARNING'}); | ||
128 | } | ||
129 | } | ||
130 | printf(" %s - %s second response time, ",$response->status_line, $rt); | ||
131 | |||
132 | # If all the required URL's give the right responses quick enough, then we | ||
133 | # should be okay. | ||
134 | exit($ERRORS{'OK'}); | ||
135 | |||
136 | sub print_usage () { | ||
137 | print "Usage: $PROGNAME -H <host> [-w <warn>] [-c <crit>]\n"; | ||
138 | exit; | ||
139 | } | ||
140 | |||
141 | sub print_help () { | ||
142 | print_revision($PROGNAME,'$Revision$'); | ||
143 | print "Copyright (c) 2003 Kev Green\n"; | ||
144 | print "\n"; | ||
145 | print "FrontPage remains a copyright/trademark of Microsoft Corporation.\n"; | ||
146 | print_usage(); | ||
147 | print "\n"; | ||
148 | print "<warn> = Unknown.\n"; | ||
149 | print "<crit> = Server error from FrontPage extensions.\n\n"; | ||
150 | support(); | ||
151 | } | ||