WAN: ticket sustained slowdowns; reboot drops no longer mean "unstable" #60

Merged
jared merged 2 commits from wan-degradation into main 2026-11-23 23:58:12 -05:00
5 changed files with 363 additions and 17 deletions

No files matched your search

+10 -1
View File
@@ -432,7 +432,8 @@ swap or recabling.
| Rx power `rx_drift_db` or more below its 7-day median (≥`modem.failure_threshold`) | P3 |
| Modem pages unreadable, e.g. after a firmware update (≥`modem.failure_threshold`) | P3 |
| UniFi logs that Smart Power auto power-cycled the modem | P3 |
| UniFi logs that the WAN failed multiple times in 24 hours (at most one ticket a day) | P2 |
| UniFi logs that the WAN failed multiple times in 24 hours, and at least 2 of those drops aren't explained by a modem restart (decided 10 minutes later; at most one ticket a day) | P2 |
| Internet degraded: at least `modem.degraded_fraction` (default half) of the last 2 hours' 5 minute periods slow, lossy or down by UniFi's WAN health. Closes with a recovery note once the last 2 hours are at most a quarter bad. A modem restart resets it: only periods from 15 minutes after the latest restart count. | P2 |
| An installed cable doesn't match the cutsheet (wrong neighbor, no link, missing port, port conflict) for `cutsheet.mismatch_ticket_hours` | P4 |
A failed Pulse ping check counts as "unknown": it neither raises nor resolves `host_unreachable`.
@@ -513,6 +514,13 @@ Uptime comes from the System Information page without a login. Firmware 6.40 sho
(older firmware sent seconds; both are read). Uptime going backwards between polls records a restart, and
the panel shows it (*restarted ... by ...*).
**Restarts and the WAN tickets.** Gandalf folds every kind of restart into one history:
- Smart Power power-cycles from the UniFi log
- uptime resets, which catch a reboot from the AT&T app, the modem's own button or a power loss
- the Restart modem button
Entries within 15 minutes of each other count as one restart; a reboot that Smart Power then power-cycles mid-boot is common. The "WAN connection unstable" ticket waits 10 minutes for the uptime reset to show up, then ignores drops from 5 minutes before to 15 minutes after a restart, so a reboot's own drops no longer open it. Both WAN tickets list the last 7 days of restarts and how long each one lasted. After 2 or more restarts in a week, they suggest asking AT&T for a replacement modem.
Outages can be over between polls: two real ones lasted about two minutes against a 5 minute poll.
So WAN outages and modem restarts also come from the UniFi system log, and a drop in the modem's uptime
records a restart even if nothing logged it. A single short outage only appears in the panel's history.
@@ -700,6 +708,7 @@ Shared by both processes. Located in the working directory (`/var/www/html/prod/
| `modem.timeout` | Seconds to wait per status page (default: 10) |
| `modem.failure_threshold` | Consecutive failures before ticketing a modem alert (default: same as `failure_threshold`). Raise it if gateway reboots or automatic firmware updates cut tickets. |
| `modem.rx_drift_db` | Rx drop below the 7-day median that raises `fiber_rx_drift` (default: 3.0) |
| `modem.degraded_fraction` | Share of the last 2 hours' WAN health periods that must be slow, lossy or down to open `wan_degraded` (default: 0.5) |
| `modem.rx_drift_min_samples` | Readings required before drift alerts start (default: 288) |
| `uptime_kuma.url`, `.token`, `.maintenance_id` | Optional. Lets the Restart modem button switch an Uptime Kuma maintenance window on and off (Kuma 2.x, over its Socket.IO API). `token` is a Kuma session token, which works with a two-factor account and stops working if the Kuma password changes; `username` and `password` can be used instead for an account without two-factor login. Create the window once in Kuma with the *manual* strategy and the monitors a modem restart takes down, pause it, and put its id here. |
| `modem.access_code` | Optional. The gateway's Device Access Code (printed on its label). With it, Gandalf logs in to read NAT session counts and to ping from the gateway when the internet is slow (see WAN modem notes). Keep it only in `config.json`, which is git-ignored and mode 600. |
+105
View File
@@ -383,6 +383,111 @@ def quality_counts(periods: List[dict], since: float) -> Dict[str, int]:
return counts
# A sustained slowdown: half of the last two hours' 5 minute periods slow, lossy or down.
# It counts as over once the last two hours have at most a quarter of their periods bad,
# so one good stretch in the middle of a bad day doesn't close and reopen it.
DEGRADED_WINDOW_S = 7200
DEGRADED_FRACTION = 0.5
DEGRADED_MIN_PERIODS = 12
RECOVERED_WINDOW_S = 7200
RECOVERED_FRACTION = 0.25
def _bad_share(periods: List[dict], since: float) -> tuple:
counts = quality_counts(periods, since)
total = sum(counts.values())
return counts, total, (total - counts['ok']) / total if total else 0.0
def degradation(periods: List[dict], newest: float, fraction: float = DEGRADED_FRACTION) -> Optional[dict]:
"""{'latency', 'loss', 'down', 'bad', 'total'} over the last two hours if the WAN has
been degraded for most of them, else None. *newest* anchors the window (the newest
period's start), so a stale timeline can't look healthy or sick by the clock alone.
Needs at least an hour of periods to decide."""
counts, total, share = _bad_share(periods, newest - DEGRADED_WINDOW_S + QUALITY_PERIOD_S)
if total < DEGRADED_MIN_PERIODS or share < fraction:
return None
return dict(counts, bad=total - counts['ok'], total=total)
def recovered(periods: List[dict], newest: float) -> bool:
"""True once the last two hours have been mostly fine again."""
_counts, total, share = _bad_share(periods, newest - RECOVERED_WINDOW_S + QUALITY_PERIOD_S)
return total > 0 and share <= RECOVERED_FRACTION
# Restart entries this close together are one restart (a reboot, then Smart Power, say).
_EPISODE_GAP_S = 900
# WAN health from this long after a restart reflects the modem as it now runs.
RESTART_SETTLE_S = 900
def restart_episodes(history: dict, button: Optional[dict], since: float) -> List[dict]:
"""Modem restarts since *since*, oldest first: [{'at', 'by'}].
Folds together the UniFi log (Smart Power), uptime resets (any reboot, including one
from the AT&T app or the modem's own button) and Gandalf's Restart modem button.
Entries within 15 minutes of each other are one restart; 'by' names the most specific
cause seen: the Gandalf button, then Smart Power, then "outside Gandalf".
"""
entries = [(r['at'], 'smart power' if r.get('by') else 'outside') for r in history.get('restarts') or []
if isinstance(r.get('at'), (int, float))]
if button and isinstance(button.get('at'), (int, float)):
entries.append((button['at'], 'gandalf'))
rank = {'gandalf': 0, 'smart power': 1, 'outside': 2}
episodes: List[dict] = []
for at, by in sorted(entries):
if at < since:
continue
if episodes and at - episodes[-1]['last'] <= _EPISODE_GAP_S:
ep = episodes[-1]
ep['last'] = at
if rank[by] < rank[ep['by']]:
ep['by'] = by
else:
episodes.append({'at': at, 'last': at, 'by': by})
return [{'at': e['at'], 'by': e['by']} for e in episodes]
def unexplained_drops(outages: List[dict], episodes: List[dict], since: float) -> List[dict]:
"""WAN drops since *since* that a modem restart doesn't explain (a restart takes the
WAN down from a few minutes before its logged time to 15 minutes after)."""
def explained(o):
return any(e['at'] - 300 <= o['failed_at'] <= e['at'] + _EPISODE_GAP_S for e in episodes)
return [o for o in outages or []
if isinstance(o.get('failed_at'), (int, float)) and o['failed_at'] >= since and not explained(o)]
_RESTART_BY = {'gandalf': "Gandalf's Restart modem button", 'smart power': 'Smart Power power-cycled it',
'outside': 'restarted outside Gandalf (AT&T app, modem button or power)'}
def _span(seconds: float) -> str:
days, rest = divmod(int(seconds), 86400)
hours = rest // 3600
return f'{days} d {hours} h' if days else f'{hours} h {rest % 3600 // 60} min'
def restart_lines(episodes: List[dict], now: float) -> List[str]:
"""Markdown lines: each restart, and how long the connection went before the next one."""
lines = []
for i, e in enumerate(episodes):
when = time.strftime('%Y-%m-%d %H:%M UTC', time.gmtime(e['at']))
nxt = episodes[i + 1]['at'] if i + 1 < len(episodes) else None
after = (f', next restart {_span(nxt - e["at"])} later' if nxt
else f', {_span(now - e["at"])} ago')
lines.append(f'- {when}: {_RESTART_BY[e["by"]]}{after}')
return lines
def replacement_hint(episodes: List[dict]) -> str:
"""Advice when restarts keep being needed: two or more in a week."""
if len(episodes) >= 2:
return (f'The modem has needed {len(episodes)} restarts in the last 7 days. If each one only '
f'fixes it for a few days, ask AT&T for a replacement BGW320.')
return ''
# ---------------------------------------------------------------------------
# Logged-in checks, used only when an access code is configured. Two pages are
# read: the NAT table's session counts, and the Troubleshoot page's ping test,
+95 -15
View File
@@ -2020,11 +2020,13 @@ class NetworkMonitor:
actionable = modem_api.apply_wan_events(
history, [e for e in events if not modem_api.is_update_key(e['key'])])
# UniFi repeats "failed multiple times" per failure, so ticket it once a day at most.
# UniFi repeats "failed multiple times" per failure, so ticket it once a day at most,
# and decide a few minutes later: a modem reboot's own drops trigger it too, and the
# uptime reset that proves the reboot only shows once the modem answers again.
unstable = [e for e in actionable if e['key'] == modem_api.LOG_WAN_UNSTABLE]
ticket_unstable = bool(unstable) and now - history.get('unstable_ticketed_at', 0) >= 86400
if ticket_unstable:
history['unstable_ticketed_at'] = now
if (unstable and not history.get('unstable_pending_at')
and now - history.get('unstable_ticketed_at', 0) >= 86400):
history['unstable_pending_at'] = now
# Save first: a failed ticket call shouldn't replay these events next cycle.
db.set_state('wan_history', history)
@@ -2041,21 +2043,94 @@ class NetworkMonitor:
'The internet connection failed badly enough to trigger auto power-cycle. '
'Check the WAN / Fiber panel for outages around this time and Rx power for a drop.',
)
if ticket_unstable:
self._one_shot_ticket(
suppressions, 'wan_unstable',
'UniFi reports the WAN connection went down multiple times in the last 24 hours.',
'WAN connection unstable', '2',
'See the WAN history on the modem page. Repeated drops with healthy Rx power '
'point toward the provider or the modem rather than the fiber.',
)
UNSTABLE_DECIDE_AFTER_S = 600
def _collect_wan_quality(self) -> None:
def _restart_context(self, now: float) -> tuple:
"""(restart episodes in the last 7 days, markdown lines, replacement hint)."""
raw = db.get_state('modem_restart')
try:
button = json.loads(raw) if raw else None
except ValueError:
button = None
episodes = modem_api.restart_episodes(self._load_wan_history(), button, now - 7 * 86400)
return episodes, modem_api.restart_lines(episodes, now), modem_api.replacement_hint(episodes)
def _decide_unstable(self, suppressions: list) -> None:
"""Ticket UniFi's "WAN failed multiple times" only if drops remain that no modem
restart explains. A reboot (from the AT&T app, Smart Power or Gandalf) drops the WAN
once or twice by itself, and that alone used to open this ticket."""
history = self._load_wan_history()
pending = history.get('unstable_pending_at')
now = time.time()
if not pending or now - pending < self.UNSTABLE_DECIDE_AFTER_S:
return
history.pop('unstable_pending_at', None)
episodes, lines, hint = self._restart_context(now)
drops = modem_api.unexplained_drops(history.get('outages'), episodes, now - 86400)
if len(drops) < 2:
db.set_state('wan_history', history)
logger.info(f'WAN "failed multiple times" explained by modem restarts '
f'({len(drops)} other drop(s) in 24 h): no ticket')
return
history['unstable_ticketed_at'] = now
db.set_state('wan_history', history)
description = (f'UniFi reports the WAN connection went down multiple times in the last 24 hours: '
f'{len(drops)} drops not explained by a modem restart.')
if lines:
description += '\n\nModem restarts in the last 7 days:\n' + '\n'.join(lines)
self._one_shot_ticket(
suppressions, 'wan_unstable', description, 'WAN connection unstable', '2',
'See the WAN history on the modem page. Repeated drops with healthy Rx power '
'point toward the provider or the modem rather than the fiber.' + (f' {hint}' if hint else ''),
)
def _collect_wan_quality(self) -> Optional[dict]:
"""Store UniFi's WAN health timeline. If UniFi can't be read, the last copy stays
and goes stale, and the dashboard stops drawing conclusions from it."""
quality = modem_api.wan_quality(self.unifi.get_wan_dashboard(), time.time())
if quality is not None:
db.set_state('wan_quality', quality)
return quality
def _process_wan_degraded(self, quality: Optional[dict], suppressions: list) -> None:
"""Ticket a sustained slowdown: most of the last two hours slow, lossy or down by
UniFi's own measure. It closes, with a recovery note, once two hours are mostly fine."""
periods = (quality or {}).get('periods') or []
if not periods:
return # nothing fresh to judge by: leave any open alert as it is
newest = periods[-1]['ts']
episodes, lines, hint = self._restart_context(time.time())
if episodes:
# A restart resets the judgement: only what came after it (once it has settled)
# counts, so a slowdown it fixed neither opens a ticket nor holds one open.
periods = [p for p in periods if p['ts'] >= episodes[-1]['at'] + modem_api.RESTART_SETTLE_S]
if not periods:
return
fraction = float((self.cfg.get('modem') or {}).get('degraded_fraction', modem_api.DEGRADED_FRACTION))
bad = modem_api.degradation(periods, newest, fraction)
if bad is None:
if modem_api.recovered(periods, newest):
db.resolve_event('wan_degraded', self.modem_name, '')
return
parts = [f'{bad[s]} {s}' for s in ('latency', 'loss', 'down') if bad[s]]
description = (f'The internet has been degraded for most of the last 2 hours: {bad["bad"]} of '
f'{bad["total"]} five-minute periods had {", ".join(parts)} (UniFi WAN health).')
try:
raw = db.get_state('modem_checks')
ping = ((json.loads(raw) if isinstance(raw, str) else raw) or {}).get('ping') or {}
except (ValueError, AttributeError):
ping = {}
if ping.get('verdict') == 'gateway':
description += (f' A ping from the modem itself was slow too (avg {ping.get("avg_ms")} ms), '
f'so the modem or the line past it is the slow hop, not the LAN.')
if lines:
description += '\n\nModem restarts in the last 7 days:\n' + '\n'.join(lines)
advice = ('Restart the modem from the WAN / Fiber panel (Restart modem): it silences Gandalf '
'and Uptime Kuma while it reboots.')
if hint:
advice += f' {hint}'
self._modem_event(suppressions, 'wan_degraded', 'warning', '', description,
'Internet degraded (high latency or packet loss)', '2', advice)
_RESTART_SETTLE_S = 180 # the modem answering this soon may not have restarted yet
_RESTART_GIVE_UP_S = 1800
@@ -2366,12 +2441,17 @@ class NetworkMonitor:
with self._wan_batch():
self._process_wan_log(suppressions)
self._collect_modem(suppressions)
self._decide_unstable(suppressions)
except Exception as e:
logger.error(f'Modem collection failed: {e}', exc_info=True)
# Internet quality as UniFi measures it (latency, loss, drops): for the dashboard
# Internet quality as UniFi measures it (latency, loss, drops): for the
# dashboard, and a ticket when it stays bad
try:
self._collect_wan_quality()
quality = self._collect_wan_quality()
if self.modem:
with self._wan_batch():
self._process_wan_degraded(quality, suppressions)
except Exception as e:
logger.error(f'WAN quality collection failed: {e}', exc_info=True)
+53
View File
@@ -558,3 +558,56 @@ class TestModemRestart:
a.session.post = MagicMock(return_value=MagicMock(status_code=200, text=LOGIN_FORM))
with pytest.raises(modem.ModemDataInvalid, match='not started'):
a.restart()
class TestRestartEpisodes:
def test_reboot_then_smart_power_is_one_restart(self):
h = {'restarts': [{'at': 1000, 'by': None}, {'at': 1200, 'by': 'RPDU'}, {'at': 1590, 'by': 'RPDU'}]}
assert modem.restart_episodes(h, None, 0) == [{'at': 1000, 'by': 'smart power'}]
def test_gandalf_button_names_the_restart(self):
h = {'restarts': [{'at': 1100, 'by': 'RPDU'}]}
assert modem.restart_episodes(h, {'at': 1000}, 0) == [{'at': 1000, 'by': 'gandalf'}]
def test_separate_days_are_separate_restarts(self):
h = {'restarts': [{'at': 1000, 'by': None}, {'at': 1000 + 86400, 'by': None}]}
assert len(modem.restart_episodes(h, None, 0)) == 2
def test_older_than_since_is_left_out(self):
assert modem.restart_episodes({'restarts': [{'at': 10, 'by': None}]}, None, 100) == []
def test_unexplained_drops(self):
eps = [{'at': 1000, 'by': 'outside'}]
outs = [{'failed_at': 800}, {'failed_at': 1800}, {'failed_at': 5000}, {'failed_at': 50}]
assert modem.unexplained_drops(outs, eps, 100) == [{'failed_at': 5000}]
def test_lines_and_hint(self):
eps = [{'at': 0, 'by': 'gandalf'}, {'at': 3 * 86400 + 4 * 3600, 'by': 'outside'}]
lines = modem.restart_lines(eps, 3 * 86400 + 5 * 3600)
assert lines[0].endswith("Gandalf's Restart modem button, next restart 3 d 4 h later")
assert lines[1].endswith('restarted outside Gandalf (AT&T app, modem button or power), 1 h 0 min ago')
assert 'replacement BGW320' in modem.replacement_hint(eps)
assert modem.replacement_hint(eps[:1]) == ''
class TestDegradation:
def periods(self, states, end=10000.0):
return [{'ts': end - (len(states) - 1 - i) * 300, 'state': s} for i, s in enumerate(states)]
def test_half_of_two_hours_is_degraded(self):
d = modem.degradation(self.periods(['ok'] * 12 + ['loss'] * 12), 10000.0)
assert d['bad'] == 12 and d['total'] == 24 and d['loss'] == 12
def test_under_half_is_not(self):
assert modem.degradation(self.periods(['ok'] * 13 + ['loss'] * 11), 10000.0) is None
def test_needs_an_hour_of_data(self):
assert modem.degradation(self.periods(['loss'] * 6), 10000.0) is None
def test_window_ignores_older_periods(self):
assert modem.degradation(self.periods(['loss'] * 30 + ['ok'] * 24), 10000.0 + 0) is None
def test_recovered(self):
assert modem.recovered(self.periods(['loss'] * 12 + ['ok'] * 18 + ['latency'] * 6), 10000.0)
assert modem.recovered(self.periods(['loss'] * 6 + ['ok'] * 18), 10000.0) # exactly a quarter
assert not modem.recovered(self.periods(['latency'] * 7 + ['ok'] * 17), 10000.0)
+100 -1
View File
@@ -475,13 +475,62 @@ class TestWanLog:
mon._process_wan_log([])
assert not mon.tickets.create.called
def test_unstable_wan_tickets_after_a_day(self, mon, db):
def test_unstable_wan_waits_before_deciding(self, mon, db):
now = time.time()
self._state(db, unifi_log_cursor=str(int(now * 1000)))
self._mon(mon, [{'key': modem_api.LOG_WAN_UNSTABLE, 'ts': now, 'device': 'UDM', 'wan': 'WAN1'}])
mon._process_wan_log([])
assert not mon.tickets.create.called
saved = dict((c.args[0], c.args[1]) for c in db.set_state.call_args_list)
assert saved['wan_history']['unstable_pending_at'] >= now
def _decide(self, mon, db, outages, restarts, button=None, pending_age=700):
now = time.time()
history = {'outages': outages, 'restarts': restarts, 'unstable_pending_at': now - pending_age}
self._state(db, wan_history=json.dumps(history),
modem_restart=json.dumps(button) if button else None)
mon._decide_unstable([])
return now
def test_drops_with_no_restart_ticket_after_the_wait(self, mon, db):
now = time.time()
self._decide(mon, db, [{'failed_at': now - 5000}, {'failed_at': now - 900}], [])
assert 'unstable' in mon.tickets.create.call_args.args[0]
def test_not_decided_before_the_wait(self, mon, db):
now = time.time()
self._decide(mon, db, [{'failed_at': now - 5000}, {'failed_at': now - 900}], [], pending_age=60)
assert not mon.tickets.create.called
def test_reboot_drops_alone_open_no_ticket(self, mon, db):
# 2026-11-24: an AT&T-app reboot, Smart Power cycling it twice, two short drops
now = time.time()
boot = now - 1500
self._decide(mon, db,
[{'failed_at': boot + 180}, {'failed_at': boot + 600}],
[{'at': boot, 'by': 'RPDU', 'confirmed': True},
{'at': boot + 386, 'by': 'RPDU', 'confirmed': False}])
assert not mon.tickets.create.called
saved = dict((c.args[0], c.args[1]) for c in db.set_state.call_args_list)
assert 'unstable_pending_at' not in saved['wan_history']
def test_restart_by_gandalf_button_explains_its_drop(self, mon, db):
now = time.time()
self._decide(mon, db, [{'failed_at': now - 1200}, {'failed_at': now - 50000}], [],
button={'at': now - 1300})
assert not mon.tickets.create.called
def test_ticket_lists_restarts_and_suggests_replacement(self, mon, db):
now = time.time()
self._decide(mon, db,
[{'failed_at': now - 20000}, {'failed_at': now - 10000}, {'failed_at': now - 900}],
[{'at': now - 3 * 86400, 'by': None, 'confirmed': True},
{'at': now - 1200 - 2 * 86400, 'by': 'RPDU', 'confirmed': True}])
desc = mon.tickets.create.call_args.args[1]
assert 'Modem restarts in the last 7 days' in desc
assert 'restarted outside Gandalf' in desc and 'Smart Power power-cycled it' in desc
assert 'replacement BGW320' in desc
def test_suppression_blocks_one_shot_ticket(self, mon, db):
now = time.time()
db.check_suppressed.return_value = True
@@ -1157,6 +1206,56 @@ class TestWanQualityCollection:
assert c.get_wan_dashboard() is None
def _timeline(states, end=100000.0):
"""WAN quality periods ending at *end*, one per state, 5 minutes apart."""
return {'periods': [{'ts': end - (len(states) - 1 - i) * 300, 'state': s} for i, s in enumerate(states)]}
class TestWanDegraded:
"""2026-11-23/24: about 20 hours of latency and loss with no ticket (gandalf#58)."""
def test_two_bad_hours_open_a_ticket(self, mon, db):
mon._process_wan_degraded(_timeline(['latency'] * 14 + ['ok'] * 6 + ['loss'] * 4), [])
assert ('wan_degraded', 'att-modem', '') in upserted(db)
title, desc = mon.tickets.create.call_args.args[:2]
assert 'Internet degraded' in title
assert '18 of 24 five-minute periods had 14 latency, 4 loss' in desc
assert 'Restart modem' in desc
def test_odd_slow_periods_do_nothing(self, mon, db):
mon._process_wan_degraded(_timeline(['ok'] * 20 + ['latency'] * 4), [])
assert not db.upsert_event.called
assert not mon.tickets.create.called
def test_mostly_fine_hour_resolves(self, mon, db):
mon._process_wan_degraded(_timeline(['latency'] * 12 + ['ok'] * 20 + ['latency'] * 4), [])
db.resolve_event.assert_called_with('wan_degraded', 'att-modem', '')
def test_in_between_leaves_it_open(self, mon, db):
# 9 of the last 24 bad: under half, but over a quarter, so no change either way
mon._process_wan_degraded(_timeline(['ok'] * 15 + ['latency'] * 9), [])
assert not db.upsert_event.called and not db.resolve_event.called
def test_no_timeline_leaves_it_alone(self, mon, db):
mon._process_wan_degraded(None, [])
assert not db.upsert_event.called and not db.resolve_event.called
def test_a_restart_resets_the_judgement(self, mon, db):
# 2026-11-24: hours of loss, then a reboot 50 minutes ago, fine since
end = time.time()
history = json.dumps({'outages': [], 'restarts': [{'at': end - 3000, 'by': None}]})
db.get_state.side_effect = lambda k, d=None: history if k == 'wan_history' else None
mon._process_wan_degraded(_timeline(['loss'] * 16 + ['down'] * 2 + ['ok'] * 6, end), [])
assert not db.upsert_event.called
db.resolve_event.assert_called_with('wan_degraded', 'att-modem', '')
def test_slow_ping_from_the_modem_is_mentioned(self, mon, db):
checks = json.dumps({'ping': {'verdict': 'gateway', 'avg_ms': 1154}})
db.get_state.side_effect = lambda k, d=None: checks if k == 'modem_checks' else None
mon._process_wan_degraded(_timeline(['loss'] * 24), [])
assert 'ping from the modem itself was slow too (avg 1154 ms)' in mon.tickets.create.call_args.args[1]
class TestModemChecks:
NOW = 1_000_000.0