Bruce Shaw wrote:
Could you post it as a patch? I'd like to have a look at it. My
code works on my E450's, V880's and 280r's.
Here's what I came up with as a patch (large) to lmSensors.c based on
the test code I posted yesterday. It works on a V1280, but I haven't
tested it further than that.
Mike
--- agent/mibgroup/ucd-snmp/lmSensors.c.orig 2004-10-15 23:04:29.000000000 -0400
+++ agent/mibgroup/ucd-snmp/lmSensors.c 2005-06-10 15:12:43.578282000 -0400
@@ -344,284 +344,236 @@
/* ******* picld sensor procedures * */
#ifdef HAVE_PICL_H
+/*
+** read_num_sensor - Read a sensor and return the scaled value.
+*/
+
static int
-process_individual_fan(picl_nodehdl_t childh,
- char propname[PICL_PROPNAMELEN_MAX])
+read_num_sensor(picl_nodehdl_t childh, char *prop ,int scale, int *value)
{
- picl_nodehdl_t sensorh;
- picl_propinfo_t sensor_info;
+ picl_nodehdl_t sensorh;
+ picl_propinfo_t sensor_info;
+ picl_errno_t error_code;
+ int valid = 1;
+
+ union valu {
+ char buf[PICL_PROPSIZE_MAX];
+ uint32_t us4;
+ uint16_t us2;
+ int32_t is4;
+ int16_t is2;
+ float f;
+ } val;
+
+ error_code = (picl_get_propinfo_by_name(childh, prop,
+ &sensor_info, &sensorh));
+
+ if (error_code != PICL_SUCCESS) {
+ DEBUGMSGTL(("ucd-snmp/lmSensors",
+ "sensor lookup failed error code->%d\n", error_code));
+ return(error_code);
+ }
+
+ error_code = picl_get_propval(sensorh, &val.buf, sensor_info.size);
+
+ if (error_code != PICL_SUCCESS) {
+ DEBUGMSGTL(("ucd-snmp/lmSensors",
+ "sensor value read error code->%d\n", error_code));
+ return(error_code);
+ }
+
+ /* Can't make assumptions about the type or size of the value we get... */
+
+ if (sensor_info.type == PICL_PTYPE_FLOAT) {
+ *value = (int)(val.f*scale);
+ } else if (sensor_info.type == PICL_PTYPE_UNSIGNED_INT) {
+ if (sensor_info.size == 2) {
+ *value = (int)(val.us2 * scale);
+ } else if (sensor_info.size == 4) {
+ *value = (int)(val.us4 * scale);
+ } else
+ valid = 0;
+ } else if (sensor_info.type == PICL_PTYPE_INT) {
+ if (sensor_info.size == 2) {
+ *value = (int)(val.is2 * scale);
+ } else if (sensor_info.size == 4) {
+ *value = (int)(val.is4 * scale);
+ } else
+ valid = 0;
+ } else
+ valid = 0;
+
+ if (valid == 0) {
+ DEBUGMSGTL(("ucd-snmp/lmSensors",
+ "Don't know how to handle data type %d with length %d\n",
+ sensor_info.type, sensor_info.size));
+ error_code = PICL_FAILURE;
+ } else
+ DEBUGMSGTL(("ucd-snmp/lmSensors", "value is %d\n", *value));
+
+ return(error_code);
+} /* end of read_num_sensor()
+
+/*
+** read_enum_sensor - Read a sensor and return the index of one of the passed
+** enumeration values or 99.
+*/
- int speed;
- int typ = 1; /*fan*/
+static int
+read_enum_sensor(picl_nodehdl_t childh, char **options, u_int *value)
+{
+ picl_nodehdl_t sensorh;
+ picl_propinfo_t sensor_info;
+ picl_errno_t error_code;
+ char state[PICL_PROPSIZE_MAX];
+ int i;
+
+ error_code = (picl_get_propinfo_by_name(childh, "State",
+ &sensor_info, &sensorh));
+
+ if (error_code != PICL_SUCCESS) {
+ DEBUGMSGTL(("ucd-snmp/lmSensors",
+ "sensor lookup failed error code->%d\n", error_code));
+ return(error_code);
+ }
+
+ error_code = picl_get_propval(sensorh, state, sensor_info.size);
+
+ if (error_code != PICL_SUCCESS) {
+ DEBUGMSGTL(("ucd-snmp/lmSensors",
+ "sensor value read error code->%d\n", error_code));
+ return(error_code);
+ }
+
+ /* Start with error value, then try to fill in something better.
+ Use case-insensitive match to find the right value since platforms
+ may return either case.
+ */
+
+ *value = 99;
+
+ for (i = 0; options[i] != NULL; i++){
+ if (strncasecmp(state, options[i], strlen(options[i])) == 0){
+ *value = i;
+ break;
+ }
+ }
+
+ DEBUGMSGTL(("ucd-snmp/lmSensors", "value is %d\n", *value));
+ return(error_code);
+} /* end of read_enum_sensor() */
+
- picl_errno_t error_code,ec2;
+static int
+process_num_sensor(picl_nodehdl_t childh,
+ char propname[PICL_PROPNAMELEN_MAX],
+ char propval[PICL_PROPNAMELEN_MAX], int typ, int scale)
+{
+ int value = 0;
+ picl_errno_t error_code;
+
+ if (sensor_array[typ].n >= MAX_SENSORS){
+ DEBUGMSGTL(("ucd-snmp/lmSensors",
+ "There are too many sensors of type %d\n",typ));
+ } else{
+ error_code = read_num_sensor(childh, propval, scale, &value);
+
+ if (error_code == PICL_SUCCESS) {
+ sensor_array[typ].sensor[sensor_array[typ].n].value = value;
+ snprintf(sensor_array[typ].sensor[sensor_array[typ].n].name,
+ (PICL_PROPNAMELEN_MAX - 1),"%s",propname);
+ sensor_array[typ].sensor[sensor_array[typ].n].
+ name[PICL_PROPNAMELEN_MAX - 1] = '\0';
+ sensor_array[typ].n++;
+ } else
+ DEBUGMSGTL(("ucd-snmp/lmSensors",
+ "read of %s returned error code %d\n", propname, error_code));
+ }
+} /* end process_num_sensor() */
- if (sensor_array[typ].n >= MAX_SENSORS){
- DEBUGMSG(("ucd-snmp/lmSensors",
- "There are too many sensors of type %d\n",typ));
- }
- else{
- error_code = (picl_get_propinfo_by_name(childh,
- "AtoDSensorValue",&sensor_info,&sensorh));
- if (error_code == PICL_SUCCESS) {
- ec2 = picl_get_propval(sensorh,&speed,sizeof(speed));
- if (ec2 == PICL_SUCCESS){
- sensor_array[typ].sensor[sensor_array[typ].n].value = speed;
- snprintf(sensor_array[typ].sensor[sensor_array[typ].n].name,
- (PICL_PROPNAMELEN_MAX - 1),"%s",propname);
- sensor_array[typ].sensor[sensor_array[typ].n].
- name[PICL_PROPNAMELEN_MAX - 1] = '\0';
- sensor_array[typ].n++;
- } /*end if ec2*/
- else
- DEBUGMSG(("ucd-snmp/lmSensors",
- "sensor value read error code->%d\n",ec2));
- } /* end if */
- else
- DEBUGMSG(("ucd-snmp/lmSensors",
- "sensor lookup failed error code->%d\n",error_code));
- }
-} /*process individual fan*/
static int
-process_temperature_sensor(picl_nodehdl_t childh,
- char propname[PICL_PROPNAMELEN_MAX])
+process_enum_sensor(picl_nodehdl_t childh,
+ char propname[PICL_PROPNAMELEN_MAX],
+ int typ, char **options)
{
- picl_nodehdl_t sensorh;
- picl_propinfo_t sensor_info;
+ int value = 0;
+ picl_errno_t error_code;
- int temp;
- int typ = 0; /*temperature*/
+ if (sensor_array[typ].n >= MAX_SENSORS){
+ DEBUGMSGTL(("ucd-snmp/lmSensors",
+ "There are too many sensors of type %d\n",typ));
+ } else{
+ error_code = read_enum_sensor(childh, options, &value);
+
+ if (error_code == PICL_SUCCESS) {
+ sensor_array[typ].sensor[sensor_array[typ].n].value = value;
+ snprintf(sensor_array[typ].sensor[sensor_array[typ].n].name,
+ (PICL_PROPNAMELEN_MAX - 1),"%s",propname);
+ sensor_array[typ].sensor[sensor_array[typ].n].
+ name[PICL_PROPNAMELEN_MAX - 1] = '\0';
+ sensor_array[typ].n++;
+ } else
+ DEBUGMSGTL(("ucd-snmp/lmSensors",
+ "read of %s returned error code %d\n", propname, error_code));
+ }
+} /* end process_enum_sensor() */
- picl_errno_t error_code,ec2;
-
- if (sensor_array[typ].n >= MAX_SENSORS){
- DEBUGMSG(("ucd-snmp/lmSensors",
- "There are too many sensors of type %d\n",typ));
- }
- else{
- error_code = (picl_get_propinfo_by_name(childh,
- "Temperature",&sensor_info,&sensorh));
- if (error_code == PICL_SUCCESS) {
- ec2 = picl_get_propval(sensorh,&temp,sizeof(temp));
- if (ec2 == PICL_SUCCESS){
- sensor_array[typ].sensor[sensor_array[typ].n].value = temp;
- snprintf(sensor_array[typ].sensor[sensor_array[typ].n].name,
- (PICL_PROPNAMELEN_MAX - 1),"%s",propname);
- sensor_array[typ].sensor[sensor_array[typ].n].
- name[PICL_PROPNAMELEN_MAX - 1] = '\0';
- sensor_array[typ].n++;
- } /*end if ec2*/
- else
- DEBUGMSG(("ucd-snmp/lmSensors",
- "sensor value read error code->%d\n",ec2));
- } /* end if */
- else
- DEBUGMSG(("ucd-snmp/lmSensors",
- "sensor lookup failed error code->%d\n",error_code));
- }
-} /* process temperature sensor */
static int
-process_digital_sensor(picl_nodehdl_t childh,
- char propname[PICL_PROPNAMELEN_MAX])
+process_temperature_sensor(picl_nodehdl_t childh,
+ char propname[PICL_PROPNAMELEN_MAX])
{
- picl_nodehdl_t sensorh;
- picl_propinfo_t sensor_info;
+ process_num_sensor(childh, propname, "Temperature", 0, 1000);
+}
- int temp; /*volts?*/
- int typ = 2; /*volts*/
+static int
+process_individual_fan(picl_nodehdl_t childh,
+ char propname[PICL_PROPNAMELEN_MAX])
+{
+ process_num_sensor(childh, propname, "AtoDSensorValue", 1, 1);
+}
- picl_errno_t error_code,ec2;
+static int
+process_voltage_sensor(picl_nodehdl_t childh,
+ char propname[PICL_PROPNAMELEN_MAX])
+{
+ process_num_sensor(childh, propname, "Voltage", 2, 1000);
+}
- if (sensor_array[typ].n >= MAX_SENSORS){
- DEBUGMSG(("ucd-snmp/lmSensors",
- "There are too many sensors of type %d\n",typ));
- }
- else{
- error_code = (picl_get_propinfo_by_name(childh,
- "AtoDSensorValue",&sensor_info,&sensorh));
- if (error_code == PICL_SUCCESS) {
- ec2 = picl_get_propval(sensorh,&temp,sizeof(temp));
- if (ec2 == PICL_SUCCESS){
- sensor_array[typ].sensor[sensor_array[typ].n].value = temp;
- snprintf(sensor_array[typ].sensor[sensor_array[typ].n].name,
- (PICL_PROPNAMELEN_MAX - 1),"%s",propname);
- sensor_array[typ].sensor[sensor_array[typ].n].
- name[PICL_PROPNAMELEN_MAX - 1] = '\0';
- sensor_array[typ].n++;
- }
- else
- DEBUGMSG(("ucd-snmp/lmSensors",
- "sensor value read error code->%d\n",ec2));
- } /* end if */
- else
- DEBUGMSG(("ucd-snmp/lmSensors",
- "sensor lookup failed error code->%d\n",error_code));
- }
-} /* process digital sensor */
+static int
+process_digital_sensor(picl_nodehdl_t childh,
+ char propname[PICL_PROPNAMELEN_MAX])
+{
+ process_num_sensor(childh, propname, "AtoDSensorValue", 2, 1);
+}
static int
process_switch(picl_nodehdl_t childh,
char propname[PICL_PROPNAMELEN_MAX])
{
- picl_nodehdl_t sensorh;
- picl_propinfo_t sensor_info;
-
- char state[32];
- int st_cnt;
- char *switch_settings[]={"OFF","ON","NORMAL","LOCKED","UNKNOWN",
- "DIAG","SECURE"};
- u_int value;
- u_int found = 0;
- int max_key_posns = 7;
- int typ = 3; /*other*/
-
- if (sensor_array[typ].n >= MAX_SENSORS){
- DEBUGMSG(("ucd-snmp/lmSensors",
- "There are too many sensors of type %d\n",typ));
- }
- else{
- picl_errno_t error_code,ec2;
+ char *settings[]={"OFF","ON","NORMAL","LOCKED","UNKNOWN",
+ "DIAG","SECURE",NULL};
- error_code = (picl_get_propinfo_by_name(childh,
- "State",&sensor_info,&sensorh));
- if (error_code == PICL_SUCCESS) {
- ec2 = picl_get_propval(sensorh,&state,sensor_info.size);
- if (ec2 == PICL_SUCCESS){
- for (st_cnt=0;st_cnt < max_key_posns;st_cnt++){
- if (strncmp(state,switch_settings[st_cnt],
- strlen(switch_settings[st_cnt])) == 0){
- value = st_cnt;
- found = 1;
- break;
- } /* end if */
- } /* end for */
- if (found==0)
- value = 99;
- sensor_array[typ].sensor[sensor_array[typ].n].value = value;
- snprintf(sensor_array[typ].sensor[sensor_array[typ].n].name,
- (PICL_PROPNAMELEN_MAX - 1),"%s",propname);
- sensor_array[typ].sensor[sensor_array[typ].n].
- name[PICL_PROPNAMELEN_MAX - 1] = '\0';
- sensor_array[typ].n++;
- } /*end if ec2*/
- else
- DEBUGMSG(("ucd-snmp/lmSensors",
- "sensor value read error code->%d\n",ec2));
- } /* end if */
- else
- DEBUGMSG(("ucd-snmp/lmSensors",
- "sensor lookup failed error code->%d\n",error_code));
- }
-} /*process switch*/
+ process_enum_sensor(childh, propname, 3, settings);
+}
static int
process_led(picl_nodehdl_t childh,
char propname[PICL_PROPNAMELEN_MAX])
{
- picl_nodehdl_t sensorh;
- picl_propinfo_t sensor_info;
+ char *settings[]={"OFF","ON","BLINK",NULL};
- char state[32];
- int st_cnt;
- char *led_settings[]={"OFF","ON","BLINK"};
- u_int value;
- u_int found = 0;
- int max_led_posns = 3;
- int typ = 3;
-
- picl_errno_t error_code,ec2;
-
- if (sensor_array[typ].n >= MAX_SENSORS){
- DEBUGMSG(("ucd-snmp/lmSensors",
- "There are too many sensors of type %d\n",typ));
- }
- else{
- error_code = (picl_get_propinfo_by_name(childh,
- "State",&sensor_info,&sensorh));
- if (error_code == PICL_SUCCESS) {
- ec2 = picl_get_propval(sensorh,&state,sensor_info.size);
- if (ec2 == PICL_SUCCESS){
- for (st_cnt=0; st_cnt < max_led_posns; st_cnt++){
- if (strncmp(state,led_settings[st_cnt],
- strlen(led_settings[st_cnt])) == 0){
- value=st_cnt;
- found = 1;
- break;
- }
- }
- if (found==0)
- value = 99;
- sensor_array[typ].sensor[sensor_array[typ].n].value = value;
- snprintf(sensor_array[typ].sensor[sensor_array[typ].n].name,
- (PICL_PROPNAMELEN_MAX - 1),"%s",propname);
- sensor_array[typ].sensor[sensor_array[typ].n].
- name[PICL_PROPNAMELEN_MAX - 1] = '\0';
- sensor_array[typ].n++;
- }
- else
- DEBUGMSG(("ucd-snmp/lmSensors",
- "sensor value read error code->%d\n",ec2));
- }
- else
- DEBUGMSG(("ucd-snmp/lmSensors",
- "sensor lookup failed error code->%d\n",error_code));
- }
+ process_enum_sensor(childh, propname, 3, settings);
}
static int
process_i2c(picl_nodehdl_t childh,
char propname[PICL_PROPNAMELEN_MAX])
{
- picl_nodehdl_t sensorh;
- picl_propinfo_t sensor_info;
+ char *settings[]={"OK",NULL};
- char state[32];
- int st_cnt;
- char *i2c_settings[]={"OK"};
- u_int value;
- u_int found = 0;
- int max_i2c_posns = 1;
- int typ = 3;
-
- picl_errno_t error_code,ec2;
-
- if (sensor_array[typ].n >= MAX_SENSORS){
- DEBUGMSG(("ucd-snmp/lmSensors",
- "There are too many sensors of type %d\n",typ));
- }
- else{
- error_code = (picl_get_propinfo_by_name(childh,
- "State",&sensor_info,&sensorh));
- if (error_code == PICL_SUCCESS) {
- ec2 = picl_get_propval(sensorh,&state,sensor_info.size);
- if (ec2 == PICL_SUCCESS){
- for (st_cnt=0;st_cnt < max_i2c_posns;st_cnt++){
- if (strncmp(state,i2c_settings[st_cnt],
- strlen(i2c_settings[st_cnt])) == 0){
- value=st_cnt;
- found = 1;
- break;
- }
- }
- if (found==0)
- value = 99;
- sensor_array[typ].sensor[sensor_array[typ].n].value = value;
- snprintf(sensor_array[typ].sensor[sensor_array[typ].n].name,
- (PICL_PROPNAMELEN_MAX - 1),"%s",propname);
- sensor_array[typ].sensor[sensor_array[typ].n].
- name[PICL_PROPNAMELEN_MAX - 1] = '\0';
- sensor_array[typ].n++;
- }
- else
- DEBUGMSG(("ucd-snmp/lmSensors",
- "sensor value read error code->%d\n",ec2));
- }
- else
- DEBUGMSG(("ucd-snmp/lmSensors",
- "sensor lookup failed error code->%d\n",error_code));
- }
+ process_enum_sensor(childh, propname, 3, settings);
}
static int
@@ -634,67 +586,81 @@
char propclass[PICL_CLASSNAMELEN_MAX];
picl_errno_t error_code;
+ DEBUGMSGTL(("ucd-snmp/lmSensors","in process_sensors()\n"));
+
/* look up first child node */
error_code = picl_get_propval_by_name(nodeh, PICL_PROP_CHILD, &childh,
sizeof (picl_nodehdl_t));
if (error_code != PICL_SUCCESS) {
+ DEBUGMSGTL(("ucd-snmp/lmSensors",
+ "picl_get_propval_by_name(%s) %d\n",
+ PICL_PROP_CHILD, error_code));
return (error_code);
}
/* step through child nodes, get the name first */
while (error_code == PICL_SUCCESS) {
+
error_code = picl_get_propval_by_name(childh, PICL_PROP_NAME,
propname, (PICL_PROPNAMELEN_MAX - 1));
if (error_code != PICL_SUCCESS) { /*we found a node with no name. Impossible.! */
- return (error_code);
- }
-
- if (strcmp(propname,PICL_NODE_PLATFORM)==0){ /*end of the chain*/
- return (255);
+ DEBUGMSGTL(("ucd-snmp/lmSensors",
+ "picl_get_propval_by_name(%s) = %d\n",
+ PICL_PROP_NAME, error_code));
+ return (error_code);
}
error_code = picl_get_propval_by_name(childh, PICL_PROP_CLASSNAME,
propclass, sizeof (propclass));
if (error_code != PICL_SUCCESS) { /*we found a node with no class. Impossible.! */
+ DEBUGMSGTL(("ucd-snmp/lmSensors",
+ "picl_get_propval_by_name(%s) = %d\n",
+ PICL_PROP_CLASSNAME, error_code));
return (error_code);
}
-/* DEBUGMSGTL(("ucd-snmp/lmSensors","found %s of class %s\n",propname,propclass)); */
+ DEBUGMSGTL(("ucd-snmp/lmSensors","found %s of class %s\n",propname,propclass));
if (strstr(propclass,"fan-tachometer"))
- process_individual_fan(childh,propname);
- if (strstr(propclass,"temperature-sensor"))
+ process_individual_fan(childh,propname);
+ else if (strstr(propclass,"temperature-sensor"))
process_temperature_sensor(childh,propname);
- if (strstr(propclass,"digital-sensor"))
+ else if (strstr(propclass,"voltage-sensor"))
+ process_voltage_sensor(childh,propname);
+ else if (strstr(propclass,"digital-sensor"))
process_digital_sensor(childh,propname);
- if (strstr(propclass,"switch"))
+ else if (strstr(propclass,"switch"))
process_switch(childh,propname);
- if (strstr(propclass,"led"))
+ else if (strstr(propclass,"led"))
process_led(childh,propname);
- if (strstr(propclass,"i2c"))
+ else if (strstr(propclass,"i2c"))
process_i2c(childh,propname);
/*
- if (strstr(propclass,"gpio"))
+ else if (strstr(propclass,"gpio"))
process_gpio(childh,propname);
*/
-
-
- /* look for children of children (note, this is recursive) */
+
+ /* look for children of children (note, this is recursive) */
- if (process_sensors(childh) == PICL_SUCCESS) {
- return (PICL_SUCCESS);
+ if (!(strstr(propclass,"picl") &&
+ (strstr(propname,"frutree") || strstr(propname,"obp")))) {
+ error_code = process_sensors(childh);
+ DEBUGMSGTL(("ucd-snmp/lmSensors",
+ "process_sensors(%s) returned %d\n",
+ propname, error_code));
}
- /* get next child node at this level*/
+ /* get next child node at this level*/
error_code = picl_get_propval_by_name(childh, PICL_PROP_PEER,
- &nexth, sizeof (picl_nodehdl_t));
+ &nexth, sizeof (picl_nodehdl_t));
if (error_code != PICL_SUCCESS) {/* no more children - buh bye*/
- return (error_code);
+ DEBUGMSGTL(("ucd-snmp/lmSensors","Out of children! Returning...\n"));
+ return (error_code);
}
childh = nexth;
-
} /* while */
+
return (error_code);
} /* process sensors */
@@ -748,6 +714,8 @@
return (error_code);
} /* get child */
+
+
#endif
/* ******** end of picld sensor procedures * */
@@ -799,18 +767,11 @@
DEBUGMSG(("ucd-snmp/lmSensors", "picld couldn't get root error code->%d\n",error_code));
}
else{
- error_code = get_child(rooth,sname,&plath);
+ error_code = process_sensors(rooth);
+ if (error_code != 255)
+ if (error_code != 7)
+ DEBUGMSG(("ucd-snmp/lmSensors", "picld had an internal problem error code->%d\n",error_code));
- if (error_code == PICL_SUCCESS){
- error_code = process_sensors(plath);
-
- if (error_code != 255)
- if (error_code != 7)
- DEBUGMSG(("ucd-snmp/lmSensors", "picld had an internal problem error code->%d\n",error_code));
- } /* endif error_code */
- else{
- DEBUGMSG(("ucd-snmp/lmSensors", "picld couldn't get system tree error code->%d\n",error_code));
- } /* end else error_code */
} /* end else */
picl_shutdown();