JP Vossen on 7 Jan 2014 15:04:34 -0800


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] Quick & Dirty NTP monitoring


On 01/07/2014 06:52 AM, Jeremy Kister wrote:
On 1/4/2014 3:51 PM, JP Vossen wrote:
So...  Anyone have a better quick & dirty method for this?  And if not,
steal this one...

If your ntp server can't sync time, your test is actually doing it's job
by crying.  You can add some retries in there if you can't get the core
issue solved.

Well, yes and no. My original test was creating false positive email alerts. My new test stopped that, but in general I dislike seeing lots of timeouts. I think the root cause it folks locking NTP servers down after the attacked (which is overall a good thing).

The overall goal is just an out-of-band sanity check that NTP really is working across my network. This came out of some issues years ago with firewall rules (lack thereof), down daemons, etc.


I can't say better, but i'd use some perl to actually query the ntp. You
can jam it all on one line easily.

perl -MNet::NTP -e '
for($i; $i<3; $i++){
  %r=get_ntp_response("127.0.0.1");
  if( $r{Stratum} <= 4 && $r{"Receive Timestamp"} >= time()-600 ){
   $s=1;
   last;
  }
  sleep 60;
}
print "error with ntp server\n" unless $s;'

I'd need to install 'libnet-ntp-perl' for that to work on my various Debuntu machines, and I'm not sure it gains me much more than this: ntptrace 2> /dev/null | head -n1 | perl -ne 'm/^[\w.]+: stratum (\d+),/ or next; print qq(NTP not in sync: $_) if ( $1 > 5 );'

(Note 'ntptrace' comes with NTP and is Perl without Net::NTP.)

Am I missing something?

Thanks for thinking about it,
JP
----------------------------|:::======|-------------------------------
JP Vossen, CISSP            |:::======|      http://bashcookbook.com/
My Account, My Opinions     |=========|      http://www.jpsdomain.org/
----------------------------|=========|-------------------------------
"Microsoft Tax" = the additional hardware & yearly fees for the add-on
software required to protect Windows from its own poorly designed and
implemented self, while the overhead incidentally flattens Moore's Law.
___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug