plugins/templates/check_template-mail-xml-fingerprint-xml.pl

filter: Statementstmt 27.3% 29 / 106 Branchbran 2.9% 1 / 34 Conditioncond 0.0% 0 / 27 MC/DCmcdc 0.0% 0 / 15 Subroutinesub 90.9% 10 / 11 Podpod n/a totaltotal 20.7% 40 / 193 CC 25 SCAR 58.5
CC
25
Cov
18%
actionOnMailBody
507.6
BEGIN
2.5
BEGIN
1.0
CRAP 348.5
« plugins/templates/check_template-mail-xml-fingerprint-xml-monitoring.pl ↑ Summary plugins/templates/check_template-mail-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-mail-xml-fingerprint-xml.pl
6 # ----------------------------------------------------------------------------------------------------------
7  
8 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶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 2 2
15  
16 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
17  
18 2 ▶use ASNMTAP::Asnmtap::Plugins v3.002.003;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶use ASNMTAP::Asnmtap::Plugins qw(:PLUGINS %STATE);
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
22  
23 2 my $objectPlugins = ASNMTAP::Asnmtap::Plugins->new (
24 _programName => 'check_template-mail-xml-fingerprint-xml.pl',
25 _programDescription => "XML fingerprint Mail XML plugin template for testing the '$APPLICATION'",
26 _programVersion => '3.002.003',
27 _programGetOptions => ['username|u|loginname=s', 'password|p|passwd=s', 'interval|i=i', 'environment|e=s', 'timeout|t:i', 'trendline|T:i'],
28 _timeout => 30,
29 _debug => 0);
30  
31 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
32  
33 0 my $username = $objectPlugins->getOptionsArgv ('username');
34 0 my $password = $objectPlugins->getOptionsArgv ('password');
35 0 my $interval = $objectPlugins->getOptionsArgv ('interval');
36  
37 0 my $environment = $objectPlugins->getOptionsArgv ('environment');
38 0 my $environmentText = $objectPlugins->getOptionsValue ('environment');
39  
40 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
41  
42 2 ▶use ASNMTAP::Asnmtap::Plugins::Mail v3.002.003;
Subroutine BEGIN: called CC=1 SCAR=0.0
43  
44 0 my %environment = ( P => 'PROD', A => 'ACC' , S => 'SIM', T => 'TEST', D => 'DEV', L => 'LOCAL' );
45  
46 my $body = "
47 <?xml version=\"1.0\" encoding=\"UTF-8\"?>
48  
49 <BaseServiceReport>
50 <Ressource>
51 <Server>Production-Server</Server>
52 <Name>Name Service to Report</Name>
53 <Date>yyyy/mm/dd</Date>
54 <Time>hh:mm:ss</Time>
55 0 <Environment>". $environment{$environment} ."</Environment>
56 <ErrorStack><![CDATA[ErrorStack .1.]]></ErrorStack>
57 <ErrorDetail><![CDATA[ErrorDetail .1.]]></ErrorDetail>
58 </Ressource>
59 </BaseServiceReport>
60 ";
61  
62 0 my $objectMAIL = ASNMTAP::Asnmtap::Plugins::Mail->new (
63 _asnmtapInherited => \$objectPlugins,
64 _SMTP => { smtp => [ qw(smtp.citap.be) ], mime => 0 },
65 _POP3 => { pop3 => 'pop3.citap.be', username => $username, password => $password },
66 _mailType => 1,
67 _text => { SUBJECT => 'uKey=MAIL_'. $environment .'_0004' },
68 _mail => {
69 from => 'alex.peeters@citap.com',
70 to => 'asnmtap@citap.com',
71 status => $APPLICATION .' Status UP',
72 body => $body
73 }
74 );
75  
76 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
77  
78 0 my ($returnCode, $numberOfMatches, $debugfileMessage, @xml);
79  
80 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
81 # Start plugin - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
82 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
83  
84 # Receiving Fingerprint Mails - - - - - - - - - - - - - - - - - - - - - -
85  
86 2 ▶use constant HEADER => '<?xml version="1.0" encoding="UTF-8"?>';
Subroutine BEGIN: called CC=1 SCAR=0.0
87 2 ▶use constant FOOTER => '</BaseServiceReport>';
Subroutine BEGIN: called CC=1 SCAR=0.0
88  
89 0 $debugfileMessage = "\n<HTML><HEAD><TITLE>Mail XML plugin template \@ $APPLICATION</TITLE></HEAD><BODY><HR><H1 style=\"margin: 0px 0px 5px; font: 125% verdana,arial,helvetica\">Mail XML plugin template @ $APPLICATION</H1><HR>\n";
90 0 $debugfileMessage .= "<TABLE WIDTH=\"100%\"><TR style=\"font: normal 68% bold verdana,arial,helvetica; text-align:left; background:#a6caf0;\"><TH>Server</TH><TH>Name</TH><TH>Environment</TH><TH>First Occurence Date</TH><TH>First Occurence Time</TH><TH>Errors</TH></TR>\n";
91 0 $debugfileMessage .= "<H3 style=\"margin-bottom: 0.5em; font: bold 90% verdana,arial,helvetica\">$environmentText</H3>";
92  
93 0 ($returnCode, $numberOfMatches) = $objectMAIL->receiving_fingerprint_mails( custom => \&actionOnMailBody, customArguments => \{ xml => \@xml, header => HEADER, footer => FOOTER, validateDTD => 0, filenameDTD => '' }, receivedState => 0, outOfDate => $interval, perfdataLabel => 'email(s) received' );
94  
95 0 ▶if ( defined $numberOfMatches and $numberOfMatches ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $numberOfMatches and $numberOfMatches) 0 0 0
Condition0%0/3
defined $numberOfMatches and $numberOfMatches
!ll&&!rl&&r
000
MC/DC0%0/2
defined $numberOfMatches and $numberOfMatches
defined $numberOfMatches $numberOfMatches
Truth table0%0/3
A and B
A= defined $numberOfMatchesB= $numberOfMatches
ABresult
0X0
100
111
96 0 my $debug = $objectPlugins->getOptionsValue ('debug');
97 0 my $fixedAlert = "+";
98  
99 0 foreach my $xml (@xml) {
100 0 $debugfileMessage .= "<TR style=\"background:#eeeee0; font: normal 68% bold verdana,arial,helvetica; color:purple;\"><TD>$xml->{Ressource}->{Server}</TD><TD>$xml->{Ressource}->{Name}</TD><TD>$xml->{Ressource}->{Environment}</TD><TD>$xml->{Ressource}->{Date}</TD><TD>$xml->{Ressource}->{Time}</TD><TD>$xml->{Ressource}->{Errors}</TD></TR>\n";
101 0 $debugfileMessage .= "<TR style=\"background:#eeeee0; font: normal 68% bold verdana,arial,helvetica; color:red;\"><TD valign=\"top\">Error Stack</TD><TD colspan=\"6\">$xml->{Ressource}->{ErrorStack}</TD></TR>\n";
102 0 ▶ $debugfileMessage .= "<TR style=\"background:#eeeee0; font: normal 68% bold verdana,arial,helvetica; color:red;\"><TD valign=\"top\">Error Detail</TD><TD colspan=\"6\">$xml->{Ressource}->{ErrorDetail}</TD></TR>\n" if ( $debug >= 2 );
Branch: 1 branch
BranchTrueFalseTotal
if $debug >= 2 0 0 0
103 0 $fixedAlert .= "$xml->{Ressource}->{Server}-$xml->{Ressource}->{Name}+";
104 }
105  
106 0 ▶ $objectPlugins->pluginValues ( { alert => $fixedAlert }, $TYPE{COMMA_APPEND} ) if ($fixedAlert ne "+");
Branch: 1 branch
BranchTrueFalseTotal
if $fixedAlert ne "+" 0 0 0
107 }
108  
109 0 $debugfileMessage .= "\n</TABLE><P style=\"font: normal 68% verdana,arial,helvetica;\" ALIGN=\"left\">Generated on: ". scalar(localtime()) ."</P>\n</BODY>\n</HTML>";
110 0 $objectPlugins->write_debugfile ( \$debugfileMessage, 0 );
111  
112 # Sending Fingerprint Mail - - - - - - - - - - - - - - - - - - - - - - -
113  
114 0 $returnCode = $objectMAIL->sending_fingerprint_mail( perfdataLabel => 'email send' );
115  
116 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
117 # End plugin - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
118 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
119  
120 0 $objectPlugins->exit (7);
121  
122 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
123  
124 # Function needed by receiving_fingerprint_mail ! - - - - - - - - - - - -
125  
126 0 ▶sub actionOnMailBody {
Subroutine actionOnMailBody: not called CC=24 SCAR=62.3
127 0 my ($self, $asnmtapInherited, $pop3, $msgnum, $arguments) = @_;
128  
129 0 my $debug = $$asnmtapInherited->getOptionsValue ('debug');
130  
131 0 ▶ unless ( defined $arguments and ref $arguments eq 'REF' and ref $$arguments eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $arguments and ref $arguments eq "REF" and ref $$arguments eq "HASH") 0 0 0
Condition0%0/6
defined $arguments and ref $arguments eq "REF" and ref $$arguments eq "HASH"
!ll&&!rl&&r
000
defined $arguments and ref $arguments eq "REF"
!ll&&!rl&&r
000
MC/DC0%0/3
defined $arguments and ref $arguments eq "REF" and ref $$arguments eq "HASH"
defined $arguments ref $arguments eq "REF" ref $$arguments eq "HASH"
Truth table0%0/4
A and B and C
A= defined $argumentsB= ref $arguments eq "REF"C= ref $$arguments eq "HASH"
ABCresult
0XX0
10X0
1100
1111
132 0 $$asnmtapInherited->pluginValues ( { stateValue => $ERRORS{UNKNOWN}, error => 'actionOnMailBody: arguments need to be an REF HASH!!!' }, $TYPE{APPEND} );
133 0 return ( $ERRORS{UNKNOWN} );
134 }
135  
136 2 ▶ no warnings 'deprecated';
Subroutine BEGIN: called CC=1 SCAR=0.0
137  
138 0 ▶ if ( $debug ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($debug) 0 0 0
139 0 print "\n\nactionOnMailBody:\n". $self->{defaultArguments}->{result} ."\n\n";
140 0 ▶ while (my ($key, $value) = each %{ $$arguments } ) { print "actionOnMailBody: $key => $value\n"; }
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$arguments;}) 0 0 0
141 0 print "\n";
142 }
143  
144 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
145  
146 2 ▶ use ASNMTAP::Asnmtap::Plugins::XML qw(&extract_XML);
Subroutine BEGIN: called CC=1 SCAR=0.0
147 0 my ($returnCode, $xml) = extract_XML ( asnmtapInherited => $asnmtapInherited, resultXML => $self->{defaultArguments}->{result}, headerXML => ${$$arguments}{header}, footerXML => ${$$arguments}{footer}, validateDTD => ${$$arguments}{validateDTD}, filenameDTD => ${$$arguments}{filenameDTD} );
148  
149 0 ▶ unless ( $returnCode ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($returnCode) { } 0 0 0
150 0 ▶ if ( $debug ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($debug) 0 0 0
151 0 print "<->\n", $xml->{Ressource}->{Server}, "\n";
152 0 print "<->\n", $xml->{Ressource}->{Name}, "\n";
153 0 print "<->\n", $xml->{Ressource}->{Date}, "\n";
154 0 print "<->\n", $xml->{Ressource}->{Time}, "\n";
155 0 print "<->\n", $xml->{Ressource}->{Environment}, "\n";
156 }
157  
158 0 my $tXml = ${$$arguments}{xml};
159 0 my $environment = $$asnmtapInherited->getOptionsArgv('environment');
160 0 my %environment = ( P => 'PROD', A => 'ACC' , S => 'SIM', T => 'TEST', D => 'DEV', L => 'LOCAL' );
161  
162 0 ▶ if ( $xml->{Ressource}->{Environment} =~ /^$environment{$environment}$/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($xml->{"Ressource"}{"Environment"} =~ /^$environment{$environment}$/i) 0 0 0
163 0 my $push = 0;
164  
165 0 foreach my $tmpXML (@{$tXml}) {
166 $push = ($tmpXML->{Ressource}->{Server} eq $xml->{Ressource}->{Server}) &&
167 ($tmpXML->{Ressource}->{Name} eq $xml->{Ressource}->{Name}) &&
168 ($tmpXML->{Ressource}->{Environment} eq $xml->{Ressource}->{Environment}) &&
169 0 ▶ ($tmpXML->{Ressource}->{ErrorStack} eq $xml->{Ressource}->{ErrorStack});
Condition0%0/9
$tmpXML->{'Ressource'}{'Server'} eq $xml->{'Ressource'}{'Server'} && $tmpXML->{'Ressource'}{'Name'} eq $xml->{'Ressource'}{'Name'} && $tmpXML->{'Ressource'}{'Environment'} eq $xml->{'Ressource'}{'Environment'} && $tmpXML->{'Ressource'}{'ErrorStack'} eq $xml->{'Ressource'}{'ErrorStack'}
!ll&&!rl&&r
000
$tmpXML->{"Ressource"}{"Server"} eq $xml->{"Ressource"}{"Server"} and $tmpXML->{"Ressource"}{"Name"} eq $xml->{"Ressource"}{"Name"} and $tmpXML->{"Ressource"}{"Environment"} eq $xml->{"Ressource"}{"Environment"}
!ll&&!rl&&r
000
$tmpXML->{"Ressource"}{"Server"} eq $xml->{"Ressource"}{"Server"} and $tmpXML->{"Ressource"}{"Name"} eq $xml->{"Ressource"}{"Name"}
!ll&&!rl&&r
000
MC/DC0%0/4
$tmpXML->{'Ressource'}{'Server'} eq $xml->{'Ressource'}{'Server'} && $tmpXML->{'Ressource'}{'Name'} eq $xml->{'Ressource'}{'Name'} && $tmpXML->{'Ressource'}{'Environment'} eq $xml->{'Ressource'}{'Environment'} && $tmpXML->{'Ressource'}{'ErrorStack'} eq $xml->{'Ressource'}{'ErrorStack'}
$tmpXML->{"Ressource"}{"Server"} eq $xml->{"Ressource"}{"Server"} $tmpXML->{"Ressource"}{"Name"} eq $xml->{"Ressource"}{"Name"} $tmpXML->{"Ressource"}{"Environment"} eq $xml->{"Ressource"}{"Environment"} $tmpXML->{'Ressource'}{'ErrorStack'} eq $xml->{'Ressource'}{'ErrorStack'}
Truth table0%0/5
A and B and C && D
A= $tmpXML->{"Ressource"}{"Server"} eq $xml->{"Ressource"}{"Server"}B= $tmpXML->{"Ressource"}{"Name"} eq $xml->{"Ressource"}{"Name"}C= $tmpXML->{"Ressource"}{"Environment"} eq $xml->{"Ressource"}{"Environment"}D= $tmpXML->{'Ressource'}{'ErrorStack'} eq $xml->{'Ressource'}{'ErrorStack'}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
170  
171 0 ▶ if ($push && $debug >= 2) { $push = ($tmpXML->{Ressource}->{ErrorDetail} eq $xml->{Ressource}->{ErrorDetail}); }
Branch: 1 branch
BranchTrueFalseTotal
if ($push and $debug >= 2) 0 0 0
Condition0%0/3
$push and $debug >= 2
!ll&&!rl&&r
000
MC/DC0%0/2
$push and $debug >= 2
$push $debug >= 2
Truth table0%0/3
A and B
A= $pushB= $debug >= 2
ABresult
0X0
100
111
172  
173 0 ▶ if ($push) {
Branch: 1 branch
BranchTrueFalseTotal
if ($push) 0 0 0
174 0 $tmpXML->{Ressource}->{Errors}++;
175 0 last;
176 }
177 }
178  
179 0 ▶ unless ( $push ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($push) 0 0 0
180 0 $xml->{Ressource}->{Errors} = 1;
181 0 push (@{$tXml}, $xml);
182 }
183  
184 0 ▶ $xml->{Ressource}->{ErrorDetail} = '' if ( $debug != 2 );
Branch: 1 branch
BranchTrueFalseTotal
if $debug != 2 0 0 0
185 0 ▶ $pop3->Delete( $msgnum ) unless ( $debug or $$asnmtapInherited->getOptionsValue ('onDemand') );
Branch: 1 branch
BranchTrueFalseTotal
unless $debug or $$asnmtapInherited->getOptionsValue("onDemand") 0 0 0
Condition0%0/3
$debug or $$asnmtapInherited->getOptionsValue("onDemand")
l!l&&r!l&&!r
000
MC/DC0%0/2
$debug or $$asnmtapInherited->getOptionsValue("onDemand")
$debug $$asnmtapInherited->getOptionsValue("onDemand")
Truth table0%0/3
A or B
A= $debugB= $$asnmtapInherited->getOptionsValue("onDemand")
ABresult
1X1
011
000
186 0 $self->{defaultArguments}->{numberOfMatches}++;
187 }
188  
189 0 ▶ if ( $debug ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($debug) 0 0 0
190 0 foreach my $xml (@{$tXml}) {
191 0 print "\n+++(out)+++\n$xml->{Ressource}->{Name}\n$xml->{Ressource}->{Date}\n$xml->{Ressource}->{Time}\n$xml->{Ressource}->{Errors}\n";
192 }
193 }
194 } else {
195 0 ▶ $pop3->Delete( $msgnum ) unless ( $debug >= 4 and $$asnmtapInherited->getOptionsValue ('onDemand') );
Branch: 1 branch
BranchTrueFalseTotal
unless $debug >= 4 and $$asnmtapInherited->getOptionsValue("onDemand") 0 0 0
Condition0%0/3
$debug >= 4 and $$asnmtapInherited->getOptionsValue("onDemand")
!ll&&!rl&&r
000
MC/DC0%0/2
$debug >= 4 and $$asnmtapInherited->getOptionsValue("onDemand")
$debug >= 4 $$asnmtapInherited->getOptionsValue("onDemand")
Truth table0%0/3
A and B
A= $debug >= 4B= $$asnmtapInherited->getOptionsValue("onDemand")
ABresult
0X0
100
111
196 }
197  
198 0 return ( $returnCode );
199 }
200  
201 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
202  
203 __END__
« plugins/templates/check_template-mail-xml-fingerprint-xml-monitoring.pl ↑ Summary plugins/templates/check_template-mail-xml.pl »