plugins/templates/check_template-XML.pl

filter: Statementstmt 73.1% 30 / 41 Branchbran 37.5% 3 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 88.8% 8 / 9 Podpod n/a totaltotal 70.6% 41 / 58 CC 3 SCAR 7.8
CC
3
Cov
67%
actionOnExtractedXML
6.0
BEGIN
2.5
BEGIN
1.0
CRAP 2.2
« plugins/templates/check_template-mail.pl ↑ Summary plugins/nagios/templates/check_template-ftp.pl »
1 #!/usr/bin/env perl
2 # ----------------------------------------------------------------------------------------------------------
3 # © Copyright 2003-2011 by Alex Peeters [alex.peeters@citap.be]
4 # ----------------------------------------------------------------------------------------------------------
5 # 2011/mm/dd, v3.002.003, check_template-XML.pl
6 # ----------------------------------------------------------------------------------------------------------
7  
8 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use warnings; # Must be used in test mode only. This reduces a little process speed
Subroutine BEGIN: called CC=1 SCAR=0.0
10 #use diagnostics; # Must be used in test mode only. This reduces a lot of process speed
11  
12 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
13  
14 0 ▶BEGIN { if ( $ENV{ASNMTAP_PERL5LIB} ) { eval 'use lib ( "$ENV{ASNMTAP_PERL5LIB}" )'; } }
Subroutine BEGIN: called CC=2 SCAR=9.2
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"ASNMTAP_PERL5LIB"}) 0 3 3
15  
16 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
17  
18 3 ▶use ASNMTAP::Asnmtap::Plugins v3.002.003;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 3 ▶use ASNMTAP::Asnmtap::Plugins qw(:PLUGINS);
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
22  
23 3 my $objectPlugins = ASNMTAP::Asnmtap::Plugins->new (
24 _programName => 'check_template-XML.pl',
25 _programDescription => "XML plugin template for testing the '$APPLICATION'",
26 _programVersion => '3.002.003',
27 _programGetOptions => ['environment|e:s', 'proxy:s', 'timeout|t:i', 'trendline|T:i'],
28 _timeout => 30,
29 _debug => 0);
30  
31 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
32  
33 3 ▶use ASNMTAP::Asnmtap::Plugins::XML qw(&extract_XML);
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
36 # Start plugin - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
37 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
38  
39 3 ▶use constant HEADER => '<?xml version="1.0" encoding="UTF-8"?>';
Subroutine BEGIN: called CC=1 SCAR=0.0
40 3 ▶use constant FOOTER => '</MonitoringXML>';
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 1 my ($returnCode, $result, $xml);
43  
44 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
45  
46 1 $result = <<EOT;
47 <?xml version="1.0" encoding="UTF-8"?>
48 <!DOCTYPE MonitoringXML SYSTEM "dtd/Monitoring-1.0.dtd">
49 <MonitoringXML>
50 <Monitoring>
51 <Schema Value="1.0"/>
52 <Results>
53 <Details Host="Host Name ..." Service="Service Name ..." Environment="LOCAL" Date="2005/11/04" Time="17:27:30" Epochtime="1131121650" Status="0" StatusMessage="StatusMessage ..." PerfData="'PerfData Label 1'=99ms;0;;; 'PerfData Label n'=99ms;0;;;"/>
54 <ErrorDetail><![CDATA[ErrorDetail .1.]]></ErrorDetail>
55 <ErrorStack><![CDATA[ErrorStack .1.]]></ErrorStack>
56 </Results>
57 </Monitoring>
58 </MonitoringXML>
59 EOT
60  
61 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
62  
63 1 ($returnCode, $xml) = extract_XML ( asnmtapInherited => \$objectPlugins, resultXML => $result, headerXML => HEADER, footerXML => FOOTER );
64 1 ▶$objectPlugins->exit (7) if ( $returnCode );
Branch: 1 branch
BranchTrueFalseTotal
if $returnCode 0 1 1
65  
66 1 ▶if ( $xml->{Monitoring}->{Results}->{Details}->{Status} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($xml->{"Monitoring"}{"Results"}{"Details"}{"Status"}) 0 1 1
67 0 $objectPlugins->pluginValues ( { stateValue => $ERRORS{CRITICAL}, error => 'BAD LUCK' }, $TYPE{APPEND} );
68 0 $objectPlugins->exit (7);
69 }
70  
71 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
72  
73 1 $returnCode = extract_XML ( asnmtapInherited => \$objectPlugins, custom => \&actionOnExtractedXML, filenameXML => 'xml/Monitoring-1.0.xml', headerXML => HEADER, footerXML => FOOTER, validateDTD => 1, filenameDTD => 'dtd/Monitoring-1.0.dtd' );
74  
75 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
76 # End plugin - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
77 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
78  
79 1 $objectPlugins->exit (7);
80  
81 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
82  
83 0 ▶sub actionOnExtractedXML {
Subroutine actionOnExtractedXML: not called CC=2 SCAR=17.9
84 0 my ($asnmtapInherited, $xml) = @_;
85  
86 0 my $returnCode;
87  
88 0 ▶ if ( $xml->{Monitoring}->{Results}->{Details}->{Status} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($xml->{'Monitoring'}{'Results'}{'Details'}{'Status'}) { } 0 0 0
89 0 $returnCode = $ERRORS{CRITICAL};
90 0 $objectPlugins->pluginValues ( { stateValue => $returnCode, error => 'BAD LUCK' }, $TYPE{APPEND} );
91 } else {
92 0 $returnCode = $ERRORS{OK};
93 0 $asnmtapInherited->pluginValues ( { stateValue => $returnCode, alert => 'XML validated' }, $TYPE{APPEND} );
94 }
95  
96 0 return ($returnCode);
97 }
98  
99 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
100  
101 __END__
« plugins/templates/check_template-mail.pl ↑ Summary plugins/nagios/templates/check_template-ftp.pl »