downgrade from pyagentx3 to pyagentx, Debian Bookworm provide only the old variant
This commit is contained in:
parent
2751e7c005
commit
041108603c
@ -55,13 +55,6 @@ rootdisp OBJECT-TYPE
|
|||||||
DESCRIPTION "Root Dispersion in Millisekunden."
|
DESCRIPTION "Root Dispersion in Millisekunden."
|
||||||
::= { local 5 }
|
::= { local 5 }
|
||||||
|
|
||||||
rootdist OBJECT-TYPE
|
|
||||||
SYNTAX INTEGER
|
|
||||||
MAX-ACCESS read-only
|
|
||||||
STATUS current
|
|
||||||
DESCRIPTION "Root Distance in Millisekunden."
|
|
||||||
::= { local 6 }
|
|
||||||
|
|
||||||
refid OBJECT-TYPE
|
refid OBJECT-TYPE
|
||||||
SYNTAX DisplayString
|
SYNTAX DisplayString
|
||||||
MAX-ACCESS read-only
|
MAX-ACCESS read-only
|
||||||
@ -97,13 +90,6 @@ system OBJECT-TYPE
|
|||||||
DESCRIPTION "Systemtyp."
|
DESCRIPTION "Systemtyp."
|
||||||
::= { local 17 }
|
::= { local 17 }
|
||||||
|
|
||||||
release OBJECT-TYPE
|
|
||||||
SYNTAX DisplayString
|
|
||||||
MAX-ACCESS read-only
|
|
||||||
STATUS current
|
|
||||||
DESCRIPTION "Betriebssystem-Release-Version."
|
|
||||||
::= { local 18 }
|
|
||||||
|
|
||||||
version OBJECT-TYPE
|
version OBJECT-TYPE
|
||||||
SYNTAX DisplayString
|
SYNTAX DisplayString
|
||||||
MAX-ACCESS read-only
|
MAX-ACCESS read-only
|
||||||
|
@ -9,8 +9,7 @@ import pwd
|
|||||||
import grp
|
import grp
|
||||||
import logging
|
import logging
|
||||||
import logging.handlers
|
import logging.handlers
|
||||||
import pyagentx3
|
import pyagentx
|
||||||
import ipaddress
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -41,68 +40,70 @@ def pass_value(x):
|
|||||||
return x
|
return x
|
||||||
|
|
||||||
LOCAL_SERVER_KEYS = [
|
LOCAL_SERVER_KEYS = [
|
||||||
['leap', pyagentx3.TYPE_INTEGER, pass_value],
|
['leap', pyagentx.TYPE_INTEGER, pass_value],
|
||||||
['stratum', pyagentx3.TYPE_INTEGER, pass_value],
|
['stratum', pyagentx.TYPE_INTEGER, pass_value],
|
||||||
['precision', pyagentx3.TYPE_INTEGER, pass_value],
|
['precision', pyagentx.TYPE_INTEGER, pass_value],
|
||||||
['rootdelay', pyagentx3.TYPE_INTEGER, int_scale1k],
|
['rootdelay', pyagentx.TYPE_INTEGER, int_scale1k],
|
||||||
['rootdisp', pyagentx3.TYPE_INTEGER, int_scale1k],
|
['rootdisp', pyagentx.TYPE_INTEGER, int_scale1k],
|
||||||
['rootdist', pyagentx3.TYPE_INTEGER, int_scale1k],
|
# ['rootdist', pyagentx.TYPE_INTEGER, int_scale1k],
|
||||||
['refid', pyagentx3.TYPE_OCTETSTRING, pass_value],
|
['refid', pyagentx.TYPE_OCTETSTRING, pass_value],
|
||||||
['reftime', pyagentx3.TYPE_OCTETSTRING, pass_value],
|
['reftime', pyagentx.TYPE_OCTETSTRING, pass_value],
|
||||||
['tc', pyagentx3.TYPE_INTEGER, pass_value],
|
['tc', pyagentx.TYPE_INTEGER, pass_value],
|
||||||
['peer', pyagentx3.TYPE_INTEGER, pass_value],
|
['peer', pyagentx.TYPE_INTEGER, pass_value],
|
||||||
['offset', pyagentx3.TYPE_INTEGER, int_scale1M],
|
['offset', pyagentx.TYPE_INTEGER, int_scale1M],
|
||||||
['frequency', pyagentx3.TYPE_INTEGER, int_scale1k],
|
['frequency', pyagentx.TYPE_INTEGER, int_scale1k],
|
||||||
['sys_jitter', pyagentx3.TYPE_INTEGER, int_scale1M],
|
['sys_jitter', pyagentx.TYPE_INTEGER, int_scale1M],
|
||||||
['clk_jitter', pyagentx3.TYPE_INTEGER, int_scale1M],
|
['clk_jitter', pyagentx.TYPE_INTEGER, int_scale1M],
|
||||||
['clock', pyagentx3.TYPE_OCTETSTRING, pass_value],
|
['clock', pyagentx.TYPE_OCTETSTRING, pass_value],
|
||||||
['processor', pyagentx3.TYPE_OCTETSTRING, pass_value],
|
['processor', pyagentx.TYPE_OCTETSTRING, pass_value],
|
||||||
['system', pyagentx3.TYPE_OCTETSTRING, pass_value],
|
['system', pyagentx.TYPE_OCTETSTRING, pass_value],
|
||||||
['release', pyagentx3.TYPE_OCTETSTRING, pass_value],
|
# ['release', pyagentx.TYPE_OCTETSTRING, pass_value],
|
||||||
['version', pyagentx3.TYPE_OCTETSTRING, pass_value],
|
['version', pyagentx.TYPE_OCTETSTRING, pass_value],
|
||||||
['clk_wander', pyagentx3.TYPE_INTEGER, int_scale1M],
|
['clk_wander', pyagentx.TYPE_INTEGER, int_scale1M],
|
||||||
['daemon_version', pyagentx3.TYPE_OCTETSTRING, pass_value],
|
# ['daemon_version', pyagentx.TYPE_OCTETSTRING, pass_value],
|
||||||
['tai', pyagentx3.TYPE_INTEGER, pass_value],
|
['tai', pyagentx.TYPE_INTEGER, pass_value],
|
||||||
['leapsec', pyagentx3.TYPE_OCTETSTRING, pass_value],
|
['leapsec', pyagentx.TYPE_OCTETSTRING, pass_value],
|
||||||
['expire', pyagentx3.TYPE_OCTETSTRING, pass_value],
|
['expire', pyagentx.TYPE_OCTETSTRING, pass_value],
|
||||||
['mintc', pyagentx3.TYPE_INTEGER, pass_value]
|
['mintc', pyagentx.TYPE_INTEGER, pass_value]
|
||||||
]
|
]
|
||||||
|
|
||||||
PEER_KEYS = [
|
PEER_KEYS = [
|
||||||
['srcadr', pyagentx3.TYPE_IPADDRESS, ipaddress.ip_address],
|
['srcadr', pyagentx.TYPE_IPADDRESS, pass_value],
|
||||||
['srcport', pyagentx3.TYPE_INTEGER, pass_value],
|
['srcport', pyagentx.TYPE_INTEGER, pass_value],
|
||||||
['dstadr', pyagentx3.TYPE_IPADDRESS, ipaddress.ip_address],
|
['dstadr', pyagentx.TYPE_IPADDRESS, pass_value],
|
||||||
['dstport', pyagentx3.TYPE_INTEGER, pass_value],
|
['dstport', pyagentx.TYPE_INTEGER, pass_value],
|
||||||
['leap', pyagentx3.TYPE_INTEGER, pass_value],
|
['leap', pyagentx.TYPE_INTEGER, pass_value],
|
||||||
['hmode', pyagentx3.TYPE_INTEGER, pass_value],
|
['hmode', pyagentx.TYPE_INTEGER, pass_value],
|
||||||
['stratum', pyagentx3.TYPE_INTEGER, pass_value],
|
['stratum', pyagentx.TYPE_INTEGER, pass_value],
|
||||||
['ppoll', pyagentx3.TYPE_INTEGER, pass_value],
|
['ppoll', pyagentx.TYPE_INTEGER, pass_value],
|
||||||
['hpoll', pyagentx3.TYPE_INTEGER, pass_value],
|
['hpoll', pyagentx.TYPE_INTEGER, pass_value],
|
||||||
['precision', pyagentx3.TYPE_INTEGER, pass_value],
|
['precision', pyagentx.TYPE_INTEGER, pass_value],
|
||||||
['rootdelay', pyagentx3.TYPE_INTEGER, int_scale1k],
|
['rootdelay', pyagentx.TYPE_INTEGER, int_scale1k],
|
||||||
['rootdisp', pyagentx3.TYPE_INTEGER, int_scale1k],
|
['rootdisp', pyagentx.TYPE_INTEGER, int_scale1k],
|
||||||
['refid', pyagentx3.TYPE_OCTETSTRING, pass_value],
|
['refid', pyagentx.TYPE_OCTETSTRING, pass_value],
|
||||||
['reftime', pyagentx3.TYPE_OCTETSTRING, pass_value],
|
['reftime', pyagentx.TYPE_OCTETSTRING, pass_value],
|
||||||
['rec', pyagentx3.TYPE_OCTETSTRING, pass_value],
|
['rec', pyagentx.TYPE_OCTETSTRING, pass_value],
|
||||||
['xmt', pyagentx3.TYPE_OCTETSTRING, pass_value],
|
['xmt', pyagentx.TYPE_OCTETSTRING, pass_value],
|
||||||
['reach', pyagentx3.TYPE_INTEGER, pass_value],
|
['reach', pyagentx.TYPE_INTEGER, pass_value],
|
||||||
['unreach', pyagentx3.TYPE_INTEGER, pass_value],
|
['unreach', pyagentx.TYPE_INTEGER, pass_value],
|
||||||
['delay-s', pyagentx3.TYPE_OCTETSTRING, pass_value],
|
['delay-s', pyagentx.TYPE_OCTETSTRING, pass_value],
|
||||||
['delay', pyagentx3.TYPE_INTEGER, int_scale1k],
|
['delay', pyagentx.TYPE_INTEGER, int_scale1k],
|
||||||
['offset', pyagentx3.TYPE_INTEGER, int_scale1M],
|
['offset', pyagentx.TYPE_INTEGER, int_scale1M],
|
||||||
['jitter', pyagentx3.TYPE_INTEGER, int_scale1M],
|
['jitter', pyagentx.TYPE_INTEGER, int_scale1M],
|
||||||
['dispersion', pyagentx3.TYPE_INTEGER, int_scale1k],
|
['dispersion', pyagentx.TYPE_INTEGER, int_scale1k],
|
||||||
['keyid', pyagentx3.TYPE_INTEGER, pass_value],
|
['keyid', pyagentx.TYPE_INTEGER, pass_value],
|
||||||
['filtdelay', pyagentx3.TYPE_OCTETSTRING, pass_value],
|
['filtdelay', pyagentx.TYPE_OCTETSTRING, pass_value],
|
||||||
['filtoffset', pyagentx3.TYPE_OCTETSTRING, pass_value],
|
['filtoffset', pyagentx.TYPE_OCTETSTRING, pass_value],
|
||||||
['pmode', pyagentx3.TYPE_INTEGER, pass_value],
|
['pmode', pyagentx.TYPE_INTEGER, pass_value],
|
||||||
['filtdisp', pyagentx3.TYPE_OCTETSTRING, pass_value],
|
['filtdisp', pyagentx.TYPE_OCTETSTRING, pass_value],
|
||||||
['flash', pyagentx3.TYPE_INTEGER, pass_value],
|
['flash', pyagentx.TYPE_INTEGER, pass_value],
|
||||||
['headway', pyagentx3.TYPE_INTEGER, pass_value],
|
['headway', pyagentx.TYPE_INTEGER, pass_value],
|
||||||
['ntscookies', pyagentx3.TYPE_INTEGER, pass_value]
|
['ntscookies', pyagentx.TYPE_INTEGER, pass_value]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class DataStore(AbstractContextManager):
|
class DataStore(AbstractContextManager):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.lock = threading.Lock()
|
self.lock = threading.Lock()
|
||||||
@ -129,8 +130,6 @@ class NtpDataCollector(threading.Thread):
|
|||||||
self.session = ntp.packet.ControlSession()
|
self.session = ntp.packet.ControlSession()
|
||||||
self.session.openhost(self.ntpserver)
|
self.session.openhost(self.ntpserver)
|
||||||
|
|
||||||
self.data_store = DataStore()
|
|
||||||
|
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
@ -150,26 +149,20 @@ class NtpDataCollector(threading.Thread):
|
|||||||
tmp_data_store['peers'][peer.associd] = dict(peer_vars)
|
tmp_data_store['peers'][peer.associd] = dict(peer_vars)
|
||||||
logger.debug(f"{peer.associd=}, {peer_vars=}")
|
logger.debug(f"{peer.associd=}, {peer_vars=}")
|
||||||
|
|
||||||
with self.data_store as ds:
|
with globalDataStore as ds:
|
||||||
ds.update_data(tmp_data_store)
|
ds.update_data(tmp_data_store)
|
||||||
|
|
||||||
time.sleep(self.period)
|
time.sleep(self.period)
|
||||||
logger.info('NtpDataCollector terminating')
|
logger.info('NtpDataCollector terminating')
|
||||||
|
|
||||||
def get_data_store(self):
|
|
||||||
return self.data_store
|
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self.stop_event.set()
|
self.stop_event.set()
|
||||||
self.join()
|
self.join()
|
||||||
|
|
||||||
class TestUpdater(pyagentx3.Updater):
|
|
||||||
def update(self):
|
|
||||||
self.set_INTEGER('1', 123)
|
|
||||||
|
|
||||||
class NtpsecDataUpdater(pyagentx3.Updater):
|
class NtpsecDataUpdater(pyagentx.Updater):
|
||||||
def update(self):
|
def update(self):
|
||||||
with self.data_store as ds:
|
with globalDataStore as ds:
|
||||||
if ds.data:
|
if ds.data:
|
||||||
try:
|
try:
|
||||||
|
|
||||||
@ -186,7 +179,7 @@ class NtpsecDataUpdater(pyagentx3.Updater):
|
|||||||
number_of_peers_oid_prefix = f"{NUMBER_OF_PEERS_PREFIX}"
|
number_of_peers_oid_prefix = f"{NUMBER_OF_PEERS_PREFIX}"
|
||||||
self._data[number_of_peers_oid_prefix] = {
|
self._data[number_of_peers_oid_prefix] = {
|
||||||
'name': number_of_peers_oid_prefix,
|
'name': number_of_peers_oid_prefix,
|
||||||
'type': pyagentx3.TYPE_INTEGER,
|
'type': pyagentx.TYPE_INTEGER,
|
||||||
'value': number_of_peers
|
'value': number_of_peers
|
||||||
}
|
}
|
||||||
for peer_index, (associd, peer) in enumerate(ds.data['peers'].items(), start=1):
|
for peer_index, (associd, peer) in enumerate(ds.data['peers'].items(), start=1):
|
||||||
@ -194,13 +187,13 @@ class NtpsecDataUpdater(pyagentx3.Updater):
|
|||||||
index_oid_prefix = f"{TABLE_OF_PEERS_PREFIX}.1.{peer_index}"
|
index_oid_prefix = f"{TABLE_OF_PEERS_PREFIX}.1.{peer_index}"
|
||||||
self._data[index_oid_prefix] = {
|
self._data[index_oid_prefix] = {
|
||||||
'name': index_oid_prefix,
|
'name': index_oid_prefix,
|
||||||
'type': pyagentx3.TYPE_INTEGER,
|
'type': pyagentx.TYPE_INTEGER,
|
||||||
'value': peer_index
|
'value': peer_index
|
||||||
}
|
}
|
||||||
associd_oid_prefix = f"{TABLE_OF_PEERS_PREFIX}.2.{peer_index}"
|
associd_oid_prefix = f"{TABLE_OF_PEERS_PREFIX}.2.{peer_index}"
|
||||||
self._data[associd_oid_prefix] = {
|
self._data[associd_oid_prefix] = {
|
||||||
'name': associd_oid_prefix,
|
'name': associd_oid_prefix,
|
||||||
'type': pyagentx3.TYPE_INTEGER,
|
'type': pyagentx.TYPE_INTEGER,
|
||||||
'value': associd
|
'value': associd
|
||||||
}
|
}
|
||||||
for key_index, data_spec in enumerate(PEER_KEYS, start=3):
|
for key_index, data_spec in enumerate(PEER_KEYS, start=3):
|
||||||
@ -216,15 +209,14 @@ class NtpsecDataUpdater(pyagentx3.Updater):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class NtpsecAgent(pyagentx3.Agent):
|
class NtpsecAgent(pyagentx.Agent):
|
||||||
def __init__(self, agent_id='NtpsecAgent', socket_path=None, data_store=None):
|
def __init__(self, agent_id='NtpsecAgent', socket_path=None):
|
||||||
logger.debug('Agent created')
|
logger.debug('Agent created')
|
||||||
self.data_store = data_store
|
super().__init__()
|
||||||
super().__init__(agent_id, socket_path)
|
|
||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
logger.debug('Agent setup')
|
logger.debug('Agent setup')
|
||||||
self.register(BASE_OID_HOTTIS_NTPSEC, NtpsecDataUpdater, freq=1, data_store=self.data_store)
|
self.register(BASE_OID_HOTTIS_NTPSEC, NtpsecDataUpdater, freq=1)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -250,7 +242,7 @@ def daemonize(pid_filename):
|
|||||||
os.dup2(log.fileno(), sys.stderr.fileno())
|
os.dup2(log.fileno(), sys.stderr.fileno())
|
||||||
|
|
||||||
logger.removeHandler(stdout_handler)
|
logger.removeHandler(stdout_handler)
|
||||||
pyagentx3.setup_logging(debug=True)
|
pyagentx.setup_logging(debug=True)
|
||||||
|
|
||||||
def set_user_group(user, group):
|
def set_user_group(user, group):
|
||||||
if group:
|
if group:
|
||||||
@ -271,7 +263,7 @@ def set_user_group(user, group):
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
level=logging.DEBUG,
|
level=logging.INFO,
|
||||||
format="%(name)s - %(levelname)s - %(message)s",
|
format="%(name)s - %(levelname)s - %(message)s",
|
||||||
handlers=[logging.handlers.SysLogHandler(address='/dev/log')]
|
handlers=[logging.handlers.SysLogHandler(address='/dev/log')]
|
||||||
)
|
)
|
||||||
@ -337,10 +329,11 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
globalDataStore = DataStore()
|
||||||
ndc = NtpDataCollector(ntpserver=ntpserver, period=period)
|
ndc = NtpDataCollector(ntpserver=ntpserver, period=period)
|
||||||
ndc.start()
|
ndc.start()
|
||||||
|
|
||||||
nsax = NtpsecAgent(data_store=ndc.get_data_store())
|
nsax = NtpsecAgent()
|
||||||
nsax.start()
|
nsax.start()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Unhandled exception: {e}")
|
logger.error(f"Unhandled exception: {e}")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user