📄 snmp_bc_sel.c
字号:
/* -*- linux-c -*- * * (C) Copyright IBM Corp. 2003, 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): * Sean Dague <http://dague.net/sean> * Peter Phan <pdphan@sourceforge.net> * Steve Sherman <stevees@us.ibm.com> */#include <glib.h>#include <time.h>#include <snmp_bc_plugin.h>oh_el *bc_selcache = NULL;/** * snmp_bc_get_sel_size: * @handle: Pointer to handler's data. * @id: Resource ID that owns the Event Log. * * Get size of event log. * * Return values: * Number of event log entries - normal case. **/static int snmp_bc_get_sel_size(struct oh_handler_state *handle, SaHpiResourceIdT id){ int i=1; /* Go synchronize cache and hardware copy of the SEL */ snmp_bc_check_selcache(handle, id, SAHPI_NEWEST_ENTRY); /* Return the entry count */ i = g_list_length(handle->elcache->elentries); return i;}/** * snmp_bc_get_sel_size_from_hardware: * @ss: Pointer to SNMP session data. * * Unfortunately, BladeCenter SNMP support does not provide access to the number * of entries in the event log. This routine finds the number by sequentially * reading the entire log index and counting the number of entries. * * Notice that this routine always reads one past the max event number's OID. * It relies on a non-zero return code from SNMP to determine when there are * no more entries. * * Return values: * Number of event log entries - normal case. **/static int snmp_bc_get_sel_size_from_hardware(struct snmp_session *ss){ struct snmp_value run_value; char oid[SNMP_BC_MAX_OID_LENGTH]; int i = 1; do { snprintf(oid, SNMP_BC_MAX_OID_LENGTH, "%s.%d", SNMP_BC_SEL_INDEX_OID, i); i++; } while(snmp_get(ss, oid, &run_value) == 0); /* Think about it, and it makes sense */ i -= 2; return i;}/** * snmp_bc_get_sel_info: * @hnd: Pointer to handler's data. * @id: Resource ID that owns the Event Log. * @info: Location to store Event Log information. * * Returns SaHpiEventLogInfoT information about Event Log. * * Return values: * SA_OK - normal case. * SA_ERR_HPI_INVALID_PARAMS - Any pointer parameter is NULL. **/SaErrorT snmp_bc_get_sel_info(void *hnd, SaHpiResourceIdT id, SaHpiEventLogInfoT *info) { char oid[SNMP_BC_MAX_OID_LENGTH]; SaErrorT err; struct snmp_value first_value; struct oh_handler_state *handle = hnd; struct tm curtime; sel_entry sel_entry; if (!hnd || !info) { dbg("Invalid parameter."); return(SA_ERR_HPI_INVALID_PARAMS); } struct snmp_bc_hnd *custom_handle = (struct snmp_bc_hnd *)handle->data; /* Build local copy of EventLogInfo */ SaHpiEventLogInfoT sel = { /* Max number of entries that can be stored */ /* in bc EventLog varies, depending on */ /* what events have been logged so far and */ /* the information each logged event contains*/ .Size = 512, /* This is clearly a guess but looks about right * from the 75% full errors we have seen. */ .UserEventMaxSize = SAHPI_MAX_TEXT_BUFFER_LENGTH, .Enabled = SAHPI_TRUE, .OverflowFlag = SAHPI_FALSE, .OverflowResetable = SAHPI_FALSE, .OverflowAction = SAHPI_EL_OVERFLOW_OVERWRITE, }; /* In Event Log, the newest entry is index at index 1 */ /* Need first value to figure out what update time is */ snprintf(oid, SNMP_BC_MAX_OID_LENGTH,"%s.%d", SNMP_BC_SEL_ENTRY_OID, 1); err = snmp_bc_snmp_get(custom_handle, oid, &first_value); if (err == SA_OK) { if (first_value.type == ASN_OCTET_STR) { err = snmp_bc_parse_sel_entry(handle, first_value.string, &sel_entry); if (err) { dbg("Cannot get first date"); return(err); } else { sel.UpdateTimestamp = (SaHpiTimeT) mktime(&sel_entry.time) * 1000000000; } } } else return(err); err = snmp_bc_get_sp_time(handle, &curtime); if ( err == SA_OK) { sel.CurrentTime = (SaHpiTimeT) mktime(&curtime) * 1000000000; } else return(err); sel.Entries = snmp_bc_get_sel_size(handle, id); sel.OverflowFlag = handle->elcache->overflow; *info = sel; return(SA_OK);}/** * snmp_bc_get_sel_entry: * @hnd: Pointer to handler's data. * @id: Resource ID that owns the Event Log. * @current: Current event's ID. * @prev: Location to store previous event's ID. * @next: Location to store next event's ID. * @entry: Location to store retrieved event. * * Gets an entry from the system Event Log. * * Return values: * SA_OK - normal case. * SA_ERR_HPI_INVALID_PARAMS - Any pointer parameter is NULL. **/SaErrorT snmp_bc_get_sel_entry(void *hnd, SaHpiResourceIdT id, SaHpiEventLogEntryIdT current, SaHpiEventLogEntryIdT *prev, SaHpiEventLogEntryIdT *next, SaHpiEventLogEntryT *entry, SaHpiRdrT *rdr, SaHpiRptEntryT *rptentry){ SaErrorT err = SA_OK; oh_el_entry tmpentry, *tmpentryptr; tmpentryptr = &tmpentry; struct oh_handler_state *handle = (struct oh_handler_state *)hnd; if (!hnd || !prev || !next || !entry) { dbg("Invalid parameter."); return(SA_ERR_HPI_INVALID_PARAMS); } if (handle->elcache != NULL) { /* Force a cache sync before servicing the request */ err = snmp_bc_check_selcache(handle, id, current); if (err) { dbg("Event Log cache check failed."); return(err); } err = oh_el_get(handle->elcache, current, prev, next, &tmpentryptr); if (err) { dbg("Getting Event Log entry=%d from cache failed. Error=%s.", current, oh_lookup_error(err)); return(err); } else { memcpy(entry, &(tmpentryptr->event), sizeof(SaHpiEventLogEntryT)); if (rdr) memcpy(rdr, &tmpentryptr->rdr, sizeof(SaHpiRdrT)); else trace("NULL rdrptr with SaHpiEventLogEntryGet()\n"); if (rptentry) memcpy(rptentry, &(tmpentryptr->res), sizeof(SaHpiRptEntryT)); else trace("NULL rptptr with SaHpiEventLogEntryGet()\n"); } } else { dbg("Missing handle->elcache"); return(SA_ERR_HPI_INTERNAL_ERROR); } return(SA_OK);}/** * snmp_bc_build_selcache * @handle: Pointer to handler's data. * @id: Resource ID that owns the Event Log. * * Builds internal event log cache. * * Return values: * SA_OK - normal case. * SA_ERR_HPI_INVALID_PARAMS - @handle is NULL. **/SaErrorT snmp_bc_build_selcache(struct oh_handler_state *handle, SaHpiResourceIdT id){ int current; SaErrorT err; if (!handle) { dbg("Invalid parameter."); return(SA_ERR_HPI_INVALID_PARAMS); } struct snmp_bc_hnd *custom_handle = handle->data; current = snmp_bc_get_sel_size_from_hardware(custom_handle->ss); if (current) { do { err = snmp_bc_sel_read_add(handle, id, current); /* FIXME:: What do we do on error - break or just record ???*/ current--; } while(current > 0); } return(SA_OK);}/** * snmp_bc_check_selcache: * @handle: Pointer to handler's data. * @id: Resource ID that owns Event Log. * @entryId: Event Log entry ID. * * Sync Event Log's cache. If this is first entry, then create the * event log cache. * * Return values: * SA_OK - normal operation. * SA_ERR_HPI_INVALID_PARAMS - @handler is NULL.**/SaErrorT snmp_bc_check_selcache(struct oh_handler_state *handle, SaHpiResourceIdT id, SaHpiEventLogEntryIdT entryId){ SaErrorT err; if (!handle) { dbg("Invalid parameter."); return(SA_ERR_HPI_INVALID_PARAMS); } if (g_list_length(handle->elcache->elentries) == 0) { err = snmp_bc_build_selcache(handle, id); } else { err = snmp_bc_selcache_sync(handle, id, entryId); } if (err) { dbg("Event Log cache build/sync failed. Error=%s", oh_lookup_error(err)); return(err); } return(SA_OK);}/** * snmp_bc_selcache_sync * @handle: Pointer to handler's data. * @id: Resource ID that owns Event Log. * @entryId: Event Log entry ID. * * Synchronizes interal event log cache. * * Return values: * SA_OK - normal operation. * SA_ERR_HPI_INVALID_PARAMS - @handle is NULL. **/SaErrorT snmp_bc_selcache_sync(struct oh_handler_state *handle, SaHpiResourceIdT id, SaHpiEventLogEntryIdT entryId){ SaHpiEventLogEntryIdT current; SaHpiEventLogEntryIdT prev; SaHpiEventLogEntryIdT next; struct snmp_value get_value; sel_entry sel_entry; oh_el_entry *fetchentry; SaHpiTimeT new_timestamp; char oid[SNMP_BC_MAX_OID_LENGTH]; SaErrorT err; int cacheupdate = 0; if (!handle) { dbg("Invalid parameter."); return(SA_ERR_HPI_INVALID_PARAMS); } struct snmp_bc_hnd *custom_handle = handle->data; err = oh_el_get(handle->elcache, SAHPI_NEWEST_ENTRY, &prev, &next, &fetchentry); if (err) fetchentry = NULL; current = 1; snprintf(oid, SNMP_BC_MAX_OID_LENGTH, "%s.%d", SNMP_BC_SEL_ENTRY_OID, current); err = snmp_get(custom_handle->ss, oid, &get_value); if (err) { dbg("SNMP log is empty."); err = oh_el_clear(handle->elcache); return(err); } if (fetchentry == NULL) { err = snmp_bc_build_selcache(handle, id); return(err); } if (snmp_bc_parse_sel_entry(handle, get_value.string, &sel_entry) < 0) { dbg("Cannot parse Event Log entry"); return(SA_ERR_HPI_INTERNAL_ERROR); } new_timestamp = (SaHpiTimeT)mktime(&sel_entry.time) * 1000000000; if (fetchentry->event.Event.Timestamp != new_timestamp) { while (1) { current++; snprintf(oid, SNMP_BC_MAX_OID_LENGTH, "%s.%d", SNMP_BC_SEL_ENTRY_OID, current);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -