-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into routing_stats
- Loading branch information
Showing
10 changed files
with
96 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# coding=utf8 | ||
## Copyright (c) 2020 Arseniy Kuznetsov | ||
## | ||
## This program is free software; you can redistribute it and/or | ||
## modify it under the terms of the GNU General Public License | ||
## as published by the Free Software Foundation; either version 2 | ||
## of the License, or (at your option) any later version. | ||
## | ||
## This program is distributed in the hope that it will be useful, | ||
## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
## GNU General Public License for more details. | ||
|
||
from mktxp.collector.base_collector import BaseCollector | ||
from mktxp.datasource.certificate_ds import CertificateMetricsDataSource | ||
from datetime import datetime | ||
|
||
class CertificateCollector(BaseCollector): | ||
'''Certificate collector''' | ||
@staticmethod | ||
def collect(router_entry): | ||
if not router_entry.config_entry.certificate: | ||
return | ||
|
||
certificate_labels = ['name', 'digest_algorithm', 'key_type', 'country', 'state', 'locality', 'organization', | ||
'common_name', 'key_size', 'subject_alt_name', 'days_valid', 'trusted', 'key_usage', | ||
'ca', 'serial_number', 'key_usage', 'ca', 'serial_number', 'fingerprint', 'akid', 'skid', | ||
'invalid_before', 'invalid_after'] | ||
|
||
translation_table = { | ||
} | ||
|
||
certificate_records = CertificateMetricsDataSource.metric_records(router_entry, translation_table=translation_table, metric_labels = certificate_labels) | ||
if isinstance(certificate_records, list): | ||
for record in certificate_records: | ||
# Convert invalid_after time to epoch time | ||
record['invalid_after_epoch'] = int(datetime.strptime(record['invalid_after'], "%Y-%m-%d %H:%M:%S").timestamp()) | ||
if certificate_records: | ||
yield BaseCollector.gauge_collector('certificate_expiration_timestamp_seconds', 'The number of seconds before expiration time the certificate should renew.', certificate_records, 'invalid_after_epoch', certificate_labels) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# coding=utf8 | ||
## Copyright (c) 2020 Arseniy Kuznetsov | ||
## | ||
## This program is free software; you can redistribute it and/or | ||
## modify it under the terms of the GNU General Public License | ||
## as published by the Free Software Foundation; either version 2 | ||
## of the License, or (at your option) any later version. | ||
## | ||
## This program is distributed in the hope that it will be useful, | ||
## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
## GNU General Public License for more details. | ||
|
||
|
||
from mktxp.datasource.base_ds import BaseDSProcessor | ||
|
||
|
||
class CertificateMetricsDataSource: | ||
'''Certificates Metrics data provider | ||
''' | ||
@staticmethod | ||
def metric_records(router_entry, *, metric_labels = None, translation_table=None): | ||
if metric_labels is None: | ||
metric_labels = [] | ||
try: | ||
certificates_records = router_entry.api_connection.router_api().get_resource('/certificate').call('print', {'detail':''}) | ||
return BaseDSProcessor.trimmed_records(router_entry, router_records = certificates_records, | ||
metric_labels = metric_labels, translation_table=translation_table) | ||
except Exception as exc: | ||
print(f'Error getting certificates info from router {router_entry.router_name}@{router_entry.config_entry.hostname}: {exc}') | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters