-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetWeblogicServerStatus.py
134 lines (123 loc) · 5.54 KB
/
getWeblogicServerStatus.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import sys
import getopt
import os
from datetime import datetime
def usage():
print "Usage:"
print "getWeblogicServerStatus.py [--vsName virtual_Server_Name] [--listenAddress listen_Address] " \
"[--port listen_Port] [--adminURL admin_URL] [--application applicaitonName]"
def connect_weblogic_domain():
print "Connecting to '%s' as '%s" % (adminURL,username)
connect(username, password, adminURL)
def getTargetServers(childNodeName):
instanceList = []
cd(childNodeName)
childNodeListing = ls(returnMap='true', returnType='c')
if childNodeListing.size() > 0:
for childNode in childNodeListing:
if childNode == 'Targets':
print("\t\t change directory to: '%s'" % childNode)
cd(childNode)
# added for cluster support
clusterNames = ls(returnMap='true', returnType='c')
if clusterNames.size() > 0:
for clusterNm in clusterNames:
print("\t\t change directory to: '%s'" % clusterNm)
cd(clusterNm)
clusterNodeListing = ls(returnMap='true', returnType='c')
for clusterNode in clusterNodeListing:
if clusterNode == 'Servers':
print("\t\t change directory to: '%s'" % clusterNode)
cd(clusterNode)
serverNames = ls(returnMap='true', returnType='c')
if serverNames.size() > 0:
for srvrNm in serverNames:
print("\t\t change directory to: '%s'" % srvrNm)
cd(srvrNm)
print("\t\t change directory to: '%s'" % 'Machine')
cd('Machine')
machineNm = ls(returnMap='true', returnType='c')
if not machineNm:
machineNm += ["undefined"]
# way to much work to get server status
myTree = currentTree()
domainRuntime()
cd('ServerLifeCycleRuntimes/' + srvrNm)
stateNm = cmo.getState()
myTree()
instanceList.append(
["generic-application", clusterNm, srvrNm, machineNm[0], stateNm])
cd('..')
cd('..')
if clusterNode == 'Machine':
# clusternode is actually a Container/srvrNm
srvrNm = clusterNm
print("\t\t ServerName: '%s'" % srvrNm)
print("\t\t change directory to: '%s'" % 'Machine')
cd('Machine')
machineNm = ls(returnMap='true', returnType='c')
if not machineNm:
machineNm += ["undefined"]
# way to much work to get server status
myTree = currentTree()
domainRuntime()
cd('ServerLifeCycleRuntimes/' + srvrNm)
stateNm = cmo.getState()
try:
stateNm
except IndexError:
stateNm = "undefined"
myTree()
instanceList.append(
["generic-application", "noCluster", srvrNm, machineNm[0], stateNm])
cd('..')
cd('..')
cd('..')
cd('..')
# navigate to parent of Targets node
cd('..')
# navigate back to parent attribute
cd('..')
return instanceList
# ===== Sourcing content from Environemnt settings ===================
try:
username = os.getenv('WL_ADMIN_USERNAME')
password = os.getenv('WL_ADMIN_PASSWORD')
adminURL = os.getenv('WL_ADMIN_T3_URL')
applicationName= "generic-application"
except:
pass
# ====== Main program ===============================
try:
opts, args = getopt.getopt(sys.argv[1:], "u:p:a:i:",
["consoleUserName=", "consolePassword=", "adminURL=","application="])
except getopt.GetoptError, err:
print str(err)
usage()
sys.exit(2)
for opt, arg in opts:
if opt in ("-u", "--consoleUserName"):
username = arg
elif opt in ("-p", "--consolePassword"):
password = arg
elif opt in ("-a", "--adminURL"):
adminURL = arg
elif opt in ("-i", "--application"):
applicationName = arg
# verify environemnt variables are defined.d
try:
username
password
adminURL
except NameError:
print "Error: Environment Variables not Set..."
sys.exit(1)
else:
print "Environment Variables set..."
print("getWeblogicServerStatus")
print (datetime.today())
connect_weblogic_domain()
serverArray = getTargetServers("AppDeployments/%s" % applicationName)
print (datetime.today())
print("start output here:")
print(serverArray)