NTP doesn't work anymore if the service is located in /usr/sbin

The NTP service isn’t discovered anymore on my Slackware-based system (Unraid). The service is launched from /usr/sbin/ntpd and it used to work in 1.6.x, so I looked at the new Linux agent code and the problem is definitely in there:

section_ntp() {
    if [ -n "$IS_DOCKERIZED" ] || [ -n "$IS_LXC_CONTAINER" ]; then
        return 0
    fi
    # First we try to identify if we're beholden to systemd
    if inpath systemctl; then
        # shellcheck disable=SC2016
        if [ "$(systemctl | awk '/ntp.service|ntpd.service/{print $3; exit}')" = "active" ]; then
            # remove heading, make first column space separated
            get_ntpq
            return
        fi
    fi

    # If we get to this point, we attempt via classic ntp daemons (ntpq required)
    if inpath ntpq; then
        # Try to determine status via /etc/init.d
        # This might also be appropriate for AIX, Solaris and others
        for _ntp_daemon in ntp ntpd openntpd; do
            # Check for a service script
            if [ -x /etc/init.d/"${_ntp_daemon}" ]; then
                # If the status returns 0, we assume we have a running service
                if /etc/init.d/"${_ntp_daemon}" status >/dev/null 2>&1; then
                    get_ntpq
                    return
                fi
            fi
        done
        unset -v _ntp_daemon
    fi
}

So this piece of code looks for ntpd in systemd or init.d. In the 1.6 agent they don’t bother with sanitary checks like this, they just try to run ntpq if it exists.

The easy way to fix this for me is literally just to add get_ntpq at the end of this session_ntp() function since the get_ntpq() function also checks if ntpq exists before calling it, thus making it somewhat safe for my specific use-case, but this needs more attention from the dev team.

Any chance for a permanent fix?

bump

Still a problem in 2.0.0p4 right now, ntp plugin doesn’t work if ntpd is launched from /usr/sbin/

Deployed 2.0.0p4 and can confirm it hasn’t been fixed yet.

Here is my suggested fix to the agent:

section_ntp() {
    if [ -n "$IS_DOCKERIZED" ] || [ -n "$IS_LXC_CONTAINER" ]; then
        return 0
    fi
    # First we try to identify if we're beholden to systemd
    if inpath systemctl; then
        # shellcheck disable=SC2016
        if [ "$(systemctl | awk '/ntp.service|ntpd.service/{print $3; exit}')" = "active" ]; then
            # remove heading, make first column space separated
            get_ntpq
            return
        fi
    fi

    # If we get to this point, we attempt via classic ntp daemons (ntpq required)
    if inpath ntpq; then
        # Try to determine status via /etc/init.d
        # This might also be appropriate for AIX, Solaris and others
        for _ntp_daemon in ntp ntpd openntpd; do
            # Check for a service script
            if [ -x /etc/init.d/"${_ntp_daemon}" ]; then
                # If the status returns 0, we assume we have a running service
                if /etc/init.d/"${_ntp_daemon}" status >/dev/null 2>&1; then
                    get_ntpq
                    return
                fi
            fi
            # this for systems that don't use initd or systemd, we can't check the service status
            if [ -x /usr/sbin/"${_ntp_daemon}" ]; then
                get_ntpq
                return
            fi
        done
        unset -v _ntp_daemon
    fi
}

The easiest way to get this integrated into the normal code base is, make a pull request on github with this fix. As it is a fix for a problem and no “enhancement” it should also be processed.

Here is my PR: Fix get_ntpq not working on Slackware and other distros by dnlldl · Pull Request #389 · tribe29/checkmk · GitHub</title
Problem still there in 2.0.0p9. By the way, I don’t think my solution is the most elegant… this should be checked thoroughly by someone with a deeper knowledge of Unix systems, this works for my specific situation on Slackware, but YMMV with other distros.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed. Contact an admin if you think this should be re-opened.