diff --git a/userspace/snmpd/wrsBootStatusGroup.c b/userspace/snmpd/wrsBootStatusGroup.c index 9be81502f48b3c231eccb1d17834012d8ae42534..a9061c0f9551ab075474159c98d241b9d82dbeb3 100644 --- a/userspace/snmpd/wrsBootStatusGroup.c +++ b/userspace/snmpd/wrsBootStatusGroup.c @@ -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 */ diff --git a/userspace/snmpd/wrsBootStatusGroup.h b/userspace/snmpd/wrsBootStatusGroup.h index 71aa64bb644534a7a6196f51abd35f522921cbee..56aaf63c2bc076e6daf625465b9190304df03a0a 100644 --- a/userspace/snmpd/wrsBootStatusGroup.h +++ b/userspace/snmpd/wrsBootStatusGroup.h @@ -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 */ diff --git a/userspace/snmpd/wrsStartCntGroup.c b/userspace/snmpd/wrsStartCntGroup.c index 98c641ddb14fb08f1623b68bb26274610abf6949..498f5e81580e1b2903158375bb029b4ba1f487e4 100644 --- a/userspace/snmpd/wrsStartCntGroup.c +++ b/userspace/snmpd/wrsStartCntGroup.c @@ -1,5 +1,6 @@ #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;