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

userspace/snmpd: add wrsBootStatusGroup

add:
--wrsConfigSource
--wrsConfigSourceHost
--wrsConfigSourceFilename
Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent faacd927
......@@ -33,6 +33,7 @@ SOURCES = \
wrsOSStatusGroup.c \
wrsVersionGroup.c \
wrsCurrentTimeGroup.c \
wrsBootStatusGroup.c \
wrsTemperatureGroup.c \
wrsStartCntGroup.c \
wrsSpllStatusGroup.c \
......
......@@ -202,10 +202,63 @@ wrsDateTAIString OBJECT-TYPE
"The current TAI time, printed as %y-%m-%d-%H:%M:%S (no time zone)"
::= { wrsCurrentTimeGroup 2 }
--wrsBootStatusGroup OBJECT IDENTIFIER ::= { wrsOperationStatus 2 }
wrsTemperatureGroup OBJECT IDENTIFIER ::= { wrsOperationStatus 3 }
--wrsBootStatusGroup (.7.1.2)
wrsBootStatusGroup OBJECT IDENTIFIER ::= { wrsOperationStatus 2 }
--wrsBootCnt OBJECT-TYPE
-- SYNTAX Counter32
-- MAX-ACCESS read-only
-- STATUS current
-- DESCRIPTION
-- "Number of switch's boots"
-- ::= { wrsBootStatusGroup 1 }
--wrsRestartReason OBJECT-TYPE
-- SYNTAX Integer32
-- MAX-ACCESS read-only
-- STATUS current
-- DESCRIPTION
-- "Reason of last switch restart"
-- ::= { wrsBootStatusGroup 3 }
wrsConfigSource OBJECT-TYPE
SYNTAX INTEGER {
na(0),
error(1),
errorMinor(2),
local(3),
tftp(4),
http(5),
ftp(6)
}
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"Source of used dotconfig, protocol if gonfig was received from network
errorMinor - cannot read status file, problem is probably somewhere else"
::= { wrsBootStatusGroup 6 }
wrsConfigSourceHost OBJECT-TYPE
SYNTAX DisplayString (SIZE (0..64))
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"Server address which provided dotconfig"
::= { wrsBootStatusGroup 7 }
wrsConfigSourceFilename OBJECT-TYPE
SYNTAX DisplayString (SIZE (0..128))
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"Path and filename of dotconfig file on server"
::= { wrsBootStatusGroup 8 }
-- wrsTemperatureGroup (.7.1.3)
wrsTemperatureGroup OBJECT IDENTIFIER ::= { wrsOperationStatus 3 }
wrsTempFPGA OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-only
......
......@@ -12,6 +12,7 @@
#include "wrsOSStatusGroup.h"
#include "wrsVersionGroup.h"
#include "wrsCurrentTimeGroup.h"
#include "wrsBootStatusGroup.h"
#include "wrsTemperatureGroup.h"
#include "wrsStartCntGroup.h"
#include "wrsSpllStatusGroup.h"
......@@ -30,6 +31,7 @@ void init_wrsSnmp(void)
init_wrsOSStatusGroup();
init_wrsVersionGroup();
init_wrsCurrentTimeGroup();
init_wrsBootStatusGroup();
init_wrsTemperatureGroup();
init_wrsStartCntGroup();
init_wrsSpllStatusGroup();
......
#include "wrsSnmp.h"
#include "wrsBootStatusGroup.h"
#define DOTCONFIGDIR "/tmp"
#define DOTCONFIG_PROTO "dot-config_proto"
#define DOTCONFIG_HOST "dot-config_host"
#define DOTCONFIG_FILENAME "dot-config_filename"
/* 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]"
#define LINE_READ_LEN(x) LINE_READ_LEN_HELPER(x)
static struct pickinfo wrsBootStatus_pickinfo[] = {
FIELD(wrsBootStatus_s, ASN_COUNTER, wrsBootCnt),
FIELD(wrsBootStatus_s, ASN_COUNTER, wrsRebootCnt),
FIELD(wrsBootStatus_s, ASN_INTEGER, wrsRestartReason),
FIELD(wrsBootStatus_s, ASN_OCTET_STR, wrsFaultIP),
FIELD(wrsBootStatus_s, ASN_OCTET_STR, wrsFaultLR),
FIELD(wrsBootStatus_s, ASN_INTEGER, wrsConfigSource),
FIELD(wrsBootStatus_s, ASN_OCTET_STR, wrsConfigSourceHost),
FIELD(wrsBootStatus_s, ASN_OCTET_STR, wrsConfigSourceFilename),
};
struct wrsBootStatus_s wrsBootStatus_s;
static void get_dotconfig_source(void)
{
char buff[10];
FILE *f;
/* Check dotconfig source.
* dotconfig source can change in runtime, i.e. from remote to local by
* web-interface */
/* read protocol used to get dotconfig */
f = fopen(DOTCONFIGDIR "/" DOTCONFIG_PROTO, "r");
if (f) {
/* readline without newline */
fscanf(f, LINE_READ_LEN(10), buff);
fclose(f);
if (!strncmp(buff, "tftp", 10))
wrsBootStatus_s.wrsConfigSource =
WRS_CONFIG_SOURCE_PROTO_TFTP;
else if (!strncmp(buff, "http", 10))
wrsBootStatus_s.wrsConfigSource =
WRS_CONFIG_SOURCE_PROTO_HTTP;
else if (!strncmp(buff, "ftp", 10))
wrsBootStatus_s.wrsConfigSource =
WRS_CONFIG_SOURCE_PROTO_FTP;
else if (!strncmp(buff, "local", 10))
wrsBootStatus_s.wrsConfigSource =
WRS_CONFIG_SOURCE_PROTO_LOCAL;
else /* unknown proto */
wrsBootStatus_s.wrsConfigSource =
WRS_CONFIG_SOURCE_PROTO_ERROR;
} else {
/* proto file not found, probably something else caused
* a problem */
wrsBootStatus_s.wrsConfigSource =
WRS_CONFIG_SOURCE_PROTO_ERROR_MINOR;
}
/* read host used to get dotconfig */
f = fopen(DOTCONFIGDIR "/" DOTCONFIG_HOST, "r");
if (f) {
/* readline without newline */
fscanf(f, LINE_READ_LEN(WRS_CONFIG_SOURCE_HOST_LEN),
wrsBootStatus_s.wrsConfigSourceHost);
fclose(f);
} else {
/* host file not found, put "error" into wrsConfigSourceHost */
strcpy(wrsBootStatus_s.wrsConfigSourceHost, "error");
}
/* read filename used to get dotconfig */
f = fopen(DOTCONFIGDIR "/" DOTCONFIG_FILENAME, "r");
if (f) {
/* readline without newline */
fscanf(f, LINE_READ_LEN(WRS_CONFIG_SOURCE_FILENAME_LEN),
wrsBootStatus_s.wrsConfigSourceFilename);
fclose(f);
} else {
/* host file not found, put "error" into
* wrsConfigSourceFilename */
strcpy(wrsBootStatus_s.wrsConfigSourceFilename, "error");
}
}
time_t wrsBootStatus_data_fill(void)
{
static time_t time_update;
time_t time_cur;
time_cur = time(NULL);
if (time_update
&& time_cur - time_update < WRSBOOTSTATUS_CACHE_TIMEOUT) {
/* cache not updated, return last update time */
return time_update;
}
time_update = time_cur;
/* get dotconfig source information */
get_dotconfig_source();
/* there was an update, return current time */
return time_update;
}
#define GT_OID WRSBOOTSTATUS_OID
#define GT_PICKINFO wrsBootStatus_pickinfo
#define GT_DATA_FILL_FUNC wrsBootStatus_data_fill
#define GT_DATA_STRUCT wrsBootStatus_s
#define GT_GROUP_NAME "wrsBootStatusGroup"
#define GT_INIT_FUNC init_wrsBootStatusGroup
#include "wrsGroupTemplate.h"
#ifndef WRS_BOOT_STATUS_GROUP_H
#define WRS_BOOT_STATUS_GROUP_H
#define WRSBOOTSTATUS_CACHE_TIMEOUT 5
#define WRSBOOTSTATUS_OID WRS_OID, 7, 1, 2
#define WRS_CONFIG_SOURCE_HOST_LEN 64
#define WRS_CONFIG_SOURCE_FILENAME_LEN 128
#define WRS_CONFIG_SOURCE_PROTO_ERROR 1 /* error */
#define WRS_CONFIG_SOURCE_PROTO_ERROR_MINOR 2 /* warning */
#define WRS_CONFIG_SOURCE_PROTO_LOCAL 3 /* ok */
/* below proto are ok, if host and filename not empty */
#define WRS_CONFIG_SOURCE_PROTO_TFTP 4
#define WRS_CONFIG_SOURCE_PROTO_HTTP 5
#define WRS_CONFIG_SOURCE_PROTO_FTP 6
struct wrsBootStatus_s {
uint32_t wrsBootCnt; /* boots since power-on must be != 0 */
uint32_t wrsRebootCnt; /* soft reboots since hard reboot
* (i.e. caused by reset button) */
int32_t wrsRestartReason; /* reason of last restart */
char wrsFaultIP[11]; /* faulty instruction pointer as string */
char wrsFaultLR[11]; /* link register at fault as string */
int32_t wrsConfigSource;
char wrsConfigSourceHost[WRS_CONFIG_SOURCE_HOST_LEN+1];
char wrsConfigSourceFilename[WRS_CONFIG_SOURCE_FILENAME_LEN+1];
};
extern struct wrsBootStatus_s wrsBootStatus_s;
time_t wrsBootStatus_data_fill(void);
void init_wrsBootStatusGroup(void);
#endif /* WRS_BOOT_STATUS_GROUP_H */
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