ASNMTAP

 view release on metacpan or  search on metacpan

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


my $returnCode = $ERRORS{OK};
my $alert      = 'OK';

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

# plugins: dynamically
my $pluginTitle              = 'Weblogic - ';
my $pluginHelpPluginFilename = 'Supervision File SNMP Monitoring Weblogic.pdf'; # default '<NIHIL>'

# plugins: statically
my $pluginTest               = 'check_SNMPTT_weblogic.pl';
my $pluginDatabaseArguments  = "--server=$_serverDB --port=$_port --database=snmptt --username=$_username --passwd=$_password";
my $pluginOndemand           = 1;
my $pluginProduction         = 1;
my $pluginPagedir            = '/index/';               # pagedirs: 'index' must exist
my $pluginResultsdir         = 'SNMPTT';                # resultsdir: 'SNMPTT' must exist

# plugins: template
my $pluginTemplate = "ondemand='$pluginOndemand', production='$pluginProduction', pagedir='$pluginPagedir', resultsdir='$pluginResultsdir', helpPluginFilename='$pluginHelpPluginFilename'";

# displayDaemons: dynamically
my $displayDaemon            = 'index';                 # displayDaemon: 'index' must exist

# displayGroups: dynamically
my $displayGroupID           = '63';                    # displayGroupID: '63' must exist, displayGroupName: '73 CITAP (SNMPTT)'

# collectorDaemons: dynamically
my %collectorDaemon;
$collectorDaemon{PROD}       = 'snmptt-01';             # collectorDaemon: 'snmptt-01' must exist
$collectorDaemon{ACC}        = 'snmptt-01-ACC';         # collectorDaemon: 'snmptt-01-ACC' must exist
$collectorDaemon{SIM}        = $collectorDaemon{PROD};
$collectorDaemon{TEST}       = 'snmptt-01-TST';         # collectorDaemon: 'snmptt-01-TST' must exist if used

# crontabs: statically
my $arguments                = '';
my $noOffline                = '';

# admin console: statically
my $adminConsoleHTTP         = 'http://';
my $adminConsoleDomainURL    = $domain;
my $adminConsoleApplication  = '/console/';
my $adminConsolePortOffset   = -100;

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

my ( $dbhWEBLOGIC, $sthWEBLOGIC, $dbhASNMTAP, $sthASNMTAP, $prepareString, $actions );

$dbhWEBLOGIC = DBI->connect ("DBI:mysql:$database:$serverDB:$port", "$username", "$password") or _ErrorTrapDBI ( 'Could not connect to MySQL server '. $serverDB, "$DBI::err ($DBI::errstr)" );
$dbhASNMTAP = DBI->connect ("DBI:mysql:$_database:$_serverDB:$_port", "$_username", "$_password") or _ErrorTrapDBI ( 'Could not connect to MySQL server '. $_serverDB, "$DBI::err ($DBI::errstr)" );

if ( $dbhWEBLOGIC and $dbhASNMTAP ) {
  my %ENVIRONMENT = ('PROD'=>'Production', 'SIM'=>'Simulation', 'ACC'=>'Acceptation');

  my ($rv, $sqlSTRING, $adminName, $hosts, $agent_location, $community, $version, $environment, $activated, $status, $uKey, $holidayBundleID, $step, $minute, $hour, $dayOfTheMonth, $monthOfTheYear, $dayOfTheWeek, $adminConsoleCheck ) = (1);
  $sqlSTRING = 'SELECT ADMIN_NAME, HOSTS, AGENT_LOCATION, COMMUNITY, VERSION, ENV, ACTIVATED, STATUS, uKey, holidayBundleID, step, minute, hour, dayOfTheMonth, monthOfTheYear, dayOfTheWeek, adminConsoleCheck FROM `ADMIN_CONFIG`';

  $actions .= "WEBLOGIC: $sqlSTRING\n" if ( $debug );
  $sthWEBLOGIC = $dbhWEBLOGIC->prepare( $sqlSTRING ) or $rv = _ErrorTrapDBI ( \$objectPlugins, 'Cannot dbh->prepare: '. $sqlSTRING );
  $sthWEBLOGIC->execute() or $rv = _ErrorTrapDBI ( \$objectPlugins, 'Cannot dbh->execute: '. $sqlSTRING ) if $rv;
  $sthWEBLOGIC->bind_columns( \$adminName, \$hosts, \$agent_location, \$community, \$version, \$environment, \$activated, \$status, \$uKey, \$holidayBundleID, \$step, \$minute, \$hour, \$dayOfTheMonth, \$monthOfTheYear, \$dayOfTheWeek, \$adminConsole...

  if ( $rv ) {
    while( $sthWEBLOGIC->fetch() ) {
      my $_Environment = substr($environment, 0, 1);
      $actions .= "\n+ $adminName, $hosts, $agent_location, $community, $version, $environment, $activated, $status, $uKey, $holidayBundleID\n" if ( $debug );

      # plugins
      my ($_uKey, $_title, $_environment, $_step, $_helpPluginFilename, $_holidayBundleID, $_activated);
      $sqlSTRING = "SELECT uKey, title, environment, step, helpPluginFilename, holidayBundleID, activated FROM `plugins` WHERE catalogID='$CATALOGID' and uKey='$uKey' order by uKey";
      $actions .= "  ASNMTAP: $sqlSTRING\n" if ( $debug );
      $sthASNMTAP = $dbhASNMTAP->prepare( $sqlSTRING ) or $rv = _ErrorTrapDBI ( \$objectPlugins, 'Cannot dbh->prepare: '. $sqlSTRING );
      $sthASNMTAP->execute() or $rv = _ErrorTrapDBI ( \$objectPlugins, 'Cannot dbh->execute: '. $sqlSTRING ) if $rv;
      $sthASNMTAP->bind_columns( \$_uKey, \$_title, \$_environment, \$_step, \$_helpPluginFilename, \$_holidayBundleID, \$_activated ) or $rv = _ErrorTrapDBI ( \$objectPlugins, 'Cannot dbh->bind: '. $sqlSTRING ) if $rv;

      if ( $rv ) {
        my $weblogicVersionTitle = ( $community =~ /^v10_/ ? ' - v10' : '' );
        my $weblogicConfig = "${agent_location}\@${hosts}" if ( $community =~ /^v10_/ );

        my ($adminHostPortState, undef) = split ( ',', $hosts, 2 );
        my ($adminHost, $adminPort, $state) = split ( ':', $adminHostPortState );
        my $adminConsole = $adminConsoleHTTP . $adminHost .'.'. $adminConsoleDomainURL .':'. ( $adminPort + $adminConsolePortOffset ) . $adminConsoleApplication if ( $adminConsoleCheck and $agent_location ne 'virtual' );

        if ( $sthASNMTAP->fetch() ) {
          my $sqlUPDATE = ( defined $update ) ? 1 : 0;
          $actions .= "  + $_uKey, $_title, $_environment, $_step, $_helpPluginFilename, $_holidayBundleID, $_activated\n" if ( $debug );

          if ( "$pluginTitle$adminName$weblogicVersionTitle" ne $_title ) {
            $sqlUPDATE++;
            $actions .= "  - title changed to '$pluginTitle$adminName$weblogicVersionTitle'\n" if ( $debug );
          }

          if ( $_Environment ne $_environment ) {
            $sqlUPDATE++;
            $actions .= "  - environment changed to '". $ENVIRONMENT{$environment} ."'\n" if ( $debug );
          }

          if ( $step != $_step ) {
            $sqlUPDATE++;
            $actions .= "  - step changed to '$step' \n" if ( $debug );
          }

          if ( $pluginHelpPluginFilename ne $_helpPluginFilename ) {
            $sqlUPDATE++;
            $actions .= "  - helpPluginFilename changed to '$pluginHelpPluginFilename'\n" if ( $debug );
          }

          if ( $holidayBundleID ne $_holidayBundleID ) {
            $sqlUPDATE++;
            $actions .= "  - holidayBundleID changed to '$holidayBundleID'\n" if ( $debug );
          }

          if ( $activated ne $_activated ) {
            $sqlUPDATE++;
            $actions .= "  - plugin ". ($activated ? '' : 'de') ."activated\n" if ( $debug );
          }

          if ( $sqlUPDATE ) {
            $sqlUPDATE = "UPDATE `plugins` SET title='$pluginTitle$adminName$weblogicVersionTitle', arguments=\"$pluginDatabaseArguments --uKey=$uKey --community=$community" . ( defined $hostname ? " --host=$adminHost" : '' ) . ( defined $weblogicCon...
            $actions .= "  ASNMTAP: $sqlUPDATE\n";
            unless ( $debug ) { $dbhASNMTAP->do( $sqlUPDATE ) or $rv = _ErrorTrapDBI (\$objectPlugins, "Cannot dbh->do: $sqlUPDATE") };
          }
        } else {
          $actions .= "  ASNMTAP: ukey '$uKey' doesn't exist\n";
          my $sqlINSERT = "INSERT INTO `plugins` SET catalogID='$CATALOGID', uKey='$uKey', title='$pluginTitle$adminName$weblogicVersionTitle', arguments=\"$pluginDatabaseArguments --uKey=$uKey --community=$community" . ( defined $hostname ? " --host...
          $actions .= "  ASNMTAP: $sqlINSERT\n";
          unless ( $debug ) { $dbhASNMTAP->do( $sqlINSERT ) or $rv = _ErrorTrapDBI (\$objectPlugins, "Cannot dbh->do: $sqlINSERT") };
        }

        $sthASNMTAP->finish() or $rv = _ErrorTrapDBI ( \$objectPlugins, 'Cannot sth->finish: '. $sqlSTRING );
      }

      # views
      my ($_displayDaemon, $_displayGroupID);
      $sqlSTRING = "SELECT uKey, displayDaemon, displayGroupID, activated FROM `views` WHERE catalogID='$CATALOGID' and uKey='$uKey' order by uKey";
      $actions .= "  ASNMTAP: $sqlSTRING\n" if ( $debug );
      $sthASNMTAP = $dbhASNMTAP->prepare( $sqlSTRING ) or $rv = _ErrorTrapDBI ( \$objectPlugins, 'Cannot dbh->prepare: '. $sqlSTRING );
      $sthASNMTAP->execute() or $rv = _ErrorTrapDBI ( \$objectPlugins, 'Cannot dbh->execute: '. $sqlSTRING ) if $rv;
      $sthASNMTAP->bind_columns( \$_uKey, \$_displayDaemon, \$_displayGroupID, \$_activated ) or $rv = _ErrorTrapDBI ( \$objectPlugins, 'Cannot dbh->bind: '. $sqlSTRING ) if $rv;

      if ( $rv ) {
        if ( $sthASNMTAP->fetch() ) {
          my $sqlUPDATE = ( defined $update ) ? 1 : 0;
          $actions .= "  + $_uKey, $_displayDaemon, $_displayGroupID, $_activated\n" if ( $debug );

          if ( $displayDaemon ne $_displayDaemon ) {
            $sqlUPDATE++;
            $actions .= "  - displayDaemon changed to '$displayDaemon'\n" if ( $debug );
          }

          if ( $displayGroupID ne $_displayGroupID ) {
            $sqlUPDATE++;
            $actions .= "  - displayGroupID changed to '$displayGroupID'\n" if ( $debug );
          }

          if ( $activated ne $_activated ) {
            $sqlUPDATE++;
            $actions .= "  - view ". ($activated ? '' : 'de') ."activated\n" if ( $debug );
          }

          if ( $sqlUPDATE ) {
            $sqlUPDATE = "UPDATE `views` SET displayDaemon='$displayDaemon', displayGroupID='$displayGroupID', activated='$activated' WHERE catalogID='$CATALOGID' and uKey='$uKey' and displayDaemon='$displayDaemon'";
            $actions .= "  ASNMTAP: $sqlUPDATE\n";
            unless ( $debug ) { $dbhASNMTAP->do( $sqlUPDATE ) or $rv = _ErrorTrapDBI (\$objectPlugins, "Cannot dbh->do: $sqlUPDATE") };
          }
        } else {
          $actions .= "  ASNMTAP: ukey '$uKey' doesn't exist\n";
          my $sqlINSERT = "INSERT INTO `views` SET catalogID='$CATALOGID', uKey='$uKey', displayDaemon='$displayDaemon', displayGroupID='$displayGroupID', activated='$activated'";
          $actions .= "  ASNMTAP: $sqlINSERT\n";
          unless ( $debug ) { $dbhASNMTAP->do( $sqlINSERT ) or $rv = _ErrorTrapDBI (\$objectPlugins, "Cannot dbh->do: $sqlINSERT") };
        }

        $sthASNMTAP->finish() or $rv = _ErrorTrapDBI ( \$objectPlugins, 'Cannot sth->finish: '. $sqlSTRING );
      }

      # crontabs
      my ($_lineNumber, $_collectorDaemon, $_arguments, $_minute, $_hour, $_dayOfTheMonth, $_monthOfTheYear, $_dayOfTheWeek, $_noOffline);
      $sqlSTRING = "SELECT uKey, lineNumber, collectorDaemon, arguments, minute, hour, dayOfTheMonth, monthOfTheYear, dayOfTheWeek, noOffline, activated FROM `crontabs` WHERE catalogID='$CATALOGID' and uKey='$uKey' and lineNumber='00' order by uKey";
      $actions .= "  ASNMTAP: $sqlSTRING\n" if ( $debug );
      $sthASNMTAP = $dbhASNMTAP->prepare( $sqlSTRING ) or $rv = _ErrorTrapDBI ( \$objectPlugins, 'Cannot dbh->prepare: '. $sqlSTRING );
      $sthASNMTAP->execute() or $rv = _ErrorTrapDBI ( \$objectPlugins, 'Cannot dbh->execute: '. $sqlSTRING ) if $rv;
      $sthASNMTAP->bind_columns( \$_uKey, \$_lineNumber, \$_collectorDaemon, \$_arguments, \$_minute, \$_hour, \$_dayOfTheMonth, \$_monthOfTheYear, \$_dayOfTheWeek, \$_noOffline, \$_activated ) or $rv = _ErrorTrapDBI ( \$objectPlugins, 'Cannot dbh->b...

      if ( $rv ) {
        if ( $sthASNMTAP->fetch() ) {
          my $sqlUPDATE = ( defined $update ) ? 1 : 0;
          $actions .= "  + $_uKey, $_lineNumber, $_collectorDaemon, $_arguments, $_minute, $_hour, $_dayOfTheMonth, $_monthOfTheYear, $_dayOfTheWeek, $_noOffline, $_activated\n" if ( $debug );

          if ( $collectorDaemon{$environment} ne $_collectorDaemon ) {
            $sqlUPDATE++;
            $actions .= "  - collectorDaemon changed to '". $collectorDaemon{$environment} ."'\n" if ( $debug );
          }

          if ( $minute ne $_minute ) {
            $sqlUPDATE++;
            $actions .= "  - minute changed to '$minute'\n" if ( $debug );
          }

          if ( $hour ne $_hour ) {
            $sqlUPDATE++;
            $actions .= "  - hour changed to '$hour'\n" if ( $debug );
          }

          if ( $dayOfTheWeek ne $_dayOfTheWeek ) {
            $sqlUPDATE++;
            $actions .= "  - dayOfTheWeek changed to '$dayOfTheWeek'\n" if ( $debug );
          }

          if ( $activated ne $_activated ) {
            $sqlUPDATE++;
            $actions .= "  - crontab ". ($activated ? '' : 'de') ."activated\n" if ( $debug );
          }

          if ( $sqlUPDATE ) {
            $sqlUPDATE = "UPDATE `crontabs` SET collectorDaemon='". $collectorDaemon{$environment} ."', arguments='$arguments', minute='$minute', hour='$hour', dayOfTheMonth='$dayOfTheMonth', monthOfTheYear='$monthOfTheYear', dayOfTheWeek='$dayOfTheW...
            $actions .= "  ASNMTAP: $sqlUPDATE\n";
            unless ( $debug ) { $dbhASNMTAP->do( $sqlUPDATE ) or $rv = _ErrorTrapDBI (\$objectPlugins, "Cannot dbh->do: $sqlUPDATE") };
          }
        } else {
          $actions .= "  ASNMTAP: ukey '$uKey' doesn't exist\n";
          my $sqlINSERT = "INSERT INTO `crontabs` SET catalogID='$CATALOGID', uKey='$uKey', lineNumber='00', collectorDaemon='". $collectorDaemon{$environment} ."', arguments='$arguments', minute='$minute', hour='$hour', dayOfTheMonth='$dayOfTheMonth...
          $actions .= "  ASNMTAP: $sqlINSERT\n";
          unless ( $debug ) { $dbhASNMTAP->do( $sqlINSERT ) or $rv = _ErrorTrapDBI (\$objectPlugins, "Cannot dbh->do: $sqlINSERT") };
        }

        $sthASNMTAP->finish() or $rv = _ErrorTrapDBI ( \$objectPlugins, 'Cannot sth->finish: '. $sqlSTRING );
      }
    }

    $sthWEBLOGIC->finish() or $rv = _ErrorTrapDBI ( \$objectPlugins, 'Cannot sth->finish: '. $sqlSTRING );
  }
}

$dbhASNMTAP->disconnect or _ErrorTrapDBI ( 'Could not disconnect from MySQL server '. $_serverDB, "$DBI::err ($DBI::errstr)" ) if ( $dbhASNMTAP );
$dbhWEBLOGIC->disconnect or _ErrorTrapDBI ( 'Could not disconnect from MySQL server '. $serverDB, "$DBI::err ($DBI::errstr)" ) if ( $dbhWEBLOGIC );

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

$objectPlugins->pluginValues ( { stateValue => $returnCode, alert => $alert }, $TYPE{APPEND} );

if ( defined $actions ) {
  unless ( sending_mail ( $SERVERLISTSMTP, $SENDEMAILTO, $SENDMAILFROM, 'ASNMTAP ~ Weblogic: '. $STATE{$returnCode} .', '. get_datetimeSignal(), $actions, $debug ) ) {



( run in 0.511 second using v1.01-cache-2.11-cpan-437f7b0c052 )