wrsStartCntGroup.c 3.1 KB
Newer Older
1
#include "wrsSnmp.h"
2
#include "snmp_shmem.h"
3 4
#include "wrsStartCntGroup.h"

5 6 7 8
#define START_CNT_SSHD "/tmp/start_cnt_sshd"
#define START_CNT_HTTPD "/tmp/start_cnt_httpd"
#define START_CNT_SNMPD "/tmp/start_cnt_snmpd"
#define START_CNT_SYSLOGD "/tmp/start_cnt_syslogd"
9
#define START_CNT_WRSWATCHDOG "/tmp/start_cnt_wrs_watchdog"
10
#define START_CNT_LLDPD "/tmp/start_cnt_lldpd"
11
#define START_CNT_LDAP "/tmp/start_cnt_ldap"
12

13 14
static struct pickinfo wrsStartCnt_pickinfo[] = {
	FIELD(wrsStartCnt_s, ASN_COUNTER, wrsStartCntHAL),
15
	FIELD(wrsStartCnt_s, ASN_COUNTER, wrsStartCntPTP),
16
	FIELD(wrsStartCnt_s, ASN_COUNTER, wrsStartCntRTUd),
17 18 19 20
	FIELD(wrsStartCnt_s, ASN_COUNTER, wrsStartCntSshd),
	FIELD(wrsStartCnt_s, ASN_COUNTER, wrsStartCntHttpd),
	FIELD(wrsStartCnt_s, ASN_COUNTER, wrsStartCntSnmpd),
	FIELD(wrsStartCnt_s, ASN_COUNTER, wrsStartCntSyslogd),
21
	FIELD(wrsStartCnt_s, ASN_COUNTER, wrsStartCntWrsWatchdog),
22
	FIELD(wrsStartCnt_s, ASN_COUNTER, wrsStartCntLldpd),
23
	FIELD(wrsStartCnt_s, ASN_COUNTER, wrsStartCntLdap),
24 25 26 27
};

struct wrsStartCnt_s wrsStartCnt_s;

28 29 30 31 32 33 34
/* read start counter from files in /tmp */
static void read_start_count(char *file, uint32_t *counter)
{
	FILE *f;

	f = fopen(file, "r");
	if (!f) {
35 36
		snmp_log(LOG_ERR, "SNMP: " SL_ER
			 " wrsStartCntGroup filed to open file %s\n", file);
37 38 39 40 41 42 43
	} else {
		/* ignore fscanf errors */
		fscanf(f, "%d", counter);
		fclose(f);
	}
}

44 45 46 47
time_t wrsStartCnt_data_fill(void){
	static time_t time_update;
	time_t time_cur;

48

49
	time_cur = get_monotonic_sec();
50 51 52 53 54 55 56 57 58 59
	if (time_update
	    && time_cur - time_update < WRSSTARTCNT_CACHE_TIMEOUT) {
		/* cache not updated, return last update time */
		return time_update;
	}
	time_update = time_cur;

	memset(&wrsStartCnt_s, 0, sizeof(wrsStartCnt_s));

	/* get start counters from shmem's */
60 61 62
	if (shmem_ready_hald()) {
		wrsStartCnt_s.wrsStartCntHAL = hal_head->pidsequence;
	} else {
63 64
		snmp_log(LOG_ERR, "SNMP: " SL_ER
                	"%s: Unable to read HAL's shmem\n", __func__);
65 66 67 68
	}
	if (shmem_ready_ppsi()) {
		wrsStartCnt_s.wrsStartCntPTP = ppsi_head->pidsequence;
	} else {
69 70
		snmp_log(LOG_ERR, "SNMP: " SL_ER
			"%s: Unable to read PPSI's shmem\n", __func__);
71
	}
72 73 74
	if (shmem_ready_rtud()) {
		wrsStartCnt_s.wrsStartCntRTUd = rtud_head->pidsequence;
	} else {
75 76
		snmp_log(LOG_ERR,  "SNMP: " SL_ER
			"%s: Unable to read rtu's shmem\n", __func__);
77
	}
78

79 80 81 82
	read_start_count(START_CNT_SSHD, &wrsStartCnt_s.wrsStartCntSshd);
	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);
83
	read_start_count(START_CNT_WRSWATCHDOG, &wrsStartCnt_s.wrsStartCntWrsWatchdog);
84
	read_start_count(START_CNT_LLDPD, &wrsStartCnt_s.wrsStartCntLldpd);
85
	read_start_count(START_CNT_LDAP, &wrsStartCnt_s.wrsStartCntLdap);
86

87 88 89 90 91 92 93 94 95
	/* there was an update, return current time */
	return time_update;
}


#define GT_OID WRSSTARTCNT_OID
#define GT_PICKINFO wrsStartCnt_pickinfo
#define GT_DATA_FILL_FUNC wrsStartCnt_data_fill
#define GT_DATA_STRUCT wrsStartCnt_s
96
#define GT_GROUP_NAME "wrsStartCntGroup"
97 98 99
#define GT_INIT_FUNC init_wrsStartCntGroup

#include "wrsGroupTemplate.h"