ASNMTAP

 view release on metacpan or  search on metacpan

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

my $versionWeblogic = ( $prefix eq 'v10_' ? '>= v10.x' : '< v10.x');
my ($agentLocation, $hosts) = split ( /\@/, $weblogicConfig ) if ( defined $weblogicConfig );

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...

if ( defined $agentLocation and defined $hosts ) {
  $debugfileMessage .= "<TD>,&nbsp;&nbsp;Agent Location:</TD><TD><B>$agentLocation</B></TD><TD>,&nbsp;&nbsp;Hosts:</TD><TD><B>$hosts</B></TD>";
}

$debugfileMessage .= "</TR></TABLE><BR>";

if ( defined $adminConsole ) {
  my (undef, undef, $tAdminConsole, undef) = split ( /\//, $adminConsole, 4 );

  use ASNMTAP::Asnmtap::Plugins::WebTransact;

  my @URLS = ();
  my $objectWebTransact = ASNMTAP::Asnmtap::Plugins::WebTransact->new ( \$objectPlugins, \@URLS );

  @URLS = (
    { Method => 'GET',  Url => $adminConsole, Qs_var => [], Qs_fixed => [], Exp => ["WebLogic Server Administration Console", "(?:Sign in to work with the WebLogic Server|Log in to work with the WebLogic Server domain)"], Exp_Fault => ">>>NIHIL<<<", ...
  );

  my $returnCode = $objectWebTransact->check ( { } );
  $debugfileMessage .= "<TABLE WIDTH=\"100%\"><TR><TD>\n<H2 style=\"margin-bottom: 0.5em; font: bold 90% verdana,arial,helvetica\">Admin Console: $adminConsole</H2></TD></TR></TABLE>";
  $debugfileMessage .= "<TABLE WIDTH=\"100%\" BORDER=\"1\"><TR style=\"font: normal verdana,arial,helvetica;\"><TD ALIGN=\"CENTER\" CLASS=\"status". $STATE{$returnCode}. "\"><B>". $STATE{$returnCode}. "</B></TD></TR></TABLE><BR>";
  $objectPlugins->appendPerformanceData ( "'Admin Console: Status'=$returnCode;1;2;0;2" );
  undef $objectWebTransact;
}

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

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 (%tableVirtualServers, %tableVirtualServersDetail, %tableVirtualServersUniqueProblemSeverity);
    $debugfileMessage .= "<TABLE WIDTH=\"100%\"><TR><TD>\n<H2 style=\"margin-bottom: 0.5em; font: bold 90% verdana,arial,helvetica\">Domain: $domainname, BOLD: are the new traps</H2></TD></TR></TABLE>";

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

      while( $sth->fetch() ) {
        my ($_eventname, $detailLine, $uniqueTrap, $trapServerName, $trapMonitorType, $trapMBeanName, $trapMBeanType, $trapAttributeName, $trapMachineName, $trapLogThreadId, $trapLogTransactionId, $trapLogUserId, $trapLogSubsystem, $trapLogMsgId, $tr...

        for ( $eventname ) {
          /^wlsLogNotification$/ && do {     # Server Log Notification: $2, $3, $4, $5, $6, $7, $8, $9, $10
            my (undef, $variables, ) = split ( /: /, $formatline, 2 );
            ($trapServerName, $trapMachineName, $trapLogThreadId, $trapLogTransactionId, $trapLogUserId, $trapLogSubsystem, $trapLogMsgId, $trapLogSeverity, $trapLogMessage) = split ( /, /, $variables, 9 );

            if ( $trapLogMessage =~ /Exception: Too many open files/ ) {
              $_eventname = 'wlsLogNotification: Too many open files';
            } elsif ( ( $trapLogSeverity eq 'Error' and $trapLogMessage =~ /which is more than the configured time \(StuckThreadMaxTime\) of/ ) 
			  or ( $trapLogSeverity eq 'Info'  and $trapLogMessage =~ /^ExecuteThread: \\*'\d+\\*' for queue: \\*'[\w.]+\\*' has become \\*\"unstuck\\*\".$/ ) ) {
              $_eventname = 'wlsLogNotification: StuckThreadMaxTime';
              ( $uniqueTrap ) = ( $trapLogMessage =~ /^(ExecuteThread: \\'\d+\\' for queue: \\'[\w.]+\\') has / );
              print "\n\n$trapLogSeverity\n$trapLogMessage\n\n" if ( $debug > 2);
            }

		    last; };
          /^wlsServerStart$/ && do {         # This trap is generated when the server $2 was started on $1
            $_eventname = 'wlsServerShutDown or wlsServerStart';
            ( $trapServerName ) = ( $formatline =~ /^This trap is generated when the server (\w+) was started on / );
            $uniqueTrap = 'wlsServerStart';
		    last; };
          /^wlsServerShutDown$/ && do {      # This trap is generated when the server $2 has been shut down $1
            $_eventname = 'wlsServerShutDown or wlsServerStart';
            ( $trapServerName ) = ( $formatline =~ /^This trap is generated when the server (\w+) has been shut down / );
            $uniqueTrap = 'wlsServerStart';
		    last; };
          /^wlsMonitorNotification$/ && do { # JMX Monitor Notification: $2, $3, $6, $7, $8
            my (undef, $variables, ) = split ( /: /, $formatline, 2 );
            ($trapServerName, $trapMonitorType, $trapMBeanName, $trapMBeanType, $trapAttributeName) = split ( /, /, $variables, 5 );

            if ( $trapMonitorType =~ /^(jmx.monitor)\.(\w+)\.(\w+)$/ ) {
              $uniqueTrap = "$trapMBeanName|$trapAttributeName|$trapMBeanType|$1.$2";
              $detailLine = "$trapMBeanName, $trapAttributeName, $trapMBeanType, $1.$2.$3";
            }

		    last; };
          /^wlsAttributeChange$/ && do {     # Observed Attribute Change: $2, $3, $4, $5, $6, $7, $8, $9
            $uniqueTrap = 'wlsAttributeChange';
            # TODO ...
		    last; };
        }

        $uniqueProblem = "$trapServerName|$_eventname|$uniqueTrap";
        $tableVirtualServersUniqueProblemSeverity { $uniqueProblem } = $severity unless ( defined $tableVirtualServersUniqueProblemSeverity { $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 (". $tableVirtualServersUniqueProblemSeverity { $uniqueProblem } ."), $uptime, $traptime, $formatline, $system_running_SNMPTT...



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