Skip to content

Instantly share code, notes, and snippets.

@tkhn
Created October 28, 2013 11:45
Show Gist options
  • Select an option

  • Save tkhn/7195462 to your computer and use it in GitHub Desktop.

Select an option

Save tkhn/7195462 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl -w
# Usage: check_sphinx_search.pl INDEX QUERY MIN-RESULTS
# Example: check_sphinx_search.pl products iphone 15000
use strict;
my $cmd = "search --limit 0 --index ${ARGV[0]} ${ARGV[1]}";
my $min = $ARGV[2];
my $output = `$cmd`;
if($?) {
bark("search command failed");
}
$output =~ s/\n//g;
if($output !~ m/matches of (\d+)/) {
bark("search command had unexpected output");
}
if($1 <= $min) {
bark("${1} matches found - too low (expected over ${min})");
}
print "OK - ${1} matches found\n";
exit;
sub bark {
print "CRITICAL - ${_[0]}\n";
exit;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment