Mechanical: ruff format, and ruff check --fix with the rule set every NAPALM driver uses (E, F, I, UP, B at line length 100, Python 3.10). Mapping and Iterable come from collections.abc, imports are sorted. What ruff cannot fix comes in the next commit.
43 lines
1.6 KiB
Python
43 lines
1.6 KiB
Python
"""LogServices and their entries (the SEL lives under Systems or Managers, by vendor)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from collections.abc import Mapping
|
|
from typing import Any
|
|
|
|
from .common import boolean, integer, link, status, text
|
|
|
|
|
|
def parse_log_service(service: Mapping[str, Any]) -> dict[str, Any]:
|
|
"""One member of ``.../LogServices``."""
|
|
state, health = status(service)
|
|
return {
|
|
"id": text(service.get("Id")),
|
|
"name": text(service.get("Name")),
|
|
"enabled": boolean(service.get("ServiceEnabled")),
|
|
"entries_path": link(service, "Entries"),
|
|
"max_records": integer(service.get("MaxNumberOfRecords")),
|
|
"overwrite_policy": text(service.get("OverWritePolicy")),
|
|
"entry_type": text(service.get("LogEntryType")),
|
|
"state": state,
|
|
"health": health,
|
|
}
|
|
|
|
|
|
def parse_log_entry(entry: Mapping[str, Any]) -> dict[str, Any]:
|
|
"""One LogEntry (SEL record or Redfish event)."""
|
|
args = entry.get("MessageArgs")
|
|
return {
|
|
"id": text(entry.get("Id")),
|
|
"created": text(entry.get("Created")),
|
|
"severity": text(entry.get("Severity")),
|
|
"message": text(entry.get("Message")),
|
|
"message_id": text(entry.get("MessageId")),
|
|
"message_args": [str(a) for a in args] if isinstance(args, list) else [],
|
|
"entry_type": text(entry.get("EntryType")),
|
|
"entry_code": text(entry.get("EntryCode")),
|
|
"sensor_type": text(entry.get("SensorType")),
|
|
"sensor_number": integer(entry.get("SensorNumber")),
|
|
"origin": link(entry, "Links", "OriginOfCondition"),
|
|
}
|