1
+ from xmlrpc .client import Boolean
1
2
import requests
2
3
import json
3
4
import time
16
17
17
18
18
19
class ManagerNet (object ):
20
+ """ Gather metrics from API Manager """
19
21
namespace = 'apic-management'
20
22
username = ''
21
23
password = ''
@@ -30,18 +32,20 @@ class ManagerNet(object):
30
32
data_time = 0
31
33
use_kubeconfig = False
32
34
errored = False
35
+ org_metrics = False
33
36
version = None
34
37
trawler = None
35
38
36
39
def __init__ (self , config , trawler ):
37
- # Takes in config object and trawler instance it's behind
40
+ """ Takes in config object and trawler instance it's behind """
38
41
# Use kubeconfig or in-cluster config for k8s comms
39
42
self .use_kubeconfig = trawler .use_kubeconfig
40
43
# Namespace to find managemnet pods
41
44
self .namespace = config .get ('namespace' , 'default' )
42
45
# Maximum frequency to pull data from APIC
43
46
self .max_frequency = int (config .get ('frequency' , 600 ))
44
47
self .grant_type = config .get ('grant_type' , 'password' )
48
+ self .org_metrics = (config .get ('process_org_metrics' , 'true' ) == 'true' )
45
49
if 'secret' in config :
46
50
# If config points to a secret, then load from that
47
51
# either in this namespace, or the specified one
@@ -51,8 +55,12 @@ def __init__(self, config, trawler):
51
55
else :
52
56
# Cloud manager username to use for REST calls
53
57
self .username = config .get ('username' , 'admin' )
54
- # Load password from secret `cloudmanager_password`
55
- self .password = trawler .read_secret ('cloudmanager_password' )
58
+ if self .grant_type == 'client_credentials' :
59
+ self .client_id = trawler .read_secret ('client_id' )
60
+ self .client_secret = trawler .read_secret ('client_secret' )
61
+ else :
62
+ # Load password from secret `cloudmanager_password`
63
+ self .password = trawler .read_secret ('cloudmanager_password' )
56
64
if self .password is None :
57
65
# Use out of box default password
58
66
self .password = 'admin'
@@ -158,6 +166,7 @@ def get_gateways(self, availability_zone = 'availability-zone-default'):
158
166
159
167
@alog .timed_function (logger .trace )
160
168
def fish (self ):
169
+ """ main metrics gathering """
161
170
if self .errored :
162
171
logger .debug ("Disabled because a fatal error already occurred" )
163
172
return
@@ -195,14 +204,16 @@ def fish(self):
195
204
for object_type in self .data ['counts' ]:
196
205
logger .debug ("Type: {}, Value: {}" .format (object_type , self .data ['counts' ][object_type ]))
197
206
self .trawler .set_gauge ('manager' , object_type , self .data ['counts' ][object_type ])
198
- for org in self .data ['orgs' ]['results' ]:
199
- if org ['org_type' ] != 'admin' :
200
- for catalog in org ['catalogs' ]['results' ]:
201
- self .process_org_metrics (org ['name' ], catalog ['name' ])
207
+ if self .org_metrics :
208
+ for org in self .data ['orgs' ]['results' ]:
209
+ if org ['org_type' ] != 'admin' :
210
+ for catalog in org ['catalogs' ]['results' ]:
211
+ self .process_org_metrics (org ['name' ], catalog ['name' ])
202
212
self .get_webhook_status ()
203
213
204
214
205
215
def process_org_metrics (self , org_name , catalog_name ):
216
+ """ process metrics for a specific catalog """
206
217
if self .token :
207
218
logger .info ("Getting data for {}:{} from API Manager" .format (org_name , catalog_name ))
208
219
url = "https://{}/api/catalogs/{}/{}/configured-gateway-services?fields=add(gateway_processing_status,events)" .format (self .hostname , org_name , catalog_name )
0 commit comments