static int process_num_sensor( picl_nodehdl_t childh, const char *propname, const char *propval, int typ ) { netsnmp_sensor_info *sp; float value; picl_errno_t error_code; sp = sensor_by_name( propname, typ ); if ( !sp ) { return -1; } error_code = read_num_sensor( childh, propval, &value ); if ( error_code == PICL_SUCCESS ) { sp->value = value; sp->flags|= NETSNMP_SENSOR_FLAG_ACTIVE; } else { DEBUGMSGTL(("sensors:arch:detail", "Failed to read %s sensor value (%d)\n", propname, error_code)); return -1; } return 0; }
int netsnmp_sensor_arch_load(netsnmp_cache *cache, void *vp) { netsnmp_sensor_info *sp; const sensors_chip_name *chip; const sensors_feature *data; const sensors_subfeature *data2; int chip_nr = 0; DEBUGMSGTL(("sensors:arch", "Reload v3 LM Sensors module\n")); while ((chip = sensors_get_detected_chips( NULL, &chip_nr))) { int a = 0; while ((data = sensors_get_features( chip, &a))) { DEBUGMSGTL(("sensors:arch:detail", "get_features (%s, %d)\n", data->name, data->number)); int b = 0; while ((data2 = sensors_get_all_subfeatures( chip, data, &b))) { char *label = NULL; double val; int type = NETSNMP_SENSOR_TYPE_OTHER; DEBUGMSGTL(("sensors:arch:detail", " get_subfeatures (%s, %d)\n", data2->name, data2->number)); /* * Check the type of this subfeature, * concentrating on the main "input" measurements. */ switch ( data2->type ) { case SENSORS_SUBFEATURE_IN_INPUT: type = NETSNMP_SENSOR_TYPE_VOLTAGE_DC; break; case SENSORS_SUBFEATURE_FAN_INPUT: type = NETSNMP_SENSOR_TYPE_RPM; break; case SENSORS_SUBFEATURE_TEMP_INPUT: type = NETSNMP_SENSOR_TYPE_TEMPERATURE; break; case SENSORS_SUBFEATURE_VID: type = NETSNMP_SENSOR_TYPE_VOLTAGE_DC; break; default: /* Skip everything other than these basic sensor features - ??? */ DEBUGMSGTL(("sensors:arch:detail", " Skip type %x\n", data2->type)); continue; } /* * Get the name and value of this subfeature */ /* if (!(label = sensors_get_label(chip, data))) { DEBUGMSGTL(("sensors:arch:detail", " Can't get name (%s)\n", label)); continue; } if (sensors_get_value(chip, data2->number, &val) < 0) { DEBUGMSGTL(("sensors:arch:detail", " Can't get value (%f)\n", val)); continue; } */ if (!(label = sensors_get_label(chip, data)) || (sensors_get_value(chip, data2->number, &val) < 0)) { DEBUGMSGTL(("sensors:arch:detail", " Can't get name/value (%s, %f)\n", label, val)); free(label); label = NULL; continue; } DEBUGMSGTL(("sensors:arch:detail", "%s = %f\n", label, val)); /* * Use this type to create a new sensor entry * (inserting it in the appropriate sub-containers) */ sp = sensor_by_name( label, type ); if ( sp ) { sp->value = val; sp->flags|= NETSNMP_SENSOR_FLAG_ACTIVE; } if (label) { free(label); label = NULL; } } /* end while data2 */ } /* end while data */ } /* end while chip */ return 0; }