Skip to content

Instantly share code, notes, and snippets.

@nicomen
Created November 7, 2012 13:34
Show Gist options
  • Save nicomen/4031609 to your computer and use it in GitHub Desktop.
Save nicomen/4031609 to your computer and use it in GitHub Desktop.
Changes to allow the check to support structs and match on a dump of the result
--- check_xml-rpc.pl.txt 2004-05-10 15:14:53.000000000 +0200
+++ check_xml-rpc-2.pl.txt 2012-11-07 14:32:32.370505789 +0100
@@ -24,6 +24,7 @@
use strict;
+use Data::Dumper;
use Getopt::Long;
use Frontier::Client;
# change the following to the directory containing utils.pm
@@ -47,6 +48,7 @@
$opts_url,
$opts_method,
$opts_parameters,
+ $opts_eval,
$opts_response
);
@@ -58,6 +60,7 @@
'u|url=s' => \$opts_url,
'm|method=s' => \$opts_method,
'p|parameters=s' => \$opts_parameters,
+ 'e|eval' => \$opts_eval,
'r|response=s' => \$opts_response);
if ($opts_version) {
@@ -88,23 +91,41 @@
# Initiate a connection and call method
my $server = Frontier::Client->new('url' =>"$opts_url");
-my @opts_parameters = split(/\,/, $opts_parameters)
+
+my @opts_parameters = ($opts_eval ? eval ($opts_parameters) : split(/\,/, $opts_parameters))
if ($opts_parameters);
+
my $result = $server->call($METHOD, @opts_parameters);
-if ($result =~ /$RESPONSE/) {
- print "OK, Method: $METHOD, Response: $result\n";
- exit $ERRORS{'OK'};
+if ($opts_eval) {
+ my $dumped_result = Dumper($result);
+
+ if ($dumped_result =~ /$RESPONSE/ms) {
-}elsif ($result) {
- print "Check failed: Expected response not matched,",
- "Response was: $result\n";
- exit $ERRORS{'CRITICAL'};
-}else{
- print "Check failed: Method call failed\n";
- exit $ERRORS{'CRITICAL'};
+ print "OK, Method: $METHOD, Response: $dumped_result\n";
+ exit $ERRORS{'OK'};
+
+ }elsif ($dumped_result) {
+ print "Check failed: Expected response not matched,",
+ "Response was: $dumped_result\n";
+ exit $ERRORS{'CRITICAL'};
+ }
+} else {
+ if ($result =~ /$RESPONSE/) {
+
+ print "OK, Method: $METHOD, Response: $result\n";
+ exit $ERRORS{'OK'};
+
+ }elsif ($result) {
+ print "Check failed: Expected response not matched,",
+ "Response was: $result\n";
+ exit $ERRORS{'CRITICAL'};
+ }
}
+print "Check failed: Method call failed\n";
+exit $ERRORS{'CRITICAL'};
+
# end of main
}
@@ -154,6 +175,8 @@
Defaults to 'pong'.
-p, --parameters: A list of comma delimited parameters to pass the method.
+-e, --eval: Evaluate parameters and dump response
+
-V, --Version: Version info.
example: check_xml-rpc.pl -u http://xml-rpc.foo.org:8080/RPC2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment