Skip to content

Commit

Permalink
Greatly improving GUI Log Messages by coloring and adding object Netb…
Browse files Browse the repository at this point in the history
…ox linking
  • Loading branch information
emersonfelipesp committed Oct 11, 2024
1 parent 6f74df6 commit e842908
Show file tree
Hide file tree
Showing 11 changed files with 240 additions and 162 deletions.
17 changes: 12 additions & 5 deletions netbox_proxbox/backend/exception.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from netbox_proxbox.backend.logging import logger

from fastapi import WebSocket

class ProxboxException(Exception):
def __init__(
self,
Expand All @@ -18,8 +19,14 @@ def __init__(

if self.python_exception:
log_message+=f"\n > Python Exception: {self.python_exception}"


logger.error(log_message)



async def exception_log(
logger,
message: str,
detail: str | None = None,
python_exception: str | None = None,
websocket: WebSocket | None = None,
):
log = logger
await log(websocket=websocket, msg=message, level="ERROR")
20 changes: 19 additions & 1 deletion netbox_proxbox/backend/logging.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
from logging.handlers import TimedRotatingFileHandler
from netbox_proxbox.backend.exception import ProxboxException

# ANSI escape sequences for colors
class AnsiColorCodes:
Expand Down Expand Up @@ -70,4 +71,21 @@ def setup_logger():
return logger


logger = setup_logger()
logger = setup_logger()

from fastapi import WebSocket

async def log(websocket: WebSocket, msg, level = None):
if websocket:
await websocket.send_text(msg)

if level == "debug": logger.debug(msg)

if level == "ERROR" or level == "error":
logger.error(msg)
#raise ProxboxException(
# message=msg,
# python_exception=python_exception
#)

else: logger.info(msg)
2 changes: 1 addition & 1 deletion netbox_proxbox/backend/routes/netbox/dcim/device_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class DeviceType(NetboxBase):
object_name = "Device Types"

async def get_base_dict(self):
manufacturer = await Manufacturer(nb = self.nb).get()
manufacturer = await Manufacturer(nb = self.nb, websocket = self.websocket).get()

return {
"model": self.default_name,
Expand Down
8 changes: 4 additions & 4 deletions netbox_proxbox/backend/routes/netbox/dcim/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ class Device(NetboxBase):
object_name = "Device"

async def get_base_dict(self):
site = await Site(nb = self.nb).get()
role = await DeviceRole(nb = self.nb).get()
device_type = await DeviceType(nb = self.nb).get()
cluster = await Cluster(nb = self.nb).get()
site = await Site(nb = self.nb, websocket = self.websocket).get()
role = await DeviceRole(nb = self.nb, websocket = self.websocket).get()
device_type = await DeviceType(nb = self.nb, websocket = self.websocket).get()
cluster = await Cluster(nb = self.nb, websocket = self.websocket).get()

return {
"name": self.default_name,
Expand Down
2 changes: 1 addition & 1 deletion netbox_proxbox/backend/routes/netbox/dcim/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Interface(NetboxBase):
object_name = "Interface"

async def get_base_dict(self):
device = await Device(nb = self.nb).get()
device = await Device(nb = self.nb, websocket = self.websocket).get()

return {
"device": device.id,
Expand Down
108 changes: 56 additions & 52 deletions netbox_proxbox/backend/routes/netbox/generic.py

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Cluster(NetboxBase):


async def get_base_dict(self):
type = await ClusterType(nb = self.nb).get()
type = await ClusterType(nb = self.nb, websocket = self.websocket).get()

return {
"name": self.default_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class VMInterface(NetboxBase):

async def get_base_dict(self):

virtual_machine = await VirtualMachine(nb = self.nb).get()
virtual_machine = await VirtualMachine(nb = self.nb, websocket = self.websocket).get()

return {
"virtual_machine": virtual_machine.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class VirtualMachine(NetboxBase):


async def get_base_dict(self):
cluster = await Cluster(nb = self.nb).get()
cluster = await Cluster(nb = self.nb, websocket = self.websocket).get()
return {
"name": self.default_name,
"slug": self.default_slug,
Expand Down
232 changes: 139 additions & 93 deletions netbox_proxbox/backend/routes/proxbox/clusters/__init__.py

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions netbox_proxbox/templates/netbox_proxbox/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ <h1>Log Messages</h1>
ws.onmessage = function(event) {
var messages = document.getElementById('messages')
var message = document.createElement('li')
var content = document.createTextNode(event.data)
message.appendChild(content)

message.innerHTML = event.data

// var content = document.createTextNode(event.data)
// message.appendChild(content)
messages.appendChild(message)
};
function sendMessage(event) {
Expand Down

0 comments on commit e842908

Please sign in to comment.