check_frontpage 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. use strict;
  16. use lib "/usr/lib/nagios/plugins";
  17. use utils qw($TIMEOUT %ERRORS &print_revision &support);
  18. use vars qw($PROGNAME);
  19. use Getopt::Long;
  20. use LWP;
  21. use vars qw($opt_V $opt_h $verbose $opt_w $opt_c $opt_H);
  22. my ($tt,$url,$response,$stime, $etime,$warning,$critical,$mimetype,$failtype,$temp,$message);
  23. my $rt = 0;
  24. $PROGNAME = "check_frontpage";
  25. sub print_help ();
  26. sub print_usage ();
  27. $ENV{'PATH'}='';
  28. $ENV{'BASH_ENV'}='';
  29. $ENV{'ENV'}='';
  30. Getopt::Long::Configure('bundling');
  31. GetOptions
  32. ("V" => \$opt_V, "version" => \$opt_V,
  33. "h" => \$opt_h, "help" => \$opt_h,
  34. "v" => \$verbose, "verbose" => \$verbose,
  35. "w=s" => \$opt_w, "warning=s" => \$opt_w,
  36. "c=s" => \$opt_c, "critical=s" => \$opt_c,
  37. "H=s" => \$opt_H, "hostname=s" => \$opt_H);
  38. if ($opt_V) {
  39. print_revision($PROGNAME,'$Revision$'); #'
  40. exit $ERRORS{'OK'};
  41. }
  42. if ($opt_h) {
  43. print_help();
  44. exit $ERRORS{'OK'};
  45. }
  46. $opt_H = shift unless ($opt_H);
  47. print_usage() unless $opt_H;
  48. 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]+)*)$/);
  49. print_usage() unless $host;
  50. ($opt_c) || ($opt_c = shift) || ($opt_c = 120);
  51. if ($opt_c =~ /([0-9]+)/) {
  52. $critical = $1;
  53. } else {
  54. $critical = 10;
  55. }
  56. ($opt_w) || ($opt_w = shift) || ($opt_w = 60);
  57. if ($opt_w =~ /([0-9]+)/) {
  58. $warning = $1;
  59. } else {
  60. $warning = 5;
  61. }
  62. # Guts go here, once we're through argument parsing and have warning and
  63. # critical thresholds.
  64. my $browser = LWP::UserAgent->new;
  65. my @urls = (
  66. # This is the "Hit Counter", which continues to work if frontpage extensions
  67. # are 'uninstall'ed from the site, but not when they are 'fulluninstall'ed.
  68. {
  69. url => "_vti_bin/fpcount.exe?Page=_borders/right.htm|Image=4",
  70. mimetype => "image/gif",
  71. message => "None, or broken frontpage extensions on server, or virtual site 'fulluninstall'ed?",
  72. failtype => "CRITICAL"
  73. },
  74. # This is the "FrontPage Configuration Information" file, which is removed
  75. # when you 'uninstall' the extensions from a site.
  76. {
  77. url => "_vti_inf.html",
  78. mimetype => "text/html",
  79. message => "Someone 'uninstall'ed extensions on virtual site?",
  80. failtype => "WARNING"
  81. }
  82. );
  83. print "FRONTPAGE: ";
  84. foreach $temp (@urls) {
  85. $url = $temp->{'url'};
  86. $mimetype = $temp->{'mimetype'};
  87. $failtype = $temp->{'failtype'};
  88. $message = $temp->{'message'};
  89. $stime = time();
  90. $response=$browser->get("http://".$host."/".$url);
  91. $etime = time();
  92. $tt = $etime - $stime;
  93. # If we got a server error, or unknown output type, report back as critical.
  94. if ($response->status_line !~ "^200") {
  95. print $message." (".$response->status_line.")\r\n";
  96. exit $ERRORS{$failtype};
  97. } elsif ($response->content_type !~ $mimetype) {
  98. print $message." (Wrong Content-type: ".$response->content_type.")\r\n";
  99. exit $ERRORS{$failtype};
  100. } else {
  101. # Because we're dealing with multiple URL's
  102. $rt += $tt;
  103. }
  104. # Decide if the response time was critical or not.
  105. #
  106. if ($rt > $critical) {
  107. print "Response time ".$rt." over critical threshold ".$critical."\r\n";
  108. exit($ERRORS{'CRITICAL'});
  109. } elsif ($rt > $warning) {
  110. print "Response time ".$rt." over warning threshold ".$warning."\r\n";
  111. exit($ERRORS{'WARNING'});
  112. }
  113. }
  114. printf(" %s - %s second response time, ",$response->status_line, $rt);
  115. # If all the required URL's give the right responses quick enough, then we
  116. # should be okay.
  117. exit($ERRORS{'OK'});
  118. sub print_usage () {
  119. print "Usage: $PROGNAME -H <host> [-w <warn>] [-c <crit>]\n";
  120. exit;
  121. }
  122. sub print_help () {
  123. print_revision($PROGNAME,'$Revision$');
  124. print "Copyright (c) 2003 Kev Green\n";
  125. print "\n";
  126. print "FrontPage remains a copyright/trademark of Microsoft Corporation.\n";
  127. print_usage();
  128. print "\n";
  129. print "<warn> = Unknown.\n";
  130. print "<crit> = Server error from FrontPage extensions.\n\n";
  131. support();
  132. }