Skip to content
Snippets Groups Projects
Commit 6f9850a3 authored by Erik Reid's avatar Erik Reid
Browse files

set timestamp when netconf doc is queried

parent f1976945
No related branches found
No related tags found
No related merge requests found
......@@ -70,7 +70,7 @@ def setup_logging():
logging.config.dictConfig(logging_config)
def ctr2point(measurement, counters):
def ctr2point(measurement, timestamp, counters):
"""
:param measurement: the measurement where the point will be written
......@@ -83,12 +83,10 @@ def ctr2point(measurement, counters):
fields = dict([_k, _v] for _k, _v in counters.items() if not _is_tag(_k))
tags = dict([_k, _v] for _k, _v in counters.items() if _is_tag(_k))
return {
'time': timestamp.strftime('%Y-%m-%dT%H:%M:%SZ'),
'measurement': measurement,
'tags': tags,
'fields': fields,
# TODO: let's set this at neconf query/response time
'time': datetime.now().strftime('%Y-%m-%dT%H:%M:%SZ'),
}
......@@ -108,29 +106,35 @@ def _managed_routers(inventory_base_urls):
def fqdn_netconf_doc_map(app_config_params):
_result = {}
for fqdn in _managed_routers(inventory_base_urls=app_config_params['inventory']):
_result[fqdn] = juniper.get_interface_info_ncrpc(fqdn)
_result[fqdn] = {
'timestamp': datetime.now(),
'doc': juniper.get_interface_info_ncrpc(fqdn)
}
return _result
def _brian_points(router_fqdn, netconf_doc, measurement_name):
def _brian_points(router_fqdn, netconf_doc, timestamp, measurement_name):
_ctr2point = partial(ctr2point, measurement_name, timestamp)
interfaces = juniper.physical_interface_counters(netconf_doc)
counters = brian.counters(router_fqdn=router_fqdn, interface_counters=interfaces)
yield from map(partial(ctr2point, measurement_name), counters)
yield from map(_ctr2point, counters)
interfaces = juniper.logical_interface_counters(netconf_doc)
counters = brian.counters(router_fqdn=router_fqdn, interface_counters=interfaces)
yield from map(partial(ctr2point, measurement_name), counters)
yield from map(_ctr2point, counters)
def _error_points(router_fqdn, netconf_doc, timestamp, measurement_name):
_ctr2point = partial(ctr2point, measurement_name, timestamp)
def _error_points(router_fqdn, netconf_doc, measurement_name):
interfaces = juniper.physical_interface_counters(netconf_doc)
counters = errors.counters(router_fqdn=router_fqdn, interface_counters=interfaces)
yield from map(partial(ctr2point, measurement_name), counters)
yield from map(_ctr2point, counters)
interfaces = juniper.logical_interface_counters(netconf_doc)
counters = errors.counters(router_fqdn=router_fqdn, interface_counters=interfaces)
yield from map(partial(ctr2point, measurement_name), counters)
yield from map(_ctr2point, counters)
def _main(app_config_params: dict):
......@@ -150,7 +154,8 @@ def _main(app_config_params: dict):
for _fqdn, _ncdoc in nc_doc_map.items():
points = _brian_points(
router_fqdn=_fqdn,
netconf_doc=_ncdoc,
netconf_doc=_ncdoc['doc'],
timestamp=_ncdoc['timestamp'],
measurement_name=influx_params['measurement'])
with contextlib.closing(influx.influx_client(influx_params)) as client:
......@@ -160,7 +165,8 @@ def _main(app_config_params: dict):
for _fqdn, _ncdoc in nc_doc_map.items():
points = _error_points(
router_fqdn=_fqdn,
netconf_doc=_ncdoc,
netconf_doc=_ncdoc['doc'],
timestamp=_ncdoc['timestamp'],
measurement_name=influx_params['measurement'])
with contextlib.closing(influx.influx_client(influx_params)) as client:
......
import concurrent.futures
import contextlib
import datetime
import itertools
import json
import logging
......@@ -173,6 +174,7 @@ def test_brian_points(router_fqdn, ifc_netconf_rpc):
for _p in cli._brian_points(
router_fqdn=router_fqdn,
netconf_doc=juniper.get_interface_info_ncrpc(router_fqdn),
timestamp=datetime.datetime.now(),
measurement_name='blah'):
jsonschema.validate(_p, influx.INFLUX_POINT)
assert _p['fields'] # any trivial points should already be filtered
......@@ -183,6 +185,7 @@ def test_error_points(router_fqdn, ifc_netconf_rpc):
for _p in cli._error_points(
router_fqdn=router_fqdn,
netconf_doc=juniper.get_interface_info_ncrpc(router_fqdn),
timestamp=datetime.datetime.now(),
measurement_name='blah'):
jsonschema.validate(_p, influx.INFLUX_POINT)
assert _p['fields'] # any trivial points should already be filtered
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment