@@ -18,6 +18,7 @@ class DataPowerNet():
18
18
password = None
19
19
use_kubeconfig = False
20
20
items = {}
21
+ timeout = 1
21
22
api_tests = None
22
23
23
24
def __init__ (self , config , trawler ):
@@ -28,9 +29,10 @@ def __init__(self, config, trawler):
28
29
self .namespace = config .get ('namespace' , None )
29
30
# Datapower username to use for REST calls
30
31
self .username = config .get ('username' , 'admin' )
32
+ self .timeout = config .get ('timeout' , 1 )
31
33
self .secret = config .get ('secret' , 'gateway-admin-secret' )
32
34
api_test_config = config .get ('api_tests' , None )
33
- if api_test_config and api_test_config ['enabled' ] == True :
35
+ if api_test_config and api_test_config ['enabled' ] is True :
34
36
self .api_tests = api_test_config ['apis' ]
35
37
# Load password from secret `datapower_password`
36
38
try :
@@ -119,16 +121,18 @@ class DataPower():
119
121
port = 5554
120
122
apiPort = 9443
121
123
trawler = None
124
+ timeout = 1
122
125
api_tests = None
123
126
labels = {}
124
127
125
- def __init__ (self , ip , port , name , namespace , username , password , trawler , api_tests = None ):
128
+ def __init__ (self , ip , port , name , namespace , username , password , trawler , api_tests = None , timeout = 1 ):
126
129
self .ip = ip
127
130
self .port = port
128
131
self .name = name
129
132
self .namespace = namespace
130
133
self .username = username
131
134
self .password = password
135
+ self .timeout = timeout
132
136
self .get_info ()
133
137
self .trawler = trawler
134
138
self .api_tests = api_tests
@@ -147,7 +151,7 @@ def get_info(self):
147
151
state = requests .get (url ,
148
152
auth = (self .username , self .password ),
149
153
verify = False ,
150
- timeout = 1
154
+ timeout = self . timeout
151
155
)
152
156
logger .trace (state )
153
157
if state .status_code == 200 :
@@ -175,7 +179,7 @@ def are_statistics_enabled(self):
175
179
state = requests .get (url ,
176
180
auth = (self .username , self .password ),
177
181
verify = False ,
178
- timeout = 1
182
+ timeout = self . timeout
179
183
)
180
184
logger .trace (state .text )
181
185
if state .status_code == 200 :
@@ -223,7 +227,7 @@ def fetch_data(self, provider, label, suffix=''):
223
227
provider )
224
228
status = requests .get (url ,
225
229
auth = (self .username , self .password ),
226
- verify = False , timeout = 1 ).json ()
230
+ verify = False , timeout = self . timeout ).json ()
227
231
logger .debug (status )
228
232
data = status .get (provider , {})
229
233
labels = self .labels
@@ -252,30 +256,24 @@ def fetch_data(self, provider, label, suffix=''):
252
256
except requests .exceptions .RequestException as e :
253
257
logger .info ("{}: {} (Check rest-mgmt is enabled and you have network connectivity)" .format (provider , e .strerror ))
254
258
255
- # https://127.0.0.1:5554/mgmt/status/apiconnect/ObjectStatus
259
+ # https://127.0.0.1:5554/mgmt/status/apiconnect/ObjectInstanceCounts
256
260
def object_counts (self ):
257
261
""" Count objects within datapower domain """
258
- logger .info ("Processing status provider ObjectStatus " )
262
+ logger .info ("Processing status provider ObjectInstanceCounts " )
259
263
try :
260
- url = "https://{}:{}/mgmt/status/{}/ObjectStatus " .format (
264
+ url = "https://{}:{}/mgmt/status/{}/ObjectInstanceCounts " .format (
261
265
self .ip ,
262
266
self .port ,
263
267
self .domain )
264
268
status = requests .get (url ,
265
- auth = (self .username , self .password ),
266
- verify = False , timeout = 1 ).json ()
269
+ auth = (self .username , self .password ),
270
+ verify = False ,
271
+ timeout = self .timeout ).json ()
267
272
logger .debug (status )
268
- data = status .get ('ObjectStatus' , [])
269
- counts = {}
273
+ data = status .get ('ObjectInstanceCounts' , [])
270
274
for item in data :
271
- if item ['Class' ] in counts :
272
- counts [item ['Class' ]] += 1
273
- else :
274
- counts [item ['Class' ]] = 1
275
- for item_class in counts :
276
- self .trawler .set_gauge ('datapower' , "{}_total" .format (item_class ), counts [item_class ], pod_name = self .name , labels = self .labels )
275
+ self .trawler .set_gauge ('datapower' , "{}_total" .format (item ['Class' ]), item ['Count' ], pod_name = self .name , labels = self .labels )
277
276
278
- logger .debug (counts )
279
277
except requests .exceptions .RequestException as e :
280
278
logger .info ("Failed to get object count: {} (Check rest-mgmt is enabled and you have network connectivity)" .format (e .strerror ))
281
279
@@ -297,7 +295,7 @@ def fetch_document_cache_summary(self, suffix=''):
297
295
provider )
298
296
status = requests .get (url ,
299
297
auth = (self .username , self .password ),
300
- verify = False , timeout = 1 ).json ()
298
+ verify = False , timeout = self . timeout ).json ()
301
299
logger .debug (status )
302
300
data = status .get (provider , {})
303
301
if type (data ) is not list :
@@ -340,7 +338,7 @@ def gateway_peering_status(self):
340
338
self .domain )
341
339
status = requests .get (url ,
342
340
auth = (self .username , self .password ),
343
- verify = False , timeout = 1 ).json ()
341
+ verify = False , timeout = self . timeout ).json ()
344
342
logger .debug (status )
345
343
346
344
for entry in status ["GatewayPeeringStatus" ]:
@@ -401,6 +399,7 @@ def invoke_api(self, api):
401
399
0 ,
402
400
pod_name = self .name , labels = {** status_labels , ** self .labels })
403
401
402
+
404
403
if __name__ == "__main__" :
405
404
net = DataPowerNet ()
406
405
net .find ()
0 commit comments