#
# NTP monitor

test ntp_NTP {
    static set name "ntp";
    static set domain ntptrace;

    static set description "Monitors NTP server via ntptrace command";
    pernode set report_item "ntp";
    set perf_frequency 0;
    set niceness 2;

    static set arguments
	"item:string:column name we should report the results under"
	"perf:int:time in minutes between sending performance data (0 for no performance data)";

    pernode precheck {
	set test_available domain_available( ${domain} );
    }

    init {
	instance import item report_item;
	instance import perf perf_frequency;
    }

    pernode monitor {
        get ${domain}.status.0 ${domain}.text.0 ${domain}.offset.0 
	    ${domain}.distance.0 ${domain}.stratum.0;
	pernode set status ${${domain}.status.0};
	pernode set text ${${domain}.text.0};
	pernode set offset ${${domain}.offset.0};
	pernode set distance ${${domain}.distance.0};
	pernode set stratum ${${domain}.stratum.0};
    }

    report {
	debug 5 status ${status} stratum ${stratum} offset ${offset} distance ${distance};
	status red ${status} == 0 "&red ntp dead";
	status yellow ${status} == 1 "&yellow ntp running unsynchronized";
	status green ${status} == 2 "&green ntp OK";
	comment html "<HR><strong>NTP status</strong><PRE>${text}</PRE>";
    }

    pernode perf {
        export always ntp.stratum, ${stratum};
        export always ntp.offset, ${offset};
        export always ntp.distance, ${distance};
    }

}
        
