summaryrefslogtreecommitdiffstats
path: root/contrib/check_frontpage
blob: ee958d304b39f4e5d0e243e3f2354dd21cd850c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#! /usr/bin/perl -w
#
# $Id$
#
# Check that FrontPage extensions appear to be working on a specified host.
# Currently only checks that the hit counter is not returning an error.
#
# Probably not a good idea to use this on a host that someone's counting
# the hits on, so create a separate vhost for frontpage extensions testing,
# or just install the extensions on the default/root host for your server, and
# point it against that hostname, running it against all vhosts on a server is
# probably rather wasteful.
#
# Kev Green, oRe Net (http://www.orenet.co.uk/).


use strict;
use lib "/usr/lib/nagios/plugins";
use utils qw($TIMEOUT %ERRORS &print_revision &support);
use vars qw($PROGNAME);
use Getopt::Long;
use LWP;
use vars qw($opt_V $opt_h $verbose $opt_w $opt_c $opt_H);
my ($tt,$url,$response,$stime, $etime,$warning,$critical,$mimetype,$failtype,$temp,$message);
my $rt = 0;

$PROGNAME = "check_frontpage";
sub print_help ();
sub print_usage ();

$ENV{'PATH'}='';
$ENV{'BASH_ENV'}='';
$ENV{'ENV'}='';

Getopt::Long::Configure('bundling');
GetOptions
	("V"   => \$opt_V, "version"    => \$opt_V,
	 "h"   => \$opt_h, "help"       => \$opt_h,
	 "v" => \$verbose, "verbose"  => \$verbose,
	 "w=s" => \$opt_w, "warning=s"  => \$opt_w,
	 "c=s" => \$opt_c, "critical=s" => \$opt_c,
	 "H=s" => \$opt_H, "hostname=s" => \$opt_H);

if ($opt_V) {
	print_revision($PROGNAME,'$Revision$'); #'
	exit $ERRORS{'OK'};
}

if ($opt_h) {
	print_help();
	exit $ERRORS{'OK'};
}

$opt_H = shift unless ($opt_H);
print_usage() unless $opt_H;
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]+)*)$/);
print_usage() unless $host;

($opt_c) || ($opt_c = shift) || ($opt_c = 120);
if ($opt_c =~ /([0-9]+)/) {
   $critical = $1;
} else {
   $critical = 10;
}

($opt_w) || ($opt_w = shift) || ($opt_w = 60);
if ($opt_w =~ /([0-9]+)/) {
   $warning = $1;
} else {
   $warning = 5;
}

# Guts go here, once we're through argument parsing and have warning and
# critical thresholds.
my $browser = LWP::UserAgent->new;

my @urls = ( 
 # This is the "Hit Counter", which continues to work if frontpage extensions
 # are 'uninstall'ed from the site, but not when they are 'fulluninstall'ed.
 {
   url => "_vti_bin/fpcount.exe?Page=_borders/right.htm|Image=4",
   mimetype => "image/gif",
   message => "None, or broken frontpage extensions on server, or virtual site 'fulluninstall'ed?",
   failtype => "CRITICAL"
 },
 # This is the "FrontPage Configuration Information" file, which is removed
 # when you 'uninstall' the extensions from a site.
 { 
   url => "_vti_inf.html",
   mimetype => "text/html",
   message => "Someone 'uninstall'ed extensions on virtual site?",
   failtype => "WARNING" 
 }
);

print "FRONTPAGE: ";

foreach $temp (@urls) {
   $url = $temp->{'url'};
   $mimetype = $temp->{'mimetype'};
   $failtype = $temp->{'failtype'};
   $message = $temp->{'message'};
   $stime = time();
   $response=$browser->get("http://".$host."/".$url);
   $etime = time();
   $tt = $etime - $stime;

# If we got a server error, or unknown output type, report back as critical.
   if ($response->status_line !~ "^200") {
      print $message." (".$response->status_line.")\r\n";
      exit $ERRORS{$failtype};
   } elsif ($response->content_type !~ $mimetype) {
      print $message." (Wrong Content-type: ".$response->content_type.")\r\n";
      exit $ERRORS{$failtype};
   } else {
      # Because we're dealing with multiple URL's
      $rt += $tt;
   }

# Decide if the response time was critical or not.
#
   if ($rt > $critical) {
      print "Response time ".$rt." over critical threshold ".$critical."\r\n";
      exit($ERRORS{'CRITICAL'});
   } elsif ($rt > $warning) {
      print "Response time ".$rt." over warning threshold ".$warning."\r\n";
      exit($ERRORS{'WARNING'});
   }
}
printf(" %s - %s second response time, ",$response->status_line, $rt);

# If all the required URL's give the right responses quick enough, then we 
# should be okay.
exit($ERRORS{'OK'});

sub print_usage () {
   print "Usage: $PROGNAME -H <host> [-w <warn>] [-c <crit>]\n";
   exit;
}

sub print_help () {
   print_revision($PROGNAME,'$Revision$');
   print "Copyright (c) 2003 Kev Green\n";
   print "\n";
   print "FrontPage remains a copyright/trademark of Microsoft Corporation.\n";
   print_usage();
   print "\n";
   print "<warn> = Unknown.\n";
   print "<crit> = Server error from FrontPage extensions.\n\n";
   support();
}