[Git][NTPsec/ntpsec][master] Show unpacked status flags in ntpmon detail display.

Eric S. Raymond gitlab at mg.gitlab.com
Sat Dec 17 20:43:30 UTC 2016


Eric S. Raymond pushed to branch master at NTPsec / ntpsec


Commits:
d013a9c6 by Eric S. Raymond at 2016-12-17T15:42:46-05:00
Show unpacked status flags in ntpmon detail display.

- - - - -


3 changed files:

- ntpclients/ntpmon
- ntpclients/ntpq
- pylib/util.py


Changes:

=====================================
ntpclients/ntpmon
=====================================
--- a/ntpclients/ntpmon
+++ b/ntpclients/ntpmon
@@ -182,6 +182,8 @@ if __name__ == '__main__':
                         sl = statline(peer_report, mru_report, nyquist)
                         stdscr.addstr(sl + "\n", curses.A_REVERSE|curses.A_DIM)
                         if detailmode:
+                            sw = ntp.util.PeerStatusWord(peers[i].status)
+                            stdscr.addstr("associd: %d %s\n" % (peers[i].associd, sw))
                             vars = session.readvar(peers[i].associd,
                                                    [],
                                                    ntp.control.CTL_OP_READVAR)


=====================================
ntpclients/ntpq
=====================================
--- a/ntpclients/ntpq
+++ b/ntpclients/ntpq
@@ -275,73 +275,12 @@ usage: help [ command ]
             statval = ntp.control.CTL_PEER_STATVAL(peer.status)
             if not showall and (statval & (ntp.control.CTL_PST_CONFIG|ntp.control.CTL_PST_REACH)) == 0:
                 continue
-            event = ntp.control.CTL_PEER_EVENT(peer.status)
-            event_count = ntp.control.CTL_PEER_NEVNT(peer.status)
-            if statval & ntp.control.CTL_PST_CONFIG:
-                conf = "yes"
-            else:
-                conf = "no"
-            if statval & ntp.control.CTL_PST_BCAST:
-                    reach = "none"
-                    if statval & ntp.control.CTL_PST_AUTHENABLE:
-                            auth = "yes"
-                    else:
-                            auth = "none"
-            elif statval & ntp.control.CTL_PST_REACH:
-                reach = "yes"
-            else:
-                reach = "no"
-            if (statval & ntp.control.CTL_PST_AUTHENABLE) == 0:
-                auth = "none"
-            elif statval & ntp.control.CTL_PST_AUTHENTIC:
-                auth = "ok "
-            else:
-                auth = "bad"
-            if self.pktversion > ntp.magic.NTP_OLDVERSION:
-                seldict = {
-                    ntp.control.CTL_PST_SEL_REJECT: "reject",
-                    ntp.control.CTL_PST_SEL_SANE: "falsetick",
-                    ntp.control.CTL_PST_SEL_CORRECT: "excess",
-                    ntp.control.CTL_PST_SEL_SELCAND: "outlier",
-                    ntp.control.CTL_PST_SEL_SYNCCAND: "candidate",
-                    ntp.control.CTL_PST_SEL_EXCESS: "backup",
-                    ntp.control.CTL_PST_SEL_SYSPEER: "sys.peer",
-                    ntp.control.CTL_PST_SEL_PPS: "pps.peer",
-                    }
-                condition = seldict[statval & 0x7]
-            else:
-                if (statval & 0x3) == OLD_CTL_PST_SEL_REJECT:
-                    if (statval & OLD_CTL_PST_SANE) == 0:
-                        condition = "insane"
-                    elif (statval & OLD_CTL_PST_DISP) == 0:
-                        condition = "hi_disp"
-                    else:
-                        condition = ""
-                elif (statval & 0x3) == OLD_CTL_PST_SEL_SELCAND:
-                        condition = "sel_cand"
-                elif (statval & 0x3) == OLD_CTL_PST_SEL_SYNCCAND:
-                    condition = "sync_cand"
-                elif (statval & 0x3) == OLD_CTL_PST_SEL_SYSPEER:
-                    condition = "sys_peer"
-            event_dict = {
-                ntp.magic.PEVNT_MOBIL: "mobilize",
-                ntp.magic.PEVNT_DEMOBIL: "demobilize",
-                ntp.magic.PEVNT_REACH: "reachable",
-                ntp.magic.PEVNT_UNREACH: "unreachable",
-                ntp.magic.PEVNT_RESTART: "restart",
-                ntp.magic.PEVNT_REPLY: "no_reply",
-                ntp.magic.PEVNT_RATE: "rate_exceeded",
-                ntp.magic.PEVNT_DENY: "access_denied",
-                ntp.magic.PEVNT_ARMED: "leap_armed",
-                ntp.magic.PEVNT_NEWPEER: "sys_peer",
-                ntp.magic.PEVNT_CLOCK: "clock_alarm",
-                }
-            last_event = event_dict.get(ntp.magic.PEER_EVENT|event, "")
+            sw = ntp.util.PeerStatusWord(peer.status)
             display = \
                      "%3d %5u  %04x   %3.3s  %4s  %4.4s %9.9s %11s %2lu" % \
                      (i + 1, peer.associd,
-                     peer.status, conf, reach, auth,
-                     condition, last_event, event_count)
+                     peer.status, sw.conf, sw.reach, sw.auth,
+                     sw.condition, sw.last_event, sw.event_count)
             self.say(display + "\n")
 
     def __dopeers(self, showall, mode):


=====================================
pylib/util.py
=====================================
--- a/pylib/util.py
+++ b/pylib/util.py
@@ -97,6 +97,75 @@ def termsize():
                 pass
     return TermSize(*size)
 
+class PeerStatusWord:
+    "A peer status wor dissected for display"
+    def __init__(self, status, pktversion=ntp.magic.NTP_VERSION):
+        self.event = ntp.control.CTL_PEER_EVENT(status)
+        self.event_count = ntp.control.CTL_PEER_NEVNT(status)
+        statval = ntp.control.CTL_PEER_STATVAL(status)
+        if statval & ntp.control.CTL_PST_CONFIG:
+            self.conf = "yes"
+        else:
+            self.conf = "no"
+        if statval & ntp.control.CTL_PST_BCAST:
+                self.reach = "none"
+                if statval & ntp.control.CTL_PST_AUTHENABLE:
+                        self.auth = "yes"
+                else:
+                        self.auth = "none"
+        elif statval & ntp.control.CTL_PST_REACH:
+            self.reach = "yes"
+        else:
+            self.reach = "no"
+        if (statval & ntp.control.CTL_PST_AUTHENABLE) == 0:
+            self.auth = "none"
+        elif statval & ntp.control.CTL_PST_AUTHENTIC:
+            self.auth = "ok "
+        else:
+            self.auth = "bad"
+        if pktversion > ntp.magic.NTP_OLDVERSION:
+            seldict = {
+                ntp.control.CTL_PST_SEL_REJECT: "reject",
+                ntp.control.CTL_PST_SEL_SANE: "falsetick",
+                ntp.control.CTL_PST_SEL_CORRECT: "excess",
+                ntp.control.CTL_PST_SEL_SELCAND: "outlier",
+                ntp.control.CTL_PST_SEL_SYNCCAND: "candidate",
+                ntp.control.CTL_PST_SEL_EXCESS: "backup",
+                ntp.control.CTL_PST_SEL_SYSPEER: "sys.peer",
+                ntp.control.CTL_PST_SEL_PPS: "pps.peer",
+                }
+            self.condition = seldict[statval & 0x7]
+        else:
+            if (statval & 0x3) == OLD_CTL_PST_SEL_REJECT:
+                if (statval & OLD_CTL_PST_SANE) == 0:
+                    self.condition = "insane"
+                elif (statval & OLD_CTL_PST_DISP) == 0:
+                    self.condition = "hi_disp"
+                else:
+                    self.condition = ""
+            elif (statval & 0x3) == OLD_CTL_PST_SEL_SELCAND:
+                    self.condition = "sel_cand"
+            elif (statval & 0x3) == OLD_CTL_PST_SEL_SYNCCAND:
+                self.condition = "sync_cand"
+            elif (statval & 0x3) == OLD_CTL_PST_SEL_SYSPEER:
+                self.condition = "sys_peer"
+        event_dict = {
+            ntp.magic.PEVNT_MOBIL: "mobilize",
+            ntp.magic.PEVNT_DEMOBIL: "demobilize",
+            ntp.magic.PEVNT_REACH: "reachable",
+            ntp.magic.PEVNT_UNREACH: "unreachable",
+            ntp.magic.PEVNT_RESTART: "restart",
+            ntp.magic.PEVNT_REPLY: "no_reply",
+            ntp.magic.PEVNT_RATE: "rate_exceeded",
+            ntp.magic.PEVNT_DENY: "access_denied",
+            ntp.magic.PEVNT_ARMED: "leap_armed",
+            ntp.magic.PEVNT_NEWPEER: "sys_peer",
+            ntp.magic.PEVNT_CLOCK: "clock_alarm",
+            }
+        self.last_event = event_dict.get(ntp.magic.PEER_EVENT|self.event, "")
+    def __str__(self):
+        return "conf=%(conf)s, reach=%(reach)s, auth=%(auth)s, cond=%(condition)s, last=%(last_event)s" % self.__dict__
+
 class PeerSummary:
     "Reusable report generator for peer statistics"
     def __init__(self, displaymode, pktversion, showhostnames, wideremote, termwidth=None, debug=0):



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/d013a9c61f424f349b4ef320e0cdb60e321b9098
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20161217/189890d7/attachment.html>


More information about the vc mailing list