Skip to content
Snippets Groups Projects
Commit 0164cd2e authored by Pelle Koster's avatar Pelle Koster
Browse files

more wip on error report

parent 65987a67
No related branches found
No related tags found
No related merge requests found
import logging import logging
import pathlib import pathlib
import pprint from typing import Sequence
from typing import Sequence, Set, Tuple
from brian_polling_manager.interface_stats.services import influx_client from brian_polling_manager.interface_stats.services import influx_client
from brian_polling_manager.inventory import load_interfaces from brian_polling_manager.inventory import load_interfaces
from influxdb import InfluxDBClient from influxdb import InfluxDBClient
...@@ -126,7 +125,7 @@ def get_error_points(client: InfluxDBClient, time_window: str): ...@@ -126,7 +125,7 @@ def get_error_points(client: InfluxDBClient, time_window: str):
def interface_errors( def interface_errors(
client: InfluxDBClient, interface_info, errors, raise_on_errors=False client: InfluxDBClient, interface_info, errors, exclusions, raise_on_errors=False
): ):
""" """
Retrieves error counters from influx Retrieves error counters from influx
...@@ -144,16 +143,15 @@ def interface_errors( ...@@ -144,16 +143,15 @@ def interface_errors(
yesterdays_data = get_error_points(client, TIME_WINDOW_YESTERDAY) yesterdays_data = get_error_points(client, TIME_WINDOW_YESTERDAY)
result = {"interfaces": [], "excluded_interfaces": []} result = {"interfaces": [], "excluded_interfaces": []}
exception_count = 0 for (router, ifc), info in interface_info.items():
for (router, ifc), today in todays_data.items():
yesterday = yesterdays_data.get((router, ifc), {})
try: try:
info = interface_info[(router, ifc)] today = todays_data[(router, ifc)]
except KeyError: except KeyError:
logger.exception(f"{router} - {ifc} not found in inventory provider") logger.error(f"{router} - {ifc} not found in influx data")
exception_count += 1
if raise_on_errors: if raise_on_errors:
raise raise
continue
yesterday = yesterdays_data.get((router, ifc), {})
counters = { counters = {
"error_counters": {err[0]: (today[err[1]] or 0) for (err) in errors}, "error_counters": {err[0]: (today[err[1]] or 0) for (err) in errors},
...@@ -162,7 +160,7 @@ def interface_errors( ...@@ -162,7 +160,7 @@ def interface_errors(
"description": info["description"], "description": info["description"],
} }
if not is_excluded_interface(info["description"]): if not is_excluded_interface(info["description"], exclusions):
counters["diff"] = { counters["diff"] = {
err[0]: (today[err[1]] or 0) - (yesterday.get(err[1], 0) or 0) err[0]: (today[err[1]] or 0) - (yesterday.get(err[1], 0) or 0)
for err in errors for err in errors
...@@ -177,7 +175,7 @@ def interface_errors( ...@@ -177,7 +175,7 @@ def interface_errors(
else: else:
result["excluded_interfaces"].append(counters) result["excluded_interfaces"].append(counters)
return result, exception_count return result
def is_excluded_interface(description: str, exclusions: Sequence[str]): def is_excluded_interface(description: str, exclusions: Sequence[str]):
...@@ -212,16 +210,12 @@ def main(): ...@@ -212,16 +210,12 @@ def main():
client = influx_client(config["influx"]) client = influx_client(config["influx"])
all_interfaces = get_relevant_interfaces(config["inventory"]) all_interfaces = get_relevant_interfaces(config["inventory"])
with client: with client:
all_error_counters = interface_errors(client, errors=ERROR_FIELDS) all_error_counters = interface_errors(
for key in sorted(all_interfaces): client,
if key not in all_error_counters: interface_info=all_interfaces,
print(f"interface {key} not found in influx data") errors=ERROR_FIELDS,
continue exclusions=config["exclude-interfaces"],
)
errors = all_error_counters[key]
if any(v > 0 for v in errors.values()):
print(*key, ",".join(str(c) for c in errors.values()))
# TODO: ensure data is from the day that we're interested in (today or yesterday) # TODO: ensure data is from the day that we're interested in (today or yesterday)
# TODO: send script failures to admin email # TODO: send script failures to admin email
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment