Suppress Test::More Output For Use In Nagios
289
post-template-default,single,single-post,postid-289,single-format-standard,bridge-core-3.0.1,qodef-qi--no-touch,qi-addons-for-elementor-1.5.3,qode-page-transition-enabled,ajax_updown,page_not_loaded,,vertical_menu_enabled,side_area_uncovered_from_content,qode-theme-ver-28.7,qode-theme-bridge,disabled_footer_top,qode_header_in_grid,wpb-js-composer js-comp-ver-6.8.0,vc_responsive,elementor-default,elementor-kit-6

Suppress Test::More Output For Use In Nagios

Suppress Test::More Output For Use In Nagios

I needed a quick way to check for XML well-formedness in a Perl Nagios script and I found that Test::XML has a test called is_well_formed_xml($xml) that does the job nicely. The only problem was that as part of the Test::More framework, Test::XML outputs test results (as it should). In my case though, I just wanted to perform the test. So I was able to suppress the output like so:

Test::More->builder->output('/dev/null');

Here is a larger code fragment if you are interested:

use Getopt::Euclid;
use Test::XML;
use Test::More;

Test::More->builder->output('/dev/null');

my $warning = $ARGV{'-w'};
my $critical = $ARGV{'-c'};

my $xml = `curl --silent 'http://example.com/some-xml-source.xml'`;

my $well_formed = is_well_formed_xml($xml);
done_testing();

if (!$well_formed) {
print "CRITICAL - XML not well formed\n";
exit(2);
}

# ... checking XML content for OK and WARNING states not shown here

I’m sure there are other quick ways to check for well-formedness but this is working well for me.



Mastodon