oracle@marsweblogic:~$ cat /export/home/oracle/automation/autorestart/wls_autorestart.py
import os
import re
import string
import array
import java.lang
from jarray import array as jarray_c
from java.util import Hashtable
from javax.management import MBeanServerConnection
from javax.management import ObjectName
from java.lang import String
from java.lang import Object
connect('weblogic','xxxxxxxx','t3://192.168.0.1:7001')
domainRuntime();
cd('ServerRuntimes')
servers = domainRuntimeService.getServerRuntimes();
stoppedServers = []
for server in servers:
try:
cd ('/ServerRuntimes/' + server.getName())
CS = get('OverallHealthState').getState()
if CS == 0:
print server.getName(), "= HEALTH_OK"
elif CS == 1:
print server.getName(), "= HEALTH_WARN :"
ms = server.getName()
shutdown(server.getName(), 'Server', force="true")
start(ms, 'Server')
elif CS == 2:
print server.getName(), "= HEALTH_CRITICAL :"
ms = server.getName()
shutdown(server.getName(), 'Server', force="true")
start(ms, 'Server')
elif CS == 3:
print server.getName(), "= HEALTH_FAILED :"
ms = server.getName()
shutdown(server.getName(), 'Server', force="true")
start(ms, 'Server')
elif CS == 4:
print server.getName(), "= HEALTH_OVERLOADED :"
ms = server.getName()
shutdown(server.getName(), 'Server', force="true")
start(ms, 'Server')
else:
print server.getName() + ': ' + get('State') + ': UNKNOWN HEALTH STATE (' + currentState + ')'
except WLSTException, e:
print server.getName() + " is not running."
stoppedServers.append(server.getName())
disconnect()
exit()
oracle@marsweblogic:~$