📄 snmp_bc_discover.c
字号:
trace("Discovered sensor: %s.", e->u.rdr_event.rdr.IdString.Data);#endif sensor_info_ptr = g_memdup(&(sensor_array[i].sensor_info), sizeof(struct SensorInfo)); err = oh_add_rdr(custom_handle->tmpcache, res_oh_event->u.res_event.entry.ResourceId, &(e->u.rdr_event.rdr), sensor_info_ptr, 0); if (err) { dbg("Cannot add RDR. Error=%s.", oh_lookup_error(err)); g_free(e); } else { custom_handle->tmpqueue = g_slist_append(custom_handle->tmpqueue, e); snmp_bc_discover_sensor_events(handle, &(res_oh_event->u.res_event.entry.ResourceEntity), sensor_array[i].sensor.Num, &(sensor_array[i])); } } else { g_free(e); } } return(SA_OK);}/** * snmp_bc_discover_controls: * @handler: Pointer to handler's data. * @control_array: Pointer to resource's static control data array. * @res_oh_event: Pointer to resource's event structure. * * Discovers resource's available controls. * * Return values: * Adds control RDRs to internal Infra-structure queues - normal case * SA_ERR_HPI_OUT_OF_SPACE - Cannot allocate space for internal memory **/SaErrorT snmp_bc_discover_controls(struct oh_handler_state *handle, struct snmp_bc_control *control_array, struct oh_event *res_oh_event){ int i; gchar *oid; SaErrorT err; SaHpiBoolT valid_control; struct oh_event *e; struct snmp_bc_hnd *custom_handle = (struct snmp_bc_hnd *)handle->data; struct snmp_session *ss = custom_handle->ss; struct ControlInfo *control_info_ptr; for (i=0; control_array[i].control.Num != 0; i++) { e = (struct oh_event *)g_malloc0(sizeof(struct oh_event)); if (e == NULL) { dbg("Out of memory."); return(SA_ERR_HPI_OUT_OF_SPACE); } oid = oh_derive_string(&(res_oh_event->u.res_event.entry.ResourceEntity), control_array[i].control_info.mib.oid); if (oid == NULL) { dbg("Cannot derive %s.", control_array[i].control_info.mib.oid); g_free(e); return(SA_ERR_HPI_INTERNAL_ERROR); } valid_control = rdr_exists(ss, oid, control_array[i].control_info.mib.not_avail_indicator_num, control_array[i].control_info.mib.write_only); g_free(oid); /* Add control RDR, if control can be read */ if (valid_control) { e->type = OH_ET_RDR; e->did = oh_get_default_domain_id(); e->u.rdr_event.rdr.RdrType = SAHPI_CTRL_RDR; e->u.rdr_event.rdr.Entity = res_oh_event->u.res_event.entry.ResourceEntity; e->u.rdr_event.rdr.RdrTypeUnion.CtrlRec = control_array[i].control; oh_init_textbuffer(&(e->u.rdr_event.rdr.IdString)); oh_append_textbuffer(&(e->u.rdr_event.rdr.IdString), control_array[i].comment);#if 0 trace("Discovered control: %s.", e->u.rdr_event.rdr.IdString.Data);#endif control_info_ptr = g_memdup(&(control_array[i].control_info), sizeof(struct ControlInfo)); err = oh_add_rdr(custom_handle->tmpcache, res_oh_event->u.res_event.entry.ResourceId, &(e->u.rdr_event.rdr), control_info_ptr, 0); if (err) { dbg("Cannot add RDR. Error=%s.", oh_lookup_error(err)); g_free(e); } else { custom_handle->tmpqueue = g_slist_append(custom_handle->tmpqueue, e); } } else { g_free(e); } } return(SA_OK);}/** * snmp_bc_discover_inventory: * @handler: Pointer to handler's data. * @inventory_array: Pointer to resource's static inventory data array. * @res_oh_event: Pointer to resource's event structure. * * Discovers resource's available inventory data records. * * Return values: * Adds inventory RDRs to internal Infra-structure queues - normal case * SA_ERR_HPI_OUT_OF_SPACE - Cannot allocate space for internal memory **/SaErrorT snmp_bc_discover_inventories(struct oh_handler_state *handle, struct snmp_bc_inventory *inventory_array, struct oh_event *res_oh_event){ int i; gchar *oid; SaHpiBoolT valid_idr; SaErrorT err; struct oh_event *e; struct snmp_bc_hnd *custom_handle = (struct snmp_bc_hnd *)handle->data; struct snmp_session *ss = custom_handle->ss; struct InventoryInfo *inventory_info_ptr; /* Assumming OidManufacturer is defined and determines readable of other VPD */ for (i=0; inventory_array[i].inventory_info.mib.oid.OidManufacturer != NULL; i++) { e = (struct oh_event *)g_malloc0(sizeof(struct oh_event)); if (e == NULL) { dbg("Out of memory."); return(SA_ERR_HPI_OUT_OF_SPACE); } oid = oh_derive_string(&(res_oh_event->u.res_event.entry.ResourceEntity), inventory_array[i].inventory_info.mib.oid.OidManufacturer); if (oid == NULL) { dbg("Cannot derive %s.", inventory_array[i].inventory_info.mib.oid.OidManufacturer); g_free(e); return(SA_ERR_HPI_INTERNAL_ERROR); } valid_idr = rdr_exists(ss, oid, 0, 0); g_free(oid); /* Add inventory RDR, if inventory can be read */ if (valid_idr) { e->type = OH_ET_RDR; e->did = oh_get_default_domain_id(); e->u.rdr_event.parent = res_oh_event->u.res_event.entry.ResourceId; e->u.rdr_event.rdr.RdrType = SAHPI_INVENTORY_RDR; e->u.rdr_event.rdr.Entity = res_oh_event->u.res_event.entry.ResourceEntity; e->u.rdr_event.rdr.RdrTypeUnion.InventoryRec = inventory_array[i].inventory; oh_init_textbuffer(&(e->u.rdr_event.rdr.IdString)); oh_append_textbuffer(&(e->u.rdr_event.rdr.IdString), inventory_array[i].comment);#if 0 trace("Discovered inventory: %s.", e->u.rdr_event.rdr.IdString.Data);#endif inventory_info_ptr = g_memdup(&(inventory_array[i].inventory_info), sizeof(struct InventoryInfo)); err = oh_add_rdr(custom_handle->tmpcache, res_oh_event->u.res_event.entry.ResourceId, &(e->u.rdr_event.rdr), inventory_info_ptr, 0); if (err) { dbg("Cannot add RDR. Error=%s.", oh_lookup_error(err)); g_free(e); } else { custom_handle->tmpqueue = g_slist_append(custom_handle->tmpqueue, e); } } else { g_free(e); } } return(SA_OK);}/** * snmp_bc_create_resourcetag: * @buffer: Location of Resource Tag buffer. * @str: Resource name. * @location: Resource location. * * Creates a user friendly Resource Tag. Takes the comment found in the * Resource's static definition, appends a trailing string (can be NULL) * plus the resource's location. * * Return values: * SaHpiTextBufferT - normal operation. * SA_ERR_HPI_INVALID_PARAMS - @buffer is NULL; or @loc not valid * SA_ERR_HPI_OUT_OF_SPACE - Cannot allocate space for internal memory. **/SaErrorT snmp_bc_create_resourcetag(SaHpiTextBufferT *buffer, const char *str, SaHpiEntityLocationT loc){ char *locstr; SaErrorT err = SA_OK; SaHpiTextBufferT working; if (!buffer || loc < SNMP_BC_HPI_LOCATION_BASE || loc > (pow(10, OH_MAX_LOCATION_DIGITS) - 1)) { return(SA_ERR_HPI_INVALID_PARAMS); } err = oh_init_textbuffer(&working); if (err) { return(err); } locstr = (gchar *)g_malloc0(OH_MAX_LOCATION_DIGITS + 1); if (locstr == NULL) { dbg("Out of memory."); return(SA_ERR_HPI_OUT_OF_SPACE); } snprintf(locstr, OH_MAX_LOCATION_DIGITS + 1, " %d", loc); if (str) { oh_append_textbuffer(&working, str); } err = oh_append_textbuffer(&working, locstr); if (!err) { err = oh_copy_textbuffer(buffer, &working); } g_free(locstr); return(err);}/** * rdr_exists: * @ss: Pointer to SNMP session. * @oid: SNMP OID string * @na: Not available integer, if applicable * @write-only: SNMP OID write-only indicator * * Determines if an SNMP OID is available to be read. OID may not exist, or if * it does exist may be write-only or indicate that it's value is non-existant. * * Return values: * SAHPI_TRUE - if OID is valid and readable. * SAHPI_FALSE - if OID's value cannot be read. **/SaHpiBoolT rdr_exists(struct snmp_session *ss, const char *oid, unsigned int na, SaHpiBoolT write_only){ SaErrorT err; struct snmp_value get_value; if (write_only == SAHPI_TRUE) { return(SAHPI_FALSE); }; /* Can't check it if its non-readable */ err = snmp_get(ss, oid, &get_value); if (err || (get_value.type == ASN_INTEGER && na && na == get_value.integer) || (get_value.type == ASN_OCTET_STR && (!strcmp(get_value.string,"Not available") || !strcmp(get_value.string,"Not installed") || !strcmp(get_value.string,"Not Readable!")))) { return(SAHPI_FALSE); } return(SAHPI_TRUE);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -