Mark host interfaces as unused
Lint / JS (eslint) (push) Successful in 44s
Lint / Python (flake8) (push) Successful in 1m40s
Lint / Notify on failure (push) Skipped
Lint / Deploy (push) Skipped
Security / Python Security (bandit) (push) Successful in 1m18s
Lint / JS (eslint) (pull_request) Successful in 10s
Security / Python Security (bandit) (pull_request) Successful in 1m13s
Test / Python Tests (pytest) (pull_request) Successful in 1m11s
Lint / Python (flake8) (pull_request) Successful in 50s
Test / Python Tests (pytest) (push) Successful in 1m1s
Lint / Notify on failure (pull_request) Skipped
Lint / Deploy (pull_request) Skipped
Lint / JS (eslint) (push) Successful in 44s
Lint / Python (flake8) (push) Successful in 1m40s
Lint / Notify on failure (push) Skipped
Lint / Deploy (push) Skipped
Security / Python Security (bandit) (push) Successful in 1m18s
Lint / JS (eslint) (pull_request) Successful in 10s
Security / Python Security (bandit) (pull_request) Successful in 1m13s
Test / Python Tests (pytest) (pull_request) Successful in 1m11s
Lint / Python (flake8) (pull_request) Successful in 50s
Test / Python Tests (pytest) (push) Successful in 1m1s
Lint / Notify on failure (pull_request) Skipped
Lint / Deploy (pull_request) Skipped
Ports that are never meant to be up (compute-storage-01 nic1-3, large1's spare NIC and USB adapter) kept their hosts "degraded" and were the source of tonight's false alerts. An admin can now mark an interface unused from the device page, with an optional reason. Unused interfaces raise no link-down alerts, don't count toward the cluster-wide alert or the host's status, and show greyed as "unused" on the dashboard, device page and rack. Marking one closes any open link-down alert on it without a recovery note. New table unused_interfaces, created with the cutsheet tables. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
aeb7a89e81
commit
3834546f38
9 files changed
+219
-14
No files matched your search
@@ -738,6 +738,15 @@ _CUTSHEET_SCHEMA = (
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
UNIQUE KEY uq_rack_name (name)
|
||||
) ENGINE=InnoDB""",
|
||||
# Host interfaces an admin has marked as not in use: no alerts, not counted in host status
|
||||
"""CREATE TABLE IF NOT EXISTS unused_interfaces (
|
||||
host VARCHAR(255) NOT NULL,
|
||||
iface VARCHAR(64) NOT NULL,
|
||||
reason VARCHAR(255) NOT NULL DEFAULT '',
|
||||
set_by VARCHAR(255) NOT NULL,
|
||||
set_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (host, iface)
|
||||
) ENGINE=InnoDB""",
|
||||
# Where a device lives in the asset inventory (HomeBox), set by hand on its Gandalf page
|
||||
"""CREATE TABLE IF NOT EXISTS device_links (
|
||||
name VARCHAR(255) NOT NULL PRIMARY KEY,
|
||||
@@ -1107,3 +1116,47 @@ def cutsheet_delete_rack(rack_id: int, user: str) -> bool:
|
||||
cur.execute('DELETE FROM cutsheet_racks WHERE id=%s', (rack_id,))
|
||||
_cs_log(cur, user, 'rack', rack_id, 'delete', f'Removed rack {before["name"]}', _cs_jsonable(before), None)
|
||||
return True
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Unused interfaces: ports an admin says aren't meant to be up
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def get_unused_interfaces() -> dict:
|
||||
"""{host: {iface: {'reason', 'set_by', 'set_at'}}}"""
|
||||
with get_conn() as conn:
|
||||
with conn.cursor() as cur:
|
||||
cur.execute('SELECT host, iface, reason, set_by, set_at FROM unused_interfaces')
|
||||
out: dict = {}
|
||||
for r in cur.fetchall():
|
||||
at = r['set_at'].isoformat() + 'Z' if hasattr(r['set_at'], 'isoformat') else r['set_at']
|
||||
out.setdefault(r['host'], {})[r['iface']] = {'reason': r['reason'], 'set_by': r['set_by'],
|
||||
'set_at': at}
|
||||
return out
|
||||
|
||||
|
||||
def set_unused_interface(host: str, iface: str, reason: str, user: str) -> None:
|
||||
"""Mark an interface unused and quietly close any link-down alert it has open.
|
||||
|
||||
The alert is resolved without a recovery note: nothing recovered, the port just isn't used.
|
||||
"""
|
||||
with get_conn() as conn:
|
||||
with conn.cursor() as cur:
|
||||
cur.execute(
|
||||
"""INSERT INTO unused_interfaces (host, iface, reason, set_by) VALUES (%s, %s, %s, %s)
|
||||
ON DUPLICATE KEY UPDATE reason=VALUES(reason), set_by=VALUES(set_by)""",
|
||||
(host, iface, reason, user),
|
||||
)
|
||||
cur.execute(
|
||||
"""UPDATE network_events SET resolved_at=NOW(), recovery_notified=1, last_seen=last_seen
|
||||
WHERE event_type='interface_down' AND target_name=%s AND target_detail=%s
|
||||
AND resolved_at IS NULL""",
|
||||
(host, iface),
|
||||
)
|
||||
|
||||
|
||||
def clear_unused_interface(host: str, iface: str) -> bool:
|
||||
with get_conn() as conn:
|
||||
with conn.cursor() as cur:
|
||||
cur.execute('DELETE FROM unused_interfaces WHERE host=%s AND iface=%s', (host, iface))
|
||||
return cur.rowcount > 0
|
||||
Reference in new issue
Block a user