ASNMTAP::Asnmtap::Plugins::XML is a Perl module that provides XML functions used by ASNMTAP-based plugins.
use ASNMTAP::Asnmtap::Plugins v3.002.003; use ASNMTAP::Asnmtap::Plugins qw(:PLUGINS); my $objectPlugins = ASNMTAP::Asnmtap::Plugins->new ( _programName => 'check_template-WebTransact-XML.pl', _programDescription => "WebTransact-XML plugin template for testing the '$APPLICATION'", _programVersion => '3.002.003', _programGetOptions => ['environment|e:s', 'proxy:s', 'timeout|t:i', 'trendline|T:i'], _timeout => 30, _debug => 0); use ASNMTAP::Asnmtap::Plugins::WebTransact; use ASNMTAP::Asnmtap::Plugins::XML qw(&extract_XML); my @URLS = (); my $objectWebTransact = ASNMTAP::Asnmtap::Plugins::WebTransact->new ( \$objectPlugins, \@URLS ); $objectPlugins->pluginValue ('message', "WebTransact-XML plugin template for testing the '$APPLICATION'"); use constant HEADER1 => '<?xml version="1.0" encoding="UTF-8" ?>'; use constant FOOTER1 => '</testsuites>'; use constant HEADER2 => '<?xml version="1.0" encoding="UTF-8"?>'; use constant FOOTER2 => '</MonitoringXML>'; my ($returnCode, $result, $xml); @URLS = ( { Method => 'GET', Url => 'http://asnmtap.citap.com/ServletTestRunner.xml', Qs_var => [], Qs_fixed => [], Exp => "\Q<testsuites>\E", Exp_Fault => ">>>NIHIL<<<", Msg => "ServletTestRunner.xml", Msg_Fault => "ServletTestRunner.xml" }, ); $returnCode = $objectWebTransact->check ( { } ); undef $objectWebTransact; $objectPlugins->exit (7) if ( $returnCode ); $result = $objectPlugins->pluginValue ('result'); ($returnCode, $xml) = extract_XML ( asnmtapInherited => \$objectPlugins, resultXML => $result, headerXML => HEADER1, footerXML => FOOTER1 ); $objectPlugins->exit (7) if ( $returnCode ); if ( $xml->{testsuite}->{failures} + $xml->{testsuite}->{errors} ) { $objectPlugins->pluginValues ( { stateValue => $ERRORS{CRITICAL}, error => 'failures or errors' }, $TYPE{APPEND} ); $objectPlugins->exit (7); } ($returnCode, $xml) = extract_XML ( asnmtapInherited => \$objectPlugins, filenameXML => 'xml/Monitoring-1.0.xml', headerXML => HEADER2, footerXML => FOOTER2, validateDTD => 1, filenameDTD => 'dtd/Monitoring-1.0.dtd' ); $objectPlugins->exit (7) if ( $returnCode ); if ( $xml->{Monitoring}->{Schema}->{Value} ne "1.0" ) { $objectPlugins->pluginValues ( { stateValue => $ERRORS{CRITICAL}, error => 'wrong schema' }, $TYPE{APPEND} ); $objectPlugins->exit (7); } $objectPlugins->pluginValues ( { stateValue => ( $objectPlugins->pluginValue ('stateValue') == $ERRORS{DEPENDENT} ? $ERRORS{OK} : $objectPlugins->pluginValue ('stateValue') ), alert => 'XML validated' }, $TYPE{APPEND} ); $objectPlugins->exit (7);
Extract one XML from resultXML and/or filenameXML between the XML HEADER and XML FOOTER.
Returns a status for $returnCode (OK..UNKNOWN) and when the status is OK for $xml the extracted XML, otherwise undef.
($returnCode, $xml) = extract_XML ( asnmtapInherited => \$objectPlugins, resultXML => $result, headerXML => HEADER1, footerXML => FOOTER1 ); ($returnCode, $xml) = extract_XML ( asnmtapInherited => \$objectPlugins, filenameXML => 'xml/Monitoring-1.0.xml', headerXML => HEADER2, footerXML => FOOTER2, validateDTD => 1, filenameDTD => 'dtd/Monitoring-1.0.dtd' ); ($returnCode, $xml) = extract_XML ( asnmtapInherited => \$objectPlugins, resultXML => $result, filenameXML => 'xml/Monitoring-1.0.xml', headerXML => HEADER2, footerXML => FOOTER2, validateDTD => 1, filenameDTD => 'dtd/Monitoring-1.0.dtd' );
A required reference to an ASNMTAP::Asnmtap::Plugins or ASNMTAP::Asnmtap::Plugins::Nagios subclass
Through this way of working we inherited the command line option --debug.
optional, is an reference to your own custom defined function
$xml: the extracted XML
sub actionOnExtractedXML { my ($asnmtapInherited, $xml) = @_; my $returnCode; if ( $xml->{Monitoring}->{Results}->{Details}->{Status} ) { $returnCode = $ERRORS{CRITICAL}; $objectPlugins->pluginValues ( { stateValue => $returnCode, error => 'BAD LUCK' }, $TYPE{APPEND} ); } else { $returnCode = $ERRORS{OK}; $asnmtapInherited->pluginValues ( { stateValue => $returnCode, alert => 'XML validated' }, $TYPE{APPEND} ); } return ($returnCode); }
and now with customArguments:
sub actionOnExtractedXML { my ($asnmtapInherited, $xml, $arguments) = @_; return ($ERRORS{OK}); }
optional, when you need to pass parameters to your own custom defined function, this can be done with customArguments.
customArguments: SCALAR, ARRAY, HASH, REF SCALAR, REF ARRAY, REF HASH
a string from where the XML need to be extracted.
resultXML and/or filenameXML are required
a filename from where the XML need to be extracted.
a required XML HEADER
XML HEADER: <?xml version="1.0" encoding="UTF-8"?>
a required XML FOOTER
XML FOOTER: </MonitoringXML>
optional, validateDTD can be 0 or 1
0, without DTD validation (default) 1, with DTD validation
required when validateDTD is 1
&extract_XML
Alex Peeters [alex.peeters@citap.be]
ASNMTAP::Asnmtap, ASNMTAP::Asnmtap::Plugins, ASNMTAP::Asnmtap::Plugins::Nagios
check_xml.pl check_xml-monitoring.pl check_xml-monitoring-1.2.pl check_template-XML.pl check_template-WebTransact-XML.pl check_template-WebTransact-XML-Cactus-parser.pl
ASNMTAP::Asnmtap::Plugins Data::Dumper XML::Parser XML::LibXML XML::Simple
(c) Copyright 2000-2011 by Alex Peeters [alex.peeters@citap.be], All Rights Reserved.
ASNMTAP is based on 'Process System daemons v1.60.17-01', Alex Peeters [alex.peeters@citap.be]
Purpose: CronTab (CT, sysdCT), Disk Filesystem monitoring (DF, sysdDF), Intrusion Detection for FW-1 (ID, sysdID) Process System daemons (PS, sysdPS), Reachability of Remote Hosts on a network (RH, sysdRH), Rotate Logfiles (system activity files) (RL), Remote Socket monitoring (RS, sysdRS), System Activity monitoring (SA, sysdSA).
'Process System daemons' is based on 'sysdaemon 1.60' written by Trans-Euro I.T Ltd
This ASNMTAP CPAN library and Plugin templates are free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The other parts of ASNMTAP may be used and modified free of charge by anyone so long as this copyright notice and the comments above remain intact. By using this code you agree to indemnify Alex Peeters from any liability that might arise from it's use.
Selling the code for this program without prior written consent is expressly forbidden. In other words, please ask first before you try and make money off of my program.
Obtain permission before redistributing this software over the Internet or in any other medium. In all cases copyright and header must remain intact.
To install ASNMTAP::Time, copy and paste the appropriate command in to your terminal.
cpanm
cpanm ASNMTAP::Time
CPAN shell
perl -MCPAN -e shell install ASNMTAP::Time
For more information on module installation, please visit the detailed CPAN module installation guide.