Compare commits
2 Commits
7082eeeda7
...
eef2517480
Author | SHA1 | Date | |
---|---|---|---|
eef2517480 | |||
fa2bec5299 |
10
fmt.sh
10
fmt.sh
@ -3,5 +3,11 @@
|
|||||||
self=$(dirname "$(readlink -f "$0")")
|
self=$(dirname "$(readlink -f "$0")")
|
||||||
cd "${self}"
|
cd "${self}"
|
||||||
|
|
||||||
python3 -m black src
|
if [ -d venv ]; then
|
||||||
python3 -m isort src
|
python=venv/bin/python3
|
||||||
|
else
|
||||||
|
python=python3
|
||||||
|
fi
|
||||||
|
|
||||||
|
"${python}" -m black src
|
||||||
|
"${python}" -m isort src
|
||||||
|
@ -142,9 +142,9 @@ class Database:
|
|||||||
self._macs: dict[cptypes.MacAddress, MacEntry] = {}
|
self._macs: dict[cptypes.MacAddress, MacEntry] = {}
|
||||||
self._state_filename = state_filename
|
self._state_filename = state_filename
|
||||||
self._changed_since_last_cleanup = False
|
self._changed_since_last_cleanup = False
|
||||||
self._send_changes: trio.MemorySendChannel[
|
self._send_changes: (
|
||||||
capport.comm.message.MacStates | list[capport.comm.message.MacStates],
|
trio.MemorySendChannel[capport.comm.message.MacStates | list[capport.comm.message.MacStates],] | None
|
||||||
] | None = None
|
) = None
|
||||||
|
|
||||||
@contextlib.asynccontextmanager
|
@contextlib.asynccontextmanager
|
||||||
async def make_changes(self) -> typing.AsyncGenerator[PendingUpdates, None]:
|
async def make_changes(self) -> typing.AsyncGenerator[PendingUpdates, None]:
|
||||||
|
@ -17,7 +17,7 @@ from . import cptypes
|
|||||||
class MetricPrinter:
|
class MetricPrinter:
|
||||||
args: CliArguments
|
args: CliArguments
|
||||||
now: int | None = None
|
now: int | None = None
|
||||||
_known_names: set[str] = dataclasses.field(default_factory=set, init=None)
|
_known_names: set[str] = dataclasses.field(default_factory=set, init=False)
|
||||||
_now_str: str = dataclasses.field(init=False)
|
_now_str: str = dataclasses.field(init=False)
|
||||||
_label_str: str = dataclasses.field(init=False)
|
_label_str: str = dataclasses.field(init=False)
|
||||||
|
|
||||||
@ -28,8 +28,8 @@ class MetricPrinter:
|
|||||||
self._now_str = ""
|
self._now_str = ""
|
||||||
labels = []
|
labels = []
|
||||||
if self.args.instance:
|
if self.args.instance:
|
||||||
labels.append(f"captive_instance=\"{self.args.instance}\"")
|
labels.append(f'captive_instance="{self.args.instance}"')
|
||||||
labels.append(f"interface=\"{self.args.interface}\"")
|
labels.append(f'interface="{self.args.interface}"')
|
||||||
self._label_str = "{" + ",".join(labels) + "}"
|
self._label_str = "{" + ",".join(labels) + "}"
|
||||||
|
|
||||||
def print_metric(self, *, name: str, mtype: str, value: typing.Any, help: str | None = None):
|
def print_metric(self, *, name: str, mtype: str, value: typing.Any, help: str | None = None):
|
||||||
@ -56,7 +56,7 @@ async def amain(args: CliArguments):
|
|||||||
unique_ipv6 = set()
|
unique_ipv6 = set()
|
||||||
async with capport.utils.ipneigh.connect() as ipn:
|
async with capport.utils.ipneigh.connect() as ipn:
|
||||||
ipn.ip.strict_check = True
|
ipn.ip.strict_check = True
|
||||||
async for (mac, addr) in ipn.dump_neighbors(args.interface):
|
async for mac, addr in ipn.dump_neighbors(args.interface):
|
||||||
if mac in captive_allowed_entries:
|
if mac in captive_allowed_entries:
|
||||||
seen_allowed_entries.add(mac)
|
seen_allowed_entries.add(mac)
|
||||||
unique_clients.add(mac)
|
unique_clients.add(mac)
|
||||||
@ -101,13 +101,13 @@ async def amain(args: CliArguments):
|
|||||||
total_ipv6,
|
total_ipv6,
|
||||||
help="Number of IPv6 addresses seen in neighbor cache",
|
help="Number of IPv6 addresses seen in neighbor cache",
|
||||||
)
|
)
|
||||||
with open('/proc/sys/net/netfilter/nf_conntrack_count') as f:
|
with open("/proc/sys/net/netfilter/nf_conntrack_count") as f:
|
||||||
printer.print_gauge(
|
printer.print_gauge(
|
||||||
"nf_conntrack_count",
|
"nf_conntrack_count",
|
||||||
int(f.readline()),
|
int(f.readline()),
|
||||||
help="Conntrack count",
|
help="Conntrack count",
|
||||||
)
|
)
|
||||||
with open('/proc/sys/net/netfilter/nf_conntrack_max') as f:
|
with open("/proc/sys/net/netfilter/nf_conntrack_max") as f:
|
||||||
printer.print_gauge(
|
printer.print_gauge(
|
||||||
"nf_conntrack_max",
|
"nf_conntrack_max",
|
||||||
int(f.readline()),
|
int(f.readline()),
|
||||||
|
@ -67,9 +67,11 @@ def _build(msg_class: type[_NlMsgBase], /, attrs: dict = {}, header: dict = {},
|
|||||||
# support passing nested attributes as dicts of subattributes (or lists of those)
|
# support passing nested attributes as dicts of subattributes (or lists of those)
|
||||||
if prime["nla_array"]:
|
if prime["nla_array"]:
|
||||||
value = [
|
value = [
|
||||||
|
(
|
||||||
_build(nla_class, attrs=elem)
|
_build(nla_class, attrs=elem)
|
||||||
if not isinstance(elem, pyroute2.netlink.nlmsg_base) and isinstance(elem, dict)
|
if not isinstance(elem, pyroute2.netlink.nlmsg_base) and isinstance(elem, dict)
|
||||||
else elem
|
else elem
|
||||||
|
)
|
||||||
for elem in value
|
for elem in value
|
||||||
]
|
]
|
||||||
elif not isinstance(value, pyroute2.netlink.nlmsg_base) and isinstance(value, dict):
|
elif not isinstance(value, pyroute2.netlink.nlmsg_base) and isinstance(value, dict):
|
||||||
|
Loading…
Reference in New Issue
Block a user