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
No related branches found
No related tags found
No related merge requests found
import json
from collections import defaultdict
from inventory_provider import db
from flask import current_app
from inventory_provider import alarmsdb, db
services_key = "inv_services"
......@@ -8,27 +9,38 @@ interfaces_key = "inv_interfaces"
equipment_locations_key = "inv_eq_locations"
service_child_to_parents_key = "inv_service_child_to_parents"
service_parent_to_children_key = "inv_service_parent_to_children"
interface_status_key = "service_status"
def update_services_to_monitor(services):
r = db.get_redis()
relevant_types = ('path', 'service', 'l2circuit')
relevant_types = ("path", "service", "l2circuit")
r.delete(services_key)
for service in services:
if service['circuit_type'].lower() in relevant_types:
r.hset(services_key, service['id'], json.dumps(service))
if service["circuit_type"].lower() in relevant_types:
r.hset(services_key, service["id"], json.dumps(service))
def update_interfaces_to_services(services):
r = db.get_redis()
mapped_interfaces = defaultdict(list)
r.delete(interfaces_key)
for service in services:
key = "{}::{}".format(
service['equipment'],
service['interface_name']
)
mapped_interfaces[key].append(service)
config = current_app.config["INVENTORY_PROVIDER_CONFIG"]
with db.connection(config["alarms-db"]) as cnx:
with db.cursor(cnx) as csr:
mapped_interfaces = defaultdict(list)
r.delete(interfaces_key)
for service in services:
key = "{}::{}".format(
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():
r.hset(interfaces_key, key, json.dumps(value))
......@@ -57,4 +69,4 @@ def update_equipment_locations(equipment_location_data):
r = db.get_redis()
r.delete(equipment_locations_key)
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