static int onlp_snmp_sensor_register_oid__(onlp_oid_t oid, void* cookie) { onlp_oid_hdr_t hdr; onlp_snmp_sensor_t s; onlp_oid_hdr_get(oid, &hdr); AIM_MEMSET(&s, 0x0, sizeof(onlp_snmp_sensor_t)); switch(ONLP_OID_TYPE_GET(oid)) { case ONLP_OID_TYPE_THERMAL: #if ONLP_SNMP_CONFIG_INCLUDE_THERMALS == 1 s.sensor_id = oid; sprintf(s.name, "%d - ", ONLP_OID_ID_GET(oid)); aim_strlcpy(s.desc, hdr.description, sizeof(s.desc)); if(onlp_snmp_sensor_reg__(ONLP_SNMP_SENSOR_TYPE_TEMP, &s) < 0) { AIM_LOG_ERROR("onlp_snmp_sensor_reg for OID 0x%x failed.", oid); } #endif break; case ONLP_OID_TYPE_FAN: #if ONLP_SNMP_CONFIG_INCLUDE_FANS == 1 s.sensor_id = oid; sprintf(s.name, "%d - ", ONLP_OID_ID_GET(oid)); aim_strlcpy(s.desc, hdr.description, sizeof(s.desc)); if(onlp_snmp_sensor_reg__(ONLP_SNMP_SENSOR_TYPE_FAN, &s) < 0) { AIM_LOG_ERROR("onlp_snmp_sensor_reg for OID 0x%x failed.", oid); } #endif break; case ONLP_OID_TYPE_PSU: #if ONLP_SNMP_CONFIG_INCLUDE_PSUS == 1 /* Register Sensors for VIN,VOUT,IIN,IOUT,PIN,POUT */ s.sensor_id = oid; sprintf(s.name, "%d - ", ONLP_OID_ID_GET(oid)); aim_strlcpy(s.desc, hdr.description, sizeof(s.desc)); if(onlp_snmp_sensor_reg__(ONLP_SNMP_SENSOR_TYPE_PSU, &s) < 0) { AIM_LOG_ERROR("onlp_snmp_sensor_reg for OID 0x%x failed.", oid); } #endif break; default: AIM_LOG_INFO("snmp type %s id %d unsupported", onlp_oid_type_name(ONLP_OID_TYPE_GET(oid)), ONLP_OID_ID_GET(oid)); break; } return 0; }
static int iterate_oids_callback__(onlp_oid_t oid, void* cookie) { int type = ONLP_OID_TYPE_GET(oid); int id = ONLP_OID_ID_GET(oid); static int thermal = 1; static int fan = 1; static int psu = 1; switch(type) { case ONLP_OID_TYPE_THERMAL: printf("thermal,Thermal %d,%d\n", id, thermal++); break; case ONLP_OID_TYPE_FAN: printf("fan,Fan %d,%d\n", id, fan++); break; case ONLP_OID_TYPE_PSU: printf("psu,PSU %d,%d\n", id, psu++); break; } return 0; }