• Skip to content

Menu 1

  • Zug
  • Blog
  • Local
  • Printed
  • Projects
  • Railroad
  • Podcasts
  • Newsletter

Thomas Beutel Art

Menu 1

  • Zug
  • Blog
  • Local
  • Printed
  • Projects
  • Railroad
  • Podcasts
  • Newsletter

Follow us

Follow us on TwitterFollow us on InstagramFollow us on PinterestSubscribe to our Channel on YouTubeFollow us on SoundCloud
AuthorPostedbyThomason September 13, 2014

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.

♡

Posted in Nagios, Perl, Programming

Post navigation

Previous
Next

© 2025MINIMAL

Follow us

Follow us on TwitterFollow us on InstagramFollow us on PinterestSubscribe to our Channel on YouTubeFollow us on SoundCloud
x