/** * main: append_root test. * * This will call append_root with NULL as the first parameter. * Should get a return of -1 from the call exiting gracefully. * * Return value: 0 on success, 1 on failure **/ int main(int argc, char **argv) { if(!append_root(NULL)) return 1; return 0; }
static void get_mc_entity_event(ipmi_mc_t *mc, SaHpiRptEntryT *entry) { uint8_t vals[4]; SaHpiEntityPathT mc_ep; char mc_name[128]; int sel_support; memset(&mc_ep, 0, sizeof(SaHpiEntityPathT)); dbg("entity_root: %s", entity_root); string2entitypath(entity_root, &mc_ep); append_root(&mc_ep); snprintf(mc_name, sizeof(mc_name), "Management Controller(%x, %x)", ipmi_mc_get_channel(mc), ipmi_mc_get_address(mc)); entry->EntryId = 0; entry->ResourceInfo.ResourceRev = 0; entry->ResourceInfo.SpecificVer = 0; entry->ResourceInfo.DeviceSupport = 0; entry->ResourceInfo.ManufacturerId = (SaHpiManufacturerIdT)ipmi_mc_manufacturer_id(mc); entry->ResourceInfo.ProductId = (SaHpiUint16T)ipmi_mc_product_id(mc); entry->ResourceInfo.FirmwareMajorRev = (SaHpiUint8T)ipmi_mc_major_fw_revision(mc); entry->ResourceInfo.FirmwareMinorRev = (SaHpiUint8T)ipmi_mc_minor_fw_revision(mc); ipmi_mc_aux_fw_revision(mc, vals); /* There are 4, and we only use first. */ entry->ResourceInfo.AuxFirmwareRev = (SaHpiUint8T)vals[0]; entry->ResourceEntity.Entry[0].EntityType = SAHPI_ENT_SYS_MGMNT_MODULE ; /*we get MC number on IPMB for unique identifier */ entry->ResourceEntity.Entry[0].EntityInstance = ipmi_mc_get_address(mc); dbg ("MC Instance: %d", entry->ResourceEntity.Entry[0].EntityInstance); sel_support = ipmi_mc_sel_device_support(mc); if (sel_support == 1) { dbg("MC supports SEL"); entry->ResourceCapabilities = SAHPI_CAPABILITY_SEL; } else { entry->ResourceCapabilities = SAHPI_CAPABILITY_RESOURCE; dbg("MC does not support SEL"); } entry->ResourceSeverity = SAHPI_OK; entry->DomainId = 0; entry->ResourceTag.DataType = SAHPI_TL_TYPE_ASCII6; entry->ResourceTag.Language = SAHPI_LANG_ENGLISH; entry->ResourceTag.DataLength = strlen(mc_name); memcpy(entry->ResourceTag.Data, mc_name, strlen(mc_name)+1); ep_concat(&entry->ResourceEntity, &mc_ep); entry->ResourceId = oh_uid_from_entity_path(&entry->ResourceEntity); dbg("MC ResourceId: %d", (int)entry->ResourceId); }
static int snmp_rsa_discover_resources(void *hnd) { SaHpiEntityPathT entity_root; guint i; struct oh_event *e; struct snmp_value get_value; // struct snmp_value get_active; struct oh_handler_state *handle = (struct oh_handler_state *)hnd; struct snmp_rsa_hnd *custom_handle = (struct snmp_rsa_hnd *)handle->data; RPTable *tmpcache = (RPTable *)g_malloc0(sizeof(RPTable)); GSList *tmpqueue = NULL; char *root_tuple = (char *)g_hash_table_lookup(handle->config,"entity_root"); memset(&entity_root, 0, sizeof(SaHpiEntityPathT)); string2entitypath(root_tuple, &entity_root); append_root(&entity_root); /* see if the chassis exists by querying system health */ if(snmp_get(custom_handle->ss,".1.3.6.1.4.1.2.3.51.1.2.7.1.0",&get_value) != 0) { /* If we get here, something is hosed. No need to do more discovery */ dbg("Couldn't fetch SNMP RSA system health.\n"); dbg("There is no chassis."); g_free(tmpcache); return -1; } /* discover the chassis */ e = snmp_rsa_discover_chassis(&entity_root); if(e != NULL) { struct ResourceMibInfo *res_mib = g_memdup(&(snmp_rpt_array[RSA_RPT_ENTRY_CHASSIS].rsa_res_info.mib), sizeof(struct snmp_rpt)); oh_add_resource(tmpcache,&(e->u.res_event.entry),res_mib,0); tmpqueue = g_slist_append(tmpqueue, e); // SaHpiResourceIdT rid = e->u.res_event.entry.ResourceId; // SaHpiEntityPathT parent_ep = e->u.res_event.entry.ResourceEntity; // find_sensors(snmp_rsa_chassis_sensors); // find_controls(snmp_rsa_chassis_controls); // find_inventories(snmp_rsa_chassis_inventories); } /* discover all cpus */ for (i = 0; i < RSA_MAX_CPU; i++) { /* see if the cpu exists by querying the thermal sensor */ if((snmp_get(custom_handle->ss,rsa_oid_cpu_detect[i],&get_value) != 0) || (get_value.type != ASN_OCTET_STR) || (strcmp(get_value.string, "Not Readable!") == 0)) { /* If we get here the CPU is not installed */ dbg("CPU %d not found.\n", i+RSA_HPI_INSTANCE_BASE); continue; } e = snmp_rsa_discover_cpu(&entity_root, i); if(e != NULL) { struct ResourceMibInfo *res_mib = g_memdup(&(snmp_rpt_array[RSA_RPT_ENTRY_CPU].rsa_res_info.mib), sizeof(struct snmp_rpt)); oh_add_resource(tmpcache,&(e->u.res_event.entry),res_mib,0); tmpqueue = g_slist_append(tmpqueue, e); // SaHpiResourceIdT rid = e->u.res_event.entry.ResourceId; // SaHpiEntityPathT parent_ep = e->u.res_event.entry.ResourceEntity; // find_sensors(snmp_rsa_cpu_sensors); // find_inventories(snmp_rsa_cpu_inventories); } } /* discover all dasd */ for (i = 0; i < RSA_MAX_DASD; i++) { /* see if the dasd exists by querying the thermal sensor */ if((snmp_get(custom_handle->ss,rsa_oid_dasd_detect[i],&get_value) != 0) || (get_value.type != ASN_OCTET_STR) || (strcmp(get_value.string, "Not Readable!") == 0)) { /* If we get here the DASD is not installed */ dbg("DASD %d not found.\n", i+RSA_HPI_INSTANCE_BASE); continue; } e = snmp_rsa_discover_dasd(&entity_root, i); if(e != NULL) { struct ResourceMibInfo *res_mib = g_memdup(&(snmp_rpt_array[RSA_RPT_ENTRY_DASD].rsa_res_info.mib), sizeof(struct snmp_rpt)); oh_add_resource(tmpcache,&(e->u.res_event.entry),res_mib,0); tmpqueue = g_slist_append(tmpqueue, e); // SaHpiResourceIdT rid = e->u.res_event.entry.ResourceId; // SaHpiEntityPathT parent_ep = e->u.res_event.entry.ResourceEntity; // find_sensors(snmp_rsa_dasd_sensors); // find_inventories(snmp_rsa_dasd_inventories); } } /* Rediscovery: Get difference between current rptcache and tmpcache. Delete obsolete items from rptcache and add new items in. */ GSList *res_new = NULL, *rdr_new = NULL, *res_gone = NULL, *rdr_gone = NULL; GSList *node = NULL; rpt_diff(handle->rptcache, tmpcache, &res_new, &rdr_new, &res_gone, &rdr_gone); dbg("%d resources have gone away.", g_slist_length(res_gone)); dbg("%d resources are new or have changed", g_slist_length(res_new)); for (node = rdr_gone; node != NULL; node = node->next) { SaHpiRdrT *rdr = (SaHpiRdrT *)node->data; SaHpiRptEntryT *res = oh_get_resource_by_ep(handle->rptcache, &(rdr->Entity)); /* Create remove rdr event and add to event queue */ struct oh_event *e = (struct oh_event *)g_malloc0(sizeof(struct oh_event)); if (e) { e->type = OH_ET_RDR_DEL; e->u.rdr_del_event.record_id = rdr->RecordId; e->u.rdr_del_event.parent_entity = rdr->Entity; handle->eventq = g_slist_append(handle->eventq, e); } else dbg("Could not allocate more memory to create event."); /* Remove rdr from plugin's rpt cache */ if (rdr && res) oh_remove_rdr(handle->rptcache, res->ResourceId, rdr->RecordId); else dbg("No valid resource or rdr at hand. Could not remove rdr."); } g_slist_free(rdr_gone); for (node = res_gone; node != NULL; node = node->next) { SaHpiRptEntryT *res = (SaHpiRptEntryT *)node->data; /* Create remove resource event and add to event queue */ struct oh_event *e = (struct oh_event *)g_malloc0(sizeof(struct oh_event)); if (e) { e->type = OH_ET_RESOURCE_DEL; e->u.res_del_event.resource_id = res->ResourceId; handle->eventq = g_slist_append(handle->eventq, e); } else dbg("Could not allocate more memory to create event."); /* Remove resource from plugin's rpt cache */ if (res) oh_remove_resource(handle->rptcache, res->ResourceId); else dbg("No valid resource at hand. Could not remove resource."); } g_slist_free(res_gone); for (node = res_new; node != NULL; node = node->next) { GSList *tmpnode = NULL; SaHpiRptEntryT *res = (SaHpiRptEntryT *)node->data; if (!res) { dbg("No valid resource at hand. Could not process new resource."); continue; } gpointer data = oh_get_resource_data(tmpcache, res->ResourceId); oh_add_resource(handle->rptcache, res, g_memdup(data, sizeof(struct snmp_rpt)),0); /* Add new/changed resources to the event queue */ for (tmpnode = tmpqueue; tmpnode != NULL; tmpnode = tmpnode->next) { struct oh_event *e = (struct oh_event *)tmpnode->data; if (e->type == OH_ET_RESOURCE && e->u.res_event.entry.ResourceId == res->ResourceId) { handle->eventq = g_slist_append(handle->eventq, e); tmpqueue = g_slist_remove_link(tmpqueue, tmpnode); g_slist_free_1(tmpnode); break; } } } g_slist_free(res_new); for (node = rdr_new; node != NULL; node = node->next) { guint rdr_data_size = 0; GSList *tmpnode = NULL; SaHpiRdrT *rdr = (SaHpiRdrT *)node->data; SaHpiRptEntryT *res = oh_get_resource_by_ep(handle->rptcache, &(rdr->Entity)); if (!res || !rdr) { dbg("No valid resource or rdr at hand. Could not process new rdr."); continue; } gpointer data = oh_get_rdr_data(tmpcache, res->ResourceId, rdr->RecordId); /* Need to figure out the size of the data associated with the rdr */ if (rdr->RdrType == SAHPI_SENSOR_RDR) rdr_data_size = sizeof(struct SensorMibInfo); else if (rdr->RdrType == SAHPI_CTRL_RDR) rdr_data_size = sizeof(struct ControlMibInfo); else if (rdr->RdrType == SAHPI_INVENTORY_RDR) rdr_data_size = sizeof(struct InventoryMibInfo); oh_add_rdr(handle->rptcache, res->ResourceId, rdr, g_memdup(data, rdr_data_size),0); /* Add new/changed rdrs to the event queue */ for (tmpnode = tmpqueue; tmpnode != NULL; tmpnode = tmpnode->next) { struct oh_event *e = (struct oh_event *)tmpnode->data; if (e->type == OH_ET_RDR && memcmp(&(e->u.rdr_event.rdr.Entity),&(rdr->Entity),sizeof(SaHpiEntityPathT)) == 0 && e->u.rdr_event.rdr.RecordId == rdr->RecordId) { handle->eventq = g_slist_append(handle->eventq, e); tmpqueue = g_slist_remove_link(tmpqueue, tmpnode); g_slist_free_1(tmpnode); break; } } } g_slist_free(rdr_new); /* Clean up tmpqueue and tmpcache */ g_slist_free(tmpqueue); oh_flush_rpt(tmpcache); g_free(tmpcache); return SA_OK; }