You are here

Discover current clock on all network nodes.

16 posts / 0 new
Last post
nc8q
nc8q's picture
Discover current clock on all network nodes.
Is there a service call like
 http://localnode.local.mesh:8080/cgi-bin/sysinfo.json or http://localnode.local.mesh:8080/cgi-bin/api?mesh=services to obtain the local clock setting on network nodes. I would like to be able to glance at all network nodes' clocks to see if any are 'way off' on time. 73, Chuck
AB4YY
Chuck, you can always install

Chuck, you can always install 'links' on one of you mesh Linux systems, if you have such, then do this or something similar:

links -dump http://localnode.local.mesh/cgi-bin/status |grep "system time:"

Here is an output from one of my nodes:

LAN AP SSID:  hAPac                   system time:  Sun Aug 20 2023 11:20:29

And of course you could make a script that would give a cleaner output as well as store to a file or whatever...

- Mike


 

nc8q
nc8q's picture
Discover current clock on all network nodes.

Hi, Mike:
Thanks.
I had not used 'links' in a few decades.
I used sysinfo.json?hosts=1
and extracted a list of hosts manually > nodelist.txt
Then coded:

while read NODE
    do
#    echo "links -no-connect -retries 1 -receive-timeout 4 -dump http://$NODE/cgi-bin/status |grep -o \"[0-9][0-9]:[0-9][0-9]:[0-9][0-9]\""
    time=$(links -no-connect -retries 1 -receive-timeout 4 -dump http://$NODE/cgi-bin/status |grep -oE "[0-9][0-9]:[0-9][0-9]:[0-9][0-9]..")
    echo "$time $NODE"
done < nodelist.txt


Redirected to an output1.txt file
Then cut -d":" -f2- output1.txt > output2.txt # only use minutes cuz some nodes are ?DST verses UTC!
sort < output2.txt > ordered-nodelist.txt

Nodes with errant times will be at the top and/or bottom of the list.

73, Chuck
 

AB4YY
Thanks for posting that,

Thanks for posting that, Chuck.  I tried it all in pieces and it works.

I wish there was an easy way to get a list of node names only versus having to manually extract them from the URL (http://localnode.local.mesh:8080/cgi-bin/sysinfo.json?hosts=1).  That would make playing around with scripts much easier.

- Mike

AB4YY
When I run my script against

When I run my script against my list of 27 nodes, it brings to light some interesting things:

  • Some nodes show with an E or U between the time and the node name.  That apparently shows EDT or UTC.  So far, seeing the E seems to be inconsistent.  I may look into that.
  • It made it obvious that one of our local nodes has time that is way off.   We will have to check that out but seeing that is a benefit of running the script.
  • One node returned "Connection refused" which is understandable due to the poor path to it.

By the way, I used 'topologr' (v0.1b5) to "Export Net" as a JSON.  Then used the Windows program "JSONedit" to reflow the JSON file, to make it a clean uncompressed file.  Then used NotePad++ to get rid of the quotes around the node names as well as the comma after each name, and then sorted the names and finally saved as nodelist.txt.

It's kind of a long, goofy way to get a nice list of node names, but works and would be just about as easy if doing a couple of hundred nodes.

(Oh, for completeness,) I run the script on my Raspberry Pi that is on the mesh, by SSHing into it from my Windows PC, in a MobaXterm terminal tab.

Also, by the way, I use JSONedit to easily get rid of the few ghost/stale/dead nodes from the topologr map to keep the map clean.

- Mike

nc8q
nc8q's picture
get a list of node names only, versus having to manually extract
AB4YY
Thanks.  Just added 'sort'

Thanks.  Just added 'sort' and it is perfect!

links -dump http://localnode.local.mesh/cgi-bin/api?mesh=remotenodes |jq '.'|grep name|cut -d":" -f2|cut -d'"' -f2 |sort

- Mike

AB4YY
If 'mktemp' is used in the

If 'mktemp' is used in the script, the list of node names will ne be seen anywhere.  This can be hand if running from different directories and not wanting that file in the current directory.
-----

#!/bin/bash
# "Discover current clock on all network nodes"
# suggested filename: meshNodesClocksCheck
nodenames=$(mktemp --suffix ".txt") #use tempory file for list of node names
links -dump http://localnode.local.mesh/cgi-bin/api?mesh=remotenodes |jq '.'|grep name|cut -d":" -f2|cut -d'"' -f2 |sort >$nodenames
while read NODE
    do
    time=$(links -no-connect -retries 1 -receive-timeout 4 -dump http://$NODE/cgi-bin/status |grep -oE "[0-9][0-9]:[0-9][0-9]:[0-9][0-9]..")
    echo "$time $NODE"
done < $nodenames
-----
!!!! I just realized that the above script does not capture localnode and local DtD nodes.  In all, I have 3 and none are in the list of 'nodenames'.  It's not obvious how to resolve this such that the one bash script runs alone and does it all.  For now, in my case, I may hard-code my 3 nodes into a file then modify this script to append to my 3 nodes.  It's no longer the nice clean solution I was looking for.  Maybe someone else can come up with a clean solution. 

- Mike
 
AB4YY
Here is a fix that seems to

Here is a fix that seems to work.  To include the localnode and any DtD nodes, the script must be manually edited to include those.  I only have 3 so it is easy for me.  I cannot see anyone having so many that it would be a real burden to make the edits.  Here is the bash code:
 

#!/bin/bash
# "Discover current clock on all network nodes"
# suggested filename: meshNodesClocksCheck
 
nodenames=$(mktemp --suffix ".txt") #use tempory file for list of node names
 
 
#!!!!!!! MAKE REQUIRED EDITS BELOW !!!!!!!
# EDIT LINES BELOW WITH YOUR LOCALNODE PLUS ANY DtD NODE(S)
# THE ORDER MAKES NO DIFFERENCE AS THEY WILL BE SORTED ANYWAY
# ANWAYS USE '>' FOR FIRST LISTED NODE
# ALL OTHERS USE ">>"
echo "AB4YY-services">$nodenames
echo "AB4YY-LHG5">>$nodenames
echo "AB4YY-NanoBridge">>$nodenames
#######END OF REQUIRED EDITS##########
 
links -dump http://localnode.local.mesh/cgi-bin/api?mesh=remotenodes |jq '.'|grep name|cut -d":" -f2|cut -d'"' -f2 |sort >>$nodenames
 
while read NODE
    do
    time=$(links -no-connect -retries 1 -receive-timeout 4 -dump http://$NODE/cgi-bin/status |grep -oE "[0-9][0-9]:[0-9][0-9]:[0-9][0-9]..")
    echo "$time $NODE"
done < $nodenames


Just to recap, Chuck (nc8q) asked about checking all nodes on a network to see if their clocks were showing correct time.  That required having a list of all the node name to do the checks.  So the bash program above will do that.  And yes, it could probably be improved but seems to work nevertheless.

- Mike

AB7PA
You can also use the api without links

You can also use the api without requiring the extra "links" package:
 

http://nodename.local.mesh/cgi-bin/api?status=sysinfo

 

{
  "pages": {
    "status": {
      "sysinfo": {
        "description": "Shack hub node",
        "date": "Tue Aug 22 2023",
        "time": "16:19:31 MST",
        "api_version": "1.5",
        "target_type": "ipq40xx\/mikrotik",
        "first_boot": false,
        "model": "MikroTik hAP ac2",
        "uptime": "0 days, 1:12:35",
        "loads": [
          0.16,
          0.19,
          0.12
        ],
        "node": "AB7PA-Hub",
        "firmware_version": "20230815-8ce7c0b"
      }
    }
  },
  "api_version": "1.5"
}
nc8q
nc8q's picture
Hi, Steve:
Hi, Steve:

Thanks. That is good to know.
I looked inside /www/cgi-bin/api and found this list of calls:
sysinfo
allhosts
localhosts
remotenodes
currentneighbors
services
previousneighbors
topology

Older nodes' OSs do not seem to support the /api calls, though.

73, Chuck
 
AB7PA
The status=sysinfo call has
The status=sysinfo call has been supported as far back as 3.19.x.x and possibly before.  Nodes running older firmware than that will have other issues bigger than their clock.
AA7AU
AA7AU's picture
Very interesting thread

This is a very interesting thread with good information, I, for one, would really appreciate a final summary write-up posted here somewhere later on if possible.

A few years back there was a utility called "MeshStat" but it was apparently never continued; this thread made me think of how useful that was for us with our little mesh island, and the hope that a similar functionality would reappear in future:

MeshStat
========
Copyright (c) 2017-2018 License: GPL 2 or higher
Author: Jonathan M. Cameron, KF6RTA     jmcameron@gmail.com

Thanks,
- Don / AA7AU
 

AB4YY
Don, see my recap at the

Don, see my recap at the bottom of posting #9.

This site probably needs a place to put little programs and hacks like this.
- Mike

AB7PA
The best way to maintain

The best way to maintain clock consistency is to have all the nodes use an NTP service on the mesh.  If nodes are all getting their time via NTP then you don't have to track down "offenders" and spend a lot of time and energy figuring out what's going on.  Here is the section in the online AREDN docs that discusses NTP and gives some easy options: https://docs.arednmesh.org/en/latest/arednServicesGuide/other_programs.html#network-time-services. Hope this helps.

AB4YY
The keywords are "If nodes

The keywords are "If nodes are all getting their time...".

Occasionally we have issues with nodes, and the script above helps identify any problem nodes.

Right now, we have one node that has such a problem, even though we have three NTP servers on the network.

- Mike

Theme by Danetsoft and Danang Probo Sayekti inspired by Maksimer