ASNMTAP

 view release on metacpan or  search on metacpan

plugins/snmptt/check_SNMPTT_oracle.pl  view on Meta::CPAN


my $community      = $objectPlugins->getOptionsArgv ('community');
my $hostname       = $objectPlugins->getOptionsArgv ('host');
my $category       = 'ORACLE';

my $environment    = $objectPlugins->getOptionsArgv ('environment');

my $debug          = $objectPlugins->getOptionsValue ('debug');
my $onDemand       = $objectPlugins->getOptionsValue ('onDemand');

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

my $serverHost   = $objectPlugins->getOptionsArgv ('server')   ? $objectPlugins->getOptionsArgv ('server')   : 'localhost';
my $serverPort   = $objectPlugins->getOptionsArgv ('port')     ? $objectPlugins->getOptionsArgv ('port')     : 3306;
my $serverUser   = $objectPlugins->getOptionsArgv ('username') ? $objectPlugins->getOptionsArgv ('username') : 'asnmtap';
my $serverPass   = $objectPlugins->getOptionsArgv ('password') ? $objectPlugins->getOptionsArgv ('password') : '<PASSWORD>';
my $serverDb     = $objectPlugins->getOptionsArgv ('database') ? $objectPlugins->getOptionsArgv ('database') : 'snmptt';

my $serverTact   = 'snmptt';
my $serverTarc   = 'snmptt_archive';
my $outOffDate   = 1800;                                        # seconds

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

my $environmentText = $objectPlugins->getOptionsValue ('environment');

if ( defined $uKey ) {
  my $message = $objectPlugins->pluginValue ('message') .' for uKey '. $uKey;
  $objectPlugins->pluginValue ( message => $message );
}

my $tMessage  = 'SNMP Trap Translator Database';

my $tHostname = ( defined $hostname ? "and hostname='$hostname'" : '' );
$hostname = 'undef' unless ( defined $hostname ) ;

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

my $debugfileMessage = "\n<HTML><HEAD><TITLE>$tMessage \@ $APPLICATION</TITLE><style type=\"text/css\">\n.statusOdd { font-family: arial,serif; font-size: 10pt; background-color: #DBDBDB; }\n.statusEven { font-family: arial,serif; font-size: 10pt; ba...
$debugfileMessage .= "<TD>,&nbsp;&nbsp;Hostname:</TD><TD><B>$hostname</B></TD>" unless ($hostname eq 'undef');
$debugfileMessage .= "<TD>,&nbsp;&nbsp;Community:</TD><TD><B>$community</B></TD><TD>,&nbsp;&nbsp;Environment:</TD><TD><B>$environmentText</B></TD></TR></TABLE><BR>";

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

my ($dbh, $sth, $sthDO, $rv, $query);
$rv = 1;

$dbh = DBI->connect ( "dbi:mysql:$serverDb:$serverHost:$serverPort", "$serverUser", "$serverPass" ) or $rv = errorTrapDBI ( \$objectPlugins,  'Sorry, cannot connect to the database' );

if ( $dbh and $rv ) {
  my ($id, $eventname, $eventid, $trapoid, $enterprise, $agentip, $severity, $uptime, $traptime, $formatline, $system_running_SNMPTT, $trapread);

  # check the depending problems from the 'SNMP Trap Translator'
  my $currentTimeslot = timelocal ( 0, (localtime)[1,2,3,4,5] );
  my $tEpochtime = $currentTimeslot;
  my $tSeverity  = $ERRORS{OK};

  $query = "SELECT SQL_NO_CACHE id, eventname, eventid, trapoid, enterprise, agentip, severity, uptime, traptime, formatline, system_running_SNMPTT, trapread FROM `$serverTact` WHERE community='$community' $tHostname and category='$category' order by...
  $sth = $dbh->prepare($query) or $rv = errorTrapDBI ( \$objectPlugins,  'Cannot dbh->prepare: '. $query ) if ( $rv );
  $rv  = $sth->execute() or $rv = errorTrapDBI ( \$objectPlugins,  'Cannot sth->execute: '. $query ) if ( $rv );
  $sth->bind_columns( \$id, \$eventname, \$eventid, \$trapoid, \$enterprise, \$agentip, \$severity, \$uptime, \$traptime, \$formatline, \$system_running_SNMPTT, \$trapread ) or $rv = errorTrapDBI ( \$objectPlugins,  'Cannot sth->bind_columns: '. $que...

  if ( $rv ) {
    my (%tableOracle, %tableOracleDetail, %tableOracleUniqueProblemSeverity);
    $debugfileMessage .= "<TABLE WIDTH=\"100%\"><TR><TD>\n<H2 style=\"margin-bottom: 0.5em; font: bold 90% verdana,arial,helvetica\">BOLD: are the new traps</H2></TD></TR></TABLE>";

    if ( $sth->rows() ) {
      my ( $uniqueProblem, $codeBefore, $codeAfter );

      while( $sth->fetch() ) {
        my ($_eventname, $detailLine, $uniqueTrap, $trapHostOwnerName) = ($eventname, $formatline, '(NULL)', $tEpochtime);
        my (undef, $variables, ) = split ( /: /, $formatline, 2 );

        for ( $eventname ) {
          /^oraEM4Alert$/ && do {    # oraEM4Alert trap: $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13
            my ($oraEM4AlertTargetName, $oraEM4AlertTargetType, $oraEM4AlertHostName, $oraEM4AlertMetricName, $oraEM4AlertKeyName, $oraEM4AlertKeyValue, $oraEM4AlertTimeStamp, $oraEM4AlertSeverity, $oraEM4AlertMessage, $oraEM4AlertRuleName, $oraEM4Al...
            $uniqueTrap = "$oraEM4AlertTargetName|$oraEM4AlertTargetType|$oraEM4AlertHostName|$oraEM4AlertMetricName";
            $detailLine = "$oraEM4AlertTargetName, $oraEM4AlertTargetType, $oraEM4AlertHostName, $oraEM4AlertMetricName, $oraEM4AlertSeverity, $oraEM4AlertMessage, $oraEM4AlertRuleName, $oraEM4AlertRuleOwner, $oraEM4AlertMetricValue";
            $trapHostOwnerName = $oraEM4AlertHostName;
            last; };
          /^oraEM4JobAlert$/ && do { # oraEM4JobAlert trap: $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14
            my ($oraEM4JobAlertJobName, $oraEM4JobAlertJobOwner, $oraEM4JobAlertJobType, $oraEM4JobAlertJobStatus, $oraEM4JobAlertTargets, $oraEM4JobAlertTimeStamp, $oraEM4JobAlertRuleName, $oraEM4JobAlertRuleOwner, $oraEM4JobAlertMetricName, $oraEM4...
            $uniqueTrap = $formatline; $detailLine = $formatline;
          # $uniqueTrap = "$oraEM4JobAlertJobName|$oraEM4JobAlertJobOwner|$oraEM4JobAlertJobType|$oraEM4JobAlertJobStatus";
          # $detailLine = "$oraEM4JobAlertJobName, $oraEM4JobAlertJobOwner, $oraEM4JobAlertJobType, $oraEM4JobAlertJobStatus, $oraEM4JobAlertTargets, $oraEM4JobAlertTimeStamp, $oraEM4JobAlertRuleName, $oraEM4JobAlertRuleOwner, $oraEM4JobAlertMetricNa...
            $trapHostOwnerName = $oraEM4JobAlertJobOwner;
            last; };
        }

        $uniqueProblem = "$trapHostOwnerName|$_eventname|$uniqueTrap";
        $tableOracleUniqueProblemSeverity { $uniqueProblem } = $severity unless ( defined $tableOracleUniqueProblemSeverity { $uniqueProblem } );

        if ( $debug ) {
          if ( $debug >= 2 ) {
            print "\nid           : $id\neventname    : $eventname\neventid      : $eventid\ntrapoid      : $trapoid\nenterprise   : $enterprise\ncommunity    : $community\nhostname     : $hostname\nagentip      : $agentip\ncategory     : $category\n...
          } else {
            print "\n$id, $eventname, $eventid, $trapoid, $enterprise, $community, $hostname, $agentip, $category, $severity (". $tableOracleUniqueProblemSeverity { $uniqueProblem } ."), $uptime, $traptime, $formatline, $system_running_SNMPTT, $trapr...
          }
        }

        if ( $severity ne 'OK' ) {
          if ( defined $tableOracle { $trapHostOwnerName } ) {
            $tableOracle { $trapHostOwnerName }++;
          } else {
            $tableOracle { $trapHostOwnerName } = 1;
          }
        }

		# update records from to SNMPTT where trapread = 0
        unless ( $trapread == 2 ) {
          unless ( $onDemand ) {
            my $sqlUPDATE = "UPDATE `$serverTact` SET uniqueProblem='$uniqueProblem' WHERE id='$id'";
            print "             = $sqlUPDATE\n" if ( $debug );
            $dbh->do ($sqlUPDATE) or $rv = errorTrapDBI ( \$objectPlugins,  'Cannot dbh->do: '. $sqlUPDATE );

            if ( $rv ) {
              my $sqlSTRING = "SELECT count(*) FROM `$serverTarc` WHERE id='$id'";
              print "             ? $sqlSTRING\n" if ( $debug );
              $sthDO = $dbh->prepare( $sqlSTRING ) or $rv = errorTrapDBI ( \$objectPlugins,  'Cannot dbh->prepare: '. $sqlSTRING );
              $sthDO->execute() or $rv = errorTrapDBI ( \$objectPlugins,  'Cannot dbh->execute: '. $sqlSTRING ) if $rv;



( run in 0.748 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )