From a350940cd1567d9289a437c4248fc9d7431dc083 Mon Sep 17 00:00:00 2001 From: kevgliss Date: Wed, 2 Sep 2015 09:19:06 -0700 Subject: [PATCH] Adding command to fetch and publish verisign units --- lemur/manage.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/lemur/manage.py b/lemur/manage.py index 4b7ff6fb..b21e60a7 100755 --- a/lemur/manage.py +++ b/lemur/manage.py @@ -4,6 +4,8 @@ import os import sys import base64 import time +import requests +import json from gunicorn.config import make_settings from cryptography.fernet import Fernet @@ -680,6 +682,38 @@ class ProvisionELB(Command): done = True +@manager.command +def publish_verisign_units(): + """ + Simple function that queries verisign for API units and posts the mertics to + Atlas API for other teams to consume. + :return: + """ + from lemur.plugins import plugins + v = plugins.get('verisign-issuer') + units = v.get_available_units() + + metrics = {} + for item in units: + if item['@type'] in metrics.keys(): + metrics[item['@type']] += int(item['@remaining']) + else: + metrics.update({item['@type']: int(item['@remaining'])}) + + for name, value in metrics.items(): + metric = [ + { + "timestamp": 1321351651, + "type": "GAUGE", + "name": "Symantec {0} Unit Count".format(name), + "tags": {}, + "value": value + } + ] + + requests.post('http://localhost:8078/metrics', data=json.dumps(metric)) + + def main(): manager.add_command("start", LemurServer()) manager.add_command("runserver", Server(host='127.0.0.1'))