/
getState.py
118 lines (80 loc) · 3.17 KB
/
getState.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
import requests
import os
import sys
import json
from pprint import pprint
failed = False
def getAppState(hostName, serverName):
global failed
print ("serverName=" + serverName)
print ('--------------------------------------------------------------------')
url = 'https://' + hostName + ':7001/management/weblogic/latest/domainRuntime/serverRuntimes/' + serverName + '/applicationRuntimes'
os.environ['no_proxy'] = hostName
os.environ['PYTHONWARNINGS'] = "ignore:Unverified HTTPS request"
headers = {
'Accept': 'application/json',
'X-Requested-By': 'MyClient',
}
params = (
('links', 'none'),
)
response = requests.get(url, headers=headers, params=params, auth=AUTH, verify=False)
data = response.json()
if data:
for key,value in data.items():
# print(key, '=', value)
for app in value:
print (app['applicationName'] + ".state=" + app['healthState']['state'])
if app['healthState']['state'] != 'ok':
print ("NOT OK")
sys.exit(1)
print ('--------------------------------------------------------------------')
else:
print ("Server " + serverName + " not running")
print ('--------------------------------------------------------------------')
def getDeploymentState(hostName):
global failed
url = 'https://' + hostName + ':7001/management/tenant-monitoring/applications'
print ("Get deplyemnt state =" + url)
print ('--------------------------------------------------------------------')
os.environ['no_proxy'] = hostName
os.environ['PYTHONWARNINGS'] = "ignore:Unverified HTTPS request"
headers = {
'Accept': 'application/json',
'X-Requested-By': 'MyClient',
}
params = (
('links', 'none'),
)
response = requests.get(url, headers=headers, params=params, auth=AUTH, verify=False)
data = response.json()
if data['body']['items']:
for key,value in data['body'].items():
# print(key, '=', value)
for app in value:
print (app['name'] + ".state=" + app['state'])
if app['state'] == 'STATE_FAILED':
print (app['name'] + " NOT OK !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
failed = True
print ('--------------------------------------------------------------------')
else:
print ("Server " + hostName + " not reachable")
failed = True
print ('--------------------------------------------------------------------')
WEBLOGIC_USER = 'weblogic'
WEBLOGIC_PASSWORD = os.environ.get('ADMIN_PWD') # set env var in shell
if not WEBLOGIC_PASSWORD:
print ("WEBLOGIC_PASSWORD must be provided")
sys.exit(1)
AUTH = (WEBLOGIC_USER, WEBLOGIC_PASSWORD)
if len(sys.argv)>1:
WEBLOGIC_HOST=sys.argv[1]
else:
WEBLOGIC_HOST=os.environ.get('HOSTNAME')
print ("WEBLOGIC_HOST=" + WEBLOGIC_HOST)
getDeploymentState(WEBLOGIC_HOST)
getAppState(WEBLOGIC_HOST, 'AdminServer')
if failed:
print ("Applications not deployed OK")
sys.exit(1)
print ("Applications deployed OK")