Hello Team,
I was so disapointed when discovered that default net-snmp lmsensors module
uses single index for all sensor's entries,
even they are placed in different oid tables.
Example:
iso.3.6.1.4.1.2021.13.16.2.1.1.15 = INTEGER: 15
iso.3.6.1.4.1.2021.13.16.2.1.1.16 = INTEGER: 16
iso.3.6.1.4.1.2021.13.16.2.1.1.17 = INTEGER: 17
iso.3.6.1.4.1.2021.13.16.2.1.2.15 = STRING: "temp1"
iso.3.6.1.4.1.2021.13.16.2.1.2.16 = STRING: "temp2"
iso.3.6.1.4.1.2021.13.16.2.1.2.17 = STRING: "temp3"
iso.3.6.1.4.1.2021.13.16.2.1.3.15 = Gauge32: 49000
iso.3.6.1.4.1.2021.13.16.2.1.3.16 = Gauge32: 50000
iso.3.6.1.4.1.2021.13.16.2.1.3.17 = Gauge32: 49000
iso.3.6.1.4.1.2021.13.16.3.1.1.11 = INTEGER: 11
iso.3.6.1.4.1.2021.13.16.3.1.1.12 = INTEGER: 12
iso.3.6.1.4.1.2021.13.16.3.1.1.13 = INTEGER: 13
iso.3.6.1.4.1.2021.13.16.3.1.1.14 = INTEGER: 14
iso.3.6.1.4.1.2021.13.16.3.1.2.11 = STRING: "fan1"
iso.3.6.1.4.1.2021.13.16.3.1.2.12 = STRING: "fan2"
iso.3.6.1.4.1.2021.13.16.3.1.2.13 = STRING: "fan3"
iso.3.6.1.4.1.2021.13.16.3.1.2.14 = STRING: "fan5"
iso.3.6.1.4.1.2021.13.16.3.1.3.11 = Gauge32: 0
iso.3.6.1.4.1.2021.13.16.3.1.3.12 = Gauge32: 4411
iso.3.6.1.4.1.2021.13.16.3.1.3.13 = Gauge32: 0
iso.3.6.1.4.1.2021.13.16.3.1.3.14 = Gauge32: 0
So i patched it by my self.
If my code is not so ugly, please accept it.
----
Dmitriy Kropachev
With best regards.
SRI INFOTECH
diff -ruN ./clean/agent/mibgroup/hardware/sensors/hw_sensors.c ./patched/agent/mibgroup/hardware/sensors/hw_sensors.c
--- ./clean/agent/mibgroup/hardware/sensors/hw_sensors.c 2007-11-14 18:19:36.000000000 +0600
+++ ./patched/agent/mibgroup/hardware/sensors/hw_sensors.c 2010-10-08 17:56:36.000000000 +0700
@@ -12,13 +12,18 @@
static int _sensorAutoUpdate = 0; /* 0 means on-demand caching */
static void _sensor_update_stats( unsigned int, void* );
+int _sensors_index_by_type[NETSNMP_SENSORS_TYPES_COUNT]={};
+int _sensors_initialized=0;
+
+netsnmp_container *_sensor_container_by_type[NETSNMP_SENSORS_TYPES_COUNT]={};
+
netsnmp_cache *_sensor_cache = NULL;
-netsnmp_container *_sensor_container = NULL;
+
static int _sensor_idx = 0;
void init_hw_sensors( void ) {
- if ( _sensor_container )
+ if ( _sensors_initialized )
return; /* Already initialised */
DEBUGMSGTL(("sensors", "Initialise Hardware Sensors module\n"));
@@ -28,12 +33,17 @@
* The four LM-SENSOR-MIB containers will be created in
* the relevant initialisation routine(s)
*/
- _sensor_container = netsnmp_container_find("sensorTable:table_container");
- if ( NULL == _sensor_container ) {
- snmp_log( LOG_ERR, "failed to create container for sensorTable");
- return;
- }
+ int n;
+ for(n=1;n<NETSNMP_SENSORS_TYPES_COUNT;n++){
+ _sensor_container_by_type[n] = netsnmp_container_find("sensorTable:table_container");
+
+ if ( NULL == _sensor_container_by_type[n] ) {
+ snmp_log( LOG_ERR, "failed to create container for sensorTable");
+ }
+ }
+
netsnmp_sensor_arch_init( );
+ _sensors_initialized=1;
/*
* If we're sampling the sensor information automatically,
@@ -63,7 +73,7 @@
/*
* Return the main sensor container
*/
-netsnmp_container *get_sensor_container( void ) { return _sensor_container; }
+netsnmp_container *get_sensor_container( int create_type ) { return _sensor_container_by_type[create_type]; }
/*
* Return the main sensor cache control structure (if defined)
@@ -107,6 +117,7 @@
_sensor_load( void )
{
netsnmp_sensor_arch_load( NULL, NULL );
+ _sensors_initialized=1;
}
/*
@@ -115,13 +126,17 @@
static void
_sensor_free( void )
{
+ _sensors_initialized=0;
netsnmp_sensor_info *sp;
+ int n;
+ for (n=1;n<NETSNMP_SENSORS_TYPES_COUNT;n++){
- for (sp = CONTAINER_FIRST( _sensor_container );
- sp;
- sp = CONTAINER_NEXT( _sensor_container, sp )) {
+ for (sp = CONTAINER_FIRST( _sensor_container_by_type[n] );
+ sp;
+ sp = CONTAINER_NEXT( _sensor_container_by_type[n], sp )) {
- sp->flags &= ~ NETSNMP_SENSOR_FLAG_ACTIVE;
+ sp->flags &= ~ NETSNMP_SENSOR_FLAG_ACTIVE;
+ }
}
}
@@ -141,22 +156,39 @@
* Look through the list for a matching entry
*/
/* .. or use a secondary index container ?? */
- for (sp = CONTAINER_FIRST( _sensor_container );
+ if ( ! _sensors_initialized ){
+ DEBUGMSGTL(("sensors:name", "Sensors wasn't initialized\n"));
+ return NULL;
+ }
+
+ if ( create_type>NETSNMP_SENSORS_TYPES_COUNT ){
+ DEBUGMSGTL(("sensors:name", "Wrong create_type (%d) was provided while maximum available value is %d \n", create_type,NETSNMP_SENSORS_TYPES_COUNT));
+ return NULL;
+ }
+
+ for (sp = CONTAINER_FIRST( _sensor_container_by_type[create_type] );
sp;
- sp = CONTAINER_NEXT( _sensor_container, sp )) {
+ sp = CONTAINER_NEXT( _sensor_container_by_type[create_type], sp )) {
if ( !strcmp( name, sp->name ))
return sp;
}
-
- /*
- * Not found...
- */
- if ( create_type == NETSNMP_SENSOR_FIND_EXIST ) {
- DEBUGMSGTL(("sensors:name", "No such sensor entry\n"));
- return NULL;
- }
-
+ if ( create_type == NETSNMP_SENSOR_FIND_EXIST ){
+ int n;
+ for (n=1;n<NETSNMP_SENSORS_TYPES_COUNT;n++){
+
+ for (sp = CONTAINER_FIRST( _sensor_container_by_type[n] );
+ sp;
+ sp = CONTAINER_NEXT( _sensor_container_by_type[n], sp )) {
+
+ if ( !strcmp( name, sp->name ))
+ return sp;
+ }
+ }
+
+ DEBUGMSGTL(("sensors:name", "Sensor entry does not exists\n"));
+ return NULL;
+ };
/*
* ... so let's create a new one, using the type supplied
*/
@@ -172,12 +204,12 @@
*/
sp->idx.len = 1;
sp->idx.oids = SNMP_MALLOC_TYPEDEF( oid );
- sp->idx.oids[0] = ++_sensor_idx;
+ sp->idx.oids[0] = ++_sensors_index_by_type[create_type];
}
DEBUGMSGTL(("sensors:name", "Create sensor entry (type = %d, index = %d\n",
- create_type, _sensor_idx));
- CONTAINER_INSERT( _sensor_container, sp );
+ create_type, _sensors_index_by_type[create_type]));
+ CONTAINER_INSERT( _sensor_container_by_type[create_type], sp );
return sp;
}
diff -ruN ./clean/agent/mibgroup/hardware/sensors/lmsensors_v2.c ./patched/agent/mibgroup/hardware/sensors/lmsensors_v2.c
--- ./clean/agent/mibgroup/hardware/sensors/lmsensors_v2.c 2008-05-21 05:40:56.000000000 +0700
+++ ./patched/agent/mibgroup/hardware/sensors/lmsensors_v2.c 2010-10-08 02:22:35.000000000 +0700
@@ -6,52 +6,79 @@
#include <time.h>
#include <sensors/sensors.h>
+
void netsnmp_sensor_arch_init( void ) {
FILE *fp = fopen("/etc/sensors.conf", "r");
- DEBUGMSGTL(("sensors:arch", "Initialise LM Sensors module\n"));
+ DEBUGMSGTL(("sensors:arch", "Initialise v3 LM Sensors module\n"));
sensors_init( fp );
}
+
int
netsnmp_sensor_arch_load(netsnmp_cache *cache, void *vp) {
netsnmp_sensor_info *sp;
const sensors_chip_name *chip;
- const sensors_feature_data *data;
+ const sensors_feature *data;
+ const sensors_subfeature *data2;
int chip_nr = 0;
- DEBUGMSGTL(("sensors:arch", "Reload LM Sensors module\n"));
- while ((chip = sensors_get_detected_chips(&chip_nr))) {
+ DEBUGMSGTL(("sensors:arch", "Reload v3 LM Sensors module\n"));
+ while ((chip = sensors_get_detected_chips( NULL, &chip_nr))) {
int a = 0;
- int b = 0;
- while ((data = sensors_get_all_features(*chip, &a, &b))) {
- DEBUGMSGTL(("sensors:arch:detail", "get_all_features (%d, %d)\n", a, b));
- char *label = NULL;
- double val;
- int type = NETSNMP_SENSOR_TYPE_OTHER;
-
- if ((data->mode & SENSORS_MODE_R) &&
- (data->mapping == SENSORS_NO_MAPPING) &&
- !sensors_get_label(*chip, data->number, &label) &&
- !sensors_get_feature(*chip, data->number, &val)) {
+ 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", "%s = %f\n", label, val));
+ DEBUGMSGTL(("sensors:arch:detail", " get_subfeatures (%s, %d)\n", data2->name, data2->number));
/*
- * Determine the type of sensor from the description.
- *
- * If the text being looked for below is not in the label of a
- * given sensor (e.g., the temp1 sensor has been labeled 'CPU'
- * rather than 'CPU temp') it will be categorised as OTHER.
+ * Check the type of this subfeature,
+ * concentrating on the main "input" measurements.
*/
- if (strstr(label, "V")) {
+ switch ( data2->type ) {
+ case SENSORS_SUBFEATURE_IN_INPUT:
type = NETSNMP_SENSOR_TYPE_VOLTAGE_DC;
- }
- if (strstr(label, "fan") || strstr(label, "Fan")) {
+ break;
+ case SENSORS_SUBFEATURE_FAN_INPUT:
type = NETSNMP_SENSOR_TYPE_RPM;
- }
- if (strstr(label, "temp") || strstr(label, "Temp")) {
+ 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));
+ continue;
+ }
+ DEBUGMSGTL(("sensors:arch:detail", "%s = %f\n", label, val));
/*
* Use this type to create a new sensor entry
@@ -62,13 +89,12 @@
sp->value = val;
sp->flags|= NETSNMP_SENSOR_FLAG_ACTIVE;
}
- }
- if (label) {
- free(label);
- label = NULL;
- }
+ if (label) {
+ free(label);
+ label = NULL;
+ }
+ } /* end while data2 */
} /* end while data */
} /* end while chip */
-
return 0;
}
diff -ruN ./clean/agent/mibgroup/ucd-snmp/lmsensorsMib.c ./patched/agent/mibgroup/ucd-snmp/lmsensorsMib.c
--- ./clean/agent/mibgroup/ucd-snmp/lmsensorsMib.c 2009-04-04 16:58:02.000000000 +0700
+++ ./patched/agent/mibgroup/ucd-snmp/lmsensorsMib.c 2010-10-11 21:18:22.000000000 +0700
@@ -7,17 +7,45 @@
netsnmp_container *sensorContainer = NULL;
void initialize_lmSensorsTable(const char *tableName, const oid *tableOID,
- netsnmp_container_op *filter, int mult );
+ int mult, int sensor_type );
-int _sensor_filter_temp( netsnmp_container *c, const void *v );
-int _sensor_filter_fan( netsnmp_container *c, const void *v );
-int _sensor_filter_volt( netsnmp_container *c, const void *v );
-int _sensor_filter_misc( netsnmp_container *c, const void *v );
static const oid lmTempSensorsTable_oid[] = {1,3,6,1,4,1,2021,13,16,2};
static const oid lmFanSensorsTable_oid[] = {1,3,6,1,4,1,2021,13,16,3};
static const oid lmVoltSensorsTable_oid[] = {1,3,6,1,4,1,2021,13,16,4};
static const oid lmMiscSensorsTable_oid[] = {1,3,6,1,4,1,2021,13,16,5};
+
+int _netsnmp_sensor_mult[NETSNMP_SENSORS_TYPES_COUNT] = {
+[NETSNMP_SENSOR_TYPE_OTHER] = 1,
+[NETSNMP_SENSOR_TYPE_VOLTAGE_AC] = 1000,
+[NETSNMP_SENSOR_TYPE_VOLTAGE_DC] = 1000,
+[NETSNMP_SENSOR_TYPE_CURRENT] = 1,
+[NETSNMP_SENSOR_TYPE_POWER] = 1,
+[NETSNMP_SENSOR_TYPE_FREQUENCY] = 1,
+[NETSNMP_SENSOR_TYPE_TEMPERATURE] = 1000,
+[NETSNMP_SENSOR_TYPE_HUMIDITY] = 1,
+[NETSNMP_SENSOR_TYPE_RPM] = 1,
+[NETSNMP_SENSOR_TYPE_VOLUME] = 1,
+[NETSNMP_SENSOR_TYPE_BOOLEAN] = 1
+};
+
+char *_netsnmp_sensor_table_name[NETSNMP_SENSORS_TYPES_COUNT] = {
+[NETSNMP_SENSOR_TYPE_OTHER] = "lmMiscSensorsTable",
+[NETSNMP_SENSOR_TYPE_VOLTAGE_AC] = "lmVoltSensorsTable",
+[NETSNMP_SENSOR_TYPE_VOLTAGE_DC] = "lmVoltSensorsTable",
+[NETSNMP_SENSOR_TYPE_CURRENT] = "lmCurSensorsTable",
+[NETSNMP_SENSOR_TYPE_POWER] = "lmPowerSensorsTable",
+[NETSNMP_SENSOR_TYPE_FREQUENCY] = "lmFreqSensorsTable",
+[NETSNMP_SENSOR_TYPE_TEMPERATURE] = "lmTempSensorsTable",
+[NETSNMP_SENSOR_TYPE_HUMIDITY] = "lmHumiditySensorsTable",
+[NETSNMP_SENSOR_TYPE_RPM] = "lmFanSensorsTable",
+[NETSNMP_SENSOR_TYPE_VOLUME] = "lmVolumeSensorsTable",
+[NETSNMP_SENSOR_TYPE_BOOLEAN] = "lmBoolSensorsTable"
+};
+
+
+
+
/* All the tables have the same length root OID */
const size_t lmSensorsTables_oid_len = OID_LENGTH(lmMiscSensorsTable_oid);
@@ -33,14 +61,13 @@
*
* They are almost identical, so we can use the same registration code.
*/
- initialize_lmSensorsTable( "lmTempSensorsTable", lmTempSensorsTable_oid,
- _sensor_filter_temp, 1000 ); /* MIB asks for mC */
- initialize_lmSensorsTable( "lmFanSensorsTable", lmFanSensorsTable_oid,
- _sensor_filter_fan, 1);
- initialize_lmSensorsTable( "lmVoltSensorsTable", lmVoltSensorsTable_oid,
- _sensor_filter_volt, 1000 ); /* MIB asks for mV */
- initialize_lmSensorsTable( "lmMiscSensorsTable", lmMiscSensorsTable_oid,
- _sensor_filter_misc, 1 );
+
+ int n;
+ for ( n = 1 ; n < NETSNMP_SENSORS_TYPES_COUNT ; n++ ){
+ oid table_oid[]={1,3,6,1,4,1,2021,13,16,n};
+ initialize_lmSensorsTable( _netsnmp_sensor_table_name[n], table_oid,
+ _netsnmp_sensor_mult[n] , n); /* MIB asks for mC */
+ }
}
/*
@@ -48,7 +75,7 @@
*/
void
initialize_lmSensorsTable(const char *tableName, const oid *tableOID,
- netsnmp_container_op *filter, int mult )
+ int mult, int sensor_type )
{
netsnmp_handler_registration *reg;
netsnmp_table_registration_info *table_info;
@@ -60,19 +87,20 @@
* and retrieve the main sensors container.
* This table will then be registered using a filter on this container.
*/
- sensorContainer = get_sensor_container();
+ sensorContainer = get_sensor_container(sensor_type);
if ( !sensorContainer ) {
init_hw_sensors( );
- sensorContainer = get_sensor_container();
+ sensorContainer = get_sensor_container(sensor_type);
}
- container = netsnmp_container_find("sensorTable:table_container");
- container->insert_filter = filter;
- netsnmp_container_add_index( sensorContainer, container );
-
-
/*
* Create a basic registration structure for the table
*/
+
+// container = netsnmp_container_find("sensorTable:table_container");
+// netsnmp_container_add_index( sensorContainer, container );
+
+
+
reg = netsnmp_create_handler_registration(
tableName, lmSensorsTables_handler,
tableOID, lmSensorsTables_oid_len, HANDLER_CAN_RONLY
@@ -82,12 +110,14 @@
* Register the table using the filtered container
* Include an indicator of any scaling to be applied to the sensor value
*/
+
+
reg->my_reg_void = (void *)mult;
table_info = SNMP_MALLOC_TYPEDEF( netsnmp_table_registration_info );
netsnmp_table_helper_add_indexes(table_info, ASN_INTEGER, 0);
table_info->min_column = COLUMN_LMSENSORS_INDEX;
table_info->max_column = COLUMN_LMSENSORS_VALUE;
- netsnmp_container_table_register( reg, table_info, container, 0 );
+ netsnmp_container_table_register( reg, table_info, sensorContainer, 0 );
/*
* If the HAL sensors module was configured as an on-demand caching
@@ -108,33 +138,6 @@
*
* Used to ensure that sensor entries appear in the appropriate table.
*/
-int _sensor_filter_temp( netsnmp_container *c, const void *v ) {
- const netsnmp_sensor_info *sp = (const netsnmp_sensor_info *)v;
- /* Only matches temperature sensors */
- return (( sp->type == NETSNMP_SENSOR_TYPE_TEMPERATURE ) ? 0 : 1 );
-}
-
-int _sensor_filter_fan( netsnmp_container *c, const void *v ) {
- const netsnmp_sensor_info *sp = (const netsnmp_sensor_info *)v;
- /* Only matches fan sensors */
- return (( sp->type == NETSNMP_SENSOR_TYPE_RPM ) ? 0 : 1 );
-}
-
-int _sensor_filter_volt( netsnmp_container *c, const void *v ) {
- const netsnmp_sensor_info *sp = (const netsnmp_sensor_info *)v;
- /* Only matches voltage sensors (AC or DC) */
- return ((( sp->type == NETSNMP_SENSOR_TYPE_VOLTAGE_DC ) ||
- ( sp->type == NETSNMP_SENSOR_TYPE_VOLTAGE_AC )) ? 0 : 1 );
-}
-
-int _sensor_filter_misc( netsnmp_container *c, const void *v ) {
- const netsnmp_sensor_info *sp = (const netsnmp_sensor_info *)v;
- /* Matches everything except temperature, fan or voltage sensors */
- return ((( sp->type == NETSNMP_SENSOR_TYPE_TEMPERATURE ) ||
- ( sp->type == NETSNMP_SENSOR_TYPE_RPM ) ||
- ( sp->type == NETSNMP_SENSOR_TYPE_VOLTAGE_DC ) ||
- ( sp->type == NETSNMP_SENSOR_TYPE_VOLTAGE_AC )) ? 1 : 0 );
-}
/*
diff -ruN ./clean/include/net-snmp/agent/hardware/sensors.h ./patched/include/net-snmp/agent/hardware/sensors.h
--- ./clean/include/net-snmp/agent/hardware/sensors.h 2007-11-13 19:59:01.000000000 +0600
+++ ./patched/include/net-snmp/agent/hardware/sensors.h 2010-10-08 08:08:42.000000000 +0700
@@ -16,6 +16,7 @@
#define NETSNMP_SENSOR_TYPE_VOLUME 11
#define NETSNMP_SENSOR_TYPE_BOOLEAN 12
+#define NETSNMP_SENSORS_TYPES_COUNT 13
#define NETSNMP_SENSOR_FLAG_ACTIVE 0x01
#define NETSNMP_SENSOR_FLAG_NAVAIL 0x02
@@ -41,7 +42,7 @@
long flags;
};
-netsnmp_container *get_sensor_container( void );
+netsnmp_container *get_sensor_container( int );
netsnmp_cache *get_sensor_cache( void );
netsnmp_sensor_info *sensor_by_name( char *, int );
NetsnmpCacheLoad netsnmp_sensor_load;
------------------------------------------------------------------------------
Download new Adobe(R) Flash(R) Builder(TM) 4
The new Adobe(R) Flex(R) 4 and Flash(R) Builder(TM) 4 (formerly
Flex(R) Builder(TM)) enable the development of rich applications that run
across multiple browsers and platforms. Download your free trials today!
http://p.sf.net/sfu/adobe-dev2dev
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders