Skip to content
Snippets Groups Projects
Commit 68652d81 authored by Robert Latta's avatar Robert Latta
Browse files

Added storing interface status information from the alarms DB

parent d01524a5
Branches
Tags
No related merge requests found
import json import json
from collections import defaultdict from collections import defaultdict
from inventory_provider import db from flask import current_app
from inventory_provider import alarmsdb, db
services_key = "inv_services" services_key = "inv_services"
...@@ -8,27 +9,38 @@ interfaces_key = "inv_interfaces" ...@@ -8,27 +9,38 @@ interfaces_key = "inv_interfaces"
equipment_locations_key = "inv_eq_locations" equipment_locations_key = "inv_eq_locations"
service_child_to_parents_key = "inv_service_child_to_parents" service_child_to_parents_key = "inv_service_child_to_parents"
service_parent_to_children_key = "inv_service_parent_to_children" service_parent_to_children_key = "inv_service_parent_to_children"
interface_status_key = "service_status"
def update_services_to_monitor(services): def update_services_to_monitor(services):
r = db.get_redis() r = db.get_redis()
relevant_types = ('path', 'service', 'l2circuit') relevant_types = ("path", "service", "l2circuit")
r.delete(services_key) r.delete(services_key)
for service in services: for service in services:
if service['circuit_type'].lower() in relevant_types: if service["circuit_type"].lower() in relevant_types:
r.hset(services_key, service['id'], json.dumps(service)) r.hset(services_key, service["id"], json.dumps(service))
def update_interfaces_to_services(services): def update_interfaces_to_services(services):
r = db.get_redis() r = db.get_redis()
mapped_interfaces = defaultdict(list) config = current_app.config["INVENTORY_PROVIDER_CONFIG"]
r.delete(interfaces_key) with db.connection(config["alarms-db"]) as cnx:
for service in services: with db.cursor(cnx) as csr:
key = "{}::{}".format( mapped_interfaces = defaultdict(list)
service['equipment'], r.delete(interfaces_key)
service['interface_name'] for service in services:
) key = "{}::{}".format(
mapped_interfaces[key].append(service) service["equipment"],
service["interface_name"]
)
mapped_interfaces[key].append(service)
if not r.hexists(interface_status_key, key):
r.hset(interface_status_key, key,
alarmsdb.get_last_known_interface_status(
csr,
service["equipment"],
service["interface_name"]
))
for key, value in mapped_interfaces.items(): for key, value in mapped_interfaces.items():
r.hset(interfaces_key, key, json.dumps(value)) r.hset(interfaces_key, key, json.dumps(value))
...@@ -57,4 +69,4 @@ def update_equipment_locations(equipment_location_data): ...@@ -57,4 +69,4 @@ def update_equipment_locations(equipment_location_data):
r = db.get_redis() r = db.get_redis()
r.delete(equipment_locations_key) r.delete(equipment_locations_key)
for ld in equipment_location_data: for ld in equipment_location_data:
r.hset(equipment_locations_key, ld['equipment_name'], json.dumps(ld)) r.hset(equipment_locations_key, ld["equipment_name"], json.dumps(ld))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment