--- /dev/null
+#!/usr/bin/perl -w
+
+use LWP::UserAgent;
+
+#
+# Simple plugin to check whether a page has the given content
+# on it. Its useful for checking whether various dynamically
+# generated pages work.
+#
+# Adrian Chadd <adrian@ucs.uwa.edu.au>
+# $Id: check_webcontents,v 1.1 2005/10/04 09:45:22 willamowius Exp $
+#
+
+
+$PLUGINS{'webcontents'} = \&check_webcontents;
+
+#
+# Configuration parameters:
+#
+#
+# Under the HOST entry in spong.hosts, have:
+# * checkurl => "url-to-check",
+# * checkfor => "perl regexp to match entire HTTP response on"
+# * checklist => [ ( checkurl => url, checkfor => string ), ... ]
+#
+
+#
+# If any of them are failures, RED is returned.
+
+sub check_webcontents {
+ my ($host) = @_;
+ my ($message, $colour, $summary);
+
+ $message = "";
+ $summary = "";
+ $colour = "green";
+
+ my ($l) = $HOSTS{$host}->{'checklist'};
+ foreach (@$l) {
+ my ($url) = $_->{'checkurl'};
+ my ($checkfor) = $_->{'checkfor'};
+ &main::debug("check_webcontents - checking $host: $url for $checkfor");
+ my ($ua) = LWP::UserAgent->new();
+ my ($response) = $ua->get($url);
+ # Fail, response red, couldn't fetch
+ if (! $response->is_success) {
+ $summary .= "$url: could not connect\n";
+ $message .= "$url: could not connect\n";
+ $colour = "red";
+ &main::debug("check_webcontents - red, $summary");
+ return ("red", $summary, "<couldn't connect>");
+ }
+ # Check contents
+ $message = $response->as_string;
+ if ($message =~ /$checkfor/) {
+ $message = "$url: OK, $checkfor' found";
+ } else {
+ $summary .= "$url: FAIL, '$checkfor' not found";
+ $message .= "$url: FAIL, '$checkfor' not found";
+ $colour = "red";
+ }
+
+ if ($summary eq "") {
+ $summary = "ALL OK";
+ }
+ }
+ &main::debug("check_webcontents - $colour, $summary");
+ return ($colour, $summary, $message);
+};
+
+1;