⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 snmp_bc_event.c

📁 HIP 硬件设备管理标准接口
💻 C
📖 第 1 页 / 共 3 页
字号:
/*      -*- linux-c -*- * * (C) Copyright IBM Corp. 2004 * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  This * file and program are licensed under a BSD style license.  See * the Copying file included with the OpenHPI distribution for * full licensing terms. * * Author(s): *      Steve Sherman <stevees@us.ibm.com> */#include <glib.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <time.h>#include <snmp_bc_plugin.h>typedef enum {	EVENT_NOT_MAPPED,	EVENT_NOT_ALERTABLE,} OEMReasonCodeT;typedef struct {	SaHpiResourceIdT      rid;	BCRptEntryT           rpt;	struct snmp_bc_sensor *sensor_array_ptr;	SaHpiEntityPathT      ep;} LogSource2ResourceT;typedef struct {	SaHpiEventT      hpievent;        SaHpiEventStateT sensor_recovery_state;	SaHpiHsStateT    hotswap_recovery_state;	SaHpiBoolT       event_res_failure;	SaHpiBoolT       event_res_failure_unexpected;} EventMapInfoT;static SaErrorT snmp_bc_parse_threshold_str(gchar *str,					    gchar *root_str,					    SaHpiTextBufferT *read_value_str,					    SaHpiTextBufferT *trigger_value_str);static SaErrorT snmp_bc_logsrc2rid(struct oh_handler_state *handle,				   gchar *src,				   LogSource2ResourceT *resinfo,				   unsigned short ovr_flags);static SaErrorT snmp_bc_set_cur_prev_event_states(struct oh_handler_state *handle,						  EventMapInfoT *eventmap_info,						  SaHpiEventT *event,						  int recovery_event);static SaErrorT snmp_bc_set_event_severity(struct oh_handler_state *handle,					   EventMapInfoT *eventmap_info,					   SaHpiEventT *event,					   SaHpiSeverityT *event_severity);static SaErrorT snmp_bc_map2oem(SaHpiEventT *event,				sel_entry *sel_entry,				OEMReasonCodeT reason);static ErrLog2EventInfoT *snmp_bc_findevent4dupstr(gchar *search_str,						     ErrLog2EventInfoT *dupstrhash_data,						     LogSource2ResourceT *resinfo);SaErrorT event2hpi_hash_init(struct oh_handler_state *handle){	if (!handle) {		dbg("Invalid parameter.");		return(SA_ERR_HPI_INVALID_PARAMS);	}	struct snmp_bc_hnd *custom_handle = (struct snmp_bc_hnd *)handle->data;	if (!custom_handle) {		dbg("Invalid parameter.");		return(SA_ERR_HPI_INVALID_PARAMS);	}	custom_handle->event2hpi_hash_ptr = g_hash_table_new(g_str_hash, g_str_equal);	if (custom_handle->event2hpi_hash_ptr == NULL) {		dbg("Out of memory.");		return(SA_ERR_HPI_OUT_OF_SPACE);	}		return(SA_OK);}static void free_hash_data(gpointer key, gpointer value, gpointer user_data){        g_free(key); /* Memory was created for these during normalization process */        g_free(value);}SaErrorT event2hpi_hash_free(struct oh_handler_state *handle){	if (!handle) {		dbg("Invalid parameter.");		return(SA_ERR_HPI_INVALID_PARAMS);	}		struct snmp_bc_hnd *custom_handle = (struct snmp_bc_hnd *)handle->data;	if (!custom_handle) {		dbg("Invalid parameter.");		return(SA_ERR_HPI_INVALID_PARAMS);	}	if (custom_handle->event2hpi_hash_ptr != NULL) {		g_hash_table_foreach(custom_handle->event2hpi_hash_ptr, free_hash_data, NULL);		g_hash_table_destroy(custom_handle->event2hpi_hash_ptr);	}	return(SA_OK);}/** * snmp_bc_discover_res_events:  * @handle: Pointer to handler's data. * @ep: Pointer to resource's entity path. * @resinfo: Pointer to a resource's event mapping information. * * Discovers a resource's events and records the static mapping * information needed to translate platform error log event messages * into HPI event types. *  * Mapping information is stored in the hash table - event2hpi_hash. * * Return values: * SA_OK - Normal case. * SA_ERR_HPI_INVALID_PARAMS - Pointer parameter(s) or event2hpi_hash_ptr are NULL. **/SaErrorT snmp_bc_discover_res_events(struct oh_handler_state *handle,				     SaHpiEntityPathT *ep,				     const struct ResourceInfo *resinfo){	int i;	int max = SNMP_BC_MAX_RESOURCE_EVENT_ARRAY_SIZE;	char *normalized_str;	char *hash_existing_key, *hash_value;	EventMapInfoT *eventmap_info;	SaHpiResourceIdT rid;	if (!handle || !ep || !resinfo) {		dbg("Invalid parameter.");		return(SA_ERR_HPI_INVALID_PARAMS);	}	struct snmp_bc_hnd *custom_handle = (struct snmp_bc_hnd *)handle->data;	if (!custom_handle || !custom_handle->event2hpi_hash_ptr) {		dbg("Invalid parameter.");		return(SA_ERR_HPI_INVALID_PARAMS);	}	rid = oh_uid_lookup(ep);	if (rid == 0) {		dbg("No RID.");		return(SA_ERR_HPI_INTERNAL_ERROR);	}	for (i=0; resinfo->event_array[i].event != NULL && i < max; i++) {		/* Normalized and convert event string */		normalized_str = oh_derive_string(ep, resinfo->event_array[i].event);		if (normalized_str == NULL) {			dbg("Cannot derive %s.", resinfo->event_array[i].event);			return(SA_ERR_HPI_INTERNAL_ERROR);		}		/*  Add to hash; Set HPI values */		if (!g_hash_table_lookup_extended(custom_handle->event2hpi_hash_ptr,						  normalized_str,						  (gpointer)&hash_existing_key,						  (gpointer)&hash_value)) {			eventmap_info = g_malloc0(sizeof(EventMapInfoT));			if (!eventmap_info) {				dbg("Out of memory.");				g_free(normalized_str);				return(SA_ERR_HPI_OUT_OF_SPACE);			}			eventmap_info->hpievent.Source = rid;			eventmap_info->hpievent.EventType = SAHPI_ET_HOTSWAP;			eventmap_info->hpievent.EventDataUnion.HotSwapEvent.HotSwapState =				resinfo->event_array[i].event_state;			eventmap_info->hotswap_recovery_state =				resinfo->event_array[i].recovery_state;			eventmap_info->event_res_failure =				resinfo->event_array[i].event_res_failure;			eventmap_info->event_res_failure_unexpected =				resinfo->event_array[i].event_res_failure_unexpected;			trace("Discovered resource event=%s.", normalized_str);			g_hash_table_insert(custom_handle->event2hpi_hash_ptr, normalized_str, eventmap_info);			/* normalized_str space is recovered when hash is freed */		}		else {			/* Event already exists (e.g. same event for multiple blades) */			g_free(normalized_str);		}	}	return(SA_OK);}/** * snmp_bc_discover_sensor_events:  * @handle: Pointer to handler's data. * @ep: Pointer to parent resource's entity path. * @sid: Sensor ID. * @sinfo: Pointer to a sensor's event mapping information. * * Discovers a sensor's events and records the static mapping * information needed to translate platform error log event messages * into HPI event types. *  * Mapping information is stored in the hash table - event2hpi_hash. * * Return values: * SA_OK - Normal case. * SA_ERR_HPI_INVALID_PARAMS - Pointer parameter(s) are NULL; sid <= 0. **/SaErrorT snmp_bc_discover_sensor_events(struct oh_handler_state *handle,					SaHpiEntityPathT *ep,					SaHpiSensorNumT sid,					const struct snmp_bc_sensor *sinfo){	int i;	int max = SNMP_BC_MAX_SENSOR_EVENT_ARRAY_SIZE;	char *normalized_str;	char *hash_existing_key, *hash_value;	EventMapInfoT *eventmap_info;	SaHpiResourceIdT rid;	if (!handle || !ep || !sinfo || sid <= 0) {		dbg("Invalid parameter.");		return(SA_ERR_HPI_INVALID_PARAMS);	}	struct snmp_bc_hnd *custom_handle = (struct snmp_bc_hnd *)handle->data;	if (!custom_handle || !custom_handle->event2hpi_hash_ptr) {		dbg("Invalid parameter.");		return(SA_ERR_HPI_INVALID_PARAMS);	}	rid = oh_uid_lookup(ep);	if (rid == 0) {		dbg("No RID.");		return(SA_ERR_HPI_INTERNAL_ERROR);	}			for (i=0; sinfo->sensor_info.event_array[i].event != NULL && i < max; i++) {		/* Normalized and convert event string */		normalized_str = oh_derive_string(ep, sinfo->sensor_info.event_array[i].event);		if (normalized_str == NULL) {			dbg("Cannot derive %s.", sinfo->sensor_info.event_array[i].event);			return(SA_ERR_HPI_INTERNAL_ERROR);		}		/*  Add to hash; Set HPI values */		if (!g_hash_table_lookup_extended(custom_handle->event2hpi_hash_ptr,						  normalized_str,						  (gpointer)&hash_existing_key, 						  (gpointer)&hash_value)) {			eventmap_info = g_malloc0(sizeof(EventMapInfoT));			if (!eventmap_info) {				dbg("Out of memory.");				g_free(normalized_str);				return(SA_ERR_HPI_OUT_OF_SPACE);			}			/* Set default values */			eventmap_info->hpievent.Source = rid;			eventmap_info->hpievent.EventType = SAHPI_ET_SENSOR;			eventmap_info->hpievent.EventDataUnion.SensorEvent.SensorNum = sid;			eventmap_info->hpievent.EventDataUnion.SensorEvent.SensorType = sinfo->sensor.Type;			eventmap_info->hpievent.EventDataUnion.SensorEvent.EventCategory = sinfo->sensor.Category;			eventmap_info->hpievent.EventDataUnion.SensorEvent.Assertion =				sinfo->sensor_info.event_array[i].event_assertion;			eventmap_info->hpievent.EventDataUnion.SensorEvent.EventState =			eventmap_info->hpievent.EventDataUnion.SensorEvent.CurrentState =				sinfo->sensor_info.event_array[i].event_state;			eventmap_info->sensor_recovery_state =				sinfo->sensor_info.event_array[i].recovery_state;			eventmap_info->event_res_failure =				sinfo->sensor_info.event_array[i].event_res_failure;			eventmap_info->event_res_failure_unexpected =				sinfo->sensor_info.event_array[i].event_res_failure_unexpected;						/* Setup static trigger info for threshold sensors - some may be event-only */			if (sinfo->sensor.Category == SAHPI_EC_THRESHOLD) {				eventmap_info->hpievent.EventDataUnion.SensorEvent.TriggerReading.IsSupported =				eventmap_info->hpievent.EventDataUnion.SensorEvent.TriggerThreshold.IsSupported =					SAHPI_TRUE;				eventmap_info->hpievent.EventDataUnion.SensorEvent.TriggerReading.Type =				eventmap_info->hpievent.EventDataUnion.SensorEvent.TriggerThreshold.Type =					sinfo->sensor.DataFormat.ReadingType;			}						trace("Discovered sensor event=%s.", normalized_str);			g_hash_table_insert(custom_handle->event2hpi_hash_ptr, normalized_str, eventmap_info);			/* normalized_str space is recovered when hash is freed */		}		else {			/* Event already exists (e.g. same event for multiple blades) */			g_free(normalized_str);		}	}	return(SA_OK);}/** * snmp_bc_log2event:  * @handle: Pointer to handler's data. * @logstr: Platform Error Log string to be mapped to an HPI event. * @event: Location to store mapped HPI event. * @isdst: Is Daylight Savings Time on or off. * * Maps platform error log messages to HPI events. *  * @isdst ("is DayLight Savings Time") parameter is a performance hack. * Design assumes the event's timestamp is the time local to the platform itself. * So instead of forcing platform accesses for each log entry to determine if * DST is in effect, the isdst parameter allows the caller to query the * hardware DST info once then make multiple translation calls. * * Return values: * SA_OK - Normal case. * SA_ERR_HPI_INVALID_PARAMS - Pointer parameter(s) are NULL. **/SaErrorT snmp_bc_log2event(struct oh_handler_state *handle,			   gchar *logstr,			   SaHpiEventT *event,			   int isdst){	sel_entry        log_entry;	gchar               *recovery_str, *login_str;	gchar               root_str[SNMP_BC_MAX_SEL_ENTRY_LENGTH];	gchar               search_str[SNMP_BC_MAX_SEL_ENTRY_LENGTH];	EventMapInfoT      *eventmap_info;	LogSource2ResourceT resinfo;	SaErrorT            err;	SaHpiBoolT          is_recovery_event, is_threshold_event;	SaHpiEventT         working;	SaHpiResourceIdT    event_rid;	SaHpiSeverityT      event_severity;	SaHpiTextBufferT    thresh_read_value, thresh_trigger_value;	SaHpiTimeT          event_time;	ErrLog2EventInfoT *strhash_data;	if (!handle || !logstr || !event) {		dbg("Invalid parameter.");		return(SA_ERR_HPI_INVALID_PARAMS);	}        struct snmp_bc_hnd *custom_handle = (struct snmp_bc_hnd *)handle->data;	if (!custom_handle) {		dbg("Invalid parameter.");		return(SA_ERR_HPI_INVALID_PARAMS);	}	memset(&working, 0, sizeof(SaHpiEventT));	is_recovery_event = is_threshold_event = SAHPI_FALSE;        /* Parse hardware log entry into its various components */	err = snmp_bc_parse_sel_entry(handle, logstr, &log_entry);	if (err) {		dbg("Cannot parse log entry=%s. Error=%s.", logstr, oh_lookup_error(err));		return(err);	}	/* Find default RID from Error Log's "Source" field - need if OEM event */	err = snmp_bc_logsrc2rid(handle, log_entry.source, &resinfo, 0);	if (err) {		dbg("Cannot translate %s to RID. Error=%s", log_entry.source, oh_lookup_error(err));		return(err);	}		/* Set dynamic event fields with default values from the log string.	   These may be overwritten in the code below */	event_rid = resinfo.rid;	event_severity = log_entry.sev; 	event_time = (SaHpiTimeT)mktime(&log_entry.time) * 1000000000;	/**********************************************************************	 * For some types of events (e.g. thresholds), dynamic data is appended	 * to some root string. Need to find this root string, since its the         * root string which is mapped in the error log to event hash table.         **********************************************************************/	/* Set default search string */	strncpy(search_str, log_entry.text, SNMP_BC_MAX_SEL_ENTRY_LENGTH);	/* Discover "recovery" event strings */	recovery_str = strstr(search_str, EVT_RECOVERY);	if (recovery_str && (recovery_str == search_str)) {		is_recovery_event = SAHPI_TRUE;		memset(search_str, 0, SNMP_BC_MAX_SEL_ENTRY_LENGTH);		strcpy(search_str, (log_entry.text + strlen(EVT_RECOVERY)));	}	/* Adjust "login" event strings - strip username */	login_str = strstr(log_entry.text, LOG_LOGIN_STRING);	if (login_str) {		gchar *id_str = strstr(log_entry.text, LOG_LOGIN_CHAR);		if (id_str != NULL) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -