diff --git a/userspace/snmpd/WR-SWITCH-MIB.txt b/userspace/snmpd/WR-SWITCH-MIB.txt index bf59a7d15c0c158602fad0719ad49895b37e0665..dac3e01ebd11fb40c5cef9ae2ab588d3a9493080 100644 --- a/userspace/snmpd/WR-SWITCH-MIB.txt +++ b/userspace/snmpd/WR-SWITCH-MIB.txt @@ -593,8 +593,10 @@ wrsSystemClockStatusDetails OBJECT-TYPE na(0), ok(1), thresholdExceeded(2), - statusFileMissing(3), - unknownStatus(4) + ntpError(3), + error(4), + IOError(5), + unknownStatus(6) } MAX-ACCESS read-only STATUS current @@ -602,7 +604,9 @@ wrsSystemClockStatusDetails OBJECT-TYPE "The system clock is compared to NTP time ok - system clock is under the threshold value thresholdExceeded - system clock has exceeded the threshold value - error - Unexpected status + IOError - IO error detected (error) + unknownStatus - Unexpected status (error) + error - Error detected warningNA - there is N/A in one of object used to calculate this value" ::= { wrsCurrentTimeGroup 3 } @@ -614,6 +618,41 @@ wrsSystemClockDrift OBJECT-TYPE "Drift of system clock expressed in seconds" ::= { wrsCurrentTimeGroup 4 } +wrsSystemClockDriftThreshold OBJECT-TYPE + SYNTAX Integer32 + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "Threshold level in seconds for system clock drift" + ::= { wrsCurrentTimeGroup 5 } + +wrsSystemClockCheckInterval OBJECT-TYPE + SYNTAX Integer32 + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "Check interval of system clock drift. + The unit is given by wrsSystemClockCheckIntervalUnit object." + + ::= { wrsCurrentTimeGroup 6 } + +wrsSystemClockCheckIntervalUnit OBJECT-TYPE + SYNTAX INTEGER { + na(0), + error(1), + minutes(2), + hours(3), + days(4) } + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "System clock check interval unit (see wrsSystemClockCheckInterval) + seconds - System clock check interval expressed in seconds + minutes - System clock check interval expressed in minutes + days - System clock check interval expressed in number of days + " + ::= { wrsCurrentTimeGroup 7 } + wrsLeapSecSource OBJECT-TYPE SYNTAX INTEGER { na(0), @@ -633,7 +672,7 @@ wrsLeapSecSource OBJECT-TYPE the error is propagated errorMinor - cannot read the status file, problem is probably somewhere else" - ::= { wrsCurrentTimeGroup 5 } + ::= { wrsCurrentTimeGroup 8 } wrsLeapSecStatusDetails OBJECT-TYPE SYNTAX INTEGER { @@ -659,7 +698,7 @@ wrsLeapSecStatusDetails OBJECT-TYPE leapSecDeleted - A leap second will be deleted at 00:00 errorMinor - cannot read the status file, problem is probably somewhere else" - ::= { wrsCurrentTimeGroup 6 } + ::= { wrsCurrentTimeGroup 9 } wrsLeapSecSourceStatusDetails OBJECT-TYPE SYNTAX INTEGER { @@ -685,7 +724,7 @@ wrsLeapSecSourceStatusDetails OBJECT-TYPE downloadError - Error detected during the download errorMinor - cannot read the status file, problem is probably somewhere else" - ::= { wrsCurrentTimeGroup 7 } + ::= { wrsCurrentTimeGroup 10 } wrsLeapSecSourceURL OBJECT-TYPE SYNTAX DisplayString (SIZE (0..128)) @@ -693,7 +732,7 @@ wrsLeapSecSourceURL OBJECT-TYPE STATUS current DESCRIPTION "Url to the leap second file" - ::= { wrsCurrentTimeGroup 8 } + ::= { wrsCurrentTimeGroup 11 } --wrsBootStatusGroup (.7.1.2) wrsBootStatusGroup OBJECT IDENTIFIER ::= { wrsOperationStatus 2 } diff --git a/userspace/snmpd/wrsCurrentTimeGroup.c b/userspace/snmpd/wrsCurrentTimeGroup.c index 7ae9abfe3375d7f04f7ff981fcfc08134cef0f55..d0be4fc314a0c44bc224629123cd780e45da8337 100644 --- a/userspace/snmpd/wrsCurrentTimeGroup.c +++ b/userspace/snmpd/wrsCurrentTimeGroup.c @@ -47,6 +47,9 @@ static struct pickinfo wrsCurrentTime_pickinfo[] = { FIELD(wrsCurrentTime_s, ASN_OCTET_STR, wrsDateTAIString), FIELD(wrsCurrentTime_s, ASN_INTEGER, wrsSystemClockStatusDetails), FIELD(wrsCurrentTime_s, ASN_INTEGER, wrsSystemClockDrift), + FIELD(wrsCurrentTime_s, ASN_INTEGER, wrsSystemClockDriftThreshold), + FIELD(wrsCurrentTime_s, ASN_INTEGER, wrsSystemClockCheckInterval), + FIELD(wrsCurrentTime_s, ASN_INTEGER, wrsSystemClockCheckIntervalUnit), FIELD(wrsCurrentTime_s, ASN_INTEGER, wrsLeapSecSource), FIELD(wrsCurrentTime_s, ASN_INTEGER, wrsLeapSecStatusDetails), FIELD(wrsCurrentTime_s, ASN_INTEGER, wrsLeapSecSourceStatusDetails), @@ -66,6 +69,8 @@ struct wrsCurrentTime_s wrsCurrentTime_s; static char *wrsSystemClockStatusDetails_str = "wrsSystemClockStatusDetails"; static char *wrsSystemClockDrift_str = "wrsSystemClockDrift"; +static char *wrsSystemClockDriftThreshold_str = "wrsSystemClockDriftThreshold"; +static char *wrsSystemClockCheckInterval_str = "wrsSystemClockCheckInterval"; static char *wrsLeapSecStatusDetails_str = "wrsLeapSecStatus"; static char *wrsLeapSecSourceStatusDetails_str = "wrsLeapSecSourceStatusDetails"; static char *wrsLeapSecSource_str = "wrsLeapSecSource"; @@ -163,13 +168,16 @@ static void get_TAI(void){ static text_status_mapping_t mapping_system_clock_monitor_status[]={ { "no_error", WRS_SYSTEM_CLOCK_STATUS_DETAILS_OK}, - { "exceeded_threshold",WRS_SYSTEM_CLOCK_STATUS_DETAILTS_THRESHOLD_EXCEEDED}, + { "exceeded_threshold",WRS_SYSTEM_CLOCK_STATUS_DETAILS_THRESHOLD_EXCEEDED}, + { "ntp_error",WRS_SYSTEM_CLOCK_STATUS_DETAILS_NTP_ERROR}, }; static void get_wrsSystemClockStatusDetails(void){ + static int first_run=1; char buff[21]; /* 1 for null char */ FILE *f; int status=0, drift=0; + static int threshold=0, unit=0, checkInterval=0; update_expected_services(); @@ -198,7 +206,7 @@ static void get_wrsSystemClockStatusDetails(void){ } /* Read drift value */ - if ( status==WRS_SYSTEM_CLOCK_STATUS_DETAILTS_THRESHOLD_EXCEEDED || + if ( status==WRS_SYSTEM_CLOCK_STATUS_DETAILS_THRESHOLD_EXCEEDED || status == WRS_SYSTEM_CLOCK_STATUS_DETAILS_OK) { slog_obj_name = wrsSystemClockDrift_str; @@ -217,12 +225,54 @@ static void get_wrsSystemClockStatusDetails(void){ "open " SYSTEMCLOCK_DRIFT "\n",slog_obj_name); } } + + // Read values depending of dot-config + if (first_run) { + char *config_item; + + // Threshold + slog_obj_name = wrsSystemClockDriftThreshold_str; + + config_item = libwr_cfg_get("SNMP_SYSTEM_CLOCK_DRIFT_THOLD"); + if (config_item) { + threshold= atoi(config_item); + } else { + snmp_log(LOG_ERR, "SNMP: " SL_ER " %s: failed to " + "read SNMP_SYSTEM_CLOCK_DRIFT_THOLD key in dot-config file\n",slog_obj_name); + } + + // Check interval value and unit + slog_obj_name = wrsSystemClockCheckInterval_str; + if ( (config_item = + libwr_cfg_get("SNMP_SYSTEM_CLOCK_CHECK_INTERVAL_MINUTES"))!=NULL) { + checkInterval=atoi(config_item); + unit=WRS_SYSTEM_CLOCK_CHECK_INTERVAL_UNIT_MINUTES; + } else if ( (config_item = + libwr_cfg_get("SNMP_SYSTEM_CLOCK_CHECK_INTERVAL_HOURS"))!=NULL) { + checkInterval=atoi(config_item); + unit=WRS_SYSTEM_CLOCK_CHECK_INTERVAL_UNIT_HOURS; + } else if ( (config_item = + libwr_cfg_get("SNMP_SYSTEM_CLOCK_CHECK_INTERVAL_DAYS"))!=NULL) { + checkInterval=atoi(config_item); + unit=WRS_SYSTEM_CLOCK_CHECK_INTERVAL_UNIT_DAYS; + } else { + unit=WRS_SYSTEM_CLOCK_CHECK_INTERVAL_UNIT_ERROR; + snmp_log(LOG_ERR, "SNMP: " SL_ER " %s: failed to " + "read SNMP_SYSTEM_CLOCK_CHECK_INTERVAL_XXXX key in dot-config file\n",slog_obj_name); + } + + first_run = 0; + } + } else { // System clock monitoring disabled status=WRS_SYSTEM_CLOCK_STATUS_DETAILS_OK; } wrsCurrentTime_s.wrsSystemClockStatusDetails = status; wrsCurrentTime_s.wrsSystemClockDrift = drift; + wrsCurrentTime_s.wrsSystemClockDriftThreshold=threshold; + wrsCurrentTime_s.wrsSystemClockCheckInterval=checkInterval; + wrsCurrentTime_s.wrsSystemClockCheckIntervalUnit=unit; } diff --git a/userspace/snmpd/wrsCurrentTimeGroup.h b/userspace/snmpd/wrsCurrentTimeGroup.h index 6c794727bb80557b5cc90cd94cbdc862c466fd9d..b1368e22c7e65f2a077705583d537ec6fc500865 100644 --- a/userspace/snmpd/wrsCurrentTimeGroup.h +++ b/userspace/snmpd/wrsCurrentTimeGroup.h @@ -13,10 +13,17 @@ #define WRS_LEAP_SEC_SOURCE_FORCE_REMOTE 5 /* Try to download the file (propagate errors) */ #define WRS_SYSTEM_CLOCK_STATUS_DETAILS_OK 1 /* ok */ -#define WRS_SYSTEM_CLOCK_STATUS_DETAILS_IO_ERROR 2 /* Status file is missing */ -#define WRS_SYSTEM_CLOCK_STATUS_DETAILS_UNKNOWN 3 /* Unknown status */ -#define WRS_SYSTEM_CLOCK_STATUS_DETAILTS_THRESHOLD_EXCEEDED \ - 4 /* Threshold exceeded */ +#define WRS_SYSTEM_CLOCK_STATUS_DETAILS_THRESHOLD_EXCEEDED \ + 2 /* Threshold exceeded */ +#define WRS_SYSTEM_CLOCK_STATUS_DETAILS_NTP_ERROR 3 /* Error accessing NTP server */ +#define WRS_SYSTEM_CLOCK_STATUS_DETAILS_ERROR 4 /* Generic error */ +#define WRS_SYSTEM_CLOCK_STATUS_DETAILS_IO_ERROR 5 /* Error: Status file is missing */ +#define WRS_SYSTEM_CLOCK_STATUS_DETAILS_UNKNOWN 6 /* Error: Unknown status */ + +#define WRS_SYSTEM_CLOCK_CHECK_INTERVAL_UNIT_ERROR 1 /* ok */ +#define WRS_SYSTEM_CLOCK_CHECK_INTERVAL_UNIT_MINUTES 2 /* Minutes */ +#define WRS_SYSTEM_CLOCK_CHECK_INTERVAL_UNIT_HOURS 3 /* Hours */ +#define WRS_SYSTEM_CLOCK_CHECK_INTERVAL_UNIT_DAYS 4 /* Days */ #define WRS_LEAP_SEC_STATUS_DETAILS_OK 1 /* Everything ok */ #define WRS_LEAP_SEC_STATUS_DETAILS_IO_ERROR 2 /* Status file is missing */ @@ -40,7 +47,10 @@ struct wrsCurrentTime_s { uint64_t wrsDateTAI; /* current time in TAI */ char wrsDateTAIString[32]; /* current time in TAI as string */ int wrsSystemClockStatusDetails; /* System clock status details*/ - int wrsSystemClockDrift; /* System monitoring clock */ + int wrsSystemClockDrift; /* Current system clock drift value */ + int wrsSystemClockDriftThreshold; /* System clock drift threshold*/ + int wrsSystemClockCheckInterval; /* System clock check interval */ + int wrsSystemClockCheckIntervalUnit; /* System clock check interval unit */ int wrsLeapSecStatusDetails; /* Leap seconds details */ int wrsLeapSecSourceStatusDetails; /* Leap second source status details*/ int wrsLeapSecSource; /* Source of the leap seconds file */