1 351991: Port net-snmp to lm_sensors-3.x.x
2 Source: upstream, svn diff -r 16736:16739
3 Reviewed-By: Jan Safranek <jsafrane@redhat.com>
6 ===================================================================
7 --- configure (revision 16736)
8 +++ configure (revision 16739)
9 @@ -32628,7 +32628,7 @@
12 # LM-SENSORS-MIB support
13 -echo " $module_list " | grep " ucd-snmp/lmSensors " > /dev/null
14 +echo " $module_list " | $GREP -i "ucd-snmp/lmsensor" > /dev/null
15 if test $? -eq 0 ; then
16 { echo "$as_me:$LINENO: checking for sensors support" >&5
17 echo $ECHO_N "checking for sensors support... $ECHO_C" >&6; }
18 Index: include/net-snmp/agent/hardware/sensors.h
19 ===================================================================
20 --- include/net-snmp/agent/hardware/sensors.h (revision 0)
21 +++ include/net-snmp/agent/hardware/sensors.h (revision 16739)
24 + * Hardware Abstraction Layer - Sensors module
29 +#define NETSNMP_SENSOR_TYPE_OTHER 1
30 +#define NETSNMP_SENSOR_TYPE_VOLTAGE_AC 3
31 +#define NETSNMP_SENSOR_TYPE_VOLTAGE_DC 4
32 +#define NETSNMP_SENSOR_TYPE_CURRENT 5
33 +#define NETSNMP_SENSOR_TYPE_POWER 6
34 +#define NETSNMP_SENSOR_TYPE_FREQUENCY 7
35 +#define NETSNMP_SENSOR_TYPE_TEMPERATURE 8
36 +#define NETSNMP_SENSOR_TYPE_HUMIDITY 9
37 +#define NETSNMP_SENSOR_TYPE_RPM 10
38 +#define NETSNMP_SENSOR_TYPE_VOLUME 11
39 +#define NETSNMP_SENSOR_TYPE_BOOLEAN 12
42 +#define NETSNMP_SENSOR_FLAG_ACTIVE 0x01
43 +#define NETSNMP_SENSOR_FLAG_NAVAIL 0x02
44 +#define NETSNMP_SENSOR_FLAG_BROKEN 0x04
45 +#define NETSNMP_SENSOR_FLAG_DISABLE 0x08
47 +#define NETSNMP_SENSOR_MASK_STATUS 0x06 /* NAVAIL|BROKEN */
50 +#define NETSNMP_SENSOR_FIND_CREATE 1 /* or use one of the sensor type values */
51 +#define NETSNMP_SENSOR_FIND_EXIST 0
53 +typedef struct netsnmp_sensor_info_s netsnmp_sensor_info;
54 +struct netsnmp_sensor_info_s {
66 +netsnmp_container *get_sensor_container( void );
67 +netsnmp_cache *get_sensor_cache( void );
68 +netsnmp_sensor_info *sensor_by_name( char *, int );
69 +NetsnmpCacheLoad netsnmp_sensor_load;
70 +NetsnmpCacheFree netsnmp_sensor_free;
72 ===================================================================
73 --- configure.in (revision 16736)
74 +++ configure.in (revision 16739)
78 # LM-SENSORS-MIB support
79 -echo " $module_list " | grep " ucd-snmp/lmSensors " > /dev/null
80 +echo " $module_list " | $GREP -i "ucd-snmp/lmsensor" > /dev/null
81 if test $? -eq 0 ; then
82 AC_MSG_CHECKING([for sensors support])
84 Index: agent/mibgroup/ucd-snmp/lmsensorsMib.c
85 ===================================================================
86 --- agent/mibgroup/ucd-snmp/lmsensorsMib.c (revision 0)
87 +++ agent/mibgroup/ucd-snmp/lmsensorsMib.c (revision 16739)
89 +#include <net-snmp/net-snmp-config.h>
90 +#include <net-snmp/net-snmp-includes.h>
91 +#include <net-snmp/agent/net-snmp-agent-includes.h>
92 +#include <net-snmp/agent/hardware/sensors.h>
93 +#include "ucd-snmp/lmsensorsMib.h"
95 +netsnmp_container *sensorContainer = NULL;
97 +void initialize_lmSensorsTable(const char *tableName, oid *tableOID,
98 + netsnmp_container_op *filter, int mult );
100 +int _sensor_filter_temp( netsnmp_container *c, const void *v );
101 +int _sensor_filter_fan( netsnmp_container *c, const void *v );
102 +int _sensor_filter_volt( netsnmp_container *c, const void *v );
103 +int _sensor_filter_misc( netsnmp_container *c, const void *v );
105 +static oid lmTempSensorsTable_oid[] = {1,3,6,1,4,1,2021,13,16,2};
106 +static oid lmFanSensorsTable_oid[] = {1,3,6,1,4,1,2021,13,16,3};
107 +static oid lmVoltSensorsTable_oid[] = {1,3,6,1,4,1,2021,13,16,4};
108 +static oid lmMiscSensorsTable_oid[] = {1,3,6,1,4,1,2021,13,16,5};
109 + /* All the tables have the same length root OID */
110 +size_t lmSensorsTables_oid_len = OID_LENGTH(lmMiscSensorsTable_oid);
113 +/* Initialise the LM Sensors MIB module */
115 +init_lmsensorsMib(void)
117 + DEBUGMSGTL(("ucd-snmp/lmsensorsMib","Initializing LM-SENSORS-MIB tables\n"));
120 + * Initialise the four LM-SENSORS-MIB tables
122 + * They are almost identical, so we can use the same registration code.
124 + initialize_lmSensorsTable( "lmTempSensorsTable", lmTempSensorsTable_oid,
125 + _sensor_filter_temp, 1000 ); /* MIB asks for mC */
126 + initialize_lmSensorsTable( "lmFanSensorsTable", lmFanSensorsTable_oid,
127 + _sensor_filter_fan, 1);
128 + initialize_lmSensorsTable( "lmVoltSensorsTable", lmVoltSensorsTable_oid,
129 + _sensor_filter_volt, 1000 ); /* MIB asks for mV */
130 + initialize_lmSensorsTable( "lmMiscSensorsTable", lmMiscSensorsTable_oid,
131 + _sensor_filter_misc, 1 );
135 + * Common initialisation code, used for setting up all four tables
138 +initialize_lmSensorsTable(const char *tableName, oid *tableOID,
139 + netsnmp_container_op *filter, int mult )
141 + netsnmp_handler_registration *reg;
142 + netsnmp_table_registration_info *table_info;
143 + netsnmp_cache *cache;
144 + netsnmp_container *container;
147 + * Ensure the HAL sensors module has been initialised,
148 + * and retrieve the main sensors container.
149 + * This table will then be registered using a filter on this container.
151 + sensorContainer = get_sensor_container();
152 + if ( !sensorContainer ) {
153 + init_hw_sensors( );
154 + sensorContainer = get_sensor_container();
156 + container = netsnmp_container_find("sensorTable:table_container");
157 + container->insert_filter = filter;
158 + netsnmp_container_add_index( sensorContainer, container );
162 + * Create a basic registration structure for the table
164 + reg = netsnmp_create_handler_registration(
165 + tableName, lmSensorsTables_handler,
166 + tableOID, lmSensorsTables_oid_len, HANDLER_CAN_RONLY
170 + * Register the table using the filtered container
171 + * Include an indicator of any scaling to be applied to the sensor value
173 + reg->my_reg_void = (void *)mult;
174 + table_info = SNMP_MALLOC_TYPEDEF( netsnmp_table_registration_info );
175 + netsnmp_table_helper_add_indexes(table_info, ASN_INTEGER, 0);
176 + table_info->min_column = COLUMN_LMSENSORS_INDEX;
177 + table_info->max_column = COLUMN_LMSENSORS_VALUE;
178 + netsnmp_container_table_register( reg, table_info, container, 0 );
181 + * If the HAL sensors module was configured as an on-demand caching
182 + * module (rather than being automatically loaded regularly),
183 + * then ensure this table makes use of that cache.
185 + cache = get_sensor_cache();
187 + netsnmp_inject_handler_before( reg, netsnmp_cache_handler_get( cache ),
188 + "table_container");
195 + * Container filters for the four tables
197 + * Used to ensure that sensor entries appear in the appropriate table.
199 +int _sensor_filter_temp( netsnmp_container *c, const void *v ) {
200 + const netsnmp_sensor_info *sp = (const netsnmp_sensor_info *)v;
201 + /* Only matches temperature sensors */
202 + return (( sp->type == NETSNMP_SENSOR_TYPE_TEMPERATURE ) ? 0 : 1 );
205 +int _sensor_filter_fan( netsnmp_container *c, const void *v ) {
206 + const netsnmp_sensor_info *sp = (const netsnmp_sensor_info *)v;
207 + /* Only matches fan sensors */
208 + return (( sp->type == NETSNMP_SENSOR_TYPE_RPM ) ? 0 : 1 );
211 +int _sensor_filter_volt( netsnmp_container *c, const void *v ) {
212 + const netsnmp_sensor_info *sp = (const netsnmp_sensor_info *)v;
213 + /* Only matches voltage sensors (AC or DC) */
214 + return ((( sp->type == NETSNMP_SENSOR_TYPE_VOLTAGE_DC ) ||
215 + ( sp->type == NETSNMP_SENSOR_TYPE_VOLTAGE_AC )) ? 0 : 1 );
218 +int _sensor_filter_misc( netsnmp_container *c, const void *v ) {
219 + const netsnmp_sensor_info *sp = (const netsnmp_sensor_info *)v;
220 + /* Matches everything except temperature, fan or voltage sensors */
221 + return ((( sp->type == NETSNMP_SENSOR_TYPE_TEMPERATURE ) ||
222 + ( sp->type == NETSNMP_SENSOR_TYPE_RPM ) ||
223 + ( sp->type == NETSNMP_SENSOR_TYPE_VOLTAGE_DC ) ||
224 + ( sp->type == NETSNMP_SENSOR_TYPE_VOLTAGE_AC )) ? 1 : 0 );
229 + * Handle requests for any of the four lmXxxxSensorsTables
231 + * This is possible because all the table share the
232 + * same structure and behaviour.
235 +lmSensorsTables_handler(
236 + netsnmp_mib_handler *handler,
237 + netsnmp_handler_registration *reginfo,
238 + netsnmp_agent_request_info *reqinfo,
239 + netsnmp_request_info *requests) {
241 + netsnmp_request_info *request;
242 + netsnmp_table_request_info *table_info;
243 + netsnmp_sensor_info *sensor_info;
244 + int mult = (int)reginfo->my_reg_void;
246 + DEBUGMSGTL(( "ucd-snmp/lmsensorsMib","lmSensorsTables_handler - root: "));
247 + DEBUGMSGOID(("ucd-snmp/lmsensorsMib", reginfo->rootoid, reginfo->rootoid_len));
248 + DEBUGMSG(( "ucd-snmp/lmsensorsMib",", mode %d\n", reqinfo->mode ));
250 + * This is a read-only table, so we only need to handle GET requests.
251 + * (The container helper converts GETNEXT->GET requests automatically).
253 + switch (reqinfo->mode) {
255 + for (request=requests; request; request=request->next) {
256 + sensor_info = (netsnmp_sensor_info *)
257 + netsnmp_container_table_extract_context(request);
258 + if ( !sensor_info ) {
259 + netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE);
263 + table_info = netsnmp_extract_table_info(request);
264 + switch (table_info->colnum) {
265 + case COLUMN_LMSENSORS_INDEX:
266 + snmp_set_var_typed_integer( request->requestvb, ASN_INTEGER,
267 + sensor_info->idx.oids[0]);
269 + case COLUMN_LMSENSORS_DEVICE:
270 + if ( sensor_info->descr[0] != '\0' ) {
271 + snmp_set_var_typed_value( request->requestvb, ASN_OCTET_STR,
272 + sensor_info->descr, strlen(sensor_info->descr));
274 + snmp_set_var_typed_value( request->requestvb, ASN_OCTET_STR,
275 + sensor_info->name, strlen(sensor_info->name));
278 + case COLUMN_LMSENSORS_VALUE:
279 + /* Multiply the value by the appropriate scaling factor for this table */
280 + snmp_set_var_typed_integer( request->requestvb, ASN_GAUGE,
281 + (int)(mult*sensor_info->value));
284 + netsnmp_set_request_error(reqinfo, request,
285 + SNMP_NOSUCHOBJECT);
292 + return SNMP_ERR_NOERROR;
294 Index: agent/mibgroup/ucd-snmp/lmsensorsMib.h
295 ===================================================================
296 --- agent/mibgroup/ucd-snmp/lmsensorsMib.h (revision 0)
297 +++ agent/mibgroup/ucd-snmp/lmsensorsMib.h (revision 16739)
299 +#ifndef LM_SENSORS_MIB_H
300 +#define LM_SENSORS_MIB_H
302 +config_require(hardware/sensors)
303 +config_add_mib(LM-SENSORS-MIB)
305 +/* function declarations */
306 +void init_lmsensorsMib(void);
309 + * Handler and Column definitions for lmXxxxSensorsTable
311 + * Note that the same handler (and hence the same
312 + * column identifiers) are used for all four tables.
313 + * This is possible because all the table share the
314 + * same structure and behaviour.
316 +Netsnmp_Node_Handler lmSensorsTables_handler;
317 +#define COLUMN_LMSENSORS_INDEX 1
318 +#define COLUMN_LMSENSORS_DEVICE 2
319 +#define COLUMN_LMSENSORS_VALUE 3
321 +#endif /* LM_SENSORS_MIB_H */
322 Index: agent/mibgroup/hardware/sensors.h
323 ===================================================================
324 --- agent/mibgroup/hardware/sensors.h (revision 0)
325 +++ agent/mibgroup/hardware/sensors.h (revision 16739)
327 +config_require(hardware/sensors/hw_sensors)
329 +#if defined(solaris)
330 +# if defined(HAVE_PICL_H)
331 +config_require(hardware/sensors/picld_sensors)
333 +config_require(hardware/sensors/kstat_sensors)
336 +config_require(hardware/sensors/lmsensors_v3)
339 +//config_require(hardware/sensors/dummy_sensors)
340 Index: agent/mibgroup/hardware/sensors/hw_sensors.h
341 ===================================================================
342 --- agent/mibgroup/hardware/sensors/hw_sensors.h (revision 0)
343 +++ agent/mibgroup/hardware/sensors/hw_sensors.h (revision 16739)
345 +void init_hw_sensors( void );
346 Index: agent/mibgroup/hardware/sensors/lmsensors_v2.h
347 ===================================================================
348 --- agent/mibgroup/hardware/sensors/lmsensors_v2.h (revision 0)
349 +++ agent/mibgroup/hardware/sensors/lmsensors_v2.h (revision 16739)
351 +config_require(hardware/sensors/hw_sensors)
352 Index: agent/mibgroup/hardware/sensors/kstat_sensors.c
353 ===================================================================
354 --- agent/mibgroup/hardware/sensors/kstat_sensors.c (revision 0)
355 +++ agent/mibgroup/hardware/sensors/kstat_sensors.c (revision 16739)
357 +#include <net-snmp/net-snmp-config.h>
358 +#include <net-snmp/net-snmp-includes.h>
359 +#include <net-snmp/agent/net-snmp-agent-includes.h>
360 +#include <net-snmp/agent/hardware/sensors.h>
362 +#include "util_funcs.h"
366 +#include </usr/platform/sun4u/include/sys/envctrl.h>
368 +void netsnmp_sensor_arch_init( void ) {
369 + DEBUGMSGTL(("sensors:arch", "Initialise KStat Sensors module\n"));
374 +netsnmp_sensor_arch_load(netsnmp_cache *cache, void *vp) {
375 + netsnmp_sensor_info *sp;
378 + const char *fantypes[]={"CPU","PWR","AFB"};
383 + envctrl_fan_t *fan_info;
384 + envctrl_ps_t *power_info;
385 + envctrl_encl_t *enc_info;
388 + DEBUGMSGTL(("sensors:arch", "Reload KStat Sensors module\n"));
392 + DEBUGMSGTL(("sensors:arch", "Couldn't open kstat\n"));
398 + * Retrieve fan information
400 + kp = kstat_lookup( kc, ENVCTRL_MODULE_NAME, 0, ENVCTRL_KSTAT_FANSTAT);
401 + if (( kp == 0 ) || (kstat_read( kc, kp, 0 ) == -1 )) {
402 + DEBUGMSGTL(("sensors:arch", "No fan information\n"));
404 + fan_info = (envctrl_fan_t *)kp->ks_data;
405 + for (i=0; i<kp->ks_ndata; i++) {
406 + memset( name, 0, 256 );
407 + snprintf( name, 255, "%s%d", fantypes[fan_info->type], fan_info->instance );
409 + sp = sensor_by_name( name, NETSNMP_SENSOR_TYPE_RPM );
411 + sp->value = fan_info->fanspeed;
412 + sp->flags|= NETSNMP_SENSOR_FLAG_ACTIVE;
413 + snprintf( sp->descr, 255, "fan type %s number %d",
414 + fantypes[fan_info->type], fan_info->instance );
423 + * Retrieve Power Supply information
425 + kp = kstat_lookup( kc, ENVCTRL_MODULE_NAME, 0, ENVCTRL_KSTAT_PSNAME);
426 + if (( kp == 0 ) || (kstat_read( kc, kp, 0 ) == -1 )) {
427 + DEBUGMSGTL(("sensors:arch", "No PSU information\n"));
429 + power_info = (envctrl_ps_t *)kp->ks_data;
430 + for (i=0; i<kp->ks_ndata; i++) {
431 + memset( name, 0, 256 );
432 + snprintf( name, 255, "PSU%d", power_info->instance );
434 + sp = sensor_by_name( name, NETSNMP_SENSOR_TYPE_TEMPERATURE);
436 + sp->value = power_info->ps_tempr;
437 + sp->flags|= NETSNMP_SENSOR_FLAG_ACTIVE;
438 + snprintf( sp->descr, 255, "power supply %d", power_info->instance );
447 + * Retrieve Enclosure information
449 + kp = kstat_lookup( kc, ENVCTRL_MODULE_NAME, 0, ENVCTRL_KSTAT_ENCL);
450 + if (( kp == 0 ) || (kstat_read( kc, kp, 0 ) == -1 )) {
451 + DEBUGMSGTL(("sensors:arch", "No enclosure information\n"));
453 + enc_info = (envctrl_encl_t *)kp->ks_data;
454 + for (i=0; i<kp->ks_ndata; i++) {
456 + * The enclosure information covers several different types of sensor
458 + switch ( enc_info->type ) {
459 + case ENVCTRL_ENCL_FSP:
460 + DEBUGMSGTL(("sensors:arch:detail", "Enclosure Front Panel\n"));
461 + sp = sensor_by_name( "FSP", NETSNMP_SENSOR_TYPE_OTHER);
463 + sp->value = enc_info->value;
464 + sp->flags|= NETSNMP_SENSOR_FLAG_ACTIVE;
468 + case ENVCTRL_ENCL_AMBTEMPR:
469 + DEBUGMSGTL(("sensors:arch:detail", "Enclosure Ambient Temperature\n"));
470 + sp = sensor_by_name( "Ambient", NETSNMP_SENSOR_TYPE_TEMPERATURE);
472 + sp->value = enc_info->value;
473 + sp->flags|= NETSNMP_SENSOR_FLAG_ACTIVE;
477 + case ENVCTRL_ENCL_CPUTEMPR:
478 + DEBUGMSGTL(("sensors:arch:detail", "Enclosure CPU Temperature\n"));
479 + memset( name, 0, 256 );
480 + snprintf( name, 255, "CPU%d", enc_info->instance );
481 + sp = sensor_by_name( name, NETSNMP_SENSOR_TYPE_TEMPERATURE);
483 + sp->value = enc_info->value;
484 + sp->flags|= NETSNMP_SENSOR_FLAG_ACTIVE;
485 + snprintf( sp->descr, 255, "CPU%d temperature", enc_info->instance );
489 + case ENVCTRL_ENCL_BACKPLANE4:
490 + DEBUGMSGTL(("sensors:arch:detail", "Enclosure Backplane4\n"));
491 + sp = sensor_by_name( "Backplane4", NETSNMP_SENSOR_TYPE_OTHER);
493 + sp->value = enc_info->value;
494 + sp->flags|= NETSNMP_SENSOR_FLAG_ACTIVE;
498 + case ENVCTRL_ENCL_BACKPLANE8:
499 + DEBUGMSGTL(("sensors:arch:detail", "Enclosure Backplane4\n"));
500 + sp = sensor_by_name( "Backplane4", NETSNMP_SENSOR_TYPE_OTHER);
502 + sp->value = enc_info->value;
503 + sp->flags|= NETSNMP_SENSOR_FLAG_ACTIVE;
508 + DEBUGMSGTL(("sensors:arch:detail", "Unrecognised Enclosure entry (%d)n",
518 Index: agent/mibgroup/hardware/sensors/lmsensors_v3.h
519 ===================================================================
520 --- agent/mibgroup/hardware/sensors/lmsensors_v3.h (revision 0)
521 +++ agent/mibgroup/hardware/sensors/lmsensors_v3.h (revision 16739)
523 +config_require(hardware/sensors/hw_sensors)
524 Index: agent/mibgroup/hardware/sensors/dummy_sensors.c
525 ===================================================================
526 --- agent/mibgroup/hardware/sensors/dummy_sensors.c (revision 0)
527 +++ agent/mibgroup/hardware/sensors/dummy_sensors.c (revision 16739)
529 +#include <net-snmp/net-snmp-config.h>
530 +#include <net-snmp/net-snmp-includes.h>
531 +#include <net-snmp/agent/net-snmp-agent-includes.h>
532 +#include <net-snmp/agent/hardware/sensors.h>
535 +void netsnmp_sensor_arch_init( void ) {
536 + /* Nothing to do */
537 + DEBUGMSGTL(("sensors:arch", "Initialise Dummy Sensors module\n"));
541 +netsnmp_sensor_arch_load(netsnmp_cache *cache, void *vp) {
544 + netsnmp_sensor_info *sp;
547 + tm = localtime(&now);
549 + DEBUGMSGTL(("sensors:arch", "Reload Dummy Sensors module\n"));
551 + /* First pseudo-sensor - slowly-rising temperature */
552 + sp = sensor_by_name( "minute", NETSNMP_SENSOR_TYPE_TEMPERATURE );
553 + sp->value = tm->tm_min;
554 + snprintf( sp->descr, 256, "Minute-based pseudo-sensor - slowly-rising temperature" );
555 + sp->flags|= NETSNMP_SENSOR_FLAG_ACTIVE;
557 + /* Second pseudo-sensor - quickly-rising temperature */
558 + sp = sensor_by_name( "second", NETSNMP_SENSOR_TYPE_TEMPERATURE );
559 + sp->value = tm->tm_sec;
560 + snprintf( sp->descr, 256, "Second-based pseudo-sensor - quickly-rising temperature" );
561 + sp->flags|= NETSNMP_SENSOR_FLAG_ACTIVE;
563 + /* Third pseudo-sensor - annual fan speed */
564 + sp = sensor_by_name( "year", NETSNMP_SENSOR_TYPE_RPM );
565 + sp->value = tm->tm_year + 1900;
566 + snprintf( sp->descr, 256, "RPM pseudo-sensor - annual fan speed" );
567 + sp->flags|= NETSNMP_SENSOR_FLAG_ACTIVE;
569 + /* Fourth pseudo-sensor - daily voltage */
570 + sp = sensor_by_name( "day", NETSNMP_SENSOR_TYPE_VOLTAGE_DC );
571 + sp->value = tm->tm_mday-20;
572 + snprintf( sp->descr, 256, "Day-based pseudo-sensor - positive or negative voltage" );
573 + sp->flags|= NETSNMP_SENSOR_FLAG_ACTIVE;
575 + /* Fifth pseudo-sensor - monthly voltage */
576 + sp = sensor_by_name( "month", NETSNMP_SENSOR_TYPE_VOLTAGE_DC );
577 + sp->value = tm->tm_mon;
578 + snprintf( sp->descr, 256, "Month-based pseudo-sensor - positive voltage" );
579 + sp->flags|= NETSNMP_SENSOR_FLAG_ACTIVE;
581 + /* Sixth pseudo-sensor - annual daily something */
582 + sp = sensor_by_name( "yday", NETSNMP_SENSOR_TYPE_OTHER );
583 + sp->value = tm->tm_yday;
584 + snprintf( sp->descr, 256, "Day-based pseudo-sensor - annual something" );
585 + sp->flags|= NETSNMP_SENSOR_FLAG_ACTIVE;
589 Index: agent/mibgroup/hardware/sensors/kstat_sensors.h
590 ===================================================================
591 --- agent/mibgroup/hardware/sensors/kstat_sensors.h (revision 0)
592 +++ agent/mibgroup/hardware/sensors/kstat_sensors.h (revision 16739)
594 +config_require(hardware/sensors/hw_sensors)
595 Index: agent/mibgroup/hardware/sensors/picld_sensors.c
596 ===================================================================
597 --- agent/mibgroup/hardware/sensors/picld_sensors.c (revision 0)
598 +++ agent/mibgroup/hardware/sensors/picld_sensors.c (revision 16739)
600 +#include <net-snmp/net-snmp-config.h>
601 +#include <net-snmp/net-snmp-includes.h>
602 +#include <net-snmp/agent/net-snmp-agent-includes.h>
603 +#include <net-snmp/agent/hardware/sensors.h>
605 +#include "util_funcs.h"
609 +#include </usr/platform/sun4u/include/sys/envctrl.h>
611 +void netsnmp_sensor_arch_init( void ) {
612 + DEBUGMSGTL(("sensors:arch", "Initialise PICLd Sensors module\n"));
618 + * Handle a numeric-valued sensor
621 +read_num_sensor( picl_nodehdl_t childh, char *propval, float *value )
623 + picl_nodehdl_t sensorh;
624 + picl_propinfo_t sensor_info;
625 + picl_errno_t error_code;
628 + char buf[PICL_PROPSIZE_MAX];
637 + * Retrieve the specified sensor information and value
639 + error_code = picl_get_propinfo_by_name(childh, propval, &sensor_info, &sensorh);
640 + if ( error_code != PICL_SUCCESS ) {
641 + DEBUGMSGTL(("sensors:arch:detail", "sensor info lookup failed (%d)\n",
643 + return( error_code );
646 + error_code = picl_get_propval(sensorh, &val.buf, sensor_info.size);
647 + if ( error_code != PICL_SUCCESS ) {
648 + DEBUGMSGTL(("sensors:arch:detail", "sensor value lookup failed (%d)\n",
650 + return( error_code );
654 + * Check the validity (type and size) of this value
656 + if ( sensor_info.type == PICL_PTYPE_FLOAT ) {
658 + } else if ( sensor_info.type == PICL_PTYPE_UNSIGNED_INT ) {
659 + /* 16-bit or 32-bit unsigned integers */
660 + if ( sensor_info.size == 2 ) {
662 + } else if ( sensor_info.size == 4 ) {
665 + DEBUGMSGTL(("sensors:arch:detail", "unsigned integer (%d bit)\n",
666 + sensor_info.size * 8));
667 + return PICL_FAILURE;
669 + } else if ( sensor_info.type == PICL_PTYPE_INT ) {
670 + /* 16-bit or 32-bit signed integers */
671 + if ( sensor_info.size == 2 ) {
673 + } else if ( sensor_info.size == 4 ) {
676 + DEBUGMSGTL(("sensors:arch:detail", "signed integer (%d bit)\n",
677 + sensor_info.size * 8));
678 + return PICL_FAILURE;
681 + DEBUGMSGTL(("sensors:arch:detail", "unrecognised type (%d)\n",
682 + sensor_info.type));
683 + return PICL_FAILURE;
690 +process_num_sensor( picl_nodehdl_t childh, char *propname, char *propval, int typ )
692 + netsnmp_sensor_info *sp;
694 + picl_errno_t error_code;
696 + sp = sensor_by_name( propname, typ );
701 + error_code = read_num_sensor( childh, propval, &value );
702 + if ( error_code == PICL_SUCCESS ) {
704 + sp->flags|= NETSNMP_SENSOR_FLAG_ACTIVE;
706 + DEBUGMSGTL(("sensors:arch:detail", "Failed to read %s sensor value (%d)\n",
707 + propname, error_code));
716 + * Handle an enumeration-valued sensor
718 +char *switch_settings[] = { "OFF","ON","NORMAL","LOCKED",
719 + "UNKNOWN","DIAG","SECURE",
721 +char *led_settings[] = { "OFF","ON","BLINK",
723 +char *i2c_settings[] = { "OK",
727 +read_enum_sensor( picl_nodehdl_t childh, float *value, char **options )
729 + picl_nodehdl_t sensorh;
730 + picl_propinfo_t sensor_info;
731 + picl_errno_t error_code;
732 + char state[PICL_PROPSIZE_MAX];
736 + * Retrieve the specified sensor information and value
738 + error_code = picl_get_propinfo_by_name(childh, "State", &sensor_info, &sensorh);
739 + if ( error_code != PICL_SUCCESS ) {
740 + DEBUGMSGTL(("sensors:arch:detail", "sensor info lookup failed (%d)\n",
742 + return( error_code );
745 + error_code = picl_get_propval(sensorh, state, sensor_info.size);
746 + if ( error_code != PICL_SUCCESS ) {
747 + DEBUGMSGTL(("sensors:arch:detail", "sensor value lookup failed (%d)\n",
749 + return( error_code );
753 + * Try to find a matching entry in the list of options.
754 + * Note that some platforms may use upper or lower case
755 + * versions of these enumeration values
756 + * (so the checks are case insensitive)
758 + *value = 99; /* Dummy value */
759 + for ( i=0; options[i] != NULL; i++ ) {
760 + if (strncasecmp(state, options[i], strlen(options[i])) == 0) {
766 + DEBUGMSGTL(("sensors:arch:detail", "Enumeration state %s not matched\n",
768 + return 0; /* Or an error ? */
772 +process_enum_sensor( picl_nodehdl_t childh, char *propname, int typ, char **options )
774 + netsnmp_sensor_info *sp;
776 + picl_errno_t error_code;
778 + sp = sensor_by_name( propname, typ );
783 + error_code = read_enum_sensor( childh, &value, options );
784 + if ( error_code == PICL_SUCCESS ) {
786 + sp->flags|= NETSNMP_SENSOR_FLAG_ACTIVE;
788 + DEBUGMSGTL(("sensors:arch:detail", "Failed to read %s sensor value (%d)\n",
789 + propname, error_code));
795 +process_enum_sensor( picl_nodehdl_t childh, char *propname, int typ, char **options )
803 + * Recursively walk through the tree of sensors
806 +process_sensors( int level, picl_nodehdl_t nodeh ) {
807 + picl_nodehdl_t childh, nexth;
808 + char propname[ PICL_PROPNAMELEN_MAX ];
809 + char propclass[ PICL_CLASSNAMELEN_MAX ];
810 + picl_errno_t error_code;
813 + DEBUGMSGTL(("sensors:arch:detail", "process_sensors - level %d\n", level));
815 + /* Look up the first child node at this level */
816 + error_code = pick_get_propval_by_name( nodeh, PICL_PROP_CHILD,
817 + &childh, sizeof(childh));
818 + if ( error_code != PICL_SUCCESS ) {
819 + DEBUGMSGTL(("sensors:arch:detail", "Failed to get first child node (%d)\n",
821 + return( error_code );
824 + /* Step through the child nodes, retrieving the name and class of each one */
825 + while ( error_code == PICL_SUCCESS ) {
826 + error_code = pick_get_propval_by_name( childh, PICL_PROP_NAME,
827 + propname, sizeof(propname)-1);
828 + if ( error_code != PICL_SUCCESS ) {
829 + /* The Node With No Name */
830 + DEBUGMSGTL(("sensors:arch:detail", "get property name failed (%d)\n",
832 + return( error_code );
835 + error_code = pick_get_propval_by_name( childh, PICL_PROP_CLASSNAME,
836 + propclass, sizeof(propclass)-1);
837 + if ( error_code != PICL_SUCCESS ) {
838 + /* The Classless Society */
839 + DEBUGMSGTL(("sensors:arch:detail", "get property class failed (%d)\n",
841 + return( error_code );
844 + DEBUGMSGTL(("sensors:arch:detail", "Name: %s, Class %s\n",
845 + propname, propclass ));
849 + * Three classes represent further groups of sensors, etc.
850 + * Call 'process_sensors' recursively to handle this next level
852 + if (( strstr( propclass, "picl" )) ||
853 + ( strstr( propclass, "frutree" )) ||
854 + ( strstr( propclass, "obp" ))) {
855 + process_sensors( level, childh );
858 + * Otherwise retrieve the value appropriately based on the
859 + * class of the sensor.
861 + * We need to specify the name of the PICL property to retrieve
862 + * for this class of sensor, and the Net-SNMP sensor type.
864 + else if ( strstr( propclass, "fan-tachometer" )) {
865 + process_num_sensor( childh, propname, "AtoDSensorValue",
866 + NETSNMP_SENSOR_TYPE_RPM );
867 + } else if ( strstr( propclass, "fan" )) {
868 + process_num_sensor( childh, propname, "Speed",
869 + NETSNMP_SENSOR_TYPE_RPM );
870 + } else if ( strstr( propclass, "temperature-sensor" )) {
871 + process_num_sensor( childh, propname, "Temperature",
872 + NETSNMP_SENSOR_TYPE_TEMPERATURE );
873 + } else if ( strstr( propclass, "voltage-sensor" )) {
874 + process_num_sensor( childh, propname, "Voltage",
875 + /* ?? */ NETSNMP_SENSOR_TYPE_VOLTAGE_DC );
876 + } else if ( strstr( propclass, "digital-sensor" )) {
877 + process_num_sensor( childh, propname, "AtoDSensorValue",
878 + /* ?? */ NETSNMP_SENSOR_TYPE_VOLTAGE_DC );
880 + * Enumeration-valued sensors use a fixed PICL property ("State"),
881 + * but take a list of the values appropriate for that sensor,
882 + * as well as the Net-SNMP sensor type.
884 + } else if ( strstr( propclass, "switch" )) {
885 + process_enum_sensor( childh, propname, NETSNMP_SENSOR_TYPE_OTHER,
887 + } else if ( strstr( propclass, "led" )) {
888 + process_enum_sensor( childh, propname, NETSNMP_SENSOR_TYPE_OTHER,
890 + } else if ( strstr( propclass, "i2c" )) {
891 + process_enum_sensor( childh, propname, NETSNMP_SENSOR_TYPE_BOOLEAN, /* ?? */
894 + /* Skip other classes of sensor */
895 + DEBUGMSGTL(("sensors:arch:detail", "Skipping class %s\n", propclass ));
899 + * Move on to the next child node at the current level (if any)
901 + error_code = pick_get_propval_by_name( childh, PICL_PROP_PEER,
902 + &nexth, sizeof(nexth));
903 + if ( error_code != PICL_SUCCESS ) {
904 + /* That's All Folks! */
905 + return (( error_code == PICL_PROPNOTFOUND )
906 + ? PICL_SUCCESS : error_code );
916 +netsnmp_sensor_arch_load(netsnmp_cache *cache, void *vp) {
918 + picl_nodehdl_t rooth;
920 + DEBUGMSGTL(("sensors:arch", "Reload PICLd Sensors module\n"));
922 + error_code = picl_get_root(&rooth);
923 + if ( error_code != PICL_SUCCESS) {
924 + DEBUGMSGTL(("sensors:arch", "Couldn't get root node (error %d)\n", error_code));
928 + error_code = process_sensors(0, rooth);
929 + if ( error_code != 255 )
930 + if ( error_code != 7 ) /* ignore PICL_PROPNOTFOUND error */
931 + DEBUGMSGTL(("sensors:arch", "Internal PICLd problem (error %d)\n", error_code));
936 +void netsnmp_sensor_arch_shutdown( void ) {
937 + DEBUGMSGTL(("sensors:arch", "Shutdown PicLD Sensors module\n"));
941 Index: agent/mibgroup/hardware/sensors/hw_sensors.c
942 ===================================================================
943 --- agent/mibgroup/hardware/sensors/hw_sensors.c (revision 0)
944 +++ agent/mibgroup/hardware/sensors/hw_sensors.c (revision 16739)
946 +#include <net-snmp/net-snmp-config.h>
947 +#include <net-snmp/net-snmp-includes.h>
948 +#include <net-snmp/agent/net-snmp-agent-includes.h>
949 +#include <net-snmp/agent/hardware/sensors.h>
952 +extern NetsnmpCacheLoad netsnmp_sensor_arch_load;
953 +extern void netsnmp_sensor_arch_init( void );
954 +static int _sensor_load( void );
955 +static void _sensor_free( void );
957 +static int _sensorAutoUpdate = 0; /* 0 means on-demand caching */
958 +static void _sensor_update_stats( unsigned int, void* );
960 +netsnmp_cache *_sensor_cache = NULL;
961 +netsnmp_container *_sensor_container = NULL;
962 +static int _sensor_idx = 0;
964 +void init_hw_sensors( void ) {
966 + if ( _sensor_container )
967 + return; /* Already initialised */
969 + DEBUGMSGTL(("sensors", "Initialise Hardware Sensors module\n"));
972 + * Define a container to hold the basic list of sensors
973 + * The four LM-SENSOR-MIB containers will be created in
974 + * the relevant initialisation routine(s)
976 + _sensor_container = netsnmp_container_find("sensorTable:table_container");
977 + if ( NULL == _sensor_container ) {
978 + snmp_log( LOG_ERR, "failed to create container for sensorTable");
981 + netsnmp_sensor_arch_init( );
984 + * If we're sampling the sensor information automatically,
985 + * then arrange for this to be triggered regularly.
987 + * If we're not sampling these values regularly,
988 + * create a suitable cache handler instead.
990 + if ( _sensorAutoUpdate ) {
991 + DEBUGMSGTL(("sensors", "Reloading Hardware Sensors automatically (%d)\n",
992 + _sensorAutoUpdate));
993 + snmp_alarm_register( _sensorAutoUpdate, SA_REPEAT,
994 + _sensor_update_stats, NULL );
997 + _sensor_cache = netsnmp_cache_create( 5, netsnmp_sensor_load,
998 + netsnmp_sensor_free, NULL, 0 );
999 + DEBUGMSGTL(("sensors", "Reloading Hardware Sensors on-demand (%p)\n",
1004 +void shutdown_hw_sensors( void ) {
1009 + * Return the main sensor container
1011 +netsnmp_container *get_sensor_container( void ) { return _sensor_container; }
1014 + * Return the main sensor cache control structure (if defined)
1016 +netsnmp_cache *get_sensor_cache( void ) { return _sensor_cache; }
1020 + * Wrapper routine for automatically updating sensor statistics
1023 +_sensor_update_stats( unsigned int clientreg, void *data )
1030 + * Wrapper routine for re-loading sensor statistics on demand
1033 +netsnmp_sensor_load( netsnmp_cache *cache, void *data )
1035 + return _sensor_load();
1039 + * Wrapper routine for releasing expired sensor statistics
1042 +netsnmp_sensor_free( netsnmp_cache *cache, void *data )
1049 + * Architecture-independent processing of loading sensor statistics
1052 +_sensor_load( void )
1054 + netsnmp_sensor_arch_load( NULL, NULL );
1058 + * Architecture-independent release of sensor statistics
1061 +_sensor_free( void )
1063 + netsnmp_sensor_info *sp;
1065 + for (sp = CONTAINER_FIRST( _sensor_container );
1067 + sp = CONTAINER_NEXT( _sensor_container, sp )) {
1069 + sp->flags &= ~ NETSNMP_SENSOR_FLAG_ACTIVE;
1075 + * Retrieve a sensor entry by name,
1076 + * or (optionally) insert a new one into the container
1078 +netsnmp_sensor_info *
1079 +sensor_by_name( char *name, int create_type )
1081 + netsnmp_sensor_info *sp;
1083 + DEBUGMSGTL(("sensors:name", "Get sensor entry (%s)\n", name));
1086 + * Look through the list for a matching entry
1088 + /* .. or use a secondary index container ?? */
1089 + for (sp = CONTAINER_FIRST( _sensor_container );
1091 + sp = CONTAINER_NEXT( _sensor_container, sp )) {
1093 + if ( !strcmp( name, sp->name ))
1100 + if ( create_type == NETSNMP_SENSOR_FIND_EXIST ) {
1101 + DEBUGMSGTL(("sensors:name", "No such sensor entry\n"));
1106 + * ... so let's create a new one, using the type supplied
1108 + sp = SNMP_MALLOC_TYPEDEF( netsnmp_sensor_info );
1110 + strcpy( sp->name, name );
1111 + sp->type = create_type;
1113 + * Set up the index value.
1115 + * All this trouble, just for a simple integer.
1116 + * Surely there must be a better way?
1119 + sp->idx.oids = SNMP_MALLOC_TYPEDEF( oid );
1120 + sp->idx.oids[0] = ++_sensor_idx;
1123 + DEBUGMSGTL(("sensors:name", "Create sensor entry (type = %d, index = %d\n",
1124 + create_type, _sensor_idx));
1125 + CONTAINER_INSERT( _sensor_container, sp );
1129 Index: agent/mibgroup/hardware/sensors/dummy_sensors.h
1130 ===================================================================
1131 --- agent/mibgroup/hardware/sensors/dummy_sensors.h (revision 0)
1132 +++ agent/mibgroup/hardware/sensors/dummy_sensors.h (revision 16739)
1134 +config_require(hardware/sensors/hw_sensors)
1135 Index: agent/mibgroup/hardware/sensors/lmsensors_v2.c
1136 ===================================================================
1137 --- agent/mibgroup/hardware/sensors/lmsensors_v2.c (revision 0)
1138 +++ agent/mibgroup/hardware/sensors/lmsensors_v2.c (revision 16739)
1140 +#include <net-snmp/net-snmp-config.h>
1141 +#include <net-snmp/net-snmp-includes.h>
1142 +#include <net-snmp/agent/net-snmp-agent-includes.h>
1143 +#include <net-snmp/agent/hardware/sensors.h>
1145 +#include "util_funcs.h"
1147 +#include <sensors/sensors.h>
1149 +void netsnmp_sensor_arch_init( void ) {
1150 + FILE *fp = fopen("/etc/sensors.conf", "r");
1151 + DEBUGMSGTL(("sensors:arch", "Initialise LM Sensors module\n"));
1152 + sensors_init( fp );
1156 +netsnmp_sensor_arch_load(netsnmp_cache *cache, void *vp) {
1157 + netsnmp_sensor_info *sp;
1158 + const sensors_chip_name *chip;
1159 + const sensors_feature_data *data;
1162 + DEBUGMSGTL(("sensors:arch", "Reload LM Sensors module\n"));
1163 + while ((chip = sensors_get_detected_chips(&chip_nr))) {
1167 + while ((data = sensors_get_all_features(*chip, &a, &b))) {
1168 + DEBUGMSGTL(("sensors:arch:detail", "get_all_features (%d, %d)\n", a, b));
1169 + char *label = NULL;
1171 + int type = NETSNMP_SENSOR_TYPE_OTHER;
1173 + if ((data->mode & SENSORS_MODE_R) &&
1174 + (data->mapping == SENSORS_NO_MAPPING) &&
1175 + !sensors_get_label(*chip, data->number, &label) &&
1176 + !sensors_get_feature(*chip, data->number, &val)) {
1178 + DEBUGMSGTL(("sensors:arch:detail", "%s = %f\n", label, val));
1180 + * Determine the type of sensor from the description.
1182 + * If the text being looked for below is not in the label of a
1183 + * given sensor (e.g., the temp1 sensor has been labeled 'CPU'
1184 + * rather than 'CPU temp') it will be categorised as OTHER.
1186 + if (strstr(label, "V")) {
1187 + type = NETSNMP_SENSOR_TYPE_VOLTAGE_DC;
1189 + if (strstr(label, "fan") || strstr(label, "Fan")) {
1190 + type = NETSNMP_SENSOR_TYPE_RPM;
1192 + if (strstr(label, "temp") || strstr(label, "Temp")) {
1193 + type = NETSNMP_SENSOR_TYPE_TEMPERATURE;
1197 + * Use this type to create a new sensor entry
1198 + * (inserting it in the appropriate sub-containers)
1200 + sp = sensor_by_name( label, type );
1203 + sp->flags|= NETSNMP_SENSOR_FLAG_ACTIVE;
1210 + } /* end while data */
1211 + } /* end while chip */
1215 Index: agent/mibgroup/hardware/sensors/picld_sensors.h
1216 ===================================================================
1217 --- agent/mibgroup/hardware/sensors/picld_sensors.h (revision 0)
1218 +++ agent/mibgroup/hardware/sensors/picld_sensors.h (revision 16739)
1220 +config_require(hardware/sensors/hw_sensors)
1221 Index: agent/mibgroup/hardware/sensors/lmsensors_v3.c
1222 ===================================================================
1223 --- agent/mibgroup/hardware/sensors/lmsensors_v3.c (revision 0)
1224 +++ agent/mibgroup/hardware/sensors/lmsensors_v3.c (revision 16739)
1226 +#include <net-snmp/net-snmp-config.h>
1227 +#include <net-snmp/net-snmp-includes.h>
1228 +#include <net-snmp/agent/net-snmp-agent-includes.h>
1229 +#include <net-snmp/agent/hardware/sensors.h>
1231 +#include "util_funcs.h"
1233 +#include <sensors/sensors.h>
1236 +void netsnmp_sensor_arch_init( void ) {
1237 + FILE *fp = fopen("/etc/sensors.conf", "r");
1238 + DEBUGMSGTL(("sensors:arch", "Initialise v3 LM Sensors module\n"));
1239 + sensors_init( fp );
1243 +netsnmp_sensor_arch_load(netsnmp_cache *cache, void *vp) {
1244 + netsnmp_sensor_info *sp;
1245 + const sensors_chip_name *chip;
1246 + const sensors_feature *data;
1247 + const sensors_subfeature *data2;
1250 + DEBUGMSGTL(("sensors:arch", "Reload v3 LM Sensors module\n"));
1251 + while ((chip = sensors_get_detected_chips( NULL, &chip_nr))) {
1254 + while ((data = sensors_get_features( chip, &a))) {
1255 + DEBUGMSGTL(("sensors:arch:detail", "get_features (%s, %d)\n", data->name, data->number));
1259 + while ((data2 = sensors_get_all_subfeatures( chip, data, &b))) {
1260 + char *label = NULL;
1262 + int type = NETSNMP_SENSOR_TYPE_OTHER;
1264 + DEBUGMSGTL(("sensors:arch:detail", " get_subfeatures (%s, %d)\n", data2->name, data2->number));
1266 + * Check the type of this subfeature,
1267 + * concentrating on the main "input" measurements.
1269 + switch ( data2->type ) {
1270 + case SENSORS_SUBFEATURE_IN_INPUT:
1271 + type = NETSNMP_SENSOR_TYPE_VOLTAGE_DC;
1273 + case SENSORS_SUBFEATURE_FAN_INPUT:
1274 + type = NETSNMP_SENSOR_TYPE_RPM;
1276 + case SENSORS_SUBFEATURE_TEMP_INPUT:
1277 + type = NETSNMP_SENSOR_TYPE_TEMPERATURE;
1279 + case SENSORS_SUBFEATURE_VID:
1280 + type = NETSNMP_SENSOR_TYPE_VOLTAGE_DC;
1283 + /* Skip everything other than these basic sensor features - ??? */
1284 + DEBUGMSGTL(("sensors:arch:detail", " Skip type %x\n", data2->type));
1289 + * Get the name and value of this subfeature
1292 + if (!(label = sensors_get_label(chip, data))) {
1293 + DEBUGMSGTL(("sensors:arch:detail", " Can't get name (%s)\n", label));
1296 + if (sensors_get_value(chip, data2->number, &val) < 0) {
1297 + DEBUGMSGTL(("sensors:arch:detail", " Can't get value (%f)\n", val));
1301 + if (!(label = sensors_get_label(chip, data)) ||
1302 + (sensors_get_value(chip, data2->number, &val) < 0)) {
1303 + DEBUGMSGTL(("sensors:arch:detail", " Can't get name/value (%s, %f)\n", label, val));
1306 + DEBUGMSGTL(("sensors:arch:detail", "%s = %f\n", label, val));
1309 + * Use this type to create a new sensor entry
1310 + * (inserting it in the appropriate sub-containers)
1312 + sp = sensor_by_name( label, type );
1315 + sp->flags|= NETSNMP_SENSOR_FLAG_ACTIVE;
1321 + } /* end while data2 */
1322 + } /* end while data */
1323 + } /* end while chip */