Commit 976c6328 authored by Maciej Lipinski's avatar Maciej Lipinski

[snmp] Bugfix: do not check startCnt when daemon is disabled.

SNMP checkes whether monitored daemons where restarted by looking
at the respective /tmp/start_cnt_X file. Such file is not created
if a daemon is disabled in configuration (dotconfig). Such
disabling is a new feature. It turns out that not all of SNMP
deamon was updated to accommodate it. The SNMP daemon was checking
at start which daemons are disbled but later did not use this
info in wrsStartCntGroup and the startCnt of the disabled deamons
was attempted to be checked, resulting in an error. This has
been fixed.
parent 7acf532b
......@@ -86,25 +86,11 @@ static struct wrs_km_item kernel_modules[] = {
[9] = {"libcomposite"},
};
/* user space daemon list item */
struct wrs_usd_item {
char *key; /* process name */
int32_t exp; /* expected number of processes */
uint32_t cnt; /* number of processes found */
};
#define UDI_HTTP 4 /* index of web server in userspace_daemons array */
#define UDI_MONIT 5 /* index of MONIT in userspace_daemons array */
#define UDI_LLDP 8 /* index of LLDP in userspace_daemons array */
#define UDI_NSLCD 9 /* index of NSLCD (LDAP) in userspace_daemons array */
/* user space daemon list */
/* - key contain process name reported by ps command
* - positive exp describe exact number of expected processes
* - negative exp describe minimum number of expected processes. Usefull for
* processes that is hard to predict number of their instances. For example
* new sshd process is spawned at ssh login.
*/
static struct wrs_usd_item userspace_daemons[] = {
/* This structure is filled/used here and it is also used in
wrsStartCntGroup to recognize on deamons the startCnt should
be checked. Note, wrs_usd_item struct and UDI_* are defined in
wrsBootStatusGroup.h. */
struct wrs_usd_item userspace_daemons[] = {
[0] = {.key = "/usr/sbin/sshd", .exp = -1}, /* expect at least one
* sshd process */
[1] = {"/wr/bin/wrsw_hal", 1}, /* two wrsw_hal instances */
......
......@@ -107,4 +107,24 @@ extern struct wrsBootStatus_s wrsBootStatus_s;
time_t wrsBootStatus_data_fill(void);
void init_wrsBootStatusGroup(void);
/* user space daemon list item */
struct wrs_usd_item {
char *key; /* process name */
int32_t exp; /* expected number of processes */
uint32_t cnt; /* number of processes found */
};
#define UDI_HTTP 4 /* index of web server in userspace_daemons array */
#define UDI_MONIT 5 /* index of MONIT in userspace_daemons array */
#define UDI_LLDP 8 /* index of LLDP in userspace_daemons array */
#define UDI_NSLCD 9 /* index of NSLCD (LDAP) in userspace_daemons array */
/* user space daemon list */
/* - key contain process name reported by ps command
* - positive exp describe exact number of expected processes
* - negative exp describe minimum number of expected processes. Usefull for
* processes that is hard to predict number of their instances. For example
* new sshd process is spawned at ssh login.
*/
#endif /* WRS_BOOT_STATUS_GROUP_H */
#include "wrsSnmp.h"
#include "snmp_shmem.h"
#include "wrsBootStatusGroup.h"
#include "wrsStartCntGroup.h"
#define START_CNT_SSHD "/tmp/start_cnt_sshd"
......@@ -10,6 +11,11 @@
#define START_CNT_LLDPD "/tmp/start_cnt_lldpd"
#define START_CNT_LDAP "/tmp/start_cnt_ldap"
/* This structure is defined in read in wrsBootStatusGroup.c.
It is used here to know which deamons are disabled and
therefore shall not be checked for start cnt. */
extern struct wrs_usd_item userspace_daemons[];
static struct pickinfo wrsStartCnt_pickinfo[] = {
FIELD(wrsStartCnt_s, ASN_COUNTER, wrsStartCntHAL),
FIELD(wrsStartCnt_s, ASN_COUNTER, wrsStartCntPTP),
......@@ -33,7 +39,7 @@ static void read_start_count(char *file, uint32_t *counter)
f = fopen(file, "r");
if (!f) {
snmp_log(LOG_ERR, "SNMP: " SL_ER
" wrsStartCntGroup filed to open file %s\n", file);
" wrsStartCntGroup failed to open file %s\n", file);
} else {
/* ignore fscanf errors */
fscanf(f, "%d", counter);
......@@ -77,12 +83,19 @@ time_t wrsStartCnt_data_fill(void){
}
read_start_count(START_CNT_SSHD, &wrsStartCnt_s.wrsStartCntSshd);
read_start_count(START_CNT_HTTPD, &wrsStartCnt_s.wrsStartCntHttpd);
if(userspace_daemons[UDI_HTTP].exp) /* check only if enabled (exp != 0) */
read_start_count(START_CNT_HTTPD, &wrsStartCnt_s.wrsStartCntHttpd);
read_start_count(START_CNT_SNMPD, &wrsStartCnt_s.wrsStartCntSnmpd);
read_start_count(START_CNT_SYSLOGD, &wrsStartCnt_s.wrsStartCntSyslogd);
read_start_count(START_CNT_WRSWATCHDOG, &wrsStartCnt_s.wrsStartCntWrsWatchdog);
read_start_count(START_CNT_LLDPD, &wrsStartCnt_s.wrsStartCntLldpd);
read_start_count(START_CNT_LDAP, &wrsStartCnt_s.wrsStartCntLdap);
if(userspace_daemons[UDI_LLDP].exp) /* check only if enabled (exp != 0) */
read_start_count(START_CNT_LLDPD, &wrsStartCnt_s.wrsStartCntLldpd);
if(userspace_daemons[UDI_NSLCD].exp) /* check only if enabled (exp != 0) */
read_start_count(START_CNT_LDAP, &wrsStartCnt_s.wrsStartCntLdap);
/* there was an update, return current time */
return time_update;
......
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