Adding pending certificate metric. (#473)
This commit is contained in:
parent
d99681904e
commit
a6360ebfe5
|
@ -82,5 +82,5 @@ def configure_hook(app):
|
||||||
return response
|
return response
|
||||||
return json_handler
|
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)
|
app.error_handler_spec[None][code] = make_json_handler(code)
|
||||||
|
|
|
@ -7,7 +7,6 @@ import os
|
||||||
import sys
|
import sys
|
||||||
import base64
|
import base64
|
||||||
import time
|
import time
|
||||||
import arrow
|
|
||||||
import requests
|
import requests
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
@ -770,46 +769,17 @@ def publish_verisign_units():
|
||||||
requests.post('http://localhost:8078/metrics', data=json.dumps(metric))
|
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
|
Query the Verisign for any certificates that need to be approved.
|
||||||
"""
|
|
||||||
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.
|
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
end = arrow.utcnow()
|
from lemur.plugins import plugins
|
||||||
start = end.replace(hours=-window)
|
from lemur.extensions import metrics
|
||||||
items = Certificate.query.filter(Certificate.not_before <= end.format('YYYY-MM-DD')) \
|
v = plugins.get('verisign-issuer')
|
||||||
.filter(Certificate.not_before >= start.format('YYYY-MM-DD')).all()
|
certs = v.get_pending_certificates()
|
||||||
|
metrics.send('pending_certificates', 'gauge', certs)
|
||||||
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))
|
|
||||||
|
|
||||||
|
|
||||||
class Report(Command):
|
class Report(Command):
|
||||||
|
@ -951,7 +921,6 @@ def main():
|
||||||
manager.add_command("create_role", CreateRole())
|
manager.add_command("create_role", CreateRole())
|
||||||
manager.add_command("provision_elb", ProvisionELB())
|
manager.add_command("provision_elb", ProvisionELB())
|
||||||
manager.add_command("rotate_elbs", RotateELBs())
|
manager.add_command("rotate_elbs", RotateELBs())
|
||||||
manager.add_command("rolling", Rolling())
|
|
||||||
manager.add_command("sources", Sources())
|
manager.add_command("sources", Sources())
|
||||||
manager.add_command("report", Report())
|
manager.add_command("report", Report())
|
||||||
manager.run()
|
manager.run()
|
||||||
|
|
|
@ -188,6 +188,25 @@ class VerisignIssuerPlugin(IssuerPlugin):
|
||||||
response = self.session.post(url, headers={'content-type': 'application/x-www-form-urlencoded'})
|
response = self.session.post(url, headers={'content-type': 'application/x-www-form-urlencoded'})
|
||||||
return handle_response(response.content)['Response']['Order']
|
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):
|
class VerisignSourcePlugin(SourcePlugin):
|
||||||
title = 'Verisign'
|
title = 'Verisign'
|
||||||
|
|
Loading…
Reference in New Issue