-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add site tags and a ton of refactoring
- Loading branch information
1 parent
9b31fdb
commit 3cfaf01
Showing
5 changed files
with
148 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
venv/ | ||
venv/* | ||
.env | ||
.env* | ||
__pycache__/ | ||
__pycache__/* | ||
*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
from dataclasses import dataclass | ||
import dataclasses | ||
from typing import Protocol | ||
|
||
from zabbix_client import NUMERIC_FLOAT, TEXT, TemplateItem | ||
|
||
|
||
class HostProto(Protocol): | ||
name: str | ||
tags: dict | ||
prefix: str | ||
|
||
# Parsing stats | ||
def stats(self) -> dict: | ||
... | ||
|
||
# For creating a template automatically in Zabbix | ||
# TODO: Figure out better way to define templates | ||
@staticmethod | ||
def build_template(): | ||
... | ||
|
||
|
||
@dataclass | ||
class DataLinkStatistics: | ||
rxRate: int | ||
txRate: int | ||
downlinkCapacity: int | ||
uplinkCapacity: int | ||
downlinkUtilization: float | ||
uplinkUtilization: float | ||
signalLocal: int | ||
signalRemote: int | ||
signalChain0: int | ||
signalChain1: int | ||
signalRemoteChain0: int | ||
signalRemoteChain1: int | ||
linkScore: float | ||
score: int | ||
scoreMax: int | ||
airTimeScore: int | ||
linkScoreHint: str | ||
theoreticalDownlinkCapacity: int | ||
theoreticalUplinkCapacity: int | ||
|
||
|
||
class DataLink(HostProto): | ||
name: str | ||
tags: dict | ||
from_stats: DataLinkStatistics | ||
to_stats: DataLinkStatistics | ||
prefix = "uisp2zabbix.p2p" | ||
|
||
def __init__(self, name, from_site, to_site, from_stats, to_stats): | ||
self.name = name | ||
self.tags = {"from": from_site, "to": to_site} | ||
self.from_stats = from_stats | ||
self.to_stats = to_stats | ||
|
||
def stats(self): | ||
stats = {} | ||
|
||
for k, v in self.from_stats.__dict__.items(): | ||
stats[f"from_{k}"] = v | ||
|
||
for k, v in self.to_stats.__dict__.items(): | ||
stats[f"to_{k}"] = v | ||
|
||
return stats | ||
|
||
@staticmethod | ||
def build_template(): | ||
# Set up the items in the new template | ||
items = [] | ||
for field in dataclasses.fields(DataLinkStatistics): | ||
if field.type == float or field.type == int: | ||
t = NUMERIC_FLOAT | ||
if "signal" in field.name: | ||
u = "dB" | ||
elif "Rate" in field.name or "Capacity" in field.name: | ||
u = "bps" # TODO: Is this bps or Kbps? | ||
else: | ||
u = "" | ||
else: | ||
t = TEXT | ||
u = "" | ||
|
||
for direction in ["from", "to"]: | ||
items.append( | ||
TemplateItem( | ||
f"{direction}_{field.name}", | ||
f"{DataLink.prefix}.{direction}_{field.name}", | ||
t, | ||
u, | ||
) | ||
) | ||
return items |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters