WAN: ticket sustained slowdowns; reboot drops no longer mean "unstable"
Lint / JS (eslint) (push) Successful in 11s
Lint / Python (flake8) (push) Successful in 1m28s
Lint / Notify on failure (push) Skipped
Lint / Deploy (push) Skipped
Security / Python Security (bandit) (push) Successful in 1m38s
Lint / Python (flake8) (pull_request) Successful in 57s
Test / Python Tests (pytest) (push) Successful in 1m20s
Lint / JS (eslint) (pull_request) Successful in 17s
Lint / Notify on failure (pull_request) Skipped
Lint / Deploy (pull_request) Skipped
Security / Python Security (bandit) (pull_request) Successful in 2m54s
Test / Python Tests (pytest) (pull_request) Successful in 3m9s

On 2026-11-23/24 the WAN was degraded for about 20 hours with no ticket,
and the only ticket came from the owner's reboot fixing it.

- wan_degraded (P2): half or more of the last 2 hours of UniFi WAN health
  periods slow, lossy or down. Closes with a recovery note once the last
  2 hours are at most a quarter bad. Mentions a slow ping from the modem.
- "WAN connection unstable" waits 10 minutes, then counts only drops that
  no modem restart explains (Smart Power, uptime reset, or the Restart
  modem button, folded into one restart when within 15 minutes).
- Both list the last 7 days of restarts and how long each lasted, and
  suggest asking AT&T for a replacement after 2+ restarts in a week.

Closes #58

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jaredandClaude Opus 5.5 committed 2026-11-23 23:51:26 -05:00
1 parent bba483bb05
commit a31437f2e5
5 files changed
+346 -17

No files matched your search

+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)