plugins/templates/check_template-mail-xml.pl

filter: Statementstmt 27.6% 29 / 105 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.8% 40 / 192 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.pl ↑ Summary blib/lib/ASNMTAP/Asnmtap/Plugins/SOAP.pm »
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.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.pl',
25 _programDescription => "Mail XML plugin template for testing the '$APPLICATION'",
26 _programVersion => '3.002.003',
27 _programGetOptions => ['username|u|loginname=s', 'password|p|passwd=s', '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 $environment = $objectPlugins->getOptionsArgv ('environment');
36  
37 0 my $environmentText = $objectPlugins->getOptionsValue ('environment');
38  
39 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
40  
41 2 ▶use ASNMTAP::Asnmtap::Plugins::Mail v3.002.003;
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43 0 my %environment = ( P => 'PROD', A => 'ACC' , S => 'SIM', T => 'TEST', D => 'DEV', L => 'LOCAL' );
44  
45 my $body = "
46 <?xml version=\"1.0\" encoding=\"UTF-8\"?>
47  
48 <BaseServiceReport>
49 <Ressource>
50 <Server>Production-Server</Server>
51 <Name>Name Service to Report</Name>
52 <Date>yyyy/mm/dd</Date>
53 <Time>hh:mm:ss</Time>
54 0 <Environment>". $environment{$environment} ."</Environment>
55 <ErrorStack><![CDATA[ErrorStack .1.]]></ErrorStack>
56 <ErrorDetail><![CDATA[ErrorDetail .1.]]></ErrorDetail>
57 </Ressource>
58 </BaseServiceReport>
59 ";
60  
61 0 my $objectMAIL = ASNMTAP::Asnmtap::Plugins::Mail->new (
62 _asnmtapInherited => \$objectPlugins,
63 _SMTP => { smtp => [ qw(smtp.citap.be) ], mime => 0 },
64 _POP3 => { pop3 => 'pop3.citap.be', username => $username, password => $password },
65 _mailType => 0,
66 _text => { SUBJECT => 'uKey=MAIL_'. $environment .'_0003' },
67 _mail => {
68 from => 'alex.peeters@citap.com',
69 to => 'asnmtap@citap.com',
70 status => $APPLICATION .' Status UP',
71 body => $body
72 }
73 );
74  
75 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
76  
77 0 my ($returnCode, $numberOfMatches, $debugfileMessage, @xml);
78  
79 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
80 # Start plugin - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
81 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
82  
83 # Receiving Fingerprint Mails - - - - - - - - - - - - - - - - - - - - - -
84  
85 2 ▶use constant HEADER => '<?xml version="1.0" encoding="UTF-8"?>';
Subroutine BEGIN: called CC=1 SCAR=0.0
86 2 ▶use constant FOOTER => '</BaseServiceReport>';
Subroutine BEGIN: called CC=1 SCAR=0.0
87  
88 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";
89 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";
90 0 $debugfileMessage .= "<H3 style=\"margin-bottom: 0.5em; font: bold 90% verdana,arial,helvetica\">$environmentText</H3>";
91  
92 0 ($returnCode, $numberOfMatches) = $objectMAIL->receiving_fingerprint_mails( custom => \&actionOnMailBody, customArguments => \{ xml => \@xml, header => HEADER, footer => FOOTER, validateDTD => 0, filenameDTD => '' }, receivedState => 0, perfdataLabel => 'email(s) received' );
93  
94 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
95 0 my $debug = $objectPlugins->getOptionsValue ('debug');
96 0 my $fixedAlert = "+";
97  
98 0 foreach my $xml (@xml) {
99 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";
100 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";
101 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
102 0 $fixedAlert .= "$xml->{Ressource}->{Server}-$xml->{Ressource}->{Name}+";
103 }
104  
105 0 ▶ $objectPlugins->pluginValues ( { alert => $fixedAlert }, $TYPE{COMMA_APPEND} ) if ($fixedAlert ne "+");
Branch: 1 branch
BranchTrueFalseTotal
if $fixedAlert ne "+" 0 0 0
106 }
107  
108 0 $debugfileMessage .= "\n</TABLE><P style=\"font: normal 68% verdana,arial,helvetica;\" ALIGN=\"left\">Generated on: ". scalar(localtime()) ."</P>\n</BODY>\n</HTML>";
109 0 $objectPlugins->write_debugfile ( \$debugfileMessage, 0 );
110  
111 # Sending Fingerprint Mail - - - - - - - - - - - - - - - - - - - - - - -
112  
113 0 $returnCode = $objectMAIL->sending_fingerprint_mail( perfdataLabel => 'email send' );
114  
115 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
116 # End plugin - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
117 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
118  
119 0 $objectPlugins->exit (7);
120  
121 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
122  
123 # Function needed by receiving_fingerprint_mail ! - - - - - - - - - - - -
124  
125 0 ▶sub actionOnMailBody {
Subroutine actionOnMailBody: not called CC=24 SCAR=62.3
126 0 my ($self, $asnmtapInherited, $pop3, $msgnum, $arguments) = @_;
127  
128 0 my $debug = $$asnmtapInherited->getOptionsValue ('debug');
129  
130 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
131 0 $$asnmtapInherited->pluginValues ( { stateValue => $ERRORS{UNKNOWN}, error => 'actionOnMailBody: arguments need to be an REF HASH!!!' }, $TYPE{APPEND} );
132 0 return ( $ERRORS{UNKNOWN} );
133 }
134  
135 2 ▶ no warnings 'deprecated';
Subroutine BEGIN: called CC=1 SCAR=0.0
136  
137 0 ▶ if ( $debug ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($debug) 0 0 0
138 0 print "\n\nactionOnMailBody:\n". $self->{defaultArguments}->{result} ."\n\n";
139 0 ▶ while (my ($key, $value) = each %{ $$arguments } ) { print "actionOnMailBody: $key => $value\n"; }
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$arguments;}) 0 0 0
140 0 print "\n";
141 }
142  
143 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
144  
145 2 ▶ use ASNMTAP::Asnmtap::Plugins::XML qw(&extract_XML);
Subroutine BEGIN: called CC=1 SCAR=0.0
146 0 my ($returnCode, $xml) = extract_XML ( asnmtapInherited => $asnmtapInherited, resultXML => $self->{defaultArguments}->{result}, headerXML => ${$$arguments}{header}, footerXML => ${$$arguments}{footer}, validateDTD => ${$$arguments}{validateDTD}, filenameDTD => ${$$arguments}{filenameDTD} );
147  
148 0 ▶ unless ( $returnCode ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($returnCode) { } 0 0 0
149 0 ▶ if ( $debug ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($debug) 0 0 0
150 0 print "<->\n", $xml->{Ressource}->{Server}, "\n";
151 0 print "<->\n", $xml->{Ressource}->{Name}, "\n";
152 0 print "<->\n", $xml->{Ressource}->{Date}, "\n";
153 0 print "<->\n", $xml->{Ressource}->{Time}, "\n";
154 0 print "<->\n", $xml->{Ressource}->{Environment}, "\n";
155 }
156  
157 0 my $tXml = ${$$arguments}{xml};
158 0 my $environment = $$asnmtapInherited->getOptionsArgv('environment');
159 0 my %environment = ( P => 'PROD', A => 'ACC' , S => 'SIM', T => 'TEST', D => 'DEV', L => 'LOCAL' );
160  
161 0 ▶ if ( $xml->{Ressource}->{Environment} =~ /^$environment{$environment}$/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($xml->{"Ressource"}{"Environment"} =~ /^$environment{$environment}$/i) 0 0 0
162 0 my $push = 0;
163  
164 0 foreach my $tmpXML (@{$tXml}) {
165 $push = ($tmpXML->{Ressource}->{Server} eq $xml->{Ressource}->{Server}) &&
166 ($tmpXML->{Ressource}->{Name} eq $xml->{Ressource}->{Name}) &&
167 ($tmpXML->{Ressource}->{Environment} eq $xml->{Ressource}->{Environment}) &&
168 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
169  
170 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
171  
172 0 ▶ if ($push) {
Branch: 1 branch
BranchTrueFalseTotal
if ($push) 0 0 0
173 0 $tmpXML->{Ressource}->{Errors}++;
174 0 last;
175 }
176 }
177  
178 0 ▶ unless ( $push ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($push) 0 0 0
179 0 $xml->{Ressource}->{Errors} = 1;
180 0 push (@{$tXml}, $xml);
181 }
182  
183 0 ▶ $xml->{Ressource}->{ErrorDetail} = '' if ( $debug != 2 );
Branch: 1 branch
BranchTrueFalseTotal
if $debug != 2 0 0 0
184 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
185 0 $self->{defaultArguments}->{numberOfMatches}++;
186 }
187  
188 0 ▶ if ( $debug ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($debug) 0 0 0
189 0 foreach my $xml (@{$tXml}) {
190 0 print "\n+++(out)+++\n$xml->{Ressource}->{Name}\n$xml->{Ressource}->{Date}\n$xml->{Ressource}->{Time}\n$xml->{Ressource}->{Errors}\n";
191 }
192 }
193 } else {
194 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
195 }
196  
197 0 return ( $returnCode );
198 }
199  
200 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
201  
202 __END__
« plugins/templates/check_template-mail-xml-fingerprint-xml.pl ↑ Summary blib/lib/ASNMTAP/Asnmtap/Plugins/SOAP.pm »