Skip to content

Commit 085e29a

Browse files
fix: ability to turn off org metrics
1 parent 94eebc8 commit 085e29a

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

manager_net.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from xmlrpc.client import Boolean
12
import requests
23
import json
34
import time
@@ -16,6 +17,7 @@
1617

1718

1819
class ManagerNet(object):
20+
""" Gather metrics from API Manager """
1921
namespace = 'apic-management'
2022
username = ''
2123
password = ''
@@ -30,18 +32,20 @@ class ManagerNet(object):
3032
data_time = 0
3133
use_kubeconfig = False
3234
errored = False
35+
org_metrics = False
3336
version = None
3437
trawler = None
3538

3639
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 """
3841
# Use kubeconfig or in-cluster config for k8s comms
3942
self.use_kubeconfig = trawler.use_kubeconfig
4043
# Namespace to find managemnet pods
4144
self.namespace = config.get('namespace', 'default')
4245
# Maximum frequency to pull data from APIC
4346
self.max_frequency = int(config.get('frequency', 600))
4447
self.grant_type = config.get('grant_type', 'password')
48+
self.org_metrics = (config.get('process_org_metrics', 'true') == 'true')
4549
if 'secret' in config:
4650
# If config points to a secret, then load from that
4751
# either in this namespace, or the specified one
@@ -51,8 +55,12 @@ def __init__(self, config, trawler):
5155
else:
5256
# Cloud manager username to use for REST calls
5357
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')
5664
if self.password is None:
5765
# Use out of box default password
5866
self.password = 'admin'
@@ -158,6 +166,7 @@ def get_gateways(self, availability_zone = 'availability-zone-default'):
158166

159167
@alog.timed_function(logger.trace)
160168
def fish(self):
169+
""" main metrics gathering """
161170
if self.errored:
162171
logger.debug("Disabled because a fatal error already occurred")
163172
return
@@ -195,14 +204,16 @@ def fish(self):
195204
for object_type in self.data['counts']:
196205
logger.debug("Type: {}, Value: {}".format(object_type, self.data['counts'][object_type]))
197206
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'])
202212
self.get_webhook_status()
203213

204214

205215
def process_org_metrics(self, org_name, catalog_name):
216+
""" process metrics for a specific catalog """
206217
if self.token:
207218
logger.info("Getting data for {}:{} from API Manager".format(org_name, catalog_name))
208219
url = "https://{}/api/catalogs/{}/{}/configured-gateway-services?fields=add(gateway_processing_status,events)".format(self.hostname, org_name, catalog_name)

0 commit comments

Comments
 (0)