Commit 06baf24b authored by Adam Wujek's avatar Adam Wujek 💬

Merge branch 'adam-custom_boot_script'

Implement [Feature: 1363] support of a custom script to be run at boot
parents b8b50972 c8fb2979
......@@ -275,6 +275,7 @@ config WRS_LOG_OTHER
In the current version following programs uses this option:
--wrs_watchdog
--wrs_auxclk
--wrs_custom_boot_script.sh
This collective entry is to avoid number of entries in dot-config.
The string can be a pathname (e.g. /dev/kmsg) or a <facility>.<level>
spefification like "daemon.debug". An empty strings is used
......@@ -772,6 +773,47 @@ config NIC_THROTTLING_VAL
endmenu
menu "Custom boot script configuration"
config CUSTOM_BOOT_SCRIPT_ENABLED
bool "Execute custom script"
default n
help
Enable execution of a custom script during boot. It can be a local
script placed at /wr/bin/custom_boot_script.sh or downloaded from
a given URL. This script can be used for some exotic configurations
that dot-config does not support. This scipt runs before switching
is enabled.
choice CUSTOM_BOOT_SCRIPT_SOURCE
prompt "Source for a custom boot script"
depends on CUSTOM_BOOT_SCRIPT_ENABLED
default CUSTOM_BOOT_SCRIPT_SOURCE_LOCAL
help
Defines the source of a custom boot script. Local or remote.
config CUSTOM_BOOT_SCRIPT_SOURCE_LOCAL
bool "Use local custom script"
help
Use /wr/bin/custom_boot_script.sh to be executed at boot.
config CUSTOM_BOOT_SCRIPT_SOURCE_REMOTE
bool "Use remote custom script"
help
Use the URL in CUSTOM_BOOT_SCRIPT_SOURCE_REMOTE_URL to download the
custom boot script.
endchoice
config CUSTOM_BOOT_SCRIPT_SOURCE_REMOTE_URL
string "URL of a custom script"
depends on CUSTOM_BOOT_SCRIPT_SOURCE_REMOTE
help
URL to the custom script. HOSTNAME, IPADDR and MACADDR are
substituted before retrieving the file.
Example: "tftp://morgana/custom-script-IPADDR"
endmenu
menu "Developer options"
config MONIT_DISABLE
bool "Disable monit"
......
......@@ -577,8 +577,9 @@ value is changed by the web interface, proper action is taken.
Logging options for the three main WRS processes and other programs.
@t{CONFIG_WRS_LOG_OTHER} is currently used by:
@itemize
@item wrs_watchdog
@item wrs_auxclk
@item @t{wrs_watchdog}
@item @t{wrs_auxclk}
@item @t{wrs_custom_boot_script.sh}
@end itemize
Each value
can be a pathname, to select logging to file (and @t{/dev/kmsg}
......@@ -791,10 +792,27 @@ value is changed by the web interface, proper action is taken.
Limit the Rx bandwidth of the traffic that goes from WR ports to Linux.
Throttling can be enabled to prevent Linux using 100% of the processing
power to receive Ethernet frames coming from WR ports to the CPU.
To enable throttling set @t{CONFIG_NIC_THROTTLING_ENABLED}.
@t{CONFIG_NIC_THROTTLING_VAL} contains maximum allowed bandwidth
in KB/s.
@item CONFIG_CUSTOM_BOOT_SCRIPT_ENABLED
@itemx CONFIG_CUSTOM_BOOT_SCRIPT_SOURCE_LOCAL
@itemx CONFIG_CUSTOM_BOOT_SCRIPT_SOURCE_REMOTE
@itemx CONFIG_CUSTOM_BOOT_SCRIPT_SOURCE_REMOTE_URL
It is possible to run a custom script at boot time. In this case please set @t{CONFIG_CUSTOM_BOOT_SCRIPT_ENABLED}.
To run a script from the local filesystem please set @t{CONFIG_CUSTOM_BOOT_SCRIPT_SOURCE_LOCAL}.
The script at the location @t{/wr/bin/custom_boot_script.sh} will be executed.
As an alternative, you can choose @t{CONFIG_CUSTOM_BOOT_SCRIPT_SOURCE_REMOTE} and be able to
specify an URL (@t{http://}, @t{ftp://} or @t{tftp://}) in @t{CONFIG_CUSTOM_BOOT_SCRIPT_SOURCE_REMOTE_URL} whence
the switch will download the script to be executed at boot time.
The filename in the URL can include @t{HOSTNAME}, @t{IPADDR}
and/or @t{MACADDR}, so the same configuration string can be used to set up a batch
of switches with different configurations.
@item CONFIG_MONIT_DISABLE
Disable monitoring of running processes by monit. Monit by default
......
......@@ -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}{}
......
#!/bin/sh
set -o pipefail
dotconfig=/wr/etc/dot-config
tmpdir=/tmp
tmpscript="$tmpdir"/custom_boot_script.sh
custom_boot_status_file="$tmpdir"/custom_boot_script_status
custom_boot_source_file="$tmpdir"/custom_boot_script_source
custom_boot_source_url_file="$tmpdir"/custom_boot_script_url
print_error() {
echo "$1"
eval echo "$0: $1" $LOGPIPE
}
start() {
echo -n "Executing custom boot script: "
if [ -f $dotconfig ]; then
. $dotconfig
else
echo "$0 unable to source dot-config ($dotconfig)!"
fi
# set log destination
WRS_LOG=$CONFIG_WRS_LOG_OTHER
# if empty turn it to /dev/null
if [ -z $WRS_LOG ]; then
WRS_LOG="/dev/null";
fi
# if a pathname, use it
if echo "$WRS_LOG" | grep / > /dev/null; then
eval LOGPIPE=\" \> $WRS_LOG 2\>\&1 \";
else
# not a pathname: use verbatim
eval LOGPIPE=\" 2\>\&1 \| logger -t wr-switch -p $WRS_LOG\"
fi
# If custom boot script is not enabled, exit
if [ ! "$CONFIG_CUSTOM_BOOT_SCRIPT_ENABLED" = "y" ]; then
echo "disabled"
echo "disabled" > "$custom_boot_status_file"
exit;
fi
if [ "$CONFIG_CUSTOM_BOOT_SCRIPT_SOURCE_LOCAL" = "y" ]; then
echo "local" > "$custom_boot_source_file"
execute_script=/wr/bin/custom_boot_script.sh
fi
if [ "$CONFIG_CUSTOM_BOOT_SCRIPT_SOURCE_REMOTE" = "y" ]; then
echo "remote" > "$custom_boot_source_file"
# replace IPADDR and MACADDR, to have a device-specific name
macaddr=$(cat /sys/class/net/eth0/address)
ipaddr=$(ifconfig eth0 | grep inet | cut -d: -f 2 | cut '-d ' -f 1)
if [ -z "$ipaddr" ]; then
eval echo "$0: Warning no IP set!" $LOGPIPE
fi
host_name=`hostname`
URL=$(echo $CONFIG_CUSTOM_BOOT_SCRIPT_SOURCE_REMOTE_URL | \
sed -e s/MACADDR/$macaddr/ -e s/IPADDR/$ipaddr/ -e s/HOSTNAME/$host_name/)
# split the parts, as we need to handle tftp by hand
proto=$(echo $URL | cut -d: -f 1)
host=$(echo $URL | cut -d/ -f 3)
filename=$(echo $URL | cut -d/ -f 4-)
# save URL of custom boot script, to be used by SNMPd
echo "$URL" > "$custom_boot_source_url_file"
rm -f "$tmpscript"
case $proto in
http|ftp)
wget $URL -O "$tmpscript"
;;
tftp)
tftp -g -r "$filename" -l "$tmpscript" "$host"
;;
*)
echo "Invalid URL for custom boot script: \"$URL\"" >& 2
;;
esac
if [ ! -f "$tmpscript" ]; then
print_error "Download error!"
echo "download_error" > "$custom_boot_status_file"
exit
fi
execute_script="$tmpscript"
chmod +x "$execute_script"
fi
if [ -z "$execute_script" ]; then
print_error "Please specify local or remote in dot-config!"
echo "wrong_source" > "$custom_boot_source_file"
echo "wrong_source" > "$custom_boot_status_file"
exit
fi
if [ ! -f "$execute_script" ]; then
print_error "$execute_script not found!"
exit
fi
# redirect output of script to OTHER_LOG
eval "$execute_script" start $LOGPIPE
ret=$?
if [ $ret -eq 0 ]; then
echo "OK"
echo "ok" > "$custom_boot_status_file"
else
echo "Failed"
echo "failed" > "$custom_boot_status_file"
fi
}
stop() {
if [ -f $dotconfig ]; then
. $dotconfig
else
echo "$0 unable to source dot-config ($dotconfig)!"
fi
# set log destination
WRS_LOG=$CONFIG_WRS_LOG_OTHER
# if empty turn it to /dev/null
if [ -z $WRS_LOG ]; then
WRS_LOG="/dev/null";
fi
# if a pathname, use it
if echo "$WRS_LOG" | grep / > /dev/null; then
eval LOGPIPE=\" \> $WRS_LOG 2\>\&1 \";
else
# not a pathname: use verbatim
eval LOGPIPE=\" 2\>\&1 \| logger -t wr-switch -p $WRS_LOG\"
fi
if [ ! "$CONFIG_CUSTOM_BOOT_SCRIPT_ENABLED" = "y" ]; then
exit;
fi
echo -n "Stopping custom boot script: "
if [ "$CONFIG_CUSTOM_BOOT_SCRIPT_SOURCE_LOCAL" = "y" ]; then
execute_script=/wr/bin/custom_boot_script.sh
fi
if [ "$CONFIG_CUSTOM_BOOT_SCRIPT_SOURCE_REMOTE" = "y" ]; then
execute_script="$tmpscript"
fi
if [ -z "$execute_script" ]; then
print_error "Please specify local or remote in dot-config!"
exit
fi
if [ ! -f "$execute_script" ]; then
print_error "$execute_script not found!"
exit
fi
# redirect output of script to OTHER_LOG
eval "$execute_script" stop $LOGPIPE
ret=$?
if [ $ret -eq 0 ]; then
echo "OK"
else
echo "Failed"
fi
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
restart
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
;;
esac
../init.d/wrs_custom_boot_script.sh
\ No newline at end of file
#!/bin/sh
# Adam Wujek, CERN 2016
#
# Example of a custom script to be used at boot time.
start() {
echo "$0: start"
}
stop() {
echo "$0: stop"
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
restart
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
;;
esac
......@@ -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