#!/bin/env perl
BEGIN {
if
(
$ENV
{ASNMTAP_PERL5LIB} ) {
eval
'use lib ( "$ENV{ASNMTAP_PERL5LIB}" )'
; } }
my
$objectPlugins
= ASNMTAP::Asnmtap::Plugins->new (
_programName
=>
'check_template-WebTransact-XML-Cactus-parser.pl'
,
_programDescription
=>
"WebTransact XML Cactus parser HTTP/HTTPS plugin template for testing the '$APPLICATION'"
,
_programVersion
=>
'3.000.017'
,
_programGetOptions
=> [
'filename|f:s'
,
'environment|e:s'
,
'proxy:s'
,
'timeout|t:i'
,
'trendline|T:i'
],
_timeout
=> 300,
_debug
=> 0);
my
$filename
=
$objectPlugins
->getOptionsArgv (
'filename'
) ?
$objectPlugins
->getOptionsArgv (
'filename'
) :
undef
;
my
$httpNotByFile
= (
defined
$filename
) ? 0 : 1;
use
constant
HEADER
=>
'<?xml version="1.0" encoding="UTF-8" ?>'
;
use
constant
TESTSUITE
=>
'be.asnmtap.common.businessservices.service.TestAsnmtapServiceRemote'
;
use
constant
EXP_FAULT
=>
'>>>NIHIL<<<'
;
my
$timeTestsuiteWarning
= 30;
my
$timeTestsuiteCritical
= 45;
my
@testcase
= ([
'testHeavyLoad1'
, 10, 20],
[
'testHeavyLoad2'
, 10, 20]);
my
(
$returnCode
,
$result
,
$xml
);
my
$debug
=
$objectPlugins
->getOptionsValue (
'debug'
);
if
(
$httpNotByFile
) {
my
@URLS
= (
{
Method
=>
'GET'
,
Url
=> URL,
Qs_var
=> [],
Qs_fixed
=> [
suite
=> TESTSUITE],
Exp
=> EXP,
Exp_Fault
=> EXP_FAULT,
Msg
=> MSG,
Msg_Fault
=> MSG_FAULT },
);
my
$objectWebTransact
= ASNMTAP::Asnmtap::Plugins::WebTransact->new ( \
$objectPlugins
, \
@URLS
);
$returnCode
=
$objectWebTransact
->check ( { } );
undef
$objectWebTransact
;
$objectPlugins
->
exit
(7)
if
(
$returnCode
);
$result
=
$objectPlugins
->pluginValue (
'result'
);
$filename
=
undef
;
}
else
{
$result
=
undef
;
}
if
(
$debug
>= 2 ) {
print
"\n<header>\n"
. HEADER .
"\n</header>\n"
;
print
"<in>\n$result\n</in>\n"
if
(
defined
$result
);
}
if
(
defined
$result
) {
(
$returnCode
,
$xml
) = extract_XML (
asnmtapInherited
=> \
$objectPlugins
,
resultXML
=>
$result
,
headerXML
=> HEADER,
footerXML
=> FOOTER );
}
elsif
(
defined
$filename
) {
(
$returnCode
,
$xml
) = extract_XML (
asnmtapInherited
=> \
$objectPlugins
,
filenameXML
=>
$filename
,
headerXML
=> HEADER,
footerXML
=> FOOTER );
}
else
{
$objectPlugins
->pluginValues ( {
stateValue
=>
$ERRORS
{UNKNOWN},
alert
=>
"No resultXML and filenameXML defined."
,
result
=>
undef
},
$TYPE
{APPEND} );
}
$objectPlugins
->
exit
(7)
if
(
$returnCode
);
if
(
$debug
) {
print
"xml->{testsuite}->{name}<->\n"
,
$xml
->{testsuite}->{name},
"\n"
;
print
"xml->{testsuite}->{tests}<->\n"
,
$xml
->{testsuite}->{tests},
"\n"
;
print
"xml->{testsuite}->{failures}<->\n"
,
$xml
->{testsuite}->{failures},
"\n"
;
print
"xml->{testsuite}->{errors}<->\n"
,
$xml
->{testsuite}->{errors},
"\n"
;
print
"xml->{testsuite}->{time}<->\n"
,
$xml
->{testsuite}->{
time
},
"\n"
;
foreach
my
$testcase
(
@testcase
) {
my
$nameTestcase
=
$testcase
->[TESTCASE];
print
"nameTestcase<->\n $nameTestcase\n"
;
if
(
defined
$xml
->{testsuite}->{testcase}->{
$nameTestcase
}) {
print
" "
,
$xml
->{testsuite}->{testcase}->{
$nameTestcase
}->{
time
},
"\n"
;
if
(
defined
$xml
->{testsuite}->{testcase}->{
$nameTestcase
}->{failure}) {
print
" "
,
$xml
->{testsuite}->{testcase}->{
$nameTestcase
}->{failure}->{message},
"\n"
;
print
" "
,
$xml
->{testsuite}->{testcase}->{
$nameTestcase
}->{failure}->{content},
"\n"
;
print
" "
,
$xml
->{testsuite}->{testcase}->{
$nameTestcase
}->{failure}->{type},
"\n"
;
}
}
}
}
if
( TESTSUITE ne
$xml
->{testsuite}->{name} ) {
$objectPlugins
->pluginValues ( {
stateValue
=>
$ERRORS
{UNKNOWN},
error
=>
'Wrong testsuite: '
.
$xml
->{testsuite}->{name},
result
=>
undef
},
$TYPE
{APPEND} );
$objectPlugins
->
exit
(7);
}
if
( (
my
$numberTests
=
@testcase
) ne
$xml
->{testsuite}->{tests} ) {
$objectPlugins
->pluginValues ( {
stateValue
=>
$ERRORS
{UNKNOWN},
error
=>
'Wrong # of tests, Known: $numberTests, Returned: '
.
$xml
->{testsuite}->{tests},
result
=>
undef
},
$TYPE
{APPEND} );
$objectPlugins
->
exit
(7);
}
if
(
$xml
->{testsuite}->{failures} +
$xml
->{testsuite}->{errors}) {
$objectPlugins
->pluginValues ( {
stateValue
=>
$ERRORS
{CRITICAL},
alert
=>
"Tests $xml->{testsuite}->{tests} - Failures $xml->{testsuite}->{failures} - Errors $xml->{testsuite}->{errors}"
,
result
=>
undef
},
$TYPE
{APPEND} );
$returnCode
=
$ERRORS
{CRITICAL};
}
my
(
$alertHeader
,
$alertMessage
,
$debugfileMessage
);
$debugfileMessage
=
"\n<HTML><HEAD><TITLE>Cactus XML::Parser \@ $APPLICATION: Unit Test Results</TITLE></HEAD><BODY><HR><H1 style=\"margin: 0px 0px 5px; font: 125% verdana,arial,helvetica\">WebTransact XML Cactus parser @ $APPLICATION: Unit Test Results</H1>\n"
;
$debugfileMessage
.=
"<HR><H2 style=\"margin-top: 1em; margin-bottom: 0.5em; font: bold 100% verdana,arial,helvetica\">Summary</H2>"
;
$debugfileMessage
.=
"<TABLE WIDTH=\"100%\"><TR style=\"font: normal 68% bold verdana,arial,helvetica; text-align:left; background:#a6caf0;\"><TH>Tests</TH><TH>Failures</TH><TH>Errors</TH><TH>Time</TH><TR>"
;
$debugfileMessage
.=
"<TR style=\"background:#eeeee0; font: normal 68% bold verdana,arial,helvetica; color:purple;\"><TD>$xml->{testsuite}->{tests}</TD><TD>$xml->{testsuite}->{failures}</TD><TD>$xml->{testsuite}->{errors}</TD><TD>$xml->{testsuite}->{time}"
;
if
(
$xml
->{testsuite}->{
time
} >=
$timeTestsuiteCritical
) {
$returnCode
=
$ERRORS
{CRITICAL};
$alertHeader
=
"Time $xml->{testsuite}->{time} > $timeTestsuiteCritical"
;
$debugfileMessage
.=
" > $timeTestsuiteCritical"
;
}
elsif
(
$xml
->{testsuite}->{
time
} >=
$timeTestsuiteWarning
) {
$returnCode
=
$ERRORS
{WARNING};
$alertHeader
=
"Time $xml->{testsuite}->{time} > $timeTestsuiteWarning"
;
$debugfileMessage
.=
" > $timeTestsuiteWarning"
;
}
else
{
$alertHeader
=
"Time $xml->{testsuite}->{time}"
;
}
$debugfileMessage
.=
"</TD></TR></TABLE>\n"
;
$debugfileMessage
.=
"<table width=\"100%\" border=\"0\"><tr><td style=\"font: verdana,arial,helvetica; text-align: justify;\">Note: <i>failures</i> are anticipated and checked for with assertions while <i>errors</i> are unanticipated.</td></tr></table>\n"
;
$debugfileMessage
.=
"<H3 style=\"margin-bottom: 0.5em; font: bold 90% verdana,arial,helvetica\">Testcase $xml->{testsuite}->{name}</H3><TABLE WIDTH=\"100%\"><TR style=\"font: normal 68% bold verdana,arial,helvetica; text-align:left; background:#a6caf0;\"><TH>Name</TH><TH>Status</TH><TH>Type</TH><TH>Time(s)</TH></TR>\n"
;
foreach
my
$testcase
(
@testcase
) {
my
$nameTestcase
=
$testcase
->[TESTCASE];
if
(
defined
$xml
->{testsuite}->{testcase}->{
$nameTestcase
}) {
if
(
defined
$xml
->{testsuite}->{testcase}->{
$nameTestcase
}->{failure}) {
$alertMessage
.=
"+$nameTestcase:F"
;
$debugfileMessage
.=
"<TR valign=\"top\" style=\"background:#eeeee0; font: normal 68% bold verdana,arial,helvetica; color:purple;\"><TD>$nameTestcase</TD><TD>Failure</TD><TD>$xml->{testsuite}->{testcase}->{$nameTestcase}->{failure}->{message}<BR> <BR>$xml->{testsuite}->{testcase}->{$nameTestcase}->{failure}->{content}</TD><TD>$xml->{testsuite}->{testcase}->{$nameTestcase}->{time}</TD></TR>"
;
}
elsif
(
defined
$xml
->{testsuite}->{testcase}->{
$nameTestcase
}->{error}) {
$alertMessage
.=
"+$nameTestcase:E"
;
$debugfileMessage
.=
"<TR valign=\"top\" style=\"background:#eeeee0; font: normal 68% bold verdana,arial,helvetica; color:red;\"><TD>$nameTestcase</TD><TD>Error</TD><TD>$xml->{testsuite}->{testcase}->{$nameTestcase}->{error}->{message}<BR> <BR>$xml->{testsuite}->{testcase}->{$nameTestcase}->{error}->{content}</TD><TD>$xml->{testsuite}->{testcase}->{$nameTestcase}->{time}</TD></TR>"
;
}
elsif
(
$xml
->{testsuite}->{testcase}->{
$nameTestcase
}->{
time
} >=
$testcase
->[CRITICAL]) {
$alertHeader
.=
"+$nameTestcase:C $xml->{testsuite}->{testcase}->{$nameTestcase}->{time}"
;
$alertMessage
.=
"+$nameTestcase:C"
;
$debugfileMessage
.=
"<TR valign=\"top\" style=\"background:#eeeee0; font: normal 68% bold verdana,arial,helvetica; color:red;\"><TD>$nameTestcase</TD><TD>Critical</TD><TD>$xml->{testsuite}->{testcase}->{$nameTestcase}->{time} >= $testcase->[CRITICAL]</TD><TD>$xml->{testsuite}->{testcase}->{$nameTestcase}->{time}</TD></TR>"
;
}
elsif
(
$xml
->{testsuite}->{testcase}->{
$nameTestcase
}->{
time
} >=
$testcase
->[WARNING]) {
$alertHeader
.=
"+$nameTestcase:W $xml->{testsuite}->{testcase}->{$nameTestcase}->{time}"
;
$alertMessage
.=
"+$nameTestcase:W"
;
$debugfileMessage
.=
"<TR valign=\"top\" style=\"background:#eeeee0; font: normal 68% bold verdana,arial,helvetica; color:purple;\"><TD>$nameTestcase</TD><TD>Warning</TD><TD>$xml->{testsuite}->{testcase}->{$nameTestcase}->{time} >= $testcase->[WARNING]</TD><TD>$xml->{testsuite}->{testcase}->{$nameTestcase}->{time}</TD></TR>"
;
}
}
}
$debugfileMessage
.=
"\n</TABLE><P style=\"font: normal 68% verdana,arial,helvetica;\" ALIGN=\"left\">Generated on: "
.
scalar
(
localtime
()) .
"</P>\n</BODY>\n</HTML>"
;
if
(
defined
$alertMessage
) {
$objectPlugins
->pluginValues ( {
stateValue
=>
$ERRORS
{CRITICAL},
alert
=>
$alertHeader
.
', '
.
$objectPlugins
->pluginValue (
'alert'
) .
' '
.
$alertMessage
.
'+'
,
result
=>
undef
},
$TYPE
{REPLACE} );
$objectPlugins
->write_debugfile ( \
$debugfileMessage
, 0 );
}
elsif
(
$returnCode
==
$ERRORS
{DEPENDENT}) {
$objectPlugins
->pluginValues ( {
stateValue
=>
$ERRORS
{OK},
alert
=>
$xml
->{testsuite}->{name},
result
=>
undef
},
$TYPE
{APPEND} );
}
else
{
my
$alert
=
$objectPlugins
->pluginValue (
'alert'
);
$objectPlugins
->pluginValues ( {
stateValue
=>
$returnCode
,
alert
=>
$alertHeader
. (
defined
$alert
?
', '
.
$alert
:
''
),
result
=>
undef
},
$TYPE
{REPLACE} );
}
$objectPlugins
->
exit
(7);
Hide Show 29 lines of Pod