Flag hosts whose reported hostname differs from their registered name
A note on the dashboard row and host page, not a status change, so a token copied to the wrong machine is visible. Only the first DNS label is compared, ignoring case, since registered names are usually hostname -s and the agent reports hostname -f. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
313961d70b
commit
63ca790779
4 files changed
+49
-3
No files matched your search
@@ -34,6 +34,26 @@ class EvaluateTest(unittest.TestCase):
|
||||
self.assertEqual(s.level, "ok", s.reasons)
|
||||
self.assertEqual(s.reasons, [])
|
||||
|
||||
def test_hostname_mismatch_is_a_note_not_a_level(self):
|
||||
rep = report(reported_hostname="db01.example.internal")
|
||||
s = evaluate(NOW - 60, rep, NOW, CFG, "web01")
|
||||
self.assertEqual(s.level, "ok")
|
||||
self.assertEqual(len(s.reasons), 1)
|
||||
self.assertIn("registered as web01 but reports itself as db01.example.internal", s.reasons[0])
|
||||
# Same worst level as without the check.
|
||||
rep = report(reported_hostname="db01", reboot_required=True)
|
||||
self.assertEqual(evaluate(NOW - 60, rep, NOW, CFG, "web01").level, "reboot")
|
||||
|
||||
def test_hostname_match_is_lenient_and_optional(self):
|
||||
for registered, reported in (("web01", "web01.example.internal"), ("WEB01", "web01"),
|
||||
("web01.example.internal", "web01"), ("web01", "web01"),
|
||||
("web01", None)):
|
||||
with self.subTest(registered=registered, reported=reported):
|
||||
rep = report() if reported is None else report(reported_hostname=reported)
|
||||
self.assertEqual(evaluate(NOW - 60, rep, NOW, CFG, registered).reasons, [])
|
||||
# Without a registered name (alerts, history rows) nothing is compared.
|
||||
self.assertEqual(evaluate(NOW - 60, report(reported_hostname="db01"), NOW, CFG).reasons, [])
|
||||
|
||||
def test_never_reported(self):
|
||||
self.assertEqual(evaluate(None, None, NOW, CFG).level, "stale")
|
||||
|
||||
|
||||
Reference in new issue
Block a user