[Git][NTPsec/ntpsec][master] 2 commits: ntpsnmpd documentation update.

Ian Bruene gitlab at mg.gitlab.com
Sun Feb 25 20:47:48 UTC 2018


Ian Bruene pushed to branch master at NTPsec / ntpsec


Commits:
38c45c0f by Ian Bruene at 2018-02-25T14:47:06-06:00
ntpsnmpd documentation update.

- - - - -
31a9d208 by Ian Bruene at 2018-02-25T14:47:06-06:00
Added configuration loading 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
@@ -33,9 +33,10 @@ running NTP and SNMP daemons for ntpsnmpd to work.
 
 == Known Limitations ==
 
-This is a prototype. Parts of the AgentX standard are not yet implemented.
+This is still a prototype. Parts of the AgentX standard are not yet fully
+implemented.
 
-== Known Deviations from the MIB ==
+== Known Deviations from RFC 5907 ==
 
 The ntpEntStatusEntityUptime OID specifies a bizzare time formant. This
 does not match what the SNMP tools expect to see from a TimeTicks variable.
@@ -43,7 +44,7 @@ Instead the daemon returns a normal TimeTicks value.
 
 The ntpEntNotifConfigChanged trap is left unimplemented. This is because
 there currently is no way to implement what it wants, and it demands alerts
-regarding changes that are not part of NTPs jurisdiction.
+regarding changes that are not part of NTP's jurisdiction.
 
 The ntpEntTimeResolution OID currently uses data from the sys_fuzz variable
 as the base for it's calculations. It is by no means certain that this is


=====================================
ntpclients/ntpsnmpd.py
=====================================
--- a/ntpclients/ntpsnmpd.py
+++ b/ntpclients/ntpsnmpd.py
@@ -10,6 +10,7 @@ import time
 import socket
 import select
 import subprocess
+import shlex
 
 try:
     import ntp.packet
@@ -29,7 +30,6 @@ print("PC:", PacketControl)
 # TODO This is either necessary, or a different workaround is.
 ntp.util.deunicode_units()
 
-logfile = "ntpsnmpd.log"
 logfp = sys.stderr
 nofork = False
 debug = 0
@@ -41,6 +41,7 @@ snmpTrapOID = (1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0)
 snmpSysUptime = (1, 3, 6, 1, 2, 1, 1, 3, 0)
 
 DEFHOST = "localhost"
+DEFLOG = "ntpsnmpd.log"
 
 
 class DataSource(ntp.agentx.MIBControl):
@@ -1086,6 +1087,35 @@ def daemonize(runfunc, *runArgs):
     runfunc(*runArgs)
 
 
+optionList = ["master-address", "logfile", "ntp-address"]
+
+def loadSettings(filename, optionList):
+    if os.path.isfile(filename) is False:
+        return None
+    options = {}
+    with open(filename) as f:
+        data = f.read()
+        parser = shlex.shlex(data)
+        data = [x for x in parser]
+        i = 0
+        dataLen = len(data)
+        while i < dataLen:
+            if data[i] in optionList:
+                options[data[i]] = data[i+1]
+                i += 1
+            i += 1
+    return options
+
+
+def storeSettings(filename, options):
+    data = []
+    for key in options.keys():
+        data.append("%s %s\n" % (key, options[key]))
+    data = "".join(data)
+    with open(filename, "w") as f:
+        f.write(data)
+
+
 usage = """
 USAGE: ntpsnmpd [-n] [ntp host]
   Flg Arg Option-Name   Description
@@ -1114,11 +1144,24 @@ if __name__ == "__main__":
         sys.stderr.write(usage)
         raise SystemExit(1)
 
-    masterAddr = "/var/agentx/master"  # Default NET-SNMP configuration
+    masterAddr = "/var/agentx/master"
+    logfile = DEFLOG
+    hostname = DEFHOST
+    # Load configuration file
+    conf = loadSettings("/etc/ntpsnmpd.conf",
+                        ("master-addr", "logfile", "ntp-addr"))
+    if conf is not None:
+        for key in conf.keys():
+            if key == "master-addr":
+                masterAddr = conf[key]
+            elif key == "logfile":
+                logfile = conf[key]
+            elif key == "ntp-addr":
+                hostname = conf[key]
+
     fileLogging = False
     for (switch, val) in options:
         if switch in ("-n", "--no-fork"):
-            # currently non functional, as nofork is inited to True
             nofork = True
         elif switch in ("-x", "--master-addr"):
             if ":" in val:
@@ -1142,10 +1185,10 @@ if __name__ == "__main__":
             logfile = val
             fileLogging = True
 
-        if fileLogging is True:
-            if logfp != sys.stderr:
-                logfp.close()
-            logfp = open(val, "a", 1)  # 1 => line buffered
+    if fileLogging is True:
+        if logfp != sys.stderr:
+            logfp.close()
+        logfp = open(logfile, "a", 1)  # 1 => line buffered
 
     hostname = arguments[0] if arguments else DEFHOST
 



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/3703251c18d4dfd4c1b5c334875d4f7392d4789a...31a9d20825416d77485751458a738009cd4f2ecc

---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/3703251c18d4dfd4c1b5c334875d4f7392d4789a...31a9d20825416d77485751458a738009cd4f2ecc
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/20180225/7ec02aee/attachment.html>


More information about the vc mailing list