Standard for feeding test data to a Nagios plugin?

Posted by chiborg on Server Fault See other posts from Server Fault or by chiborg
Published on 2012-12-11T10:18:41Z Indexed on 2012/12/11 11:05 UTC
Read the original article Hit count: 255

Filed under:
|
|

I'm developing a Nagios plugin in Perl (no Nagios::Plugin, just plain Perl). The error condition I'm checking for normally comes from a command output, called inside the plugin. However, it would be very inconvenient to create the error condition, so I'm looking for a way to feed test output to the plugin to see if it works correctly.

The easiest way I found at the moment would be with a command line option to optionally read input from a file instead of calling the command.

if($opt_f) {
  open(FILE, $opt_f);
  @output = <FILE>;
  close FILE;
}
else {
  @output = `my_command`;
}

Are there other, better ways to do this?

© Server Fault or respective owner

Related posts about perl

Related posts about testing