Adding pending certificate metric. (#473)

This commit is contained in:
kevgliss 2016-11-01 14:24:45 -07:00 committed by GitHub
parent d99681904e
commit a6360ebfe5
3 changed files with 29 additions and 41 deletions

View File

@ -82,5 +82,5 @@ def configure_hook(app):
return response
return json_handler
for code in default_exceptions.iterkeys():
for code, value in default_exceptions.items():
app.error_handler_spec[None][code] = make_json_handler(code)

View File

@ -7,7 +7,6 @@ import os
import sys
import base64
import time
import arrow
import requests
import json
@ -770,46 +769,17 @@ def publish_verisign_units():
requests.post('http://localhost:8078/metrics', data=json.dumps(metric))
class Rolling(Command):
@manager.command
def publish_unapproved_verisign_certificates():
"""
Rotates existing certificates to a new one on an ELB
"""
option_list = (
Option('-w', '--window', dest='window', default=24),
)
def run(self, window):
"""
Simple function that queries verisign for API units and posts the mertics to
Atlas API for other teams to consume.
Query the Verisign for any certificates that need to be approved.
:return:
"""
end = arrow.utcnow()
start = end.replace(hours=-window)
items = Certificate.query.filter(Certificate.not_before <= end.format('YYYY-MM-DD')) \
.filter(Certificate.not_before >= start.format('YYYY-MM-DD')).all()
metrics = {}
for i in items:
name = "{0},{1}".format(i.owner, i.issuer)
if metrics.get(name):
metrics[name] += 1
else:
metrics[name] = 1
for name, value in metrics.iteritems():
owner, issuer = name.split(",")
metric = [
{
"timestamp": 1321351651,
"type": "GAUGE",
"name": "Issued Certificates",
"tags": {"owner": owner, "issuer": issuer, "window": window},
"value": value
}
]
requests.post('http://localhost:8078/metrics', data=json.dumps(metric))
from lemur.plugins import plugins
from lemur.extensions import metrics
v = plugins.get('verisign-issuer')
certs = v.get_pending_certificates()
metrics.send('pending_certificates', 'gauge', certs)
class Report(Command):
@ -951,7 +921,6 @@ def main():
manager.add_command("create_role", CreateRole())
manager.add_command("provision_elb", ProvisionELB())
manager.add_command("rotate_elbs", RotateELBs())
manager.add_command("rolling", Rolling())
manager.add_command("sources", Sources())
manager.add_command("report", Report())
manager.run()

View File

@ -188,6 +188,25 @@ class VerisignIssuerPlugin(IssuerPlugin):
response = self.session.post(url, headers={'content-type': 'application/x-www-form-urlencoded'})
return handle_response(response.content)['Response']['Order']
def get_pending_certificates(self):
"""
Uses Verisign to fetch the number of certificate awaiting approval.
:return:
"""
url = current_app.config.get("VERISIGN_URL") + '/reportingws'
end = arrow.now()
start = end.replace(days=-7)
data = {
'reportType': 'summary',
'certProductType': 'Server',
'startDate': start.format("MM/DD/YYYY"),
'endDate': end.format("MM/DD/YYYY"),
}
response = self.session.post(url, data=data)
return response.json()['certificateSummary'][0]['Pending']
class VerisignSourcePlugin(SourcePlugin):
title = 'Verisign'