Skip to content

Commit

Permalink
added event for storing configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
chuckablack committed Oct 12, 2020
1 parent d79bc9b commit 8ced076
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 42 deletions.
23 changes: 20 additions & 3 deletions quokka/controller/ConfigurationMonitorTask.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
from time import sleep
from datetime import datetime

from quokka.controller.utils import log_console
from quokka.controller.device.device_info import get_device_info
from quokka.models.apis import get_all_device_ids, get_device, record_device_config
from quokka.models.apis import (
get_all_device_ids,
get_device,
record_device_config,
log_event,
)


class ConfigurationMonitorTask:
Expand Down Expand Up @@ -41,9 +47,13 @@ def monitor(self, interval):
continue

try:
result, config = get_device_info(device, "config", get_live_info=True)
result, config = get_device_info(
device, "config", get_live_info=True
)
if result != "success":
log_console(f"!!! Unable to get device info (config) for {device['name']}")
log_console(
f"!!! Unable to get device info (config) for {device['name']}"
)
continue

except BaseException as e:
Expand All @@ -54,6 +64,13 @@ def monitor(self, interval):

# If we made it here, we got the configuration, so store it in the DB
record_device_config(device_id, config["config"]["running"])
log_event(
str(datetime.now())[:-3],
"configuration",
device['name'],
"INFO",
f"Stored configuration for: {device['name']}",
)

for _ in range(0, int(interval / 10)):
sleep(10)
Expand Down
12 changes: 9 additions & 3 deletions quokka/controller/HostMonitorTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@


class HostMonitorTask:

def __init__(self):
self.terminate = False

Expand All @@ -32,14 +31,21 @@ def monitor(self, interval):
log_console(f"--- monitor:host pinging {host['ip_address']}")
try:
ping_output = subprocess.check_output(
["ping", "-c3", "-n", "-i0.5", "-W2", str(host["ip_address"])])
["ping", "-c3", "-n", "-i0.5", "-W2", str(host["ip_address"])]
)
host["availability"] = True
host["response_time"] = get_response_time(str(ping_output))
host["last_heard"] = str(datetime.now())[:-3]

except subprocess.CalledProcessError:
host["availability"] = False
log_event(str(datetime.now())[:-3], "host", host['name'], "INFO", "Availability failed")
log_event(
str(datetime.now())[:-3],
"host monitor",
host["name"],
"INFO",
f"Availability failed for host: {host['name']}",
)

record_host_status(host)
set_host(host)
Expand Down
19 changes: 16 additions & 3 deletions quokka/controller/ServiceMonitorTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
from dns.resolver import Resolver, Timeout, NXDOMAIN
from ntplib import NTPClient, NTPException

from quokka.models.apis import get_all_services, set_service, record_service_status, log_event
from quokka.models.apis import (
get_all_services,
set_service,
record_service_status,
log_event,
)
from quokka.controller.utils import log_console


Expand Down Expand Up @@ -36,7 +41,9 @@ def get_avail_and_rsp_time(service):
log_console(f'!!! DNS monitor: nonexistent domain name {service["data"]}')
return False, None
except Timeout as e:
log_console(f'!!! DNS monitor: DNS request timed out for {service["target"]}')
log_console(
f'!!! DNS monitor: DNS request timed out for {service["target"]}'
)
return False, None
except BaseException as e:
log_console(f"!!! DNS monitor: Exception occurred: {repr(e)}")
Expand Down Expand Up @@ -101,7 +108,13 @@ def monitor(self, interval):
if not availability:
record_service_status(service)
set_service(service)
log_event(str(datetime.now())[:-3], "service", service['name'], "WARNING", "Availability failed")
log_event(
str(datetime.now())[:-3],
"service monitor",
service["name"],
"WARNING",
f"Availability failed for service: {service['name']}",
)
continue

service["response_time"] = int(response_time * 1000)
Expand Down
16 changes: 13 additions & 3 deletions quokka/controller/device/device_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ def get_device_status(device):
except BaseException as e:
info = f"!!! Exception in monitoring device, get environment: {repr(e)}"
log_console(info)
log_event(str(datetime.now())[:-3], "device", device['name'], "SEVERE", info)
log_event(
str(datetime.now())[:-3], "device", device["name"], "SEVERE", info
)
result = "failed"

else:
Expand All @@ -52,11 +54,19 @@ def get_device_status(device):
except BaseException as e:
info = f"!!! Exception in monitoring device, get facts: {repr(e)}"
log_console(info)
log_event(str(datetime.now())[:-3], "device", device['name'], "SEVERE", info)
log_event(
str(datetime.now())[:-3], "device", device["name"], "SEVERE", info
)
result = "failed"

if result != "success":
log_event(str(datetime.now())[:-3], "device", device['name'], "SEVERE", "Availability failed")
log_event(
str(datetime.now())[:-3],
"device monitor",
device["name"],
"SEVERE",
f"Availability failed for device: {device['name']}",
)

else:
device_status["availability"] = True
Expand Down
2 changes: 0 additions & 2 deletions quokka/data/cisco.iosxe.standard.config.diff.CSR-sandbox
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@
+ ip address 192.168.254.201 255.255.255.0
+interface GigabitEthernet2
+ description to
- no ip address
+ shutdown
+interface GigabitEthernet3
+ description to
+interface GigabitEthernet4
Expand Down
18 changes: 0 additions & 18 deletions quokka/data/devices.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,3 @@
transport: HTTP-REST
hostname: sdwan-atlanta-midtown.tallac.com
vendor: tallac

- id: 10
ip_address:
serial: 111-111-115
name: SDWAN-Atlanta
os: talos
transport: HTTP-REST
hostname: sdwan-atlanta-midtown.tallac.com
vendor: tallac

- id: 12
ip_address:
serial: 111-111-115
name: SDWAN-Atlanta
os: talos
transport: HTTP-REST
hostname: sdwan-atlanta-midtown.tallac.com
vendor: tallac
7 changes: 0 additions & 7 deletions quokka/data/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,3 @@
target: us.pool.ntp.org
sla_availability: 95
sla_response_time: 0.5

- id: 7
name: NTP us.pool.ntp.org
type: ntp
target: us.pool.ntp.org
sla_availability: 95
sla_response_time: 0.5
24 changes: 21 additions & 3 deletions quokka/models/apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,22 @@ def set_devices(devices):
for device in devices:

if device["id"] in ids:
log_event(str(datetime.now())[:-3], "importing devices", "devices.yaml", "ERROR", f"Duplicate device id: {device['id']}")
log_event(
str(datetime.now())[:-3],
"importing devices",
"devices.yaml",
"ERROR",
f"Duplicate device id: {device['id']}",
)
continue
if device["name"] in names:
log_event(str(datetime.now())[:-3], "importing devices", "devices.yaml", "ERROR", f"Duplicate device name: {device['name']}")
log_event(
str(datetime.now())[:-3],
"importing devices",
"devices.yaml",
"ERROR",
f"Duplicate device name: {device['name']}",
)
continue

ids.add(device["id"])
Expand Down Expand Up @@ -255,7 +267,13 @@ def import_services(filename=None):
for service in services:

if service["id"] in ids:
log_event(str(datetime.now())[:-3], "importing services", filename, "ERROR", f"Duplicate service id: {service['id']}")
log_event(
str(datetime.now())[:-3],
"importing services",
filename,
"ERROR",
f"Duplicate service id: {service['id']}",
)
continue

ids.add(service["id"])
Expand Down

0 comments on commit 8ced076

Please sign in to comment.