plugins/templates/check_template-WebTransact-XML-Monitoring.pl

filter: Statementstmt 33.6% 33 / 98 Branchbran 1.4% 1 / 70 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 100% 11 / 11 Podpod n/a totaltotal 21.6% 45 / 208 CC 2 SCAR 2.2
CC
2
Cov
18%
BEGIN
2.5
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
« plugins/nagios/templates/check_xml-monitoring.pl ↑ Summary plugins/templates/check_template-WebTransact-XML.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-WebTransact-XML-Monitoring.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 Date::Calc qw(check_date check_time);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 3 ▶use Time::Local;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
22  
23 3 ▶use ASNMTAP::Asnmtap::Plugins v3.002.003;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 3 ▶use ASNMTAP::Asnmtap::Plugins qw(:PLUGINS);
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
27  
28 3 my $schema = "1.0";
29  
30 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
31  
32 3 my $objectPlugins = ASNMTAP::Asnmtap::Plugins->new (
33 _programName => 'check_template-WebTransact-XML-Monitoring.pl',
34 _programDescription => "WebTransact XML Monitoring plugin template for testing the '$APPLICATION'",
35 _programVersion => '3.002.003',
36 _programUsagePrefix => '--message=<message> [-H|--hostname <hostname> -s|--service <service>]|[--uKey <uKey>] [--validation <validation>]',
37 _programHelpPrefix => "--message=<message>
38 --message=message
39 -H, --hostname=<Nagios Hostname>
40 -s, --service=<Nagios service name>
41 --uKey=<uKey>
42 --validation=F|T
43 F(alse) : dtd validation off (default)
44 T(true) : dtd validation on",
45 _programGetOptions => ['message=s', 'url|U=s', 'hostname|H:s', 'service|s:s', 'uKey:s', 'validation:s', 'interval|i=i', 'proxy:s', 'environment|e=s', 'trendline|T:i'],
46 _timeout => 30,
47 _debug => 0);
48  
49 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
50  
51 0 my $url = $objectPlugins->getOptionsArgv ('url');
52  
53 0 my $message = $objectPlugins->getOptionsArgv ('message');
54 0 ▶$objectPlugins->printUsage ('Missing command line argument message') unless (defined $message);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $message 0 0 0
55 0 $objectPlugins->pluginValue ( message => $message );
56  
57 0 my ($uKey, $hostname, $service);
58 0 ▶$uKey = $objectPlugins->getOptionsArgv ('uKey') ? $objectPlugins->getOptionsArgv ('uKey') : undef;
Branch: 1 branch
BranchTrueFalseTotal
$objectPlugins->getOptionsArgv('uKey') ? : 0 0 0
59  
60 0 ▶unless ( defined $uKey ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $uKey) 0 0 0
61 0 ▶ $hostname = $objectPlugins->getOptionsArgv ('hostname') ? $objectPlugins->getOptionsArgv ('hostname') : undef;
Branch: 1 branch
BranchTrueFalseTotal
$objectPlugins->getOptionsArgv('hostname') ? : 0 0 0
62 0 ▶ $objectPlugins->printUsage ('Missing command line argument uKey or hostname') unless (defined $hostname);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $hostname 0 0 0
63  
64 0 ▶ $service = $objectPlugins->getOptionsArgv ('service') ? $objectPlugins->getOptionsArgv ('service') : undef;
Branch: 1 branch
BranchTrueFalseTotal
$objectPlugins->getOptionsArgv('service') ? : 0 0 0
65 0 ▶ $objectPlugins->printUsage ('Missing command line argument service') unless ( defined $service);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $service 0 0 0
66 }
67  
68 0 ▶my $validateDTD = $objectPlugins->getOptionsArgv ('validation') ? $objectPlugins->getOptionsArgv ('validation') : 'F';
Branch: 1 branch
BranchTrueFalseTotal
$objectPlugins->getOptionsArgv('validation') ? : 0 0 0
69  
70 0 ▶if (defined $validateDTD) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $validateDTD) 0 0 0
71 0 ▶ $objectPlugins->printUsage ('Invalid validation option: '. $validateDTD) unless ($validateDTD =~ /^[FT]$/);
Branch: 1 branch
BranchTrueFalseTotal
unless $validateDTD =~ /^[FT]$/ 0 0 0
72 0 ▶ $validateDTD = ($validateDTD eq 'T') ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$validateDTD eq 'T' ? : 0 0 0
73 }
74  
75 0 my $resultOutOfDate = $objectPlugins->getOptionsArgv ('interval');
76  
77 0 ▶my $environment = $objectPlugins->getOptionsArgv ('environment') ? $objectPlugins->getOptionsArgv ('environment') : 'P';
Branch: 1 branch
BranchTrueFalseTotal
$objectPlugins->getOptionsArgv('environment') ? : 0 0 0
78  
79 0 my $debug = $objectPlugins->getOptionsValue ('debug');
80  
81 0 my $reverse = 0;
82  
83 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
84  
85 3 ▶use ASNMTAP::Asnmtap::Plugins::WebTransact;
Subroutine BEGIN: called CC=1 SCAR=0.0
86 3 ▶use ASNMTAP::Asnmtap::Plugins::XML qw(&extract_XML);
Subroutine BEGIN: called CC=1 SCAR=0.0
87  
88 3 ▶use constant HEADER => '<?xml version="1.0" encoding="UTF-8"?>';
Subroutine BEGIN: called CC=1 SCAR=0.0
89 3 ▶use constant FOOTER => '</MonitoringXML>';
Subroutine BEGIN: called CC=1 SCAR=0.0
90  
91 0 my @URLS = ();
92 0 my $objectWebTransact = ASNMTAP::Asnmtap::Plugins::WebTransact->new ( \$objectPlugins, \@URLS );
93  
94 0 my ($returnCode, $result, $xml);
95  
96 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
97  
98 0 @URLS = (
99 { Method => 'GET', Url => $url, Qs_var => [], Qs_fixed => [], Exp => "\Q<MonitoringXML>\E", Exp_Fault => ">>>NIHIL<<<", Msg => "XML", Msg_Fault => "XML" },
100 );
101  
102 0 $returnCode = $objectWebTransact->check ( { } );
103 0 undef $objectWebTransact;
104 0 ▶$objectPlugins->exit (7) if ( $returnCode );
Branch: 1 branch
BranchTrueFalseTotal
if $returnCode 0 0 0
105  
106 0 $result = $objectPlugins->pluginValue ('result');
107 0 ($returnCode, $xml) = extract_XML ( asnmtapInherited => \$objectPlugins, resultXML => $result, headerXML => HEADER, footerXML => FOOTER, validateDTD => $validateDTD, filenameDTD => "dtd/Monitoring-$schema.dtd" );
108 0 ▶$objectPlugins->exit (3) if ( $returnCode );
Branch: 1 branch
BranchTrueFalseTotal
if $returnCode 0 0 0
109  
110 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
111  
112 0 my $currentTimeslot = timelocal ((localtime)[0,1,2,3,4,5]);
113 0 my %environment = ( P => 'PROD', S => 'SIM', A => 'ACC', T => 'TEST', D => 'DEV', L => 'LOCAL' );
114  
115 0 my $match = 0;
116  
117 0 ▶if ( defined $xml->{Monitoring}{Results}{Extension}{Element}{eName} and $xml->{Monitoring}{Results}{Extension}{Element}{eName} eq 'uKey') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $xml->{'Monitoring'}{'Results'}{'Extension'}{'Element'}{'eName'} and $xml->{'Monitoring'}{'Results'}{'Extension'}{'Element'}{'eName'} eq 'uKey') { } 0 0 0
Condition0%0/3
defined $xml->{"Monitoring"}{"Results"}{"Extension"}{"Element"}{"eName"} and $xml->{"Monitoring"}{"Results"}{"Extension"}{"Element"}{"eName"} eq "uKey"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $xml->{"Monitoring"}{"Results"}{"Extension"}{"Element"}{"eName"} and $xml->{"Monitoring"}{"Results"}{"Extension"}{"Element"}{"eName"} eq "uKey"
defined $xml->{"Monitoring"}{"Results"}{"Extension"}{"Element"}{"eName"} $xml->{"Monitoring"}{"Results"}{"Extension"}{"Element"}{"eName"} eq "uKey"
Truth table0%0/3
A and B
A= defined $xml->{"Monitoring"}{"Results"}{"Extension"}{"Element"}{"eName"}B= $xml->{"Monitoring"}{"Results"}{"Extension"}{"Element"}{"eName"} eq "uKey"
ABresult
0X0
100
111
118 0 ▶ $match = 1 if ( defined $xml->{Monitoring}{Results}{Extension}{Element}{eValue} and $xml->{Monitoring}{Results}{Extension}{Element}{eValue} eq $uKey );
Branch: 1 branch
BranchTrueFalseTotal
if defined $xml->{"Monitoring"}{"Results"}{"Extension"}{"Element"}{"eValue"} and $xml->{"Monitoring"}{"Results"}{"Extension"}{"Element"}{"eValue"} eq $uKey 0 0 0
Condition0%0/3
defined $xml->{"Monitoring"}{"Results"}{"Extension"}{"Element"}{"eValue"} and $xml->{"Monitoring"}{"Results"}{"Extension"}{"Element"}{"eValue"} eq $uKey
!ll&&!rl&&r
000
MC/DC0%0/2
defined $xml->{"Monitoring"}{"Results"}{"Extension"}{"Element"}{"eValue"} and $xml->{"Monitoring"}{"Results"}{"Extension"}{"Element"}{"eValue"} eq $uKey
defined $xml->{"Monitoring"}{"Results"}{"Extension"}{"Element"}{"eValue"} $xml->{"Monitoring"}{"Results"}{"Extension"}{"Element"}{"eValue"} eq $uKey
Truth table0%0/3
A and B
A= defined $xml->{"Monitoring"}{"Results"}{"Extension"}{"Element"}{"eValue"}B= $xml->{"Monitoring"}{"Results"}{"Extension"}{"Element"}{"eValue"} eq $uKey
ABresult
0X0
100
111
119 } else {
120 0 ▶ $match = 1 if ( $xml->{Monitoring}{Results}{Details}{Host} eq $hostname and $xml->{Monitoring}{Results}{Details}{Service} eq $service );
Branch: 1 branch
BranchTrueFalseTotal
if $xml->{"Monitoring"}{"Results"}{"Details"}{"Host"} eq $hostname and $xml->{"Monitoring"}{"Results"}{"Details"}{"Service"} eq $service 0 0 0
Condition0%0/3
$xml->{"Monitoring"}{"Results"}{"Details"}{"Host"} eq $hostname and $xml->{"Monitoring"}{"Results"}{"Details"}{"Service"} eq $service
!ll&&!rl&&r
000
MC/DC0%0/2
$xml->{"Monitoring"}{"Results"}{"Details"}{"Host"} eq $hostname and $xml->{"Monitoring"}{"Results"}{"Details"}{"Service"} eq $service
$xml->{"Monitoring"}{"Results"}{"Details"}{"Host"} eq $hostname $xml->{"Monitoring"}{"Results"}{"Details"}{"Service"} eq $service
Truth table0%0/3
A and B
A= $xml->{"Monitoring"}{"Results"}{"Details"}{"Host"} eq $hostnameB= $xml->{"Monitoring"}{"Results"}{"Details"}{"Service"} eq $service
ABresult
0X0
100
111
121 }
122  
123 0 ▶if ($match and $xml->{Monitoring}{Schema}{Value} eq $schema and $xml->{Monitoring}{Results}{Details}{Environment} =~ /^$environment{$environment}$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($match and $xml->{'Monitoring'}{'Schema'}{'Value'} eq $schema and $xml->{'Monitoring'}{'Results'}{'Details'}{'Environment'} =~ /^$environment{$environment}$/i) { } 0 0 0
Condition0%0/6
$match and $xml->{"Monitoring"}{"Schema"}{"Value"} eq $schema and $xml->{"Monitoring"}{"Results"}{"Details"}{"Environment"} =~ /^$environment{$environment}$/i
!ll&&!rl&&r
000
$match and $xml->{"Monitoring"}{"Schema"}{"Value"} eq $schema
!ll&&!rl&&r
000
MC/DC0%0/3
$match and $xml->{"Monitoring"}{"Schema"}{"Value"} eq $schema and $xml->{"Monitoring"}{"Results"}{"Details"}{"Environment"} =~ /^$environment{$environment}$/i
$match $xml->{"Monitoring"}{"Schema"}{"Value"} eq $schema $xml->{"Monitoring"}{"Results"}{"Details"}{"Environment"} =~ /^$environment{$environment}$/i
Truth table0%0/4
A and B and C
A= $matchB= $xml->{"Monitoring"}{"Schema"}{"Value"} eq $schemaC= $xml->{"Monitoring"}{"Results"}{"Details"}{"Environment"} =~ /^$environment{$environment}$/i
ABCresult
0XX0
10X0
1100
1111
124 0 my ($checkEpochtime, $checkDate, $checkTime) = ($xml->{Monitoring}{Results}{Details}{Epochtime}, $xml->{Monitoring}{Results}{Details}{Date}, $xml->{Monitoring}{Results}{Details}{Time});
125  
126 # yyyy[-/]mm[-/]dd[Z|[+-]hh:mm]
127 0 ▶ $checkDate = reverse ( $checkDate ) if ($reverse);
Branch: 1 branch
BranchTrueFalseTotal
if $reverse 0 0 0
128 0 ($checkDate, my $offsetDate) = split (/(Z|[+-]\d+:\d+)/, $checkDate, 2);
129  
130 0 ▶ if ($reverse) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reverse) 0 0 0
131 0 $checkDate = reverse ( $checkDate );
132 0 ▶ $offsetDate = reverse ( $offsetDate ) if ( defined $offsetDate );
Branch: 1 branch
BranchTrueFalseTotal
if defined $offsetDate 0 0 0
133 }
134  
135 # yyyy[-/]mm[-/]dd
136 0 my ($checkYear, $checkMonth, $checkDay) = split (/[\/-]/, $checkDate);
137 0 ▶ print "$checkDate, $checkYear, $checkMonth, $checkDay\n" if ( $debug );
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
138  
139 # hh:mm:ss[Z|[+-]hh:mm]
140 0 ($checkTime, my $offsetTime) = split (/[Z+-]/, $checkTime, 2);
141 0 my ($checkHour, $checkMin, $checkSec) = split (/:/, $checkTime);
142 0 ▶ print "$checkTime, $checkHour, $checkMin, $checkSec\n" if ( $debug );
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
143  
144 0 my $xmlEpochtime = timelocal ( $checkSec, $checkMin, $checkHour, $checkDay, ($checkMonth-1), ($checkYear-1900) );
145 0 ▶ print "$checkEpochtime, $xmlEpochtime ($checkDate, $checkTime), $currentTimeslot - $checkEpochtime = ". ($currentTimeslot - $checkEpochtime) ." > $resultOutOfDate\n" if ( $objectPlugins->getOptionsValue ('debug') );
Branch: 1 branch
BranchTrueFalseTotal
if $objectPlugins->getOptionsValue("debug") 0 0 0
146  
147 0 ▶ unless ( check_date ( $checkYear, $checkMonth, $checkDay) or check_time($checkHour, $checkMin, $checkSec ) ) {
Branch: 3 branches
BranchTrueFalseTotal
if (check_date($checkYear, $checkMonth, $checkDay) or check_time($checkHour, $checkMin, $checkSec)) { } 0 0 0
if (do { $checkEpochtime != $xmlEpochtime }) { } 0 0 0
elsif ($currentTimeslot - $checkEpochtime > $resultOutOfDate) { } 0 0 0
Condition0%0/3
check_date($checkYear, $checkMonth, $checkDay) or check_time($checkHour, $checkMin, $checkSec)
l!l&&r!l&&!r
000
MC/DC0%0/2
check_date($checkYear, $checkMonth, $checkDay) or check_time($checkHour, $checkMin, $checkSec)
check_date($checkYear, $checkMonth, $checkDay) check_time($checkHour, $checkMin, $checkSec)
Truth table0%0/3
A or B
A= check_date($checkYear, $checkMonth, $checkDay)B= check_time($checkHour, $checkMin, $checkSec)
ABresult
1X1
011
000
148 0 $objectPlugins->pluginValues ( { stateValue => $ERRORS{UNKNOWN}, error => "Date or Time into XML from URL '$url' are wrong: $checkDate $checkTime", result => undef }, $TYPE{APPEND} );
149 } elsif ( $checkEpochtime != $xmlEpochtime ) {
150 0 $objectPlugins->pluginValues ( { stateValue => $ERRORS{UNKNOWN}, error => "Epochtime difference from Date and Time into XML from URL '$url' are wrong: $checkEpochtime != $xmlEpochtime ($checkDate $checkTime)", result => undef }, $TYPE{APPEND} );
151 } elsif ( $currentTimeslot - $checkEpochtime > $resultOutOfDate ) {
152 0 $objectPlugins->pluginValues ( { stateValue => $ERRORS{UNKNOWN}, error => "Result into XML from URL '$url' are out of date: $checkDate $checkTime", result => undef }, $TYPE{APPEND} );
153 } else {
154 0 $objectPlugins->pluginValues ( { stateError => $STATE{$xml->{Monitoring}{Results}{Details}{Status}}, alert => $xml->{Monitoring}{Results}{Details}{StatusMessage}, result => $xml->{Monitoring}{Results}{Details}{content} }, $TYPE{APPEND} );
155 0 ▶ $objectPlugins->appendPerformanceData( $xml->{Monitoring}{Results}{Details}{PerfData} ) if ( $xml->{Monitoring}{Results}{Details}{PerfData} );
Branch: 1 branch
BranchTrueFalseTotal
if $xml->{"Monitoring"}{"Results"}{"Details"}{"PerfData"} 0 0 0
156 }
157 } else {
158 0 my $tError = 'Content Error:';
159 0 ▶ $tError .= ' - Schema: '. $xml->{Monitoring}{Schema}{Value} ." ne $schema" if ($xml->{Monitoring}{Schema}{Value} ne $schema);
Branch: 1 branch
BranchTrueFalseTotal
if $xml->{"Monitoring"}{"Schema"}{"Value"} ne $schema 0 0 0
160  
161 0 ▶ if ( $xml->{Monitoring}{Results}{Extension}{Element}{eName} eq 'uKey') {
Branch: 1 branch
BranchTrueFalseTotal
if ($xml->{'Monitoring'}{'Results'}{'Extension'}{'Element'}{'eName'} eq 'uKey') { } 0 0 0
162 0 ▶ $tError .= ' - uKey: '. $xml->{Monitoring}{Results}{Extension}{Element}{eValue} ." ne $uKey" if ($xml->{Monitoring}{Results}{Extension}{Element}{eValue} ne $uKey);
Branch: 1 branch
BranchTrueFalseTotal
if $xml->{"Monitoring"}{"Results"}{"Extension"}{"Element"}{"eValue"} ne $uKey 0 0 0
163 } else {
164 0 ▶ $tError .= ' - Host: '. $xml->{Monitoring}{Results}{Details}{Host} ." ne $hostname" if ($xml->{Monitoring}{Results}{Details}{Host} ne $hostname);
Branch: 1 branch
BranchTrueFalseTotal
if $xml->{"Monitoring"}{"Results"}{"Details"}{"Host"} ne $hostname 0 0 0
165 0 ▶ $tError .= ' - Service: '. $xml->{Monitoring}{Results}{Details}{Service} ." ne $service" if ($xml->{Monitoring}{Results}{Details}{Service} ne $service);
Branch: 1 branch
BranchTrueFalseTotal
if $xml->{"Monitoring"}{"Results"}{"Details"}{"Service"} ne $service 0 0 0
166 }
167  
168 0 ▶ $tError .= ' - Environment: ' .$xml->{Monitoring}{Results}{Details}{Environment} ." ne ". $environment{$environment} if ($xml->{Monitoring}{Results}{Details}{Environment} !~ /^$environment{$environment}$/i);
Branch: 1 branch
BranchTrueFalseTotal
unless $xml->{"Monitoring"}{"Results"}{"Details"}{"Environment"} =~ /^$environment{$environment}$/i 0 0 0
169 0 $objectPlugins->pluginValues ( { stateValue => $ERRORS{UNKNOWN}, error => $tError, result => undef }, $TYPE{APPEND} );
170 }
171  
172 0 $objectPlugins->exit (3);
173  
174 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
175  
176 __END__
« plugins/nagios/templates/check_xml-monitoring.pl ↑ Summary plugins/templates/check_template-WebTransact-XML.pl »