Find the answer to your Linux question:
Results 1 to 5 of 5
Is it possible to monitor the NTP drift value ( I mean measuring the time difference between the NTP server and the server that I am trying to monitor) using ...
  1. #1
    Just Joined!
    Join Date
    Dec 2011
    Posts
    4

    Is it possible to monitor NTP through SNMP in Linux

    Is it possible to monitor the NTP drift value ( I mean measuring the time difference between the NTP server and the server that I am trying to monitor) using SNMP.

    Appreciate any help in this regard.

  2. #2
    Linux Guru
    Join Date
    May 2011
    Posts
    1,843
    All this is assuming you have snmp daemon configured and running on your Linux box.

    You can get current system date/time with:

    Code:
    snmpwalk -Cc -On -v2c -c public localhost .1.3.6.1.4.1.2021.100.4.0
    provided that snmpd is set up and configured properly for this on the Linux box, but you probably want something more granular.

    There may be a way to directly access NTP info via an OID, but I don't know it.

    Fortunately, it is possible to monitor anything in SNMP via the exec directive or maybe pass (PASS-THROUGH-CONTROL), never used the latter. For example, you can put this in your snmpd.conf on the Linux box:
    Code:
    # run external script to return drift info
    exec 1.3.6.1.4.1.2021.8.1.101 get-drift /tmp/get-drift.sh
    Then create /tmp/get-drift.sh and put in it the code to determine drift. I don't know how to do that, but I gather it would be some sort of ntpdate command. Here's something to start with that would work on a RH/Fedora box, e.g.:
    Code:
    #!/bin/bash
    
    # location of ntp config file
    ntpConf=/etc/ntp.conf
    
    # make sure it exists
    ! [ -f $ntpConf ] && echo "$ntpConf: No such file" && exit 1
    
    # get an ntp server from the config file
    server=$(awk '/^server/{print $2}' $ntpConf|head -n1)
    
    # see if we need to stop the ntp daemon
    pidof ntpd >/dev/null 2>&1
    if [ $? -eq 0 ]; then
      /etc/init.d/ntpd stop >/dev/null 2>&1 || exit 1
      restart_ntp=1
    fi
    
    # do something with this output
    output=$(ntpdate -d $server 2>&1)
    
    # restart the daemon if necessary (distro-specific)
    [ -n "$restart_ntp" ] && /etc/init.d/ntpd start >/dev/null 2>&1
    Note that the above doesn't actually output anything. You'll have to figure that out yourself. Just be sure to send whatever you get on a single line of output, to make it easier for snmpwalk to parse.

    Don't forget to make your script executable:
    Code:
    chmod +x /tmp/get-drift.sh
    Then you'd call it (locally) with something like:
    Code:
    snmpwalk -c public -v2c localhost .1.3.6.1.4.1.2021.8.1.101
    again, depends on your snmpd config.

    Read more on snmp.conf in the man page:
    Code:
    man 5 snmpd.conf
    Last edited by atreyu; 12-02-2011 at 03:01 PM. Reason: snmpwalk cmd

  3. #3
    Just Joined!
    Join Date
    Dec 2011
    Posts
    4
    Thanks let me try this.b

  4. #4
    Just Joined!
    Join Date
    Dec 2011
    Posts
    4
    Is there any direct MIB from SNMP for monitoring the NTP time difference

  5. #5
    Just Joined!
    Join Date
    Dec 2011
    Posts
    4
    I am able to get the drift value using the above method. but still trying to find a MIB for NTP monitoring.someone help please

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...