[Git][NTPsec/ntpsec][master] 2 commits: Clean up for ntpsnmpd beta.

Ian Bruene gitlab at mg.gitlab.com
Fri Feb 16 16:27:32 UTC 2018


Ian Bruene pushed to branch master at NTPsec / ntpsec


Commits:
dc706df1 by Ian Bruene at 2018-02-16T09:46:12-06:00
Clean up for ntpsnmpd beta.

Extraneous comments and debugging statements removed
Daemonization fork restored
Off-by-one bug in dynamic MIB subtrees fixed

- - - - -
125dab26 by Ian Bruene at 2018-02-16T10:26:31-06:00
Added logfile and help options to ntpsnmpd.

- - - - -


2 changed files:

- docs/includes/ntpsnmpd-body.txt
- ntpclients/ntpsnmpd.py


Changes:

=====================================
docs/includes/ntpsnmpd-body.txt
=====================================
--- a/docs/includes/ntpsnmpd-body.txt
+++ b/docs/includes/ntpsnmpd-body.txt
@@ -20,6 +20,10 @@
   Increase debugging level by 1.
 +-D+ num, +--set-debug-level+=num::
   The debug level is set to the following integer argument.
++-l+ filename, +--logfile+=filename::
+  Log debugging output to the specified file.
++-h+, +--help+::
+  Print a usage message summarizing options end exit.
 +-V+, +--version+::
   Print the version string and exit.
 


=====================================
ntpclients/ntpsnmpd.py
=====================================
--- a/ntpclients/ntpsnmpd.py
+++ b/ntpclients/ntpsnmpd.py
@@ -28,7 +28,7 @@ ntp.util.deunicode_units()
 
 logfile = "ntpsnmpd.log"
 logfp = sys.stderr
-nofork = True  # don't daemonize while still under construction
+nofork = False
 debug = 0
 defaultTimeout = 30
 
@@ -389,7 +389,7 @@ class DataSource:  # This will be broken up in future to be less NTP-specific
         return self.readCallbackSkeletonSimple(oid, "precision",
                                                ax.VALUE_INTEGER)
 
-    def cbr_timeDistance(self, oid):  # DUMMY
+    def cbr_timeDistance(self, oid):
         # Displaystring
         data = self.safeReadvar(0, ["rootdist"], raw=True)
         if data is None:
@@ -844,7 +844,6 @@ class DataSource:  # This will be broken up in future to be less NTP-specific
 
         if self.notifyHeartbeat is True:
             self.doNotifyHeartbeat(control)
-        # Test code
 
     def doNotifyModeChange(self, control):
         oldMode = self.oldValues.get("mode")
@@ -1042,7 +1041,7 @@ class DataSource:  # This will be broken up in future to be less NTP-specific
             return (adds, rms)
         return
 
-    def misc_getMode(self):  # DUMMY: not fully implemented
+    def misc_getMode(self):  # FIXME: not fully implemented
         try:
             # Don't care about the data, this is a ploy to the the rstatus
             self.session.readvar(0, ["stratum"])
@@ -1098,12 +1097,13 @@ class DataSource:  # This will be broken up in future to be less NTP-specific
             # This function assumes that it is a leaf node and that the
             # last number in the OID is the index.
             index = oid.subids[-1]  # if called properly this works (Ha!)
+            index -= 1 # SNMP reserves index 0, effectively 1-based lists
             associd = self.misc_getPeerIDs()[index]
             return handler(oid, associd)
         subs = {}
         associds = self.misc_getPeerIDs()  # need the peer count
         for i in range(len(associds)):
-            subs[i] = ax.mibnode(readCallback, None, None, None)
+            subs[i+1] = ax.mibnode(readCallback, None, None, None)
         return subs
 
     def readCallbackSkeletonSimple(self, oid, varname, dataType):
@@ -1434,7 +1434,6 @@ class PacketControl:
         else:
             resp = ax.ResponsePDU(True, self.sessionID, packet.transactionID,
                                   packet.packetID, 0, ax.ERR_NOERROR, 0)
-        print("About to send:", resp)
         self.sendPacket(resp, False)
 
     def handle_UndoSetPDU(self, packet):
@@ -1527,8 +1526,10 @@ USAGE: ntpsnmpd [-n]
                                 - default /var/agentx/master
    -d no  debug-level     Increase output debug message level
                                 - may appear multiple times
+   -l Str logfile         Logs debug messages to the provided filename
    -D Int set-debug-level Set the output debug message level
                                 - may appear multiple times
+   -h no  help            Print a usage message.
    -V no  version         Output version information and exit
 """
 
@@ -1537,9 +1538,9 @@ if __name__ == "__main__":
     try:
         (options, arguments) = getopt.getopt(
             sys.argv[1:],
-            "nx:dD:V",
+            "nx:dD:Vhl",
             ["no-fork", "master-address", "debug-level", "set-debug-level",
-             "version"])
+             "version", "help", "logfile"])
     except getopt.GetoptError as e:
         sys.stderr.write("%s\n" % e)
         sys.stderr.write(usage)
@@ -1565,6 +1566,13 @@ if __name__ == "__main__":
         elif switch in ("-V", "--version"):
             print("ntpsnmpd %s" % ntp.util.stdversion())
             raise SystemExit(0)
+        elif switch in ("-h", "--help"):
+            print(usage)
+            raise SystemExit(0)
+        elif switch in ("-l", "--logfile"):
+            if logfp != sys.stderr:
+                logfp.close()
+            logfp = open(val, "a", 1)  # 1 => line buffered
 
     if nofork is True:
         mainloop(masterAddr)



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/115eb27336a3d4bae11259f22fa4960ff3742e58...125dab26c243028d858ae4e57a5ab5e7a0b331c1

---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/115eb27336a3d4bae11259f22fa4960ff3742e58...125dab26c243028d858ae4e57a5ab5e7a0b331c1
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20180216/ab709a6b/attachment.html>


More information about the vc mailing list