ASNMTAP
view release on metacpan or search on metacpan
plugins/snmptt/create_weblogic_configuration_database_with_SNMP.pl view on Meta::CPAN
_programHelpPrefix => "-K, --uKey=<uKey>
-s, --server=<hostname> (default: localhost)
--database=<database> (default: weblogic)",
_programGetOptions => ['uKey|K:s', 'server|s:s', 'port|P:i', 'database:s', 'username|u|loginname:s', 'password|p|passwd:s', 'environment|e:s'],
_timeout => 30,
_debug => 0);
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
my $serverDB = $objectPlugins->getOptionsArgv ('server') ? $objectPlugins->getOptionsArgv ('server') : 'localhost';
my $port = $objectPlugins->getOptionsArgv ('port') ? $objectPlugins->getOptionsArgv ('port') : 3306;
my $database = $objectPlugins->getOptionsArgv ('database') ? $objectPlugins->getOptionsArgv ('database') : 'weblogicConfig';
my $username = $objectPlugins->getOptionsArgv ('username') ? $objectPlugins->getOptionsArgv ('username') : 'jUnit';
my $password = $objectPlugins->getOptionsArgv ('password') ? $objectPlugins->getOptionsArgv ('password') : '<PASSWORD>';
my $uniqueKey = $objectPlugins->getOptionsArgv ('uKey');
my $debug = $objectPlugins->getOptionsValue ('debug');
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
my %serverTable = ( serverName => "SNMPv2-SMI::enterprises.140.625.730.1.15", # `SERVER_NAME`
serverParent => "SNMPv2-SMI::enterprises.140.625.730.1.20", # `DOMAIN_NAME`
serverMachine => "SNMPv2-SMI::enterprises.140.625.730.1.115", # `MACHINE`
serverListenPort => "SNMPv2-SMI::enterprises.140.625.730.1.120", # `LISTEN_PORT`
serverCluster => "SNMPv2-SMI::enterprises.140.625.730.1.130", # `CLUSTER_NAME`
serverExpectedToRun => "SNMPv2-SMI::enterprises.140.625.730.1.155", # `EXPECTED_TO_RUN`
serverListenAddress => "SNMPv2-SMI::enterprises.140.625.730.1.220" ); # `LISTEN_ADDRESS`
my %clusterTable = ( clusterName => "SNMPv2-SMI::enterprises.140.625.510.1.15", # `CLUSTER_NAME`
clusterServers => "SNMPv2-SMI::enterprises.140.625.510.1.25" ); # `CLUSTER_SERVERS`
my %queueTable = ( queueOID => "SNMPv2-SMI::enterprises.140.625.220.1.15.32" ); # `QUEUE_OID`
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
my $callsystem = 0;
my %infoServers = ();
my %infoClusters = ();
my %infoQueues = ();
my $returnCode = $ERRORS{OK};
my $alert = 'OK';
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
my ( $dbh, $sth, $prepareString );
$dbh = DBI->connect ("DBI:mysql:$database:$serverDB:$port", "$username", "$password") or _ErrorTrapDBI ( 'Could not connect to MySQL server '. $serverDB, "$DBI::err ($DBI::errstr)" );
if ( $dbh ) {
my $rv = 1;
my %adminServers = ();
my ( $adminName, $hosts, $community, $environment, $version, $activated, $uKey );
my $sqlSTRING = 'SELECT ADMIN_NAME, HOSTS, COMMUNITY, VERSION, ENV, ACTIVATED, uKey FROM `ADMIN_CONFIG`';
$sqlSTRING .= " WHERE UKEY='$uniqueKey'" if ( defined $uniqueKey );
print " $sqlSTRING\n" if ( $debug );
$sth = $dbh->prepare( $sqlSTRING ) or $rv = _ErrorTrapDBI ( \$objectPlugins, 'Cannot dbh->prepare: '. $sqlSTRING );
$sth->execute() or $rv = _ErrorTrapDBI ( \$objectPlugins, 'Cannot dbh->execute: '. $sqlSTRING ) if $rv;
$sth->bind_columns( \$adminName, \$hosts, \$community, \$version, \$environment, \$activated, \$uKey ) or $rv = _ErrorTrapDBI ( \$objectPlugins, 'Cannot dbh->bind: '. $sqlSTRING ) if $rv;
if ( $rv ) {
while( $sth->fetch() ) {
$adminServers{"$adminName"}->{hosts} = $hosts;
$adminServers{"$adminName"}->{community} = $community;
$adminServers{"$adminName"}->{version} = $version;
$adminServers{"$adminName"}->{environment} = $environment;
$adminServers{"$adminName"}->{activated} = $activated;
$adminServers{"$adminName"}->{uKey} = $uKey;
}
$sth->finish() or $rv = _ErrorTrapDBI ( \$objectPlugins, 'Cannot dbh->finish: '. $sqlSTRING );
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
while ( my ($domain, $hash) = each( %adminServers ) ) {
while ( my ($key, $oid) = each( %serverTable ) ) { _snmpwalk ( \$objectPlugins, \%infoServers, $domain, $hash, $key, $oid, $callsystem, 1, $debug ); }
}
print $debug, "\n", Dumper ( %infoServers ), "\n" if ( $debug > 3 );
while ( my ($domain, $hash) = each( %infoServers ) ) {
print "\n$domain\n" if ( $debug );
while ( my ($key, $server) = each( %{$hash} ) ) {
if ( $debug ) {
print "\n";
while ( my ($key, $value) = each( %{$server} ) ) { print "$key = $value\n"; }
}
my $domain_name = ( defined $server->{serverParent} ? $server->{serverParent} : 'DOMAIN:'. $domain );
my $sqlSTRING = 'SELECT count(SERVER_NAME) FROM `SERVERS` WHERE SERVER_NAME="'. $server->{serverName} .'" AND DOMAIN_NAME="'. $domain_name .'"';
print " $sqlSTRING\n" if ( $debug );
$sth = $dbh->prepare( $sqlSTRING ) or $rv = _ErrorTrapDBI ( \$objectPlugins, 'Cannot dbh->prepare: '. $sqlSTRING );
$sth->execute() or $rv = _ErrorTrapDBI ( \$objectPlugins, 'Cannot dbh->execute: '. $sqlSTRING ) if $rv;
if ( $rv ) {
my $updateRecord = $sth->fetchrow_array();
$sth->finish() or $rv = _ErrorTrapDBI ( \$objectPlugins, 'Cannot dbh->finish: '. $sqlSTRING );
if ( $updateRecord ) {
$sqlSTRING = 'UPDATE `SERVERS` SET SERVER_NAME="'. $server->{serverName} .'", DOMAIN_NAME="'. $domain_name .'", MACHINE="'. $server->{serverMachine} .'", LISTEN_PORT="'. $server->{serverListenPort} .'", CLUSTER_NAME="'. $server->{serverClus...
} else {
$sqlSTRING = 'INSERT INTO `SERVERS` SET SERVER_NAME="'. $server->{serverName} .'", DOMAIN_NAME="'. $domain_name .'", MACHINE="'. $server->{serverMachine} .'", LISTEN_PORT="'. $server->{serverListenPort} .'", CLUSTER_NAME="'. $server->{serve...
}
print " $sqlSTRING\n" if ( $debug );
$dbh->do ( $sqlSTRING ) or $rv = _ErrorTrapDBI ( \$objectPlugins, 'Cannot dbh->do: '. $sqlSTRING );
}
}
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
while ( my ($domain, $hash) = each( %adminServers ) ) {
while ( my ($key, $oid) = each( %clusterTable ) ) { _snmpwalk ( \$objectPlugins, \%infoClusters, $domain, $hash, $key, $oid, $callsystem, 2, $debug ); }
}
( run in 1.245 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )