Fix cert_check to use global collect_period
With the new addition of collect_period, cert_check needed to be reconfigured so the two features don't interfere with each other. Depends-On: I423b1f14d4b0580e625e5f57c729c4a6c9923a93 Change-Id: Ic4a41335c88c21ace0395bf6b1b1640557c23977
This commit is contained in:
parent
ab5b6bb7b9
commit
63619348a3
|
@ -1,9 +1,8 @@
|
||||||
# (C) Copyright 2016 Hewlett Packard Enterprise Development Company LP
|
# (C) Copyright 2016 Hewlett Packard Enterprise Development LP
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import socket
|
import socket
|
||||||
import ssl
|
import ssl
|
||||||
import time
|
|
||||||
from urlparse import urlparse
|
from urlparse import urlparse
|
||||||
|
|
||||||
from monasca_agent.collector.checks import AgentCheck
|
from monasca_agent.collector.checks import AgentCheck
|
||||||
|
@ -20,27 +19,11 @@ class CertificateCheck(AgentCheck):
|
||||||
self._ca_certs = init_config.get('ca_certs')
|
self._ca_certs = init_config.get('ca_certs')
|
||||||
self._ciphers = init_config.get('ciphers')
|
self._ciphers = init_config.get('ciphers')
|
||||||
self._timeout = init_config.get('timeout')
|
self._timeout = init_config.get('timeout')
|
||||||
self._collection_period = init_config.get('collect_period')
|
|
||||||
self._last_collect_time = datetime.fromordinal(1)
|
|
||||||
self._skip_collection = False
|
|
||||||
self.log.debug('ca_certs file is %s' % self._ca_certs)
|
self.log.debug('ca_certs file is %s' % self._ca_certs)
|
||||||
self.log.debug('cipers are %s' % self._ciphers)
|
self.log.debug('cipers are %s' % self._ciphers)
|
||||||
self.log.debug('timeout is %f' % self._timeout)
|
self.log.debug('timeout is %f' % self._timeout)
|
||||||
self.log.debug('collection_period is %d' % self._collection_period)
|
|
||||||
|
|
||||||
def prepare_run(self):
|
|
||||||
"""Check if it is time for the measurements to be collected"""
|
|
||||||
time_since_last = datetime.now() - self._last_collect_time
|
|
||||||
if time_since_last.seconds < self._collection_period:
|
|
||||||
self.log.debug('Skipping collection for %d seconds' %
|
|
||||||
(self._collection_period - time_since_last.seconds))
|
|
||||||
self._skip_collection = True
|
|
||||||
return
|
|
||||||
self._skip_collection = False
|
|
||||||
|
|
||||||
def check(self, instance):
|
def check(self, instance):
|
||||||
if self._skip_collection:
|
|
||||||
return
|
|
||||||
url = instance.get('url', None)
|
url = instance.get('url', None)
|
||||||
dimensions = self._set_dimensions(None, instance)
|
dimensions = self._set_dimensions(None, instance)
|
||||||
dimensions['url'] = url
|
dimensions['url'] = url
|
||||||
|
@ -53,7 +36,6 @@ class CertificateCheck(AgentCheck):
|
||||||
dimensions=dimensions)
|
dimensions=dimensions)
|
||||||
self.log.debug('%d days till expiration for %s' % (expire_in.days,
|
self.log.debug('%d days till expiration for %s' % (expire_in.days,
|
||||||
url))
|
url))
|
||||||
self._last_collect_time = datetime.now()
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.log.warning('Exception trying to GET certificate for %s: %s' %
|
self.log.warning('Exception trying to GET certificate for %s: %s' %
|
||||||
|
|
Loading…
Reference in New Issue