[Git][NTPsec/ntpsec][master] Cooked-variable display in ntpmon.
Eric S. Raymond
gitlab at mg.gitlab.com
Sat Dec 17 22:00:40 UTC 2016
Eric S. Raymond pushed to branch master at NTPsec / ntpsec
Commits:
9d7fc335 by Eric S. Raymond at 2016-12-17T16:59:35-05:00
Cooked-variable display in ntpmon.
- - - - -
3 changed files:
- ntpclients/ntpmon
- ntpclients/ntpq
- pylib/util.py
Changes:
=====================================
ntpclients/ntpmon
=====================================
--- a/ntpclients/ntpmon
+++ b/ntpclients/ntpmon
@@ -183,11 +183,12 @@ if __name__ == '__main__':
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))
+ stdscr.addstr("assoc=%d, %s,\n" \
+ % (peers[i].associd, sw))
vars = session.readvar(peers[i].associd,
[],
ntp.control.CTL_OP_READVAR)
- stdscr.addstr(str(vars))
+ stdscr.addstr(ntp.util.cook(vars))
elif span.entries:
stdscr.addstr(ntp.util.MRUSummary.header + "\n",
curses.A_BOLD)
=====================================
ntpclients/ntpq
=====================================
--- a/ntpclients/ntpq
+++ b/ntpclients/ntpq
@@ -399,63 +399,7 @@ usage: help [ command ]
self.say("status=%04x %s,\n" % \
(self.session.rstatus,
ntp.ntpc.statustoa(dtype, self.session.rstatus)))
-
- text = ""
- for (name, value) in variables.items():
- item = "%s=" % name
- if name in ("reftime", "clock", "org", "rec", "xmt"):
- item += ntp.ntpc.prettydate(value)
- elif name in ("srcadr", "peeradr", "dstadr", "refid"):
- # C ntpq cooked these in obscure ways. Since they
- # came up from the daemon as human-readable
- # strings this was probably a bad idea, but we'll
- # leave this case separated in case somebody thinks
- # re-cooking them is a good idea.
- item += value
- elif name == "leap":
- item += ("00", "01", "10", "11")[value]
- elif name == "reach":
- item += "%03lo" % value
- elif name in("filtdelay", "filtoffset", "filtdisp", "filterror"):
- item += "\t".join(value.split())
- elif name == "flash":
- item += "%02x" % value
- if value == 0:
- item += " ok"
- else:
- # flasher bits
- tstflagnames = (
- "pkt_dup", # BOGON1
- "pkt_bogus", # BOGON2
- "pkt_unsync", # BOGON3
- "pkt_denied", # BOGON4
- "pkt_auth", # BOGON5
- "pkt_stratum", # BOGON6
- "pkt_header", # BOGON7
- "pkt_autokey", # BOGON8
- "pkt_crypto", # BOGON9
- "peer_stratum", # BOGON10
- "peer_dist", # BOGON11
- "peer_loop", # BOGON12
- "peer_unreach" # BOGON13
- )
- for (i, n) in enumerate(tstflagnames):
- if (1 << i) & value:
- item += tstflagnames[i] + " "
- item = item[:-1]
- else:
- item += repr(value)
- item += ", "
- lastcount = 0
- for c in text:
- if c == '\n':
- lastcount = 0
- else:
- lastcount += 1
- if lastcount + len(item) > ntp.util.termsize().width - 2:
- text = text[:-1] + "\n"
- text += item
- text = text[:-2] + "\n"
+ text = ntp.util.cook(variables)
text = text.replace("'", '"')
self.say(text)
=====================================
pylib/util.py
=====================================
--- a/pylib/util.py
+++ b/pylib/util.py
@@ -164,7 +164,68 @@ class PeerStatusWord:
}
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__
+ return "conf=%(conf)s, reach=%(reach)s, auth=%(auth)s, cond=%(condition)s, event=%(last_event)s ec=%(event_count)s" % self.__dict__
+
+def cook(variables):
+ "Cooked-mode variable display."
+ width = ntp.util.termsize().width - 2
+ text = ""
+ for (name, value) in variables.items():
+ item = "%s=" % name
+ if name in ("reftime", "clock", "org", "rec", "xmt"):
+ item += ntp.ntpc.prettydate(value)
+ elif name in ("srcadr", "peeradr", "dstadr", "refid"):
+ # C ntpq cooked these in obscure ways. Since they
+ # came up from the daemon as human-readable
+ # strings this was probably a bad idea, but we'll
+ # leave this case separated in case somebody thinks
+ # re-cooking them is a good idea.
+ item += value
+ elif name == "leap":
+ item += ("00", "01", "10", "11")[value]
+ elif name == "reach":
+ item += "%03lo" % value
+ elif name in("filtdelay", "filtoffset", "filtdisp", "filterror"):
+ item += "\t".join(value.split())
+ elif name == "flash":
+ item += "%02x" % value
+ if value == 0:
+ item += " ok"
+ else:
+ # flasher bits
+ tstflagnames = (
+ "pkt_dup", # BOGON1
+ "pkt_bogus", # BOGON2
+ "pkt_unsync", # BOGON3
+ "pkt_denied", # BOGON4
+ "pkt_auth", # BOGON5
+ "pkt_stratum", # BOGON6
+ "pkt_header", # BOGON7
+ "pkt_autokey", # BOGON8
+ "pkt_crypto", # BOGON9
+ "peer_stratum", # BOGON10
+ "peer_dist", # BOGON11
+ "peer_loop", # BOGON12
+ "peer_unreach" # BOGON13
+ )
+ for (i, n) in enumerate(tstflagnames):
+ if (1 << i) & value:
+ item += tstflagnames[i] + " "
+ item = item[:-1]
+ else:
+ item += repr(value)
+ item += ", "
+ lastcount = 0
+ for c in text:
+ if c == '\n':
+ lastcount = 0
+ else:
+ lastcount += 1
+ if lastcount + len(item) > width:
+ text = text[:-1] + "\n"
+ text += item
+ text = text[:-2] + "\n"
+ return text
class PeerSummary:
"Reusable report generator for peer statistics"
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/9d7fc335d798b41fba04e0538dd46efd90dbe312
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20161217/3ba24272/attachment.html>
More information about the vc
mailing list