adding additional status code metrics (#555)
This commit is contained in:
parent
7f823a04cd
commit
834814f867
@ -76,13 +76,16 @@ def configure_hook(app):
|
||||
def after(response):
|
||||
return response
|
||||
|
||||
@app.after_request
|
||||
def log_status(response):
|
||||
metrics.send('status_code_{}'.format(response.status_code), 'counter', 1)
|
||||
return response
|
||||
|
||||
@app.errorhandler(Exception)
|
||||
def handle_error(e):
|
||||
code = 500
|
||||
if isinstance(e, HTTPException):
|
||||
code = e.code
|
||||
|
||||
metrics.send('{}_status_code'.format(code), 'counter', 1)
|
||||
|
||||
app.logger.exception(e)
|
||||
return jsonify(error=str(e)), code
|
||||
|
@ -30,6 +30,18 @@ from lemur.plugins import lemur_digicert as digicert
|
||||
from lemur.common.utils import validate_conf
|
||||
|
||||
|
||||
def log_status_code(r, *args, **kwargs):
|
||||
"""
|
||||
Is a request hook that logs all status codes to the digicert api.
|
||||
|
||||
:param r:
|
||||
:param args:
|
||||
:param kwargs:
|
||||
:return:
|
||||
"""
|
||||
metrics.send('digicert_status_code_{}'.format(r.status_code))
|
||||
|
||||
|
||||
def signature_hash(signing_algorithm):
|
||||
"""Converts Lemur's signing algorithm into a format DigiCert understands.
|
||||
|
||||
@ -160,8 +172,6 @@ def handle_response(response):
|
||||
:param response:
|
||||
:return:
|
||||
"""
|
||||
metrics.send('digicert_status_code_{0}'.format(response.status_code), 'counter', 1)
|
||||
|
||||
if response.status_code > 399:
|
||||
raise Exception(response.json()['message'])
|
||||
|
||||
@ -174,8 +184,6 @@ def handle_cis_response(response):
|
||||
:param response:
|
||||
:return:
|
||||
"""
|
||||
metrics.send('digicert_cis_status_code_{0}'.format(response.status_code), 'counter', 1)
|
||||
|
||||
if response.status_code > 399:
|
||||
raise Exception(response.json()['errors'][0]['message'])
|
||||
|
||||
@ -188,7 +196,6 @@ def get_certificate_id(session, base_url, order_id):
|
||||
order_url = "{0}/services/v2/order/certificate/{1}".format(base_url, order_id)
|
||||
response_data = handle_response(session.get(order_url))
|
||||
if response_data['status'] != 'issued':
|
||||
metrics.send('digicert_retries', 'counter', 1)
|
||||
raise Exception("Order not in issued state.")
|
||||
|
||||
return response_data['certificate']['id']
|
||||
@ -204,7 +211,6 @@ def get_cis_certificate(session, base_url, order_id):
|
||||
response = session.get(certificate_url)
|
||||
|
||||
if response.status_code == 404:
|
||||
metrics.send('digicert_retries', 'counter', 1)
|
||||
raise Exception("Order not in issued state.")
|
||||
|
||||
return response.content
|
||||
@ -239,6 +245,8 @@ class DigiCertSourcePlugin(SourcePlugin):
|
||||
}
|
||||
)
|
||||
|
||||
self.session.hooks = dict(response=log_status_code)
|
||||
|
||||
super(DigiCertSourcePlugin, self).__init__(*args, **kwargs)
|
||||
|
||||
def get_certificates(self):
|
||||
@ -276,6 +284,8 @@ class DigiCertIssuerPlugin(IssuerPlugin):
|
||||
}
|
||||
)
|
||||
|
||||
self.session.hooks = dict(response=log_status_code)
|
||||
|
||||
super(DigiCertIssuerPlugin, self).__init__(*args, **kwargs)
|
||||
|
||||
def create_certificate(self, csr, issuer_options):
|
||||
@ -349,6 +359,8 @@ class DigiCertCISIssuerPlugin(IssuerPlugin):
|
||||
}
|
||||
)
|
||||
|
||||
self.session.hooks = dict(response=log_status_code)
|
||||
|
||||
super(DigiCertCISIssuerPlugin, self).__init__(*args, **kwargs)
|
||||
|
||||
def create_certificate(self, csr, issuer_options):
|
||||
|
@ -13,8 +13,11 @@ import xmltodict
|
||||
|
||||
from flask import current_app
|
||||
|
||||
from lemur.plugins.bases import IssuerPlugin, SourcePlugin
|
||||
from lemur.extensions import metrics
|
||||
|
||||
from lemur.plugins import lemur_verisign as verisign
|
||||
from lemur.plugins.bases import IssuerPlugin, SourcePlugin
|
||||
|
||||
from lemur.common.utils import get_psuedo_random_string
|
||||
|
||||
|
||||
@ -61,6 +64,18 @@ VERISIGN_ERRORS = {
|
||||
}
|
||||
|
||||
|
||||
def log_status_code(r, *args, **kwargs):
|
||||
"""
|
||||
Is a request hook that logs all status codes to the verisign api.
|
||||
|
||||
:param r:
|
||||
:param args:
|
||||
:param kwargs:
|
||||
:return:
|
||||
"""
|
||||
metrics.send('symantec_status_code_{}'.format(r.status_code))
|
||||
|
||||
|
||||
def process_options(options):
|
||||
"""
|
||||
Processes and maps the incoming issuer options to fields/options that
|
||||
@ -141,6 +156,7 @@ class VerisignIssuerPlugin(IssuerPlugin):
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.session = requests.Session()
|
||||
self.session.cert = current_app.config.get('VERISIGN_PEM_PATH')
|
||||
self.session.hooks = dict(response=log_status_code)
|
||||
super(VerisignIssuerPlugin, self).__init__(*args, **kwargs)
|
||||
|
||||
def create_certificate(self, csr, issuer_options):
|
||||
|
Loading…
Reference in New Issue
Block a user