Commit 985a10d5 authored by Adam Wujek's avatar Adam Wujek

[FEATURE: #268] userspace/snmpd: improve reporting of offset between NTP and WR time

Add wrsSystemClockDriftUs (in microseconds) as int32. There is no need
to export this value as int64, with greater values of the offset
the exact information about the offset is not needed.
Signed-off-by: 's avatarAdam Wujek <dev_public@wujek.eu>
parent 4d778f25
......@@ -95,12 +95,17 @@ setCronConfig ()
compareToThreshold ()
{
local __resultvar=$1
local __c_offset=$2
# $(( )) to remove leading "+"
local __c_offset=$(( $2 ))
local __c_threshold=$3
if (( $__c_offset >= __c_threshold )) ; then
x=$(expr $__c_offset - $__c_threshold)
debug "System clock drift is exceedind the threshold by ${x} sec"
x=$(( $__c_offset - $__c_threshold ))
debug "X1System clock drift is exceeding the threshold by ${x} sec"
eval $__resultvar="1"
elif (( -$__c_offset >= __c_threshold )) ; then
x=$(( $__c_offset + $__c_threshold ))
debug "X2System clock drift is exceeding the threshold by ${x} sec"
eval $__resultvar="1"
else
debug "System clock drift is not exceeding the threshold"
......@@ -109,27 +114,36 @@ compareToThreshold ()
}
#
# Decode NTPD deamon output to get the offset in ms
# Decode NTPD deamon output to get the offset in seconds.useconds
#
decodeOffsetMs ()
decodeOffset ()
{
local __resultvar=$1
local __str=$2
local __offset=$(echo $__str | sed -n 's/.* offset:[+-]\?\([0-9]*\).*/\1/p')
local __offset=$(echo $__str | sed -n 's/.* offset:\?\([+-][0-9]*\)\.\?\([0-9]*\) .*/\1.\2/p')
if [[ -z "$__offset" ]] ; then
# Empty string
debug "Invalid Offset !!!"
debug "NTP msg=\"$__str\""
eval $__resultvar="-1"
else
offset=$(expr $__offset + 0)
debug "NTP offset=$__offset ms"
return 1
else
# Change the sign of the offset. ntpd returns a positive
# offset when the ntp time is ahead of the local time, which is
# counter-intuitive.
if [ "${__offset:0:1}" = "-" ]; then
__offset=+${__offset:1}
elif [ "${__offset:0:1}" = "+" ]; then
__offset=-${__offset:1}
fi
debug "NTP offset=$__offset s"
eval $__resultvar="'$__offset'"
return 0
fi
}
#
# Kill the NTPD daemon in background after few seconds
#
......@@ -171,9 +185,9 @@ read_ntp_server()
killNTPD 10
ntpRes=$($ntpTool -n -w -q -d -p $server 2>&1)
if [ -n "$ntpRes" ] ; then
decodeOffsetMs offset "$ntpRes"
if (( $offset >= 0 )) ; then
compareToThreshold alarmState $offset $ltThreshold
decodeOffset offset "$ntpRes"
if [ $? -eq 0 ] ; then
compareToThreshold alarmState ${offset%.*} $ltThreshold
if (( $alarmState == 1 )) ; then
# Exceeded Threshold
writeMsg "exceeded_threshold" $systemClockMonitoringStatus
......
......@@ -30,6 +30,7 @@ wrSwitchMIB MODULE-IDENTITY
DESCRIPTION
"Updates for v6.1 WRS firmware release
Added objects:
- wrsSystemClockDriftUs
- wrsVersionFeatures
"
......@@ -731,6 +732,15 @@ wrsLeapSecSourceURL OBJECT-TYPE
"Url to the leap second file"
::= { wrsCurrentTimeGroup 11 }
wrsSystemClockDriftUs OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"Drift of system clock expressed in microseconds with saturation to
min/max integer values"
::= { wrsCurrentTimeGroup 12 }
--wrsBootStatusGroup (.7.1.2)
wrsBootStatusGroup OBJECT IDENTIFIER ::= { wrsOperationStatus 2 }
......
......@@ -66,6 +66,7 @@
"wrsLeapSecStatusDetails" "1.3.6.1.4.1.96.100.7.1.1.9"
"wrsLeapSecSourceStatusDetails" "1.3.6.1.4.1.96.100.7.1.1.10"
"wrsLeapSecSourceURL" "1.3.6.1.4.1.96.100.7.1.1.11"
"wrsSystemClockDriftUs" "1.3.6.1.4.1.96.100.7.1.1.12"
"wrsBootStatusGroup" "1.3.6.1.4.1.96.100.7.1.2"
"wrsBootCnt" "1.3.6.1.4.1.96.100.7.1.2.1"
"wrsRebootCnt" "1.3.6.1.4.1.96.100.7.1.2.2"
......
......@@ -54,6 +54,7 @@ static struct pickinfo wrsCurrentTime_pickinfo[] = {
FIELD(wrsCurrentTime_s, ASN_INTEGER, wrsLeapSecStatusDetails),
FIELD(wrsCurrentTime_s, ASN_INTEGER, wrsLeapSecSourceStatusDetails),
FIELD(wrsCurrentTime_s, ASN_OCTET_STR, wrsLeapSecSourceUrl),
FIELD(wrsCurrentTime_s, ASN_INTEGER, wrsSystemClockDriftUs),
};
static service_exp_t services[]={
......@@ -176,7 +177,9 @@ static void get_wrsSystemClockStatusDetails(void){
static int first_run=1;
char buff[21]; /* 1 for null char */
FILE *f;
int status=0, drift=0;
int status = 0;
int drift = 0;
int drift_us = 0;
static int threshold=0, unit=0, checkInterval=0;
update_expected_services();
......@@ -212,10 +215,11 @@ static void get_wrsSystemClockStatusDetails(void){
if ((f=fopen(SYSTEMCLOCK_DRIFT, "r"))!=NULL) {
/* readline without newline */
if ( fscanf(f, "%d", &drift)!=1 ) {
if (fscanf(f, "%d.%d", &drift, &drift_us) != 2) {
snmp_log(LOG_ERR, "SNMP: " SL_ER " %s: invalid "
"drift value in file " SYSTEMCLOCK_DRIFT "\n",slog_obj_name);
drift=0;
drift = 0;
drift_us = 0;
}
fclose(f);
} else {
......@@ -270,6 +274,7 @@ static void get_wrsSystemClockStatusDetails(void){
}
wrsCurrentTime_s.wrsSystemClockStatusDetails = status;
wrsCurrentTime_s.wrsSystemClockDrift = drift;
wrsCurrentTime_s.wrsSystemClockDriftUs = int_saturate((int64_t)drift * 1000000 + (int64_t)drift_us);
wrsCurrentTime_s.wrsSystemClockDriftThreshold=threshold;
wrsCurrentTime_s.wrsSystemClockCheckInterval=checkInterval;
wrsCurrentTime_s.wrsSystemClockCheckIntervalUnit=unit;
......
......@@ -55,6 +55,7 @@ struct wrsCurrentTime_s {
int wrsLeapSecSourceStatusDetails; /* Leap second source status details*/
int wrsLeapSecSource; /* Source of the leap seconds file */
char wrsLeapSecSourceUrl[WRS_LEAP_SECOND_SOURCE_URL_LEN + 1]; /* URL to download leap second file */
int wrsSystemClockDriftUs; /* Current system clock drift value in us */
};
extern struct wrsCurrentTime_s wrsCurrentTime_s;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment