Inspired by another thread on here I was wondering if I could have an expert eye passed over this script?
If I run the script with App1, App2 or App3 individually it takes about 3 mins per run. However when I invoke the ALL option that time increases to an hour. I'm no doubt managing my memory awfully so any advise would be great.
I'm new to this so getting this far has been good; my customer is happy running the 3 separately but I like to finish things properly.
# Get Domain State
import sys,os
from weblogic.management.security.authentication import UserEditorMBean
from time import strftime, sleep
today = strftime('%Y%m%d %H:%M.%S')
#import wlstutility
#wlstutility.initialise(globals())
#from wlstutility import *
#from wlstutility.constructors import *
from java.io import FileInputStream
environment = []
component = []
adminURL = ""
adminServerName = ""
configFile = ""
userKeyFile = ""
userConfigFile = ""
keyFile = ""
adminServersFail = 0
adminServersErrorCapture = []
adminServerRunning = 0
adminServerLog = []
connectToAdminServerFail = 0
setEnvironmentPropertiesFail = 0
managedServersFail = 0
managedServersErrorCapture = []
managedServerRunning = 0
managedServerState = []
otherErrorCount = 0
otherErrorCapture = []
exitCode = 255
def setEnvironmentProperties(environment, component):
try:
global setEnvironmentPropertiesFail
setEnvironmentPropertiesFail = 0
print "Checking and connecting to " + component
print strftime('%Y%m%d %H:%M.%S') + " INFO: environment: " + environment
domainPFile = environment + "/" + component+ ".properties"
print strftime('%Y%m%d %H:%M.%S') + " INFO: domainPFile: " + domainPFile
print strftime('%Y%m%d %H:%M.%S') + " INFO: component: " + component
loadProperties(domainPFile)
dpInputStream = FileInputStream(domainPFile)
domainProps = Properties()
domainProps.load(dpInputStream)
global configFile
configFile = "./"+environment+"/"+component+"configFile"
print strftime('%Y%m%d %H:%M.%S') + " INFO: configFile: " + configFile
global userConfigFile
userConfigFile=configFile
global keyFile
keyFile = "./"+environment+"/"+component+"keyFile"
print strftime('%Y%m%d %H:%M.%S') + " INFO: keyFile: " + keyFile
global userKeyFile
userKeyFile=keyFile
global adminUrl
adminUrl="t3://" + adminListenAddress + ":" + adminListenPort
print strftime('%Y%m%d %H:%M.%S') + " INFO: adminUrl: " + adminUrl
global adminServerName
adminServerName = adminServerName
global clusterAddress
clusterAddress = clusterName
print strftime('%Y%m%d %H:%M.%S') + " INFO: clusterAddress: " + clusterAddress
except:
print " FATAL: Could NOT set properties for " + environment + " " + component
global setEnvironmentPropertiesFail
setEnvironmentPropertiesFail += 1
global otherErrorCount
otherErrorCount += 1
global otherErrorCapture
otherErrorCapture.append(" WARNING: Properties Could Not Be Set For " + environment + " " + component)
global adminServerLog
adminServerLog.append(environment + ";" + adminServerName + ";" + " " + ';' + " " + ';' + component + ';' + "PROPSNOTFOUND")
def connectToAdmin():
try:
global connectToAdminServerFail
connectToAdminServerFail = 0
print strftime('%Y%m%d %H:%M.%S') + " INFO: Connecting to running AdminServer"
connect(userConfigFile=configFile, userKeyFile=keyFile, url=adminUrl)
print strftime('%Y%m%d %H:%M.%S') + " INFO: Getting " + adminServerName + " Server Status"
domainRuntime()
cd('/ServerRuntimes/' + adminServerName)
ss = cmo.getState()
hs = cmo.getHealthState()
x = hs.toString().split(',')[1].split(':')[1]
print strftime('%Y%m%d %H:%M.%S') + " INFO: " + adminServerName + ': ' + ss + ': ' + x
cd('../..')
global adminServerLog
adminServerLog.append(environment + ";" + adminServerName + ";" + ss + ';' + x + ';' + component + ';')
except:
global connectToAdminServerFail
connectToAdminServerFail += 1
print strftime('%Y%m%d %H:%M.%S') + " FATAL: Cannot connect to " + adminUrl + " ensure property files are correct"
global adminServersErrorCapture
adminServersErrorCapture.append(environment + ";" + adminUrl + ";" + component)
global adminServerLog
adminServerLog.append(environment + ';' + adminServerName + ';' + "" + ';' + " " + ';' + component + ';' + 'FAILEDCONNECTADMIN')
def findManagedServers():
print strftime('%Y%m%d %H:%M.%S') + " INFO: Finding Managed Servers"
try:
global findManagedServerFail
findManagedServerFail = 0
domainConfig()
print "CD to cluster" + clusterAddress
cd('Clusters/' +clusterAddress)
global managedServers
managedServers=cmo.getServers()
global numberofManagedServers
numberofManagedServers=`len(managedServers)`
print strftime('%Y%m%d %H:%M.%S') + " INFO: Found " + numberofManagedServers + " Managed Servers"
except:
global findManagedServerFail
findManagedServerFail += 1
print strftime('%Y%m%d %H:%M.%S') + " FATAL: Error navigating DomainConfig MBean tree for managed servers"
global managedServerState
managedServerState.append(environment + ';' + "Managed Server Name NOT Found" + ';' + " " + ';' + " " + ';' + component + ';' + "FAILEDMSMBEAN")
def getManagedServerState():
domainRuntime()
for servers in managedServers:
managedServerName=servers.getName()
print "Checking MS State of " + managedServerName
try:
print strftime('%Y%m%d %H:%M.%S') + " INFO: Getting " + managedServerName + " Server Status"
cd('/ServerRuntimes/' + managedServerName)
ss = cmo.getState()
hs = cmo.getHealthState()
x = hs.toString().split(',')[1].split(':')[1]
print strftime('%Y%m%d %H:%M.%S') + " INFO: " + managedServerName + ': ' + ss + ': ' + x
cd('../..')
global managedServerState
managedServerState.append(environment + ';' + managedServerName + ';' + ss + ';' + x + ';' + component + ';')
except:
print strftime('%Y%m%d %H:%M.%S') + " WARNING: " + managedServerName + " could NOT be contacted please investigate!"
global managedServersFail
managedServersFail =+ 1
global managedServersErrorCapture
managedServersErrorCapture.append(environment + ';' + managedServerName + ';' + " " + ';' + " " + ';' + component)
global managedServerState
managedServerState.append(environment + ';' + managedServerName + ';' + " " + ';' + " " + ';' + component + ';' + "FAILEDCONNECTMANAGED")
if managedServersFail == numberofManagedServers:
print strftime('%Y%m%d %H:%M.%S') + " FATAL: No Managed Servers Can Be Contacted in Cluster " + clusterAddress
exitCode = -1
def internalServiceBus(component):
if component == INTSB:
try:
domainRuntime()
for server in serverNames:
cd ('ServerRuntimes/intsb_ms1/JMSRuntime/intsb_ms1.jms/JMSServers/idecideserver_1/Destinations/[email protected]')
except:
print strftime('%Y%m%d %H:%M.%S') + " Warning: Unable to connect to " + managedServerName
managedServersFail += 1
managedServersErrorCapture.append(server + " Unable to navigate domainRuntime MBean tree, please investigate")
exitCode = -1
def exitDomainState():
print ""
print "---------------------------------------------------"
print " Domain State Checks Complete"
print "---------------------------------------------------"
print ""
print ""
print "The Following Services are Running Without Issue:"
print ""
for smallsEnv in environments:
print smallsEnv
for smallsComponents in components:
for keys in adminServerLog:
key=keys.split(";")
if key[0] == smallsEnv:
if key[4] == smallsComponents:
if key[5] != "FAILEDCONNECTADMIN" and key[5] != "PROPSNOTFOUND":
printcount = 0
while printcount < 1:
print "-" + smallsComponents
print "--Administration Server"
printcount += 1
if key[2] == "RUNNING":
print " INFO: Weblogic Server " + key[1] + " is currently " + key[2] + " " + key[3]
global msprintcount
msprintcount = 0
for keys in managedServerState:
key=keys.split(";")
if key[0] == smallsEnv:
if key[4] == smallsComponents:
if key[5] != "FAILEDCONNECTMANAGED":
while msprintcount < 1:
print "--Managed Servers"
global msprintcount
msprintcount += 1
if key[2] == "RUNNING":
print " INFO: Weblogic Server " + key[1] + " is currently " + key[2] + " " + key[3]
print "---------------------------------------------------"
print ""
print ""
print "---------------------------------------------------"
print "The Following Services have issues :"
print "---------------------------------------------------"
print ""
for smallsEnv in environments:
global smallscount
smallscount = 0
for smallsComponents in components:
for keys in adminServerLog:
key=keys.split(";")
if key[0] == smallsEnv:
if key[4] == smallsComponents:
if key[5] == "FAILEDCONNECTADMIN" or key[5] == "PROPSNOTFOUND" or key[2] != "RUNNING" or key[3] != "HEALTH_OK":
printcount = 0
while printcount < 1:
while smallscount < 1:
print smallsEnv
smallscount += 1
print "-" + smallsComponents
print "--Administration Server"
printcount += 1
if key[5] == "FAILEDCONNECTADMIN":
print " FATAL: Could NOT Connect to " + key[1] + " Administration Server - Check Properties and/or server logs"
if key[5] == "PROPSNOTFOUND":
print " FATAL: Properties NOT found for " + smallsComponents + " Please Check Files"
if (key[2] != "RUNNING") and `len(key[2])` < 1:
print " WARNING: Weblogic Server " + key[1] + " is communicating but has a state of " + key[2] + " check log files"
if (key[3] != "HEALTH_OK") and `len(key[2])` < 1:
print " WARNING: Weblogic Server " + key[1] + " is " + key[2] + " but has a bad health status"
global msprintcount
msprintcount = 0
for keys in managedServerState:
key=keys.split(";")
if key[0] == smallsEnv:
if key[4] == smallsComponents:
if key[5] == "FAILEDMSMBEAN" or key[5] == "FAILEDCONNECTMANAGED" or key[2] != "RUNNING" or key[3] != "HEALTH_OK":
while msprintcount < 1:
while smallscount < 1:
print smallsEnv
print "-" + smallsComponents
smallscount += 1
print "--Managed Servers"
global msprintcount
msprintcount += 1
if key[5] == "FAILEDCONNECTMANAGED":
print " FATAL: Could NOT Connect to Managed Server: " + key[1] + " - server state " + key[2] + " check console and logfiles"
if key[5] == "FAILEDMSMBEAN":
print " ERROR: Failed to traverse Managed Server MBEAN Tree in domainConfig() - Check Admin server health and properties, this error can also be generated if the domain has NO managed servers"
if (key[2] != "RUNNING") and `len(key[2])` < 1:
print " WARNING: Weblogic Server " + key[1] + " is communicating but has a state of " + key[2] + " check log files"
if (key[3] != "HEALTH_OK") and `len(key[2])` < 1:
print " WARNING: Weblogic Server " + key[1] + " is " + key[2] + "but has a bad health status"
global smallscount
smallscount = 0
disconnect()
exit()
try:
environment=sys.argv[1]
component=sys.argv[2]
print "Environment " + environment
if environment == "App1":
global environments
environments = []
environments.extend(["SM1","SM2","SM3",])
global components
components = []
components.extend(["IL2CMS","IL2FORMS","IL2PORTAL","IL3FORMS","IL3COMMS",])
if environment == "App2":
global environments
environments = []
environments.extend(["SM1","SM2","SM3","SM4",])
global components
components = []
components.extend(["BPM","INTSB","EXTSB","OPA","VRD","BULKINTSB","BULKEXTSB",])
if environment == "App3":
global environments
environments = []
environments.extend(["SM1","SM2","SM3",])
global components
components = []
components.extend(["ETL","PORTAL","SB","SP",])
if environment == "ALL":
global environments
environments = []
environments.extend(["SM1","SM2","SM3","SM4"])
global components
components = []
components.extend(["IL2CMS","IL2FORMS","IL2PORTAL","IL3FORMS","IL3COMMS","BPM","INTSB","EXTSB","OPA","VRD","BULKINTSB","BULKEXTSB","ETL","PORTAL","SB","SP",])
for environmentState in environments:
print "Checking and connecting to " + environmentState
for componentState in components:
environment = environmentState
component = componentState
setEnvironmentProperties(environment, component)
if setEnvironmentPropertiesFail == 0:
connectToAdmin()
if connectToAdminServerFail == 0:
findManagedServers()
if findManagedServerFail == 0:
getManagedServerState()
disconnect()
# if setEnvironmentPropertiesFail > 0:
# global managedServerState
# managedServerState.append(environment + ';' + managedServerName + ';;;' + component + ';' + "FAILED")
exitDomainState()
# environments = [environment]
# components = [component]
# setEnvironmentProperties(environment, component)
# connectToAdmin()
# findManagedServers()
# getManagedServerState()
# exitDomainState()
# exit()
finally:
exit()