Commit 03ad7c21 authored by Adam Wujek's avatar Adam Wujek 💬

userspace/snmpd: add wrsBootConfigStatus to wrsBootStatusGroup

wrsBootConfigStatus provide information if dot-config was loaded/downloaded
successfully. Please note that there is no verification of local config.

Update:
--MIB
--wrsBootStatusGroup.c and wrsBootStatusGroup.h
--apply_dot-config
--S20dot-config
Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent b814d3e0
......@@ -13,8 +13,11 @@ tmpdir=/tmp
if [ -f $dotconfig ]; then
. $dotconfig
echo "local" > "$tmpdir"/dot-config_proto
#assume that local config is always ok
echo "config_ok" > "$tmpdir"/dot-config_status
else
echo "no_config" > "$tmpdir"/dot-config_proto
echo "config_error" > "$tmpdir"/dot-config_status
fi
# Create /etc/resolv.conf, so we can use it. /etc is ramdisk anyways
......@@ -54,13 +57,20 @@ if [ -n "$CONFIG_DOTCONF_URL" ]; then
echo "Invalid URL for dot-config: \"$URL\"" >& 2
;;
esac
# If it exists, it is not empty or too small, and the checker is happy..
if [ -f $tmpconfig ] &&
[ $(cat $tmpconfig | wc -c) -gt 200 ] &&
/wr/bin/wrs_checkcfg $tmpconfig /wr/etc/Kconfig; then
echo "Using newly-downloaded dot-config from $URL"
# copy it in place to use the new file (unless it is identical)
cmp -s $tmpconfig $dotconfig || cp $tmpconfig $dotconfig
if [ -f $tmpconfig ]; then
# If it exists, it is not empty or too small, and the checker is happy
if [ $(cat $tmpconfig | wc -c) -gt 200 ] &&
/wr/bin/wrs_checkcfg $tmpconfig /wr/etc/Kconfig; then
echo "Using newly-downloaded dot-config from $URL"
# copy it in place to use the new file (unless it is identical)
cmp -s $tmpconfig $dotconfig || cp $tmpconfig $dotconfig
# info for SNMP that downloading was successful and checker is happy
echo "config_ok" > "$tmpdir"/dot-config_status
else
echo "check_error" > "$tmpdir"/dot-config_status
fi
else
echo "download_error" > "$tmpdir"/dot-config_status
fi
fi
......
......@@ -27,6 +27,8 @@ if [ "$1" == "local_config" ]; then
# network
rm /tmp/dot-config_*
echo "local" > /tmp/dot-config_proto
#assume that local config is always ok
echo "config_ok" > /tmp/dot-config_status
fi
# Check and complain, but we need to edit some files even if unconfigured.
......
......@@ -300,6 +300,23 @@ wrsConfigSourceFilename OBJECT-TYPE
"Path and filename of dotconfig file on server"
::= { wrsBootStatusGroup 8 }
wrsBootConfigStatus OBJECT-TYPE
SYNTAX INTEGER {
na(0),
ok(1),
error(2),
downloadError(3),
checkError(4),
errorMinor(5)
}
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"Result of loading or downloading dot-config file
downloadError - unable to download file from given source
checkError - config file is not valid or too short (less than 200 characters).
errorMinor - cannot read status file, problem is probably somewhere else"
::= { wrsBootStatusGroup 9 }
-- wrsTemperatureGroup (.7.1.3)
wrsTemperatureGroup OBJECT IDENTIFIER ::= { wrsOperationStatus 3 }
......
......@@ -8,6 +8,7 @@
#define DOTCONFIG_PROTO "dot-config_proto"
#define DOTCONFIG_HOST "dot-config_host"
#define DOTCONFIG_FILENAME "dot-config_filename"
#define DOTCONFIG_DOWNLOAD "dot-config_status"
/* Macros for fscanf function to read line with maximum of "x" characters
* without new line. Macro expands to something like: "%10[^\n]" */
......@@ -27,6 +28,7 @@ static struct pickinfo wrsBootStatus_pickinfo[] = {
FIELD(wrsBootStatus_s, ASN_INTEGER, wrsConfigSource),
FIELD(wrsBootStatus_s, ASN_OCTET_STR, wrsConfigSourceHost),
FIELD(wrsBootStatus_s, ASN_OCTET_STR, wrsConfigSourceFilename),
FIELD(wrsBootStatus_s, ASN_INTEGER, wrsBootConfigStatus),
};
struct wrsBootStatus_s wrsBootStatus_s;
......@@ -104,7 +106,7 @@ static void get_boot_info(void){
static void get_dotconfig_source(void)
{
char buff[10];
char buff[21]; /* 1 for null char */
FILE *f;
/* Check dotconfig source.
......@@ -114,7 +116,7 @@ static void get_dotconfig_source(void)
f = fopen(DOTCONFIGDIR "/" DOTCONFIG_PROTO, "r");
if (f) {
/* readline without newline */
fscanf(f, LINE_READ_LEN(10), buff);
fscanf(f, LINE_READ_LEN(20), buff);
fclose(f);
if (!strncmp(buff, "tftp", 10))
wrsBootStatus_s.wrsConfigSource =
......@@ -137,6 +139,7 @@ static void get_dotconfig_source(void)
wrsBootStatus_s.wrsConfigSource =
WRS_CONFIG_SOURCE_PROTO_ERROR_MINOR;
}
/* read host used to get dotconfig */
f = fopen(DOTCONFIGDIR "/" DOTCONFIG_HOST, "r");
if (f) {
......@@ -161,6 +164,30 @@ static void get_dotconfig_source(void)
* wrsConfigSourceFilename */
strcpy(wrsBootStatus_s.wrsConfigSourceFilename, "error");
}
f = fopen(DOTCONFIGDIR "/" DOTCONFIG_DOWNLOAD, "r");
if (f) {
/* readline without newline */
fscanf(f, LINE_READ_LEN(20), buff);
fclose(f);
if (!strncmp(buff, "config_ok", 20))
wrsBootStatus_s.wrsBootConfigStatus =
WRS_CONFIG_STATUS_OK;
else if (!strncmp(buff, "check_error", 20))
wrsBootStatus_s.wrsBootConfigStatus =
WRS_CONFIG_STATUS_CHECK_ERROR;
else if (!strncmp(buff, "download_error", 20))
wrsBootStatus_s.wrsBootConfigStatus =
WRS_CONFIG_STATUS_DL_ERROR;
else
wrsBootStatus_s.wrsBootConfigStatus =
WRS_CONFIG_STATUS_ERROR;
} else {
/* status file not found, probably something else caused
* a problem */
wrsBootStatus_s.wrsConfigSource =
WRS_CONFIG_STATUS_ERROR_MINOR;
}
}
time_t wrsBootStatus_data_fill(void)
......
......@@ -16,6 +16,12 @@
#define WRS_CONFIG_SOURCE_PROTO_HTTP 5
#define WRS_CONFIG_SOURCE_PROTO_FTP 6
#define WRS_CONFIG_STATUS_OK 1 /* ok */
#define WRS_CONFIG_STATUS_ERROR 2 /* error */
#define WRS_CONFIG_STATUS_DL_ERROR 3 /* error */
#define WRS_CONFIG_STATUS_CHECK_ERROR 4 /* error */
#define WRS_CONFIG_STATUS_ERROR_MINOR 5 /* warning */
struct wrsBootStatus_s {
uint32_t wrsBootCnt; /* boots since power-on must be != 0 */
uint32_t wrsRebootCnt; /* soft reboots since hard reboot
......@@ -26,6 +32,7 @@ struct wrsBootStatus_s {
int32_t wrsConfigSource;
char wrsConfigSourceHost[WRS_CONFIG_SOURCE_HOST_LEN+1];
char wrsConfigSourceFilename[WRS_CONFIG_SOURCE_FILENAME_LEN+1];
int32_t wrsBootConfigStatus;
};
extern struct wrsBootStatus_s wrsBootStatus_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