[Git][NTPsec/ntpsec][master] In pyntpq, ifstats listing now works.
Eric S. Raymond
gitlab at mg.gitlab.com
Thu Nov 3 18:03:38 UTC 2016
Eric S. Raymond pushed to branch master at NTPsec / ntpsec
Commits:
f3a163fd by Eric S. Raymond at 2016-11-03T13:01:44-04:00
In pyntpq, ifstats listing now works.
- - - - -
3 changed files:
- ntpq/pyntpq
- pylib/packet.py
- pylib/util.py
Changes:
=====================================
ntpq/pyntpq
=====================================
--- a/ntpq/pyntpq
+++ b/ntpq/pyntpq
@@ -1227,12 +1227,15 @@ usage: mrulist [ tag=value ] [ tag=value ] [ tag=value ] [ tag=value ]
"show statistics for each local address ntpd is using"
try:
self.session.password()
- entries = self.session.ifstat()
- formatter = IfstatSummary()
- self.say(IfstatSummary.header)
- self.say(("=" * IfstatSummary.width) + "\n")
- for entry in entries:
- self.say(formatter.summary(entry) + "\n")
+ entries = self.session.ifstats()
+ if self.rawmode:
+ print(self.session.response)
+ else:
+ formatter = IfstatsSummary()
+ self.say(IfstatsSummary.header)
+ self.say(("=" * IfstatsSummary.width) + "\n")
+ for (i, entry) in enumerate(entries):
+ self.say(formatter.summary(i, entry))
except Mode6Exception as e:
self.warn(e.message + "\n")
return
@@ -1249,11 +1252,14 @@ usage: ifstats
try:
self.session.password()
entries = self.session.reslist()
- formatter = ReslistSummary()
- self.say(ReslistSummary.header)
- self.say(("=" * ReslistSummary.width) + "\n")
- for entry in entries:
- self.say(formatter.summary(entry))
+ if self.rawmode:
+ print(self.session.response)
+ else:
+ formatter = ReslistSummary()
+ self.say(ReslistSummary.header)
+ self.say(("=" * ReslistSummary.width) + "\n")
+ for entry in entries:
+ self.say(formatter.summary(entry))
except Mode6Exception as e:
self.warn(e.message + "\n")
return
=====================================
pylib/packet.py
=====================================
--- a/pylib/packet.py
+++ b/pylib/packet.py
@@ -975,6 +975,6 @@ class Mode6Session:
def ifstats(self):
"Retrieve ifstats data."
- print(self.__ordlist("ifstats"))
+ return self.__ordlist("ifstats")
# end
=====================================
pylib/util.py
=====================================
--- a/pylib/util.py
+++ b/pylib/util.py
@@ -339,7 +339,37 @@ class ReslistSummary:
# want to make ntpd stop generating garbage
for c in s:
if not c.isalnum() and not c in "/.: \n":
- print("Failed on %s" % repr(c))
+ return ''
+ return s
+
+class IfstatsSummary:
+ "Reusable class for ifstats entry summary generation."
+ header = """\
+ interface name send
+ # address/broadcast drop flag ttl mc received sent failed peers uptime
+ """
+ width = 72
+ def summary(self, i, variables):
+ try:
+ s = "%3u %-24.24s %c %4x %3d %2d %6d %6d %6d %5d %8d\n %s\n" % \
+ (i, variables['name'],
+ '.' if variables['en'] else 'D',
+ variables.get('flags', '?'),
+ variables.get('tl', '?'),
+ variables.get('mc', '?'),
+ variables.get('rx', '?'),
+ variables.get('tx', '?'),
+ variables.get('txerr', '?'),
+ variables.get('pc', '?'),
+ variables.get('up', '?'),
+ variables.get('addr', '?'))
+ if variables.get("bcast"):
+ s += " %s\n" % variables['bcast']
+ except TypeError:
+ # Can happen when ntpd ships a corrupted response
+ return ''
+ for c in s:
+ if not c.isalnum() and not c in "/.:[] \n":
return ''
return s
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/f3a163fdfb50e98f8ab34c721e4749701bfea1f6
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20161103/1d8370b8/attachment.html>
More information about the vc
mailing list