Skip to content

Commit

Permalink
Merge pull request #2 from nbowes24/maintenance-work
Browse files Browse the repository at this point in the history
Setup maintenance filtering
  • Loading branch information
chelnak authored Feb 14, 2020
2 parents d383407 + 307c1de commit 51c997e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
14 changes: 10 additions & 4 deletions exporter/collectors/test_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
import logging
from prometheus_client.core import GaugeMetricFamily
from status_cake_client import tests as t
from status_cake_client import maintenance as m

logger = logging.getLogger("test_collector")


def parse_test_response(r):
def parse_test_response(r, m):
t = []
for i in r.json():
t.append(
Expand All @@ -17,7 +18,8 @@ def parse_test_response(r):
"test_type": i['TestType'],
"test_name": i['WebsiteName'],
"test_url": i['WebsiteURL'],
"test_status_int": str(1 if (i["Status"] == "Up") else 0)
"test_status_int": str(1 if (i["Status"] == "Up") else 0),
"maintenance_status_int": str(1 if (str(i["TestID"])) in m else 0)
}
)

Expand All @@ -41,7 +43,6 @@ def parse_test_details_response(r):

return t


class TestCollector(object):

def __init__(self, username, api_key, tags):
Expand All @@ -55,8 +56,13 @@ def collect(self):

try:

maintenance = m.get_maintenance(self.api_key, self.username)
#Grab the test_ids from the response
m_test_id_list = [i['all_tests'] for i in maintenance.json()['data']]
#Flatten the test_ids into a list
m_test_id_flat_list = [item for sublist in m_test_id_list for item in sublist]
tests = t.get_tests(self.api_key, self.username, self.tags)
parsed_tests = parse_test_response(tests)
parsed_tests = parse_test_response(tests, m_test_id_flat_list)

test_id_list = [i['TestID'] for i in tests.json()]
test_details = []
Expand Down
17 changes: 17 additions & 0 deletions exporter/status_cake_client/maintenance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env python3

import logging
from .base import get

logger = logging.getLogger(__name__)


def get_maintenance(apikey, username, state="ACT"):
endpoint = "Maintenance"
params = {
"state": state
}

response = get(apikey, username, endpoint, params)

return response

0 comments on commit 51c997e

Please sign in to comment.