pylib documentation / examples?
James Browning
jamesb192 at jamesb192.com
Fri Jul 19 20:49:51 UTC 2024
On Friday, July 19, 2024 12:45:05 PM PDT Hal Murray via users wrote:
> > Is there any documentation for ntpsec pylib? And/or examples?
>
> There isn't any documentation. You can read the code. I find it very
> hard to read/understand. YMMV.
>
> The best example is probably ntpq
>
> docs/mode6.adoc has a description of the on-wire protocol
> I don't know how up to date it is
> That may help you understand how things work.
>
> You can use tcpdump to look at the wire while poking a server with
ntpq
> Most of the answers are text in the form name=value
>
>
> > For a visualization project, I'm trying to retrieve as much
variables
> > from a running ntpsec isntance as there are available.
>
> That could be interesting. Please let us know how it turns out.
>
> There are 4 types of data. Maybe more that I can't think of right
now.
>
> The first is global variables.
> The second is counters.
> The third is per-interface data.
> The fourth is the mru list.
You should be able to run the following to get the list of variables
(but no type info).
$ ntpq -c "rv 0 sys_vars_list"
which seem to not work for a while,
$ ntpq -c "rv ${associd} peer_var_list"
or
$ ntpq -c "cv ${associd} clock_var_list"'
Here's a mockup of a Python implementation to programmatically retrieve
the variable lists.
```python
from ntp.control import CTL_OP_READCLOCK, CTL_OP_READVAR
from ntp.packet import Authenticator, ControlSession
control = ControlSession()
control.openhost('localhost') # , ...)
sys_vars = control.readvar(associd=0, varlist=['sys_var_list'],
opcode=CTL_OP_READVAR)
peer_vars = control.readvar(associd=ipeer, varlist=['peer_var_list'],
opcode=CTL_OP_READVAR)
clock_vars = control.readvar(associd=ipeer, varlist=['clock_var_list'],
opcode=CTL_OP_READCLOCK)
# Mostly only if you want traffic analysis.
control.auth = Authenticator(keyfile='/vae/ntpsec/ntp.keys')
control.auth.controlkey(keyid=1)
if_stats = control.ifstats()
re_slist - control.reslist()
span = control.mrulist() # variables (None, dict), rawhook (None,
callable), direct (None, callable)
```
The message crafted with the use of Artificial stupidity; because I
don't have enough on my own.
-30-
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: This is a digitally signed message part.
URL: <https://lists.ntpsec.org/pipermail/users/attachments/20240719/cb41d832/attachment.bin>
More information about the users
mailing list