Python script to query NTP status and return it as JSON

Setting up and automatically keeping an eagle eye on NTP from software can be a bit of a (difficult) black art. A common way to query NTP status is to run:

This returns some NTP status information. It’s output can be a bit difficult to work with from your software, so I have included a small python 3 script which runs runs “ntpq -p” parses, and prints the output in Json format. So instead of shelling out to ntpq you can shell out to this script and deal with the resulting json string instead… This can be handy if you don’t have access to a Python NTP library.

GitHub repo is here.