ASNMTAP
view release on metacpan or search on metacpan
plugins/templates/check_template-mail-xml-fingerprint-xml-monitoring-1.1.pl view on Meta::CPAN
my $receivedState = 0;
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
my $objectPlugins = ASNMTAP::Asnmtap::Plugins->new (
_programName => 'check_template-mail-xml-fingerprint-xml-monitoring-1.1.pl',
_programDescription => "XML fingerprint Mail XML monitoring plugin template for testing the '$APPLICATION'",
_programVersion => '3.002.003',
_programUsagePrefix => '--message=<message> -H|--hostname <hostname> -s|--service <service> [--validation <validation>]',
_programHelpPrefix => "--message=<message>
--message=message
-H, --hostname=<Nagios Hostname>
-s, --service=<Nagios service name>
--validation=F|T
F(alse) : dtd validation off (default)
T(true) : dtd validation on",
_programGetOptions => ['message=s', 'hostname|H=s', 'service|s=s', 'validation:s', 'username|u|loginname=s', 'password|p|passwd=s', 'interval|i=i', 'environment|e=s', 'timeout|t:i', 'trendline|T:i'],
_timeout => 10,
_debug => 0);
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
my $message = $objectPlugins->getOptionsArgv ('message');
$objectPlugins->printUsage ('Missing command line argument message') unless (defined $message);
$objectPlugins->pluginValue ( message => $message );
my $hostname = $objectPlugins->getOptionsArgv ('hostname') ? $objectPlugins->getOptionsArgv ('hostname') : undef;
$objectPlugins->printUsage ('Missing command line argument hostname') unless (defined $hostname);
my $service = $objectPlugins->getOptionsArgv ('service') ? $objectPlugins->getOptionsArgv ('service') : undef;
$objectPlugins->printUsage ('Missing command line argument service') unless ( defined $service);
my $validateDTD = $objectPlugins->getOptionsArgv ('validation') ? $objectPlugins->getOptionsArgv ('validation') : 'F';
if (defined $validateDTD) {
$objectPlugins->printUsage ('Invalid validation option: '. $validateDTD) unless ($validateDTD =~ /^[FT]$/);
$validateDTD = ($validateDTD eq 'T') ? 1 : 0;
}
my $username = $objectPlugins->getOptionsArgv ('username');
my $password = $objectPlugins->getOptionsArgv ('password');
my $resultOutOfDate = $objectPlugins->getOptionsArgv ('interval');
my $environment = $objectPlugins->getOptionsArgv ('environment');
my $environmentText = $objectPlugins->getOptionsValue ('environment');
my $debug = $objectPlugins->getOptionsValue ('debug');
my $reverse = 0;
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
use ASNMTAP::Asnmtap::Plugins::Mail v3.002.003;
my $body = '
<?xml version="1.0" encoding="UTF-8"?>
<MonitoringXML>
<Monitoring>
<Schema Value="1.1"/>
<Results>
<Details Host="Host Name ..." Service="Service Name ..." Environment="LOCAL" Date="2009/09/15" Time="17:27:30" Epochtime="1253028450" Status="2" StatusMessage="StatusMessage ..."/>
<ErrorDetail><![CDATA[ErrorDetail .1.]]></ErrorDetail>
<ErrorStack><![CDATA[ErrorStack .1.]]></ErrorStack>
<SubResults>
<SubDetails Host="Host Name ..." Service="Service Name ..." Environment="LOCAL" Date="2009/09/15" Time="17:27:30" Epochtime="1253028450" Status="2" StatusMessage="StatusMessage ..."/>
<SubErrorDetail><![CDATA[SubErrorDetail .1.]]></SubErrorDetail>
<SubErrorStack><![CDATA[SubErrorStack .1.]]></SubErrorStack>
</SubResults>
</Results>
</Monitoring>
</MonitoringXML>
';
my $objectMAIL = ASNMTAP::Asnmtap::Plugins::Mail->new (
_asnmtapInherited => \$objectPlugins,
_SMTP => { smtp => [ qw(smtp.citap.be) ], mime => 0 },
_POP3 => { pop3 => 'pop3.citap.be', username => $username, password => $password },
_mailType => 1,
_text => { SUBJECT => 'uKey=MAIL_'. $environment .'_0006' },
_mail => {
from => 'alex.peeters@citap.com',
to => 'asnmtap@citap.com',
status => $APPLICATION .' Status UP',
body => $body
}
);
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
my ($returnCode, $numberOfMatches, $debugfileMessage, @xml);
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Start plugin - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
$debugfileMessage = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n<HTML><HEAD><TITLE>$message \@ $APPLICATION</TITLE><style type=\"text/css\">\n.statusOdd { font-family: arial,serif; font-size: 10pt; background-color: #DBDBDB; ...
$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>First Occurence Date</TH><TH>First Occurence Time</TH><TH>Status</TH><TH>Sta...
$debugfileMessage .= "<H3 style=\"margin-bottom: 0.5em; font: bold 90% verdana,arial,helvetica\">$environmentText</H3>";
($returnCode, $numberOfMatches) = $objectMAIL->receiving_fingerprint_mails( custom => \&actionOnMailBody, customArguments => \{ xml => \@xml, header => HEADER, footer => FOOTER, validateDTD => $validateDTD, filenameDTD => "Monitoring-$schema.dtd" }, ...
if ( defined $numberOfMatches and $numberOfMatches ) {
my $debug = $objectPlugins->getOptionsValue ('debug');
my %hosts = ();
my $fixedAlert = "+";
foreach my $xml (@xml) {
$debugfileMessage .= "<TR style=\"background:#0eeeee; font: normal 68% bold verdana,arial,helvetica; color:purple;\"><TD>$xml->{Monitoring}{Results}{Details}{Host}</TD><TD>$xml->{Monitoring}{Results}{Details}{Service}</TD><TD>$xml->{Monitoring}{R...
$debugfileMessage .= "<TR style=\"background:#eeeee0; font: normal 68% bold verdana,arial,helvetica; color:red;\"><TD valign=\"top\">Error Stack</TD><TD colspan=\"7\"><PRE>";
my @ErrorDetails = split (/\|/, $xml->{Monitoring}{Results}{ErrorDetail});
foreach ( @ErrorDetails ) {
my ($key, $value) = split (/=>/ , $_);
$debugfileMessage .= "<b>$key:</b> $value, ";
}
if ( @ErrorDetails ) { chop($debugfileMessage); chop($debugfileMessage); chop($debugfileMessage); }
$debugfileMessage .= "</PRE></TD></TR>\n";
$debugfileMessage .= "<TR style=\"background:#eeeee0; font: normal 68% bold verdana,arial,helvetica; color:red;\"><TD valign=\"top\">Error Detail</TD><TD colspan=\"7\"><PRE>$xml->{Monitoring}{Results}{ErrorStack}</PRE></TD></TR>\n";
# validateResultOrSubResult ( \$xml->{Monitoring}{Results}, 0, $reverse, $debug );
if ( defined $xml->{Monitoring}{Results}{SubResults} ) {
if ( ref $xml->{Monitoring}{Results}{SubResults} eq 'ARRAY') {
( run in 1.022 second using v1.01-cache-2.11-cpan-364913b4093 )