#!/usr/local/bin/perl =pod =head1 DESCRIPTION Search ultimatedomains.com for the passed in keyword and return an OK status if * The number of terms for the search is greater than 0 * The search completes without exceeding the maximum execution time specified on the command line. =cut use strict; use warnings; use FindBin; use lib "$FindBin::Bin/lib"; use Nagios::Plugin; use WWW::UltimateDomains; my $USAGE = < [-e|--env] [-w|--warning=] [-c|--critical=] [-v|--verbose] EOF my @ENVS = qw(www beta jarred rich vince max); my $np = Nagios::Plugin->new( 'version' => '$Id: check_keyword_search.pl 18 2008-01-06 14:54:07Z max $', 'shortname' => "KEYWORD_SEARCH", 'usage' => $USAGE, 'timeout' => 60 # Default timeout ); $np->add_arg(spec => 'env|e=s', help => "-e, --env=ENVIRONMENT\n " . "Env to search (" . join(',', @ENVS) . ") - [default $ENVS[0]\]", default => $ENVS[0]); $np->add_arg(spec => 'warning|w=s', default => 5, help => "-w, --warning=INTEGER:INTEGER\n" . " Warning threshold for search time [default 5]"); $np->add_arg(spec => 'critical|c=s', default => 10, help => "-c, --critical=INTEGER:INTEGER\n" . " Critical threshold for search time [default 10]"); $np->add_arg(spec => 'search|s=s', help => "-s, --search=KEYWORD\n Keyword to search", required => 1); $np->getopts; my $env = $np->opts->env; if (! grep(/$env/, @ENVS)) { die ("Invalid env argument " . $np->opts->env . "\n" . " Valid envs are " . join(',', @ENVS) . "\n"); } $np->set_thresholds('warning' => $np->opts->warning, 'critical' => $np->opts->critical); # Variables for the results of the keyword search my ($found, $time, $err_msg) = (undef, undef); eval { my $agent = WWW::UltimateDomains->new( 'Timeout' => $np->opts->critical, 'SubDomain' => $np->opts->env ); ($found, $time, $err_msg) = $agent->keyword_search($np->opts->search); }; my $search_failed = $@; $np->add_perfdata( label => "search", value => $time, uom => "s", threshold => $np->threshold() ); # Module threw a die() if ($search_failed) { $np->nagios_exit(UNKNOWN, $search_failed); } # Error during retrieval, known by WWW::UltimateDomains if ($err_msg ne '') { $np->nagios_exit(CRITICAL, $err_msg); } if ($found < 1) { $np->nagios_exit(CRITICAL, "No domains found for keyword '" . $np->opts->search . "' ($time seconds)" ) } # At this point, a positive number of domains were found, so let's make sure # the http response was received in a timely manner. my $code = $np->check_threshold(check => $time); if ($code == WARNING) { $np->nagios_exit($code, "$found results in $time seconds (> " . $np->opts->warning . "s)"); } elsif ($code == CRITICAL) { $np->nagios_exit($code, "$found results in $time seconds (> " . $np->opts->critical . "s)"); } elsif ($code == OK) { $np->nagios_exit($code, "$found results in $time seconds"); } else { # This should never happen $np->nagios_exit(UNKNOWN, "$found results in $time " . "seconds, but threshold check failed."); }