Commit c8fb2979 authored by Adam Wujek's avatar Adam Wujek 💬

[Feature: 1363] userspace/snmpd: add custom boot script objects to wrsBootStatusGroup

Add the following objects to wrsBootStatusGroup:
--wrsCustomBootScriptSource
--wrsCustomBootScriptSourceUrl
--wrsCustomBootScriptStatus
Update wrsOSStatusGroup.wrsBootSuccessful to use information from the above
objects.

Update wrs_failures
Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent 4b6c9a1a
......@@ -625,6 +625,7 @@ list of faults leading to a data error.
\item status of programming FPGA and LM32
\item status of loading kernel modules
\item status of starting userspace daemons
\item status of execution of a custom boot script
\end{itemize}
\item [] \underline{SNMP objects}:\\
{\footnotesize
......@@ -638,6 +639,9 @@ list of faults leading to a data error.
\snmpadd{WR-SWITCH-MIB::wrsBootKernelModulesMissing}\\
\snmpadd{WR-SWITCH-MIB::wrsBootUserspaceDaemonsMissing}\\
\snmpadd{WR-SWITCH-MIB::wrsFwUpdateStatus}\\
\snmpadd{WR-SWITCH-MIB::wrsCustomBootScriptSource}\\
\snmpadd{WR-SWITCH-MIB::wrsCustomBootScriptSourceUrl}\\
\snmpadd{WR-SWITCH-MIB::wrsCustomBootScriptStatus}\\
\snmpadd{WR-SWITCH-MIB::wrsBootSuccessful} \\
\snmpadd{WR-SWITCH-MIB::wrsOSStatus}\\
\snmpadd{WR-SWITCH-MIB::wrsMainSystemStatus} }
......
......@@ -54,11 +54,13 @@
the dot-config, unable to get URL to the dot-config, dot-config contains
errors, unable to read the hwinfo, unable to load the FPGA bitstream, unable
to load the LM32 software, any kernel modules or userspace daemons are
missing.\\
missing, failed to update firmware due to checksum error, unable to
download custom boot script, custom boot script fails during execution.\\
\underline{On error:}
\begin{pck_proc}
\item Dump state
\item Check \texttt{\glshyperlink{WR-SWITCH-MIB::wrsBootConfigStatus}},
\texttt{\glshyperlink{WR-SWITCH-MIB::wrsCustomBootScriptStatus}}
if it reports an error, please verify your WRS configuration.
\item Restart the switch
\item Please consult WR experts if the problem persists.
......@@ -427,7 +429,7 @@
\snmpentrye{WR-SWITCH-MIB}{wrsBootStatusGroup}{wrsRestartReasonMonit}{
Process that caused \texttt{monit} to trigger a restart.}
\snmpentrye{WR-SWITCH-MIB}{wrsBootStatusGroup}{wrsBootConfigStatus}{Result of
the dot-config verification.}
the dot-config verification.}
\snmpentrye{WR-SWITCH-MIB}{wrsBootStatusGroup}{wrsBootHwinfoReadout}{}
\snmpentrye{WR-SWITCH-MIB}{wrsBootStatusGroup}{wrsBootLoadFPGA}{}
\snmpentrye{WR-SWITCH-MIB}{wrsBootStatusGroup}{wrsBootLoadLM32}{}
......@@ -441,6 +443,14 @@
the Ethernet switching process}
\snmpentrye{WR-SWITCH-MIB}{wrsBootStatusGroup}{wrsFwUpdateStatus}{
Status of the last firmware update}
\snmpentrye{WR-SWITCH-MIB}{wrsBootStatusGroup}{wrsCustomBootScriptSource}{
Source of the custom script that can be executed once at boot time. It can
be used to setup a switch in a way not supported by dot-config.}
\snmpentrye{WR-SWITCH-MIB}{wrsBootStatusGroup}{wrsCustomBootScriptSourceUrl}{
Path to the custom boot script on a remote server (if local scripts is not
used).}
\snmpentrye{WR-SWITCH-MIB}{wrsBootStatusGroup}{wrsCustomBootScriptStatus}{
Result of custom boot script execution.}
\snmpentrye{WR-SWITCH-MIB}{wrsOperationStatus}{wrsTemperatureGroup}{}
\snmpentrye{WR-SWITCH-MIB}{wrsTemperatureGroup}{wrsTempFPGA}{}
......
......@@ -746,6 +746,59 @@ wrsFwUpdateStatus OBJECT-TYPE
checksumError - firmware checksum error"
::= { wrsBootStatusGroup 16 }
wrsCustomBootScriptSource OBJECT-TYPE
SYNTAX INTEGER {
na(0),
error(1),
errorMinor(2),
local(3),
remote(4),
disabled(5)
}
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"Source of the custom boot script
local - used custom boot script was stored on the switch
remote - custom boot script was retrieved from the network; check the
wrsCustomBootScriptSourceUrl for the path
disabled - do not run custom boot script
errorMinor - cannot read the status file, problem is probably somewhere
else"
::= { wrsBootStatusGroup 17 }
wrsCustomBootScriptSourceUrl OBJECT-TYPE
SYNTAX DisplayString (SIZE (0..128))
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"Url to the custom boot script"
::= { wrsBootStatusGroup 18 }
wrsCustomBootScriptStatus OBJECT-TYPE
SYNTAX INTEGER {
na(0),
ok(1),
failed(2),
wrongSrc(3),
downloadError(4),
disabled(5),
error(6),
errorMinor(7)
}
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"The result of execution of the custom boot script
ok - custom boot script executed successfully
failed - custom boot script failed during execution
wrongSrc - no valid source of the custom boot script present in dot-config
downloadError - unable to download a file from a given source
disabled - do not run custom boot script
error - unsupported status
errorMinor - cannot read the status file, problem is probably somewhere else"
::= { wrsBootStatusGroup 19 }
-- wrsTemperatureGroup (.7.1.3)
wrsTemperatureGroup OBJECT IDENTIFIER ::= { wrsOperationStatus 3 }
......
......@@ -23,6 +23,10 @@
#define FW_UPDATE_FILE "/update/wrs-firmware.tar.checksum_error"
#define CUSTOM_BOOT_SCRIPT_STATUS_FILE "/tmp/custom_boot_script_status"
#define CUSTOM_BOOT_SCRIPT_SOURCE_FILE "/tmp/custom_boot_script_source"
#define CUSTOM_BOOT_SCRIPT_SOURCE_URL_FILE "/tmp/custom_boot_script_url"
/* Macros for fscanf function to read line with maximum of "x" characters
* without new line. Macro expands to something like: "%10[^\n]" */
#define LINE_READ_LEN_HELPER(x) "%"#x"[^\n]"
......@@ -49,6 +53,9 @@ static struct pickinfo wrsBootStatus_pickinfo[] = {
FIELD(wrsBootStatus_s, ASN_INTEGER, wrsBootUserspaceDaemonsMissing),
FIELD(wrsBootStatus_s, ASN_COUNTER, wrsGwWatchdogTimeouts),
FIELD(wrsBootStatus_s, ASN_INTEGER, wrsFwUpdateStatus),
FIELD(wrsBootStatus_s, ASN_INTEGER, wrsCustomBootScriptSource),
FIELD(wrsBootStatus_s, ASN_OCTET_STR, wrsCustomBootScriptSourceUrl),
FIELD(wrsBootStatus_s, ASN_INTEGER, wrsCustomBootScriptStatus),
};
struct wrsBootStatus_s wrsBootStatus_s;
......@@ -545,6 +552,123 @@ static void get_fw_update_status(void)
}
}
static void get_custom_boot_script_status(void)
{
static int run_once = 0;
FILE *f;
char buff[21]; /* 1 for null char */
if (run_once) {
/* custom boot script is executed once at boot time, no need
* to check it every time */
return;
}
run_once = 1;
/* Clear source url */
memset(wrsBootStatus_s.wrsCustomBootScriptSourceUrl, 0,
sizeof(wrsBootStatus_s.wrsCustomBootScriptSourceUrl));
/* result of custom boot script execution */
f = fopen(CUSTOM_BOOT_SCRIPT_STATUS_FILE, "r");
if (f) {
/* readline without newline */
fscanf(f, LINE_READ_LEN(20), buff);
fclose(f);
if (!strcmp(buff, "disabled")) {
wrsBootStatus_s.wrsCustomBootScriptStatus =
WRS_CUSTOM_BOOT_SCRIPT_STATUS_DISABLED;
/* set also source to disabled */
wrsBootStatus_s.wrsCustomBootScriptSource =
WRS_CUSTOM_BOOT_SCRIPT_SOURCE_DISABLED;
return;
} else if (!strcmp(buff, "ok"))
wrsBootStatus_s.wrsCustomBootScriptStatus =
WRS_CUSTOM_BOOT_SCRIPT_STATUS_OK;
else if (!strcmp(buff, "failed"))
wrsBootStatus_s.wrsCustomBootScriptStatus =
WRS_CUSTOM_BOOT_SCRIPT_STATUS_FAILED;
else if (!strcmp(buff, "wrong_source"))
wrsBootStatus_s.wrsCustomBootScriptStatus =
WRS_CUSTOM_BOOT_SCRIPT_STATUS_WRONG_SRC;
else if (!strcmp(buff, "download_error"))
wrsBootStatus_s.wrsCustomBootScriptStatus =
WRS_CUSTOM_BOOT_SCRIPT_STATUS_DL_ERROR;
else {/* */
wrsBootStatus_s.wrsCustomBootScriptStatus =
WRS_CUSTOM_BOOT_SCRIPT_STATUS_ERROR;
/* try again next time */
run_once = 0;
}
} else {
/* status file not found, probably something else caused
* a problem */
wrsBootStatus_s.wrsCustomBootScriptStatus =
WRS_CUSTOM_BOOT_SCRIPT_STATUS_ERROR_MINOR;
snmp_log(LOG_ERR, "SNMP: " SL_ER " wrsCustomBootScriptStatus: "
"failed to open " CUSTOM_BOOT_SCRIPT_STATUS_FILE
"\n");
/* try again next time */
run_once = 0;
}
/* source of custom boot script */
f = fopen(CUSTOM_BOOT_SCRIPT_SOURCE_FILE, "r");
if (f) {
/* readline without newline */
fscanf(f, LINE_READ_LEN(20), buff);
fclose(f);
if (!strcmp(buff, "local"))
wrsBootStatus_s.wrsCustomBootScriptSource =
WRS_CUSTOM_BOOT_SCRIPT_SOURCE_LOCAL;
else if (!strcmp(buff, "remote"))
wrsBootStatus_s.wrsCustomBootScriptSource =
WRS_CUSTOM_BOOT_SCRIPT_SOURCE_REMOTE;
else {/* */
wrsBootStatus_s.wrsCustomBootScriptSource =
WRS_CUSTOM_BOOT_SCRIPT_SOURCE_ERROR;
/* try again next time */
run_once = 0;
}
} else {
/* status file not found, probably something else caused
* a problem */
wrsBootStatus_s.wrsCustomBootScriptSource =
WRS_CUSTOM_BOOT_SCRIPT_SOURCE_ERROR_MINOR;
snmp_log(LOG_ERR, "SNMP: " SL_ER " wrsCustomBootScriptSource: "
"failed to open " CUSTOM_BOOT_SCRIPT_SOURCE_FILE
"\n");
/* try again next time */
run_once = 0;
}
/* Read custom boot script's URL only when source is remote */
if (wrsBootStatus_s.wrsCustomBootScriptSource
== WRS_CUSTOM_BOOT_SCRIPT_SOURCE_REMOTE) {
/* read URL */
f = fopen(CUSTOM_BOOT_SCRIPT_SOURCE_URL_FILE, "r");
if (f) {
/* readline without newline */
fscanf(f, LINE_READ_LEN(
WRS_CUSTOM_BOOT_SCRIPT_SOURCE_URL_LEN),
wrsBootStatus_s.wrsCustomBootScriptSourceUrl);
fclose(f);
} else {
/* host file not found, put "error" into
* wrsCustomBootScriptSourceUrl */
strcpy(wrsBootStatus_s.wrsCustomBootScriptSourceUrl,
"error");
snmp_log(LOG_ERR, "SNMP: " SL_ER
" wrsCustomBootScriptSourceUrl: failed to "
"open " CUSTOM_BOOT_SCRIPT_SOURCE_URL_FILE
"\n");
}
} else {
memset(wrsBootStatus_s.wrsCustomBootScriptSourceUrl, 0,
sizeof(wrsBootStatus_s.wrsCustomBootScriptSourceUrl));
}
}
time_t wrsBootStatus_data_fill(void)
{
......@@ -579,6 +703,9 @@ time_t wrsBootStatus_data_fill(void)
/* get info about the firmware update status */
get_fw_update_status();
/* get info about the firmware update status */
get_custom_boot_script_status();
/* there was an update, return current time */
return time_update;
}
......
......@@ -42,6 +42,23 @@
#define WRS_FW_UPDATE_STATUS_OK 1 /* ok */
#define WRS_FW_UPDATE_STATUS_CHECKSUM_ERROR 2 /* warning */
#define WRS_CUSTOM_BOOT_SCRIPT_SOURCE_ERROR 1 /* error */
#define WRS_CUSTOM_BOOT_SCRIPT_SOURCE_ERROR_MINOR 2 /* warning */
#define WRS_CUSTOM_BOOT_SCRIPT_SOURCE_LOCAL 3 /* ok */
#define WRS_CUSTOM_BOOT_SCRIPT_SOURCE_REMOTE 4 /* ok */
#define WRS_CUSTOM_BOOT_SCRIPT_SOURCE_DISABLED 5 /* ok */
#define WRS_CUSTOM_BOOT_SCRIPT_STATUS_OK 1 /* ok */
#define WRS_CUSTOM_BOOT_SCRIPT_STATUS_FAILED 2 /* error */
#define WRS_CUSTOM_BOOT_SCRIPT_STATUS_WRONG_SRC 3 /* error */
#define WRS_CUSTOM_BOOT_SCRIPT_STATUS_DL_ERROR 4 /* error */
#define WRS_CUSTOM_BOOT_SCRIPT_STATUS_DISABLED 5 /* ok */
#define WRS_CUSTOM_BOOT_SCRIPT_STATUS_ERROR 6 /* error */
#define WRS_CUSTOM_BOOT_SCRIPT_STATUS_ERROR_MINOR 7 /* warning */
#define WRS_CUSTOM_BOOT_SCRIPT_SOURCE_URL_LEN 128
struct wrsBootStatus_s {
uint32_t wrsBootCnt; /* boots since power-on must be != 0 */
uint32_t wrsRebootCnt; /* soft reboots since hard reboot
......@@ -50,8 +67,8 @@ struct wrsBootStatus_s {
char wrsFaultIP[11]; /* faulty instruction pointer as string */
char wrsFaultLR[11]; /* link register at fault as string */
int32_t wrsConfigSource;
char wrsConfigSourceUrl[WRS_CONFIG_SOURCE_URL_LEN+1];
char wrsRestartReasonMonit[WRS_RESTART_REASON_MONIT_LEN+1];
char wrsConfigSourceUrl[WRS_CONFIG_SOURCE_URL_LEN + 1];
char wrsRestartReasonMonit[WRS_RESTART_REASON_MONIT_LEN + 1];
int32_t wrsBootConfigStatus;
int32_t wrsBootHwinfoReadout;
int32_t wrsBootLoadFPGA;
......@@ -60,6 +77,9 @@ struct wrsBootStatus_s {
int32_t wrsBootUserspaceDaemonsMissing;
int32_t wrsGwWatchdogTimeouts;
int32_t wrsFwUpdateStatus;
int32_t wrsCustomBootScriptSource;
char wrsCustomBootScriptSourceUrl[WRS_CUSTOM_BOOT_SCRIPT_SOURCE_URL_LEN + 1];
int32_t wrsCustomBootScriptStatus;
};
extern struct wrsBootStatus_s wrsBootStatus_s;
......
......@@ -164,6 +164,41 @@ time_t wrsOSStatus_data_fill(void)
slog_obj_name, b->wrsBootUserspaceDaemonsMissing);
}
/* custom boot script source error */
if (b->wrsCustomBootScriptSource == WRS_CUSTOM_BOOT_SCRIPT_SOURCE_ERROR) {
o->wrsBootSuccessful = WRS_BOOT_SUCCESSFUL_ERROR;
snmp_log(LOG_ERR, "SNMP: " SL_ER " %s: unrecognized source of custom boot script\n",
slog_obj_name);
}
if (b->wrsCustomBootScriptStatus == WRS_CUSTOM_BOOT_SCRIPT_STATUS_FAILED) {
o->wrsBootSuccessful = WRS_BOOT_SUCCESSFUL_ERROR;
snmp_log(LOG_ERR, "SNMP: " SL_ER " %s: custom boot script failed during execution\n",
slog_obj_name);
}
if (b->wrsCustomBootScriptStatus == WRS_CUSTOM_BOOT_SCRIPT_STATUS_WRONG_SRC) {
o->wrsBootSuccessful = WRS_BOOT_SUCCESSFUL_ERROR;
snmp_log(LOG_ERR, "SNMP: " SL_ER " %s: unrecognized source of custom boot script\n",
slog_obj_name);
}
if (b->wrsCustomBootScriptStatus == WRS_CUSTOM_BOOT_SCRIPT_STATUS_DL_ERROR) {
o->wrsBootSuccessful = WRS_BOOT_SUCCESSFUL_ERROR;
snmp_log(LOG_ERR, "SNMP: " SL_ER " %s: error while downloading custom boot script\n",
slog_obj_name);
}
if (b->wrsCustomBootScriptStatus == WRS_CUSTOM_BOOT_SCRIPT_STATUS_ERROR) {
o->wrsBootSuccessful = WRS_BOOT_SUCCESSFUL_ERROR;
snmp_log(LOG_ERR, "SNMP: " SL_ER " %s: error in status file of custom boot script execution\n",
slog_obj_name);
}
if (b->wrsCustomBootScriptSource == WRS_CUSTOM_BOOT_SCRIPT_SOURCE_REMOTE
&& strnlen(b->wrsCustomBootScriptSourceUrl, WRS_CUSTOM_BOOT_SCRIPT_SOURCE_URL_LEN) == 0) {
o->wrsBootSuccessful = WRS_BOOT_SUCCESSFUL_ERROR;
snmp_log(LOG_ERR, "SNMP: " SL_ER " %s: empty URL for custom boot script\n",
slog_obj_name);
}
/* check if warning */
if (!o->wrsBootSuccessful) {
......@@ -217,8 +252,16 @@ time_t wrsOSStatus_data_fill(void)
snmp_log(LOG_ERR, "SNMP: " SL_W " %s: wrong data in hwinfo, unknown version of SCB\n",
slog_obj_name);
}
if (b->wrsCustomBootScriptSource == WRS_CUSTOM_BOOT_SCRIPT_SOURCE_ERROR_MINOR) {
o->wrsBootSuccessful = WRS_BOOT_SUCCESSFUL_WARNING;
snmp_log(LOG_ERR, "SNMP: " SL_W " %s: Unable to read status file of wrsCustomBootScriptSource\n",
slog_obj_name);
}
if (b->wrsCustomBootScriptStatus == WRS_CUSTOM_BOOT_SCRIPT_STATUS_ERROR_MINOR) {
o->wrsBootSuccessful = WRS_BOOT_SUCCESSFUL_WARNING;
snmp_log(LOG_ERR, "SNMP: " SL_W " %s: Unable to read status file of wrsCustomBootScriptStatus\n",
slog_obj_name);
}
}
/* check if any of fields equal to 0 */
......@@ -253,6 +296,16 @@ time_t wrsOSStatus_data_fill(void)
snmp_log(LOG_ERR, "SNMP: " SL_NA " %s: Status of wrsFwUpdateStatus not available\n",
slog_obj_name);
}
if (b->wrsCustomBootScriptSource == 0) {
o->wrsBootSuccessful = WRS_BOOT_SUCCESSFUL_WARNING_NA;
snmp_log(LOG_ERR, "SNMP: " SL_NA " %s: Status of wrsCustomBootScriptSource not available\n",
slog_obj_name);
}
if (b->wrsCustomBootScriptStatus == 0) {
o->wrsBootSuccessful = WRS_BOOT_SUCCESSFUL_WARNING_NA;
snmp_log(LOG_ERR, "SNMP: " SL_NA " %s: Status of wrsCustomBootScriptStatus not available\n",
slog_obj_name);
}
}
if ((!o->wrsBootSuccessful)
......@@ -269,6 +322,18 @@ time_t wrsOSStatus_data_fill(void)
&& b->wrsBootKernelModulesMissing == 0
&& b->wrsBootUserspaceDaemonsMissing == 0
&& b->wrsFwUpdateStatus == WRS_FW_UPDATE_STATUS_OK
/* custom boot script source and status */
&& (/* disabled */
(b->wrsCustomBootScriptSource == WRS_CUSTOM_BOOT_SCRIPT_SOURCE_DISABLED
&& b->wrsCustomBootScriptStatus == WRS_CUSTOM_BOOT_SCRIPT_STATUS_DISABLED
) || (/* local */
b->wrsCustomBootScriptSource == WRS_CUSTOM_BOOT_SCRIPT_SOURCE_LOCAL
&& b->wrsCustomBootScriptStatus == WRS_CUSTOM_BOOT_SCRIPT_STATUS_OK
) || (/* remote */
b->wrsCustomBootScriptSource == WRS_CUSTOM_BOOT_SCRIPT_SOURCE_REMOTE
&& b->wrsCustomBootScriptStatus == WRS_CUSTOM_BOOT_SCRIPT_STATUS_OK
)
)
)
) { /* OK, but check source */
/* additional check of source */
......
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