/[pkgs]/devel/net-snmp/net-snmp-5.4.1-sensors3.patch
ViewVC logotype

Contents of /devel/net-snmp/net-snmp-5.4.1-sensors3.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations) (download) (as text)
Fri Jul 25 11:03:32 2008 UTC (15 months, 4 weeks ago) by jsafrane
Branch: MAIN
CVS Tags: net-snmp-5_4_2_1-10_fc11, net-snmp-5_4_2_1-7_fc11, F-12-split, net-snmp-5_4_2-3_fc10, net-snmp-5_4_2_1-5_fc11, net-snmp-5_4_2_1-1_fc10, net-snmp-5_4_2_1-3_fc11, net-snmp-5_4_2_1-8_fc11, F-10-split, F-11-split, net-snmp-5_4_2_1-12_fc12, net-snmp-5_4_2_1-16_fc12, net-snmp-5_4_2-1_fc10, net-snmp-5_4_2_1-9_fc11, net-snmp-5_4_2_1-6_fc11, net-snmp-5_4_2-2_fc10, net-snmp-5_4_2_1-14_fc12, net-snmp-5_4_2_1-13_fc12, net-snmp-5_4_2_1-11_fc12, net-snmp-5_4_2_1-17_fc12, net-snmp-5_4_2_1-11_fc11, net-snmp-5_4_2_1-15_fc12, net-snmp-5_4_2_1-4_fc11, net-snmp-5_4_1-22_fc10
Changes since 1.1: +659 -675 lines
File MIME type: text/x-patch
rediff all patches to get rid of fuzz=2
1 jsafrane 1.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>
4    
5     Index: configure
6     ===================================================================
7 jsafrane 1.2 diff -up /dev/null net-snmp-5.4.1/agent/mibgroup/hardware/sensors/dummy_sensors.c
8     --- /dev/null 2008-07-23 14:59:56.660004489 +0200
9     +++ net-snmp-5.4.1/agent/mibgroup/hardware/sensors/dummy_sensors.c 2008-07-25 12:53:46.000000000 +0200
10     @@ -0,0 +1,60 @@
11     +#include <net-snmp/net-snmp-config.h>
12     +#include <net-snmp/net-snmp-includes.h>
13     +#include <net-snmp/agent/net-snmp-agent-includes.h>
14     +#include <net-snmp/agent/hardware/sensors.h>
15     +
16     +
17     +void netsnmp_sensor_arch_init( void ) {
18     + /* Nothing to do */
19     + DEBUGMSGTL(("sensors:arch", "Initialise Dummy Sensors module\n"));
20     +}
21     +
22     +int
23     +netsnmp_sensor_arch_load(netsnmp_cache *cache, void *vp) {
24     + time_t now;
25     + struct tm *tm;
26     + netsnmp_sensor_info *sp;
27     +
28     + time(&now);
29     + tm = localtime(&now);
30     +
31     + DEBUGMSGTL(("sensors:arch", "Reload Dummy Sensors module\n"));
32 jsafrane 1.1 +
33 jsafrane 1.2 + /* First pseudo-sensor - slowly-rising temperature */
34     + sp = sensor_by_name( "minute", NETSNMP_SENSOR_TYPE_TEMPERATURE );
35     + sp->value = tm->tm_min;
36     + snprintf( sp->descr, 256, "Minute-based pseudo-sensor - slowly-rising temperature" );
37     + sp->flags|= NETSNMP_SENSOR_FLAG_ACTIVE;
38 jsafrane 1.1 +
39 jsafrane 1.2 + /* Second pseudo-sensor - quickly-rising temperature */
40     + sp = sensor_by_name( "second", NETSNMP_SENSOR_TYPE_TEMPERATURE );
41     + sp->value = tm->tm_sec;
42     + snprintf( sp->descr, 256, "Second-based pseudo-sensor - quickly-rising temperature" );
43     + sp->flags|= NETSNMP_SENSOR_FLAG_ACTIVE;
44 jsafrane 1.1 +
45 jsafrane 1.2 + /* Third pseudo-sensor - annual fan speed */
46     + sp = sensor_by_name( "year", NETSNMP_SENSOR_TYPE_RPM );
47     + sp->value = tm->tm_year + 1900;
48     + snprintf( sp->descr, 256, "RPM pseudo-sensor - annual fan speed" );
49     + sp->flags|= NETSNMP_SENSOR_FLAG_ACTIVE;
50 jsafrane 1.1 +
51 jsafrane 1.2 + /* Fourth pseudo-sensor - daily voltage */
52     + sp = sensor_by_name( "day", NETSNMP_SENSOR_TYPE_VOLTAGE_DC );
53     + sp->value = tm->tm_mday-20;
54     + snprintf( sp->descr, 256, "Day-based pseudo-sensor - positive or negative voltage" );
55     + sp->flags|= NETSNMP_SENSOR_FLAG_ACTIVE;
56 jsafrane 1.1 +
57 jsafrane 1.2 + /* Fifth pseudo-sensor - monthly voltage */
58     + sp = sensor_by_name( "month", NETSNMP_SENSOR_TYPE_VOLTAGE_DC );
59     + sp->value = tm->tm_mon;
60     + snprintf( sp->descr, 256, "Month-based pseudo-sensor - positive voltage" );
61     + sp->flags|= NETSNMP_SENSOR_FLAG_ACTIVE;
62 jsafrane 1.1 +
63 jsafrane 1.2 + /* Sixth pseudo-sensor - annual daily something */
64     + sp = sensor_by_name( "yday", NETSNMP_SENSOR_TYPE_OTHER );
65     + sp->value = tm->tm_yday;
66     + snprintf( sp->descr, 256, "Day-based pseudo-sensor - annual something" );
67     + sp->flags|= NETSNMP_SENSOR_FLAG_ACTIVE;
68 jsafrane 1.1 +
69 jsafrane 1.2 + return 0;
70     +}
71     diff -up /dev/null net-snmp-5.4.1/agent/mibgroup/hardware/sensors/dummy_sensors.h
72     --- /dev/null 2008-07-23 14:59:56.660004489 +0200
73     +++ net-snmp-5.4.1/agent/mibgroup/hardware/sensors/dummy_sensors.h 2008-07-25 12:53:46.000000000 +0200
74     @@ -0,0 +1 @@
75     +config_require(hardware/sensors/hw_sensors)
76     diff -up /dev/null net-snmp-5.4.1/agent/mibgroup/hardware/sensors.h
77     --- /dev/null 2008-07-23 14:59:56.660004489 +0200
78     +++ net-snmp-5.4.1/agent/mibgroup/hardware/sensors.h 2008-07-25 12:53:46.000000000 +0200
79     @@ -0,0 +1,13 @@
80     +config_require(hardware/sensors/hw_sensors)
81 jsafrane 1.1 +
82 jsafrane 1.2 +#if defined(solaris)
83     +# if defined(HAVE_PICL_H)
84     +config_require(hardware/sensors/picld_sensors)
85     +# else
86     +config_require(hardware/sensors/kstat_sensors)
87     +# endif
88     +#else
89     +config_require(hardware/sensors/lmsensors_v3)
90     +#endif
91 jsafrane 1.1 +
92 jsafrane 1.2 +//config_require(hardware/sensors/dummy_sensors)
93     diff -up /dev/null net-snmp-5.4.1/agent/mibgroup/hardware/sensors/hw_sensors.c
94     --- /dev/null 2008-07-23 14:59:56.660004489 +0200
95     +++ net-snmp-5.4.1/agent/mibgroup/hardware/sensors/hw_sensors.c 2008-07-25 12:53:46.000000000 +0200
96     @@ -0,0 +1,183 @@
97 jsafrane 1.1 +#include <net-snmp/net-snmp-config.h>
98     +#include <net-snmp/net-snmp-includes.h>
99     +#include <net-snmp/agent/net-snmp-agent-includes.h>
100     +#include <net-snmp/agent/hardware/sensors.h>
101     +
102     +
103 jsafrane 1.2 +extern NetsnmpCacheLoad netsnmp_sensor_arch_load;
104     +extern void netsnmp_sensor_arch_init( void );
105     +static int _sensor_load( void );
106     +static void _sensor_free( void );
107 jsafrane 1.1 +
108 jsafrane 1.2 +static int _sensorAutoUpdate = 0; /* 0 means on-demand caching */
109     +static void _sensor_update_stats( unsigned int, void* );
110 jsafrane 1.1 +
111 jsafrane 1.2 +netsnmp_cache *_sensor_cache = NULL;
112     +netsnmp_container *_sensor_container = NULL;
113     +static int _sensor_idx = 0;
114 jsafrane 1.1 +
115 jsafrane 1.2 +void init_hw_sensors( void ) {
116 jsafrane 1.1 +
117 jsafrane 1.2 + if ( _sensor_container )
118     + return; /* Already initialised */
119 jsafrane 1.1 +
120 jsafrane 1.2 + DEBUGMSGTL(("sensors", "Initialise Hardware Sensors module\n"));
121 jsafrane 1.1 +
122     + /*
123 jsafrane 1.2 + * Define a container to hold the basic list of sensors
124     + * The four LM-SENSOR-MIB containers will be created in
125     + * the relevant initialisation routine(s)
126 jsafrane 1.1 + */
127 jsafrane 1.2 + _sensor_container = netsnmp_container_find("sensorTable:table_container");
128     + if ( NULL == _sensor_container ) {
129     + snmp_log( LOG_ERR, "failed to create container for sensorTable");
130     + return;
131 jsafrane 1.1 + }
132 jsafrane 1.2 + netsnmp_sensor_arch_init( );
133 jsafrane 1.1 +
134     + /*
135 jsafrane 1.2 + * If we're sampling the sensor information automatically,
136     + * then arrange for this to be triggered regularly.
137     + *
138     + * If we're not sampling these values regularly,
139     + * create a suitable cache handler instead.
140 jsafrane 1.1 + */
141 jsafrane 1.2 + if ( _sensorAutoUpdate ) {
142     + DEBUGMSGTL(("sensors", "Reloading Hardware Sensors automatically (%d)\n",
143     + _sensorAutoUpdate));
144     + snmp_alarm_register( _sensorAutoUpdate, SA_REPEAT,
145     + _sensor_update_stats, NULL );
146     + }
147     + else {
148     + _sensor_cache = netsnmp_cache_create( 5, netsnmp_sensor_load,
149     + netsnmp_sensor_free, NULL, 0 );
150     + DEBUGMSGTL(("sensors", "Reloading Hardware Sensors on-demand (%p)\n",
151     + _sensor_cache));
152 jsafrane 1.1 + }
153 jsafrane 1.2 +}
154 jsafrane 1.1 +
155 jsafrane 1.2 +void shutdown_hw_sensors( void ) {
156     + _sensor_free();
157 jsafrane 1.1 +}
158     +
159 jsafrane 1.2 +/*
160     + * Return the main sensor container
161     + */
162     +netsnmp_container *get_sensor_container( void ) { return _sensor_container; }
163 jsafrane 1.1 +
164     +/*
165 jsafrane 1.2 + * Return the main sensor cache control structure (if defined)
166 jsafrane 1.1 + */
167 jsafrane 1.2 +netsnmp_cache *get_sensor_cache( void ) { return _sensor_cache; }
168     +
169 jsafrane 1.1 +
170 jsafrane 1.2 +/*
171     + * Wrapper routine for automatically updating sensor statistics
172     + */
173     +void
174     +_sensor_update_stats( unsigned int clientreg, void *data )
175     +{
176     + _sensor_free();
177     + _sensor_load();
178 jsafrane 1.1 +}
179     +
180 jsafrane 1.2 +/*
181     + * Wrapper routine for re-loading sensor statistics on demand
182     + */
183     +int
184     +netsnmp_sensor_load( netsnmp_cache *cache, void *data )
185     +{
186     + return _sensor_load();
187 jsafrane 1.1 +}
188     +
189 jsafrane 1.2 +/*
190     + * Wrapper routine for releasing expired sensor statistics
191     + */
192     +void
193     +netsnmp_sensor_free( netsnmp_cache *cache, void *data )
194     +{
195     + _sensor_free();
196 jsafrane 1.1 +}
197     +
198     +
199     +/*
200 jsafrane 1.2 + * Architecture-independent processing of loading sensor statistics
201 jsafrane 1.1 + */
202 jsafrane 1.2 +static int
203     +_sensor_load( void )
204     +{
205     + netsnmp_sensor_arch_load( NULL, NULL );
206     +}
207 jsafrane 1.1 +
208 jsafrane 1.2 +/*
209     + * Architecture-independent release of sensor statistics
210     + */
211     +static void
212     +_sensor_free( void )
213     +{
214     + netsnmp_sensor_info *sp;
215 jsafrane 1.1 +
216 jsafrane 1.2 + for (sp = CONTAINER_FIRST( _sensor_container );
217     + sp;
218     + sp = CONTAINER_NEXT( _sensor_container, sp )) {
219 jsafrane 1.1 +
220 jsafrane 1.2 + sp->flags &= ~ NETSNMP_SENSOR_FLAG_ACTIVE;
221 jsafrane 1.1 + }
222     +}
223     +
224     +
225     +/*
226 jsafrane 1.2 + * Retrieve a sensor entry by name,
227     + * or (optionally) insert a new one into the container
228 jsafrane 1.1 + */
229 jsafrane 1.2 +netsnmp_sensor_info *
230     +sensor_by_name( char *name, int create_type )
231     +{
232     + netsnmp_sensor_info *sp;
233     +
234     + DEBUGMSGTL(("sensors:name", "Get sensor entry (%s)\n", name));
235     +
236     + /*
237     + * Look through the list for a matching entry
238     + */
239     + /* .. or use a secondary index container ?? */
240     + for (sp = CONTAINER_FIRST( _sensor_container );
241     + sp;
242     + sp = CONTAINER_NEXT( _sensor_container, sp )) {
243     +
244     + if ( !strcmp( name, sp->name ))
245     + return sp;
246     + }
247     +
248     + /*
249     + * Not found...
250     + */
251     + if ( create_type == NETSNMP_SENSOR_FIND_EXIST ) {
252     + DEBUGMSGTL(("sensors:name", "No such sensor entry\n"));
253     + return NULL;
254     + }
255 jsafrane 1.1 +
256 jsafrane 1.2 + /*
257     + * ... so let's create a new one, using the type supplied
258     + */
259     + sp = SNMP_MALLOC_TYPEDEF( netsnmp_sensor_info );
260     + if ( sp ) {
261     + strcpy( sp->name, name );
262     + sp->type = create_type;
263     + /*
264     + * Set up the index value.
265     + *
266     + * All this trouble, just for a simple integer.
267     + * Surely there must be a better way?
268     + */
269     + sp->idx.len = 1;
270     + sp->idx.oids = SNMP_MALLOC_TYPEDEF( oid );
271     + sp->idx.oids[0] = ++_sensor_idx;
272     + }
273 jsafrane 1.1 +
274 jsafrane 1.2 + DEBUGMSGTL(("sensors:name", "Create sensor entry (type = %d, index = %d\n",
275     + create_type, _sensor_idx));
276     + CONTAINER_INSERT( _sensor_container, sp );
277     + return sp;
278     +}
279 jsafrane 1.1 +
280 jsafrane 1.2 diff -up /dev/null net-snmp-5.4.1/agent/mibgroup/hardware/sensors/hw_sensors.h
281     --- /dev/null 2008-07-23 14:59:56.660004489 +0200
282     +++ net-snmp-5.4.1/agent/mibgroup/hardware/sensors/hw_sensors.h 2008-07-25 12:53:46.000000000 +0200
283 jsafrane 1.1 @@ -0,0 +1 @@
284     +void init_hw_sensors( void );
285 jsafrane 1.2 diff -up /dev/null net-snmp-5.4.1/agent/mibgroup/hardware/sensors/kstat_sensors.c
286     --- /dev/null 2008-07-23 14:59:56.660004489 +0200
287     +++ net-snmp-5.4.1/agent/mibgroup/hardware/sensors/kstat_sensors.c 2008-07-25 12:53:46.000000000 +0200
288 jsafrane 1.1 @@ -0,0 +1,161 @@
289     +#include <net-snmp/net-snmp-config.h>
290     +#include <net-snmp/net-snmp-includes.h>
291     +#include <net-snmp/agent/net-snmp-agent-includes.h>
292     +#include <net-snmp/agent/hardware/sensors.h>
293     +
294     +#include "util_funcs.h"
295     +#include <time.h>
296     +
297     +#include <kstat.h>
298     +#include </usr/platform/sun4u/include/sys/envctrl.h>
299     +
300     +void netsnmp_sensor_arch_init( void ) {
301     + DEBUGMSGTL(("sensors:arch", "Initialise KStat Sensors module\n"));
302     +}
303     +
304     +
305     +int
306     +netsnmp_sensor_arch_load(netsnmp_cache *cache, void *vp) {
307     + netsnmp_sensor_info *sp;
308     +
309     + int i;
310     + const char *fantypes[]={"CPU","PWR","AFB"};
311     + char name[ 256 ];
312     +
313     + kstat_ctl_t *kc;
314     + kstat_t *kp;
315     + envctrl_fan_t *fan_info;
316     + envctrl_ps_t *power_info;
317     + envctrl_encl_t *enc_info;
318     +
319     +
320     + DEBUGMSGTL(("sensors:arch", "Reload KStat Sensors module\n"));
321     +
322     + kc = kstat_open();
323     + if ( kc == 0) {
324     + DEBUGMSGTL(("sensors:arch", "Couldn't open kstat\n"));
325     + return 1;
326     + }
327     +
328     +
329     + /*
330     + * Retrieve fan information
331     + */
332     + kp = kstat_lookup( kc, ENVCTRL_MODULE_NAME, 0, ENVCTRL_KSTAT_FANSTAT);
333     + if (( kp == 0 ) || (kstat_read( kc, kp, 0 ) == -1 )) {
334     + DEBUGMSGTL(("sensors:arch", "No fan information\n"));
335     + } else {
336     + fan_info = (envctrl_fan_t *)kp->ks_data;
337     + for (i=0; i<kp->ks_ndata; i++) {
338     + memset( name, 0, 256 );
339     + snprintf( name, 255, "%s%d", fantypes[fan_info->type], fan_info->instance );
340     +
341     + sp = sensor_by_name( name, NETSNMP_SENSOR_TYPE_RPM );
342     + if ( sp ) {
343     + sp->value = fan_info->fanspeed;
344     + sp->flags|= NETSNMP_SENSOR_FLAG_ACTIVE;
345     + snprintf( sp->descr, 255, "fan type %s number %d",
346     + fantypes[fan_info->type], fan_info->instance );
347     + }
348     +
349     + fan_info++;
350     + }
351     + }
352     +
353     +
354     + /*
355     + * Retrieve Power Supply information
356     + */
357     + kp = kstat_lookup( kc, ENVCTRL_MODULE_NAME, 0, ENVCTRL_KSTAT_PSNAME);
358     + if (( kp == 0 ) || (kstat_read( kc, kp, 0 ) == -1 )) {
359     + DEBUGMSGTL(("sensors:arch", "No PSU information\n"));
360     + } else {
361     + power_info = (envctrl_ps_t *)kp->ks_data;
362     + for (i=0; i<kp->ks_ndata; i++) {
363     + memset( name, 0, 256 );
364     + snprintf( name, 255, "PSU%d", power_info->instance );
365     +
366     + sp = sensor_by_name( name, NETSNMP_SENSOR_TYPE_TEMPERATURE);
367     + if ( sp ) {
368     + sp->value = power_info->ps_tempr;
369     + sp->flags|= NETSNMP_SENSOR_FLAG_ACTIVE;
370     + snprintf( sp->descr, 255, "power supply %d", power_info->instance );
371     + }
372     +
373     + power_info++;
374     + }
375     + }
376     +
377     +
378     + /*
379     + * Retrieve Enclosure information
380     + */
381     + kp = kstat_lookup( kc, ENVCTRL_MODULE_NAME, 0, ENVCTRL_KSTAT_ENCL);
382     + if (( kp == 0 ) || (kstat_read( kc, kp, 0 ) == -1 )) {
383     + DEBUGMSGTL(("sensors:arch", "No enclosure information\n"));
384     + } else {
385     + enc_info = (envctrl_encl_t *)kp->ks_data;
386     + for (i=0; i<kp->ks_ndata; i++) {
387     + /*
388     + * The enclosure information covers several different types of sensor
389     + */
390     + switch ( enc_info->type ) {
391     + case ENVCTRL_ENCL_FSP:
392     + DEBUGMSGTL(("sensors:arch:detail", "Enclosure Front Panel\n"));
393     + sp = sensor_by_name( "FSP", NETSNMP_SENSOR_TYPE_OTHER);
394     + if ( sp ) {
395     + sp->value = enc_info->value;
396     + sp->flags|= NETSNMP_SENSOR_FLAG_ACTIVE;
397     + }
398     + break;
399     +
400     + case ENVCTRL_ENCL_AMBTEMPR:
401     + DEBUGMSGTL(("sensors:arch:detail", "Enclosure Ambient Temperature\n"));
402     + sp = sensor_by_name( "Ambient", NETSNMP_SENSOR_TYPE_TEMPERATURE);
403     + if ( sp ) {
404     + sp->value = enc_info->value;
405     + sp->flags|= NETSNMP_SENSOR_FLAG_ACTIVE;
406     + }
407     + break;
408     +
409     + case ENVCTRL_ENCL_CPUTEMPR:
410     + DEBUGMSGTL(("sensors:arch:detail", "Enclosure CPU Temperature\n"));
411     + memset( name, 0, 256 );
412     + snprintf( name, 255, "CPU%d", enc_info->instance );
413     + sp = sensor_by_name( name, NETSNMP_SENSOR_TYPE_TEMPERATURE);
414     + if ( sp ) {
415     + sp->value = enc_info->value;
416     + sp->flags|= NETSNMP_SENSOR_FLAG_ACTIVE;
417     + snprintf( sp->descr, 255, "CPU%d temperature", enc_info->instance );
418     + }
419     + break;
420     +
421     + case ENVCTRL_ENCL_BACKPLANE4:
422     + DEBUGMSGTL(("sensors:arch:detail", "Enclosure Backplane4\n"));
423     + sp = sensor_by_name( "Backplane4", NETSNMP_SENSOR_TYPE_OTHER);
424     + if ( sp ) {
425     + sp->value = enc_info->value;
426     + sp->flags|= NETSNMP_SENSOR_FLAG_ACTIVE;
427     + }
428     + break;
429     +
430     + case ENVCTRL_ENCL_BACKPLANE8:
431     + DEBUGMSGTL(("sensors:arch:detail", "Enclosure Backplane4\n"));
432     + sp = sensor_by_name( "Backplane4", NETSNMP_SENSOR_TYPE_OTHER);
433     + if ( sp ) {
434     + sp->value = enc_info->value;
435     + sp->flags|= NETSNMP_SENSOR_FLAG_ACTIVE;
436     + }
437     + break;
438     +
439     + default:
440     + DEBUGMSGTL(("sensors:arch:detail", "Unrecognised Enclosure entry (%d)n",
441     + enc_info->type));
442     + }
443     +
444     + enc_info++;
445     + }
446     + }
447     +
448     + return 0;
449     +}
450 jsafrane 1.2 diff -up /dev/null net-snmp-5.4.1/agent/mibgroup/hardware/sensors/kstat_sensors.h
451     --- /dev/null 2008-07-23 14:59:56.660004489 +0200
452     +++ net-snmp-5.4.1/agent/mibgroup/hardware/sensors/kstat_sensors.h 2008-07-25 12:53:46.000000000 +0200
453 jsafrane 1.1 @@ -0,0 +1 @@
454     +config_require(hardware/sensors/hw_sensors)
455 jsafrane 1.2 diff -up /dev/null net-snmp-5.4.1/agent/mibgroup/hardware/sensors/lmsensors_v2.c
456     --- /dev/null 2008-07-23 14:59:56.660004489 +0200
457     +++ net-snmp-5.4.1/agent/mibgroup/hardware/sensors/lmsensors_v2.c 2008-07-25 12:53:46.000000000 +0200
458     @@ -0,0 +1,75 @@
459 jsafrane 1.1 +#include <net-snmp/net-snmp-config.h>
460     +#include <net-snmp/net-snmp-includes.h>
461     +#include <net-snmp/agent/net-snmp-agent-includes.h>
462     +#include <net-snmp/agent/hardware/sensors.h>
463     +
464 jsafrane 1.2 +#include "util_funcs.h"
465     +#include <time.h>
466     +#include <sensors/sensors.h>
467 jsafrane 1.1 +
468     +void netsnmp_sensor_arch_init( void ) {
469 jsafrane 1.2 + FILE *fp = fopen("/etc/sensors.conf", "r");
470     + DEBUGMSGTL(("sensors:arch", "Initialise LM Sensors module\n"));
471     + sensors_init( fp );
472 jsafrane 1.1 +}
473     +
474     +int
475     +netsnmp_sensor_arch_load(netsnmp_cache *cache, void *vp) {
476     + netsnmp_sensor_info *sp;
477 jsafrane 1.2 + const sensors_chip_name *chip;
478     + const sensors_feature_data *data;
479     + int chip_nr = 0;
480     +
481     + DEBUGMSGTL(("sensors:arch", "Reload LM Sensors module\n"));
482     + while ((chip = sensors_get_detected_chips(&chip_nr))) {
483     + int a = 0;
484     + int b = 0;
485 jsafrane 1.1 +
486 jsafrane 1.2 + while ((data = sensors_get_all_features(*chip, &a, &b))) {
487     + DEBUGMSGTL(("sensors:arch:detail", "get_all_features (%d, %d)\n", a, b));
488     + char *label = NULL;
489     + double val;
490     + int type = NETSNMP_SENSOR_TYPE_OTHER;
491 jsafrane 1.1 +
492 jsafrane 1.2 + if ((data->mode & SENSORS_MODE_R) &&
493     + (data->mapping == SENSORS_NO_MAPPING) &&
494     + !sensors_get_label(*chip, data->number, &label) &&
495     + !sensors_get_feature(*chip, data->number, &val)) {
496 jsafrane 1.1 +
497 jsafrane 1.2 + DEBUGMSGTL(("sensors:arch:detail", "%s = %f\n", label, val));
498     + /*
499     + * Determine the type of sensor from the description.
500     + *
501     + * If the text being looked for below is not in the label of a
502     + * given sensor (e.g., the temp1 sensor has been labeled 'CPU'
503     + * rather than 'CPU temp') it will be categorised as OTHER.
504     + */
505     + if (strstr(label, "V")) {
506     + type = NETSNMP_SENSOR_TYPE_VOLTAGE_DC;
507     + }
508     + if (strstr(label, "fan") || strstr(label, "Fan")) {
509     + type = NETSNMP_SENSOR_TYPE_RPM;
510     + }
511     + if (strstr(label, "temp") || strstr(label, "Temp")) {
512     + type = NETSNMP_SENSOR_TYPE_TEMPERATURE;
513     + }
514 jsafrane 1.1 +
515 jsafrane 1.2 + /*
516     + * Use this type to create a new sensor entry
517     + * (inserting it in the appropriate sub-containers)
518     + */
519     + sp = sensor_by_name( label, type );
520     + if ( sp ) {
521     + sp->value = val;
522     + sp->flags|= NETSNMP_SENSOR_FLAG_ACTIVE;
523     + }
524     + }
525     + if (label) {
526     + free(label);
527     + label = NULL;
528     + }
529     + } /* end while data */
530     + } /* end while chip */
531     +
532     + return 0;
533     +}
534     diff -up /dev/null net-snmp-5.4.1/agent/mibgroup/hardware/sensors/lmsensors_v2.h
535     --- /dev/null 2008-07-23 14:59:56.660004489 +0200
536     +++ net-snmp-5.4.1/agent/mibgroup/hardware/sensors/lmsensors_v2.h 2008-07-25 12:53:46.000000000 +0200
537     @@ -0,0 +1 @@
538     +config_require(hardware/sensors/hw_sensors)
539     diff -up /dev/null net-snmp-5.4.1/agent/mibgroup/hardware/sensors/lmsensors_v3.c
540     --- /dev/null 2008-07-23 14:59:56.660004489 +0200
541     +++ net-snmp-5.4.1/agent/mibgroup/hardware/sensors/lmsensors_v3.c 2008-07-25 12:53:46.000000000 +0200
542     @@ -0,0 +1,101 @@
543     +#include <net-snmp/net-snmp-config.h>
544     +#include <net-snmp/net-snmp-includes.h>
545     +#include <net-snmp/agent/net-snmp-agent-includes.h>
546     +#include <net-snmp/agent/hardware/sensors.h>
547     +
548     +#include "util_funcs.h"
549     +#include <time.h>
550     +#include <sensors/sensors.h>
551     +
552     +
553     +void netsnmp_sensor_arch_init( void ) {
554     + FILE *fp = fopen("/etc/sensors.conf", "r");
555     + DEBUGMSGTL(("sensors:arch", "Initialise v3 LM Sensors module\n"));
556     + sensors_init( fp );
557     +}
558     +
559     +int
560     +netsnmp_sensor_arch_load(netsnmp_cache *cache, void *vp) {
561     + netsnmp_sensor_info *sp;
562     + const sensors_chip_name *chip;
563     + const sensors_feature *data;
564     + const sensors_subfeature *data2;
565     + int chip_nr = 0;
566     +
567     + DEBUGMSGTL(("sensors:arch", "Reload v3 LM Sensors module\n"));
568     + while ((chip = sensors_get_detected_chips( NULL, &chip_nr))) {
569     + int a = 0;
570 jsafrane 1.1 +
571 jsafrane 1.2 + while ((data = sensors_get_features( chip, &a))) {
572     + DEBUGMSGTL(("sensors:arch:detail", "get_features (%s, %d)\n", data->name, data->number));
573     + int b = 0;
574     +
575 jsafrane 1.1 +
576 jsafrane 1.2 + while ((data2 = sensors_get_all_subfeatures( chip, data, &b))) {
577     + char *label = NULL;
578     + double val;
579     + int type = NETSNMP_SENSOR_TYPE_OTHER;
580 jsafrane 1.1 +
581 jsafrane 1.2 + DEBUGMSGTL(("sensors:arch:detail", " get_subfeatures (%s, %d)\n", data2->name, data2->number));
582     + /*
583     + * Check the type of this subfeature,
584     + * concentrating on the main "input" measurements.
585     + */
586     + switch ( data2->type ) {
587     + case SENSORS_SUBFEATURE_IN_INPUT:
588     + type = NETSNMP_SENSOR_TYPE_VOLTAGE_DC;
589     + break;
590     + case SENSORS_SUBFEATURE_FAN_INPUT:
591     + type = NETSNMP_SENSOR_TYPE_RPM;
592     + break;
593     + case SENSORS_SUBFEATURE_TEMP_INPUT:
594     + type = NETSNMP_SENSOR_TYPE_TEMPERATURE;
595     + break;
596     + case SENSORS_SUBFEATURE_VID:
597     + type = NETSNMP_SENSOR_TYPE_VOLTAGE_DC;
598     + break;
599     + default:
600     + /* Skip everything other than these basic sensor features - ??? */
601     + DEBUGMSGTL(("sensors:arch:detail", " Skip type %x\n", data2->type));
602     + continue;
603     + }
604     +
605     + /*
606     + * Get the name and value of this subfeature
607     + */
608     +/*
609     + if (!(label = sensors_get_label(chip, data))) {
610     + DEBUGMSGTL(("sensors:arch:detail", " Can't get name (%s)\n", label));
611     + continue;
612     + }
613     + if (sensors_get_value(chip, data2->number, &val) < 0) {
614     + DEBUGMSGTL(("sensors:arch:detail", " Can't get value (%f)\n", val));
615     + continue;
616     + }
617     +*/
618     + if (!(label = sensors_get_label(chip, data)) ||
619     + (sensors_get_value(chip, data2->number, &val) < 0)) {
620     + DEBUGMSGTL(("sensors:arch:detail", " Can't get name/value (%s, %f)\n", label, val));
621     + continue;
622     + }
623     + DEBUGMSGTL(("sensors:arch:detail", "%s = %f\n", label, val));
624 jsafrane 1.1 +
625 jsafrane 1.2 + /*
626     + * Use this type to create a new sensor entry
627     + * (inserting it in the appropriate sub-containers)
628     + */
629     + sp = sensor_by_name( label, type );
630     + if ( sp ) {
631     + sp->value = val;
632     + sp->flags|= NETSNMP_SENSOR_FLAG_ACTIVE;
633     + }
634     + if (label) {
635     + free(label);
636     + label = NULL;
637     + }
638     + } /* end while data2 */
639     + } /* end while data */
640     + } /* end while chip */
641 jsafrane 1.1 +
642     + return 0;
643     +}
644 jsafrane 1.2 diff -up /dev/null net-snmp-5.4.1/agent/mibgroup/hardware/sensors/lmsensors_v3.h
645     --- /dev/null 2008-07-23 14:59:56.660004489 +0200
646     +++ net-snmp-5.4.1/agent/mibgroup/hardware/sensors/lmsensors_v3.h 2008-07-25 12:53:46.000000000 +0200
647 jsafrane 1.1 @@ -0,0 +1 @@
648     +config_require(hardware/sensors/hw_sensors)
649 jsafrane 1.2 diff -up /dev/null net-snmp-5.4.1/agent/mibgroup/hardware/sensors/picld_sensors.c
650     --- /dev/null 2008-07-23 14:59:56.660004489 +0200
651     +++ net-snmp-5.4.1/agent/mibgroup/hardware/sensors/picld_sensors.c 2008-07-25 12:53:46.000000000 +0200
652 jsafrane 1.1 @@ -0,0 +1,341 @@
653     +#include <net-snmp/net-snmp-config.h>
654     +#include <net-snmp/net-snmp-includes.h>
655     +#include <net-snmp/agent/net-snmp-agent-includes.h>
656     +#include <net-snmp/agent/hardware/sensors.h>
657     +
658     +#include "util_funcs.h"
659     +#include <time.h>
660     +
661     +#include <picl.h>
662     +#include </usr/platform/sun4u/include/sys/envctrl.h>
663     +
664     +void netsnmp_sensor_arch_init( void ) {
665     + DEBUGMSGTL(("sensors:arch", "Initialise PICLd Sensors module\n"));
666     + picl_initialize();
667     +}
668     +
669     +
670     +/*
671     + * Handle a numeric-valued sensor
672     + */
673     +static int
674     +read_num_sensor( picl_nodehdl_t childh, char *propval, float *value )
675     +{
676     + picl_nodehdl_t sensorh;
677     + picl_propinfo_t sensor_info;
678     + picl_errno_t error_code;
679     +
680     + union valu {
681     + char buf[PICL_PROPSIZE_MAX];
682     + uint32_t us4;
683     + uint16_t us2;
684     + int32_t is4;
685     + int16_t is2;
686     + float f;
687     + } val;
688     +
689     + /*
690     + * Retrieve the specified sensor information and value
691     + */
692     + error_code = picl_get_propinfo_by_name(childh, propval, &sensor_info, &sensorh);
693     + if ( error_code != PICL_SUCCESS ) {
694     + DEBUGMSGTL(("sensors:arch:detail", "sensor info lookup failed (%d)\n",
695     + error_code));
696     + return( error_code );
697     + }
698     +
699     + error_code = picl_get_propval(sensorh, &val.buf, sensor_info.size);
700     + if ( error_code != PICL_SUCCESS ) {
701     + DEBUGMSGTL(("sensors:arch:detail", "sensor value lookup failed (%d)\n",
702     + error_code));
703     + return( error_code );
704     + }
705     +
706     + /*
707     + * Check the validity (type and size) of this value
708     + */
709     + if ( sensor_info.type == PICL_PTYPE_FLOAT ) {
710     + *value = val.f;
711     + } else if ( sensor_info.type == PICL_PTYPE_UNSIGNED_INT ) {
712     + /* 16-bit or 32-bit unsigned integers */
713     + if ( sensor_info.size == 2 ) {
714     + *value = val.us2;
715     + } else if ( sensor_info.size == 4 ) {
716     + *value = val.us4;
717     + } else {
718     + DEBUGMSGTL(("sensors:arch:detail", "unsigned integer (%d bit)\n",
719     + sensor_info.size * 8));
720     + return PICL_FAILURE;
721     + }
722     + } else if ( sensor_info.type == PICL_PTYPE_INT ) {
723     + /* 16-bit or 32-bit signed integers */
724     + if ( sensor_info.size == 2 ) {
725     + *value = val.is2;
726     + } else if ( sensor_info.size == 4 ) {
727     + *value = val.is4;
728     + } else {
729     + DEBUGMSGTL(("sensors:arch:detail", "signed integer (%d bit)\n",
730     + sensor_info.size * 8));
731     + return PICL_FAILURE;
732     + }
733     + } else {
734     + DEBUGMSGTL(("sensors:arch:detail", "unrecognised type (%d)\n",
735     + sensor_info.type));
736     + return PICL_FAILURE;
737     + }
738     +
739     + return error_code;
740     +}
741     +
742     +static int
743     +process_num_sensor( picl_nodehdl_t childh, char *propname, char *propval, int typ )
744     +{
745     + netsnmp_sensor_info *sp;
746     + float value;
747     + picl_errno_t error_code;
748     +
749     + sp = sensor_by_name( propname, typ );
750     + if ( !sp ) {
751     + return -1;
752     + }
753     +
754     + error_code = read_num_sensor( childh, propval, &value );
755     + if ( error_code == PICL_SUCCESS ) {
756     + sp->value = value;
757     + sp->flags|= NETSNMP_SENSOR_FLAG_ACTIVE;
758     + } else {
759     + DEBUGMSGTL(("sensors:arch:detail", "Failed to read %s sensor value (%d)\n",
760     + propname, error_code));
761     + return -1;
762     + }
763     + return 0;
764     +}
765     +
766     +
767     +
768     +/*
769     + * Handle an enumeration-valued sensor
770     + */
771     +char *switch_settings[] = { "OFF","ON","NORMAL","LOCKED",
772     + "UNKNOWN","DIAG","SECURE",
773     + NULL };
774     +char *led_settings[] = { "OFF","ON","BLINK",
775     + NULL };
776     +char *i2c_settings[] = { "OK",
777     + NULL };
778     +
779     +static int
780     +read_enum_sensor( picl_nodehdl_t childh, float *value, char **options )
781     +{
782     + picl_nodehdl_t sensorh;
783     + picl_propinfo_t sensor_info;
784     + picl_errno_t error_code;
785     + char state[PICL_PROPSIZE_MAX];
786     + int i;
787     +
788     + /*
789     + * Retrieve the specified sensor information and value
790     + */
791     + error_code = picl_get_propinfo_by_name(childh, "State", &sensor_info, &sensorh);
792     + if ( error_code != PICL_SUCCESS ) {
793     + DEBUGMSGTL(("sensors:arch:detail", "sensor info lookup failed (%d)\n",
794     + error_code));
795     + return( error_code );
796     + }
797     +
798     + error_code = picl_get_propval(sensorh, state, sensor_info.size);
799     + if ( error_code != PICL_SUCCESS ) {
800     + DEBUGMSGTL(("sensors:arch:detail", "sensor value lookup failed (%d)\n",
801     + error_code));
802     + return( error_code );
803     + }
804     +
805     + /*
806     + * Try to find a matching entry in the list of options.
807     + * Note that some platforms may use upper or lower case
808     + * versions of these enumeration values
809     + * (so the checks are case insensitive)
810     + */
811     + *value = 99; /* Dummy value */
812     + for ( i=0; options[i] != NULL; i++ ) {
813     + if (strncasecmp(state, options[i], strlen(options[i])) == 0) {
814     + *value = i;
815     + return 0;
816     + }
817     + }
818     +
819     + DEBUGMSGTL(("sensors:arch:detail", "Enumeration state %s not matched\n",
820     + state));
821     + return 0; /* Or an error ? */
822     +}
823     +
824     +static int
825     +process_enum_sensor( picl_nodehdl_t childh, char *propname, int typ, char **options )
826     +{
827     + netsnmp_sensor_info *sp;
828     + float value;
829     + picl_errno_t error_code;
830     +
831     + sp = sensor_by_name( propname, typ );
832     + if ( !sp ) {
833     + return -1;
834     + }
835     +
836     + error_code = read_enum_sensor( childh, &value, options );
837     + if ( error_code == PICL_SUCCESS ) {
838     + sp->value = value;
839     + sp->flags|= NETSNMP_SENSOR_FLAG_ACTIVE;
840     + } else {
841     + DEBUGMSGTL(("sensors:arch:detail", "Failed to read %s sensor value (%d)\n",
842     + propname, error_code));
843     + return -1;
844     + }
845     + return 0;
846     +}
847     +static int
848     +process_enum_sensor( picl_nodehdl_t childh, char *propname, int typ, char **options )
849     +{
850     + return 0;
851     +}
852     +
853     +
854     +
855     +/*
856     + * Recursively walk through the tree of sensors
857     + */
858     +static int
859     +process_sensors( int level, picl_nodehdl_t nodeh ) {
860     + picl_nodehdl_t childh, nexth;
861     + char propname[ PICL_PROPNAMELEN_MAX ];
862     + char propclass[ PICL_CLASSNAMELEN_MAX ];
863     + picl_errno_t error_code;
864     +
865     + level++;
866     + DEBUGMSGTL(("sensors:arch:detail", "process_sensors - level %d\n", level));
867     +
868     + /* Look up the first child node at this level */
869     + error_code = pick_get_propval_by_name( nodeh, PICL_PROP_CHILD,
870     + &childh, sizeof(childh));
871     + if ( error_code != PICL_SUCCESS ) {
872     + DEBUGMSGTL(("sensors:arch:detail", "Failed to get first child node (%d)\n",
873     + error_code));
874     + return( error_code );
875     + }
876     +
877     + /* Step through the child nodes, retrieving the name and class of each one */
878     + while ( error_code == PICL_SUCCESS ) {
879     + error_code = pick_get_propval_by_name( childh, PICL_PROP_NAME,
880     + propname, sizeof(propname)-1);
881     + if ( error_code != PICL_SUCCESS ) {
882     + /* The Node With No Name */
883     + DEBUGMSGTL(("sensors:arch:detail", "get property name failed (%d)\n",
884     + error_code));
885     + return( error_code );
886     + }
887     +
888     + error_code = pick_get_propval_by_name( childh, PICL_PROP_CLASSNAME,
889     + propclass, sizeof(propclass)-1);
890     + if ( error_code != PICL_SUCCESS ) {
891     + /* The Classless Society */
892     + DEBUGMSGTL(("sensors:arch:detail", "get property class failed (%d)\n",
893     + error_code));
894     + return( error_code );
895     + }
896     +
897     + DEBUGMSGTL(("sensors:arch:detail", "Name: %s, Class %s\n",
898     + propname, propclass ));
899     +
900     +
901     + /*
902     + * Three classes represent further groups of sensors, etc.
903     + * Call 'process_sensors' recursively to handle this next level
904     + */
905     + if (( strstr( propclass, "picl" )) ||
906     + ( strstr( propclass, "frutree" )) ||
907     + ( strstr( propclass, "obp" ))) {
908     + process_sensors( level, childh );
909     + }
910     + /*
911     + * Otherwise retrieve the value appropriately based on the
912     + * class of the sensor.
913     + *
914     + * We need to specify the name of the PICL property to retrieve
915     + * for this class of sensor, and the Net-SNMP sensor type.
916     + */
917     + else if ( strstr( propclass, "fan-tachometer" )) {
918     + process_num_sensor( childh, propname, "AtoDSensorValue",
919     + NETSNMP_SENSOR_TYPE_RPM );
920     + } else if ( strstr( propclass, "fan" )) {
921     + process_num_sensor( childh, propname, "Speed",
922     + NETSNMP_SENSOR_TYPE_RPM );
923     + } else if ( strstr( propclass, "temperature-sensor" )) {
924     + process_num_sensor( childh, propname, "Temperature",
925     + NETSNMP_SENSOR_TYPE_TEMPERATURE );
926     + } else if ( strstr( propclass, "voltage-sensor" )) {
927     + process_num_sensor( childh, propname, "Voltage",
928     + /* ?? */ NETSNMP_SENSOR_TYPE_VOLTAGE_DC );
929     + } else if ( strstr( propclass, "digital-sensor" )) {
930     + process_num_sensor( childh, propname, "AtoDSensorValue",
931     + /* ?? */ NETSNMP_SENSOR_TYPE_VOLTAGE_DC );
932     + /*
933     + * Enumeration-valued sensors use a fixed PICL property ("State"),
934     + * but take a list of the values appropriate for that sensor,
935     + * as well as the Net-SNMP sensor type.
936     + */
937     + } else if ( strstr( propclass, "switch" )) {
938     + process_enum_sensor( childh, propname, NETSNMP_SENSOR_TYPE_OTHER,
939     + switch_settings );
940     + } else if ( strstr( propclass, "led" )) {
941     + process_enum_sensor( childh, propname, NETSNMP_SENSOR_TYPE_OTHER,
942     + led_settings );
943     + } else if ( strstr( propclass, "i2c" )) {
944     + process_enum_sensor( childh, propname, NETSNMP_SENSOR_TYPE_BOOLEAN, /* ?? */
945     + i2c_settings );
946     + } else {
947     + /* Skip other classes of sensor */
948     + DEBUGMSGTL(("sensors:arch:detail", "Skipping class %s\n", propclass ));
949     + }
950     +
951     + /*
952     + * Move on to the next child node at the current level (if any)
953     + */
954     + error_code = pick_get_propval_by_name( childh, PICL_PROP_PEER,
955     + &nexth, sizeof(nexth));
956     + if ( error_code != PICL_SUCCESS ) {
957     + /* That's All Folks! */
958     + return (( error_code == PICL_PROPNOTFOUND )
959     + ? PICL_SUCCESS : error_code );
960     + }
961     + childh = nexth;
962     + }
963     +
964     + return error_code;
965     +}
966     +
967     +
968     +int
969     +netsnmp_sensor_arch_load(netsnmp_cache *cache, void *vp) {
970     + int error_code;
971     + picl_nodehdl_t rooth;
972     +
973     + DEBUGMSGTL(("sensors:arch", "Reload PICLd Sensors module\n"));
974     +
975     + error_code = picl_get_root(&rooth);
976     + if ( error_code != PICL_SUCCESS) {
977     + DEBUGMSGTL(("sensors:arch", "Couldn't get root node (error %d)\n", error_code));
978     + return 1;
979     + }
980     +
981     + error_code = process_sensors(0, rooth);
982     + if ( error_code != 255 )
983     + if ( error_code != 7 ) /* ignore PICL_PROPNOTFOUND error */
984     + DEBUGMSGTL(("sensors:arch", "Internal PICLd problem (error %d)\n", error_code));
985     +
986     + return 0;
987     +}
988     +
989     +void netsnmp_sensor_arch_shutdown( void ) {
990     + DEBUGMSGTL(("sensors:arch", "Shutdown PicLD Sensors module\n"));
991     + picl_shutdown();
992     +}
993     +
994 jsafrane 1.2 diff -up /dev/null net-snmp-5.4.1/agent/mibgroup/hardware/sensors/picld_sensors.h
995     --- /dev/null 2008-07-23 14:59:56.660004489 +0200
996     +++ net-snmp-5.4.1/agent/mibgroup/hardware/sensors/picld_sensors.h 2008-07-25 12:53:46.000000000 +0200
997     @@ -0,0 +1 @@
998     +config_require(hardware/sensors/hw_sensors)
999     diff -up /dev/null net-snmp-5.4.1/agent/mibgroup/ucd-snmp/lmsensorsMib.c
1000     --- /dev/null 2008-07-23 14:59:56.660004489 +0200
1001     +++ net-snmp-5.4.1/agent/mibgroup/ucd-snmp/lmsensorsMib.c 2008-07-25 12:53:46.000000000 +0200
1002     @@ -0,0 +1,205 @@
1003 jsafrane 1.1 +#include <net-snmp/net-snmp-config.h>
1004     +#include <net-snmp/net-snmp-includes.h>
1005     +#include <net-snmp/agent/net-snmp-agent-includes.h>
1006     +#include <net-snmp/agent/hardware/sensors.h>
1007 jsafrane 1.2 +#include "ucd-snmp/lmsensorsMib.h"
1008 jsafrane 1.1 +
1009 jsafrane 1.2 +netsnmp_container *sensorContainer = NULL;
1010 jsafrane 1.1 +
1011 jsafrane 1.2 +void initialize_lmSensorsTable(const char *tableName, oid *tableOID,
1012     + netsnmp_container_op *filter, int mult );
1013 jsafrane 1.1 +
1014 jsafrane 1.2 +int _sensor_filter_temp( netsnmp_container *c, const void *v );
1015     +int _sensor_filter_fan( netsnmp_container *c, const void *v );
1016     +int _sensor_filter_volt( netsnmp_container *c, const void *v );
1017     +int _sensor_filter_misc( netsnmp_container *c, const void *v );
1018 jsafrane 1.1 +
1019 jsafrane 1.2 +static oid lmTempSensorsTable_oid[] = {1,3,6,1,4,1,2021,13,16,2};
1020     +static oid lmFanSensorsTable_oid[] = {1,3,6,1,4,1,2021,13,16,3};
1021     +static oid lmVoltSensorsTable_oid[] = {1,3,6,1,4,1,2021,13,16,4};
1022     +static oid lmMiscSensorsTable_oid[] = {1,3,6,1,4,1,2021,13,16,5};
1023     + /* All the tables have the same length root OID */
1024     +size_t lmSensorsTables_oid_len = OID_LENGTH(lmMiscSensorsTable_oid);
1025 jsafrane 1.1 +
1026     +
1027 jsafrane 1.2 +/* Initialise the LM Sensors MIB module */
1028     +void
1029     +init_lmsensorsMib(void)
1030     +{
1031     + DEBUGMSGTL(("ucd-snmp/lmsensorsMib","Initializing LM-SENSORS-MIB tables\n"));
1032 jsafrane 1.1 +
1033 jsafrane 1.2 + /*
1034     + * Initialise the four LM-SENSORS-MIB tables
1035 jsafrane 1.1 + *
1036 jsafrane 1.2 + * They are almost identical, so we can use the same registration code.
1037 jsafrane 1.1 + */
1038 jsafrane 1.2 + initialize_lmSensorsTable( "lmTempSensorsTable", lmTempSensorsTable_oid,
1039     + _sensor_filter_temp, 1000 ); /* MIB asks for mC */
1040     + initialize_lmSensorsTable( "lmFanSensorsTable", lmFanSensorsTable_oid,
1041     + _sensor_filter_fan, 1);
1042     + initialize_lmSensorsTable( "lmVoltSensorsTable", lmVoltSensorsTable_oid,
1043     + _sensor_filter_volt, 1000 ); /* MIB asks for mV */
1044     + initialize_lmSensorsTable( "lmMiscSensorsTable", lmMiscSensorsTable_oid,
1045     + _sensor_filter_misc, 1 );
1046 jsafrane 1.1 +}
1047     +
1048     +/*
1049 jsafrane 1.2 + * Common initialisation code, used for setting up all four tables
1050 jsafrane 1.1 + */
1051 jsafrane 1.2 +void
1052     +initialize_lmSensorsTable(const char *tableName, oid *tableOID,
1053     + netsnmp_container_op *filter, int mult )
1054     +{
1055     + netsnmp_handler_registration *reg;
1056     + netsnmp_table_registration_info *table_info;
1057     + netsnmp_cache *cache;
1058     + netsnmp_container *container;
1059 jsafrane 1.1 +
1060 jsafrane 1.2 + /*
1061     + * Ensure the HAL sensors module has been initialised,
1062     + * and retrieve the main sensors container.
1063     + * This table will then be registered using a filter on this container.
1064     + */
1065     + sensorContainer = get_sensor_container();
1066     + if ( !sensorContainer ) {
1067     + init_hw_sensors( );
1068     + sensorContainer = get_sensor_container();
1069     + }
1070     + container = netsnmp_container_find("sensorTable:table_container");
1071     + container->insert_filter = filter;
1072     + netsnmp_container_add_index( sensorContainer, container );
1073 jsafrane 1.1 +
1074     +
1075 jsafrane 1.2 + /*
1076     + * Create a basic registration structure for the table
1077     + */
1078     + reg = netsnmp_create_handler_registration(
1079     + tableName, lmSensorsTables_handler,
1080     + tableOID, lmSensorsTables_oid_len, HANDLER_CAN_RONLY
1081     + );
1082     +
1083     + /*
1084     + * Register the table using the filtered container
1085     + * Include an indicator of any scaling to be applied to the sensor value
1086     + */
1087     + reg->my_reg_void = (void *)mult;
1088     + table_info = SNMP_MALLOC_TYPEDEF( netsnmp_table_registration_info );
1089     + netsnmp_table_helper_add_indexes(table_info, ASN_INTEGER, 0);
1090     + table_info->min_column = COLUMN_LMSENSORS_INDEX;
1091     + table_info->max_column = COLUMN_LMSENSORS_VALUE;
1092     + netsnmp_container_table_register( reg, table_info, container, 0 );
1093 jsafrane 1.1 +
1094 jsafrane 1.2 + /*
1095     + * If the HAL sensors module was configured as an on-demand caching
1096     + * module (rather than being automatically loaded regularly),
1097     + * then ensure this table makes use of that cache.
1098     + */
1099     + cache = get_sensor_cache();
1100     + if ( cache ) {
1101     + netsnmp_inject_handler_before( reg, netsnmp_cache_handler_get( cache ),
1102     + "table_container");
1103     + }
1104 jsafrane 1.1 +
1105     +}
1106     +
1107     +
1108     +/*
1109 jsafrane 1.2 + * Container filters for the four tables
1110     + *
1111     + * Used to ensure that sensor entries appear in the appropriate table.
1112 jsafrane 1.1 + */
1113 jsafrane 1.2 +int _sensor_filter_temp( netsnmp_container *c, const void *v ) {
1114     + const netsnmp_sensor_info *sp = (const netsnmp_sensor_info *)v;
1115     + /* Only matches temperature sensors */
1116     + return (( sp->type == NETSNMP_SENSOR_TYPE_TEMPERATURE ) ? 0 : 1 );
1117 jsafrane 1.1 +}
1118     +
1119 jsafrane 1.2 +int _sensor_filter_fan( netsnmp_container *c, const void *v ) {
1120     + const netsnmp_sensor_info *sp = (const netsnmp_sensor_info *)v;
1121     + /* Only matches fan sensors */
1122     + return (( sp->type == NETSNMP_SENSOR_TYPE_RPM ) ? 0 : 1 );
1123     +}
1124 jsafrane 1.1 +
1125 jsafrane 1.2 +int _sensor_filter_volt( netsnmp_container *c, const void *v ) {
1126     + const netsnmp_sensor_info *sp = (const netsnmp_sensor_info *)v;
1127     + /* Only matches voltage sensors (AC or DC) */
1128     + return ((( sp->type == NETSNMP_SENSOR_TYPE_VOLTAGE_DC ) ||
1129     + ( sp->type == NETSNMP_SENSOR_TYPE_VOLTAGE_AC )) ? 0 : 1 );
1130     +}
1131 jsafrane 1.1 +
1132 jsafrane 1.2 +int _sensor_filter_misc( netsnmp_container *c, const void *v ) {
1133     + const netsnmp_sensor_info *sp = (const netsnmp_sensor_info *)v;
1134     + /* Matches everything except temperature, fan or voltage sensors */
1135     + return ((( sp->type == NETSNMP_SENSOR_TYPE_TEMPERATURE ) ||
1136     + ( sp->type == NETSNMP_SENSOR_TYPE_RPM ) ||
1137     + ( sp->type == NETSNMP_SENSOR_TYPE_VOLTAGE_DC ) ||
1138     + ( sp->type == NETSNMP_SENSOR_TYPE_VOLTAGE_AC )) ? 1 : 0 );
1139 jsafrane 1.1 +}
1140     +
1141     +
1142     +/*
1143 jsafrane 1.2 + * Handle requests for any of the four lmXxxxSensorsTables
1144     + *
1145     + * This is possible because all the table share the
1146     + * same structure and behaviour.
1147 jsafrane 1.1 + */
1148 jsafrane 1.2 +int
1149     +lmSensorsTables_handler(
1150     + netsnmp_mib_handler *handler,
1151     + netsnmp_handler_registration *reginfo,
1152     + netsnmp_agent_request_info *reqinfo,
1153     + netsnmp_request_info *requests) {
1154 jsafrane 1.1 +
1155 jsafrane 1.2 + netsnmp_request_info *request;
1156     + netsnmp_table_request_info *table_info;
1157     + netsnmp_sensor_info *sensor_info;
1158     + int mult = (int)reginfo->my_reg_void;
1159 jsafrane 1.1 +
1160 jsafrane 1.2 + DEBUGMSGTL(( "ucd-snmp/lmsensorsMib","lmSensorsTables_handler - root: "));
1161     + DEBUGMSGOID(("ucd-snmp/lmsensorsMib", reginfo->rootoid, reginfo->rootoid_len));
1162     + DEBUGMSG(( "ucd-snmp/lmsensorsMib",", mode %d\n", reqinfo->mode ));
1163 jsafrane 1.1 + /*
1164 jsafrane 1.2 + * This is a read-only table, so we only need to handle GET requests.
1165     + * (The container helper converts GETNEXT->GET requests automatically).
1166 jsafrane 1.1 + */
1167 jsafrane 1.2 + switch (reqinfo->mode) {
1168     + case MODE_GET:
1169     + for (request=requests; request; request=request->next) {
1170     + sensor_info = (netsnmp_sensor_info *)
1171     + netsnmp_container_table_extract_context(request);
1172     + if ( !sensor_info ) {
1173     + netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE);
1174     + continue;
1175     + }
1176     +
1177     + table_info = netsnmp_extract_table_info(request);
1178     + switch (table_info->colnum) {
1179     + case COLUMN_LMSENSORS_INDEX:
1180     + snmp_set_var_typed_integer( request->requestvb, ASN_INTEGER,
1181     + sensor_info->idx.oids[0]);
1182     + break;
1183     + case COLUMN_LMSENSORS_DEVICE:
1184     + if ( sensor_info->descr[0] != '\0' ) {
1185     + snmp_set_var_typed_value( request->requestvb, ASN_OCTET_STR,
1186     + sensor_info->descr, strlen(sensor_info->descr));
1187     + } else {
1188     + snmp_set_var_typed_value( request->requestvb, ASN_OCTET_STR,
1189     + sensor_info->name, strlen(sensor_info->name));
1190     + }
1191     + break;
1192     + case COLUMN_LMSENSORS_VALUE:
1193     + /* Multiply the value by the appropriate scaling factor for this table */
1194     + snmp_set_var_typed_integer( request->requestvb, ASN_GAUGE,
1195     + (int)(mult*sensor_info->value));
1196     + break;
1197     + default:
1198     + netsnmp_set_request_error(reqinfo, request,
1199     + SNMP_NOSUCHOBJECT);
1200     + break;
1201     + }
1202     + }
1203     + break;
1204 jsafrane 1.1 +
1205     + }
1206 jsafrane 1.2 + return SNMP_ERR_NOERROR;
1207 jsafrane 1.1 +}
1208 jsafrane 1.2 diff -up /dev/null net-snmp-5.4.1/agent/mibgroup/ucd-snmp/lmsensorsMib.h
1209     --- /dev/null 2008-07-23 14:59:56.660004489 +0200
1210     +++ net-snmp-5.4.1/agent/mibgroup/ucd-snmp/lmsensorsMib.h 2008-07-25 12:53:46.000000000 +0200
1211     @@ -0,0 +1,23 @@
1212     +#ifndef LM_SENSORS_MIB_H
1213     +#define LM_SENSORS_MIB_H
1214 jsafrane 1.1 +
1215 jsafrane 1.2 +config_require(hardware/sensors)
1216     +config_add_mib(LM-SENSORS-MIB)
1217 jsafrane 1.1 +
1218 jsafrane 1.2 +/* function declarations */
1219     +void init_lmsensorsMib(void);
1220 jsafrane 1.1 +
1221 jsafrane 1.2 +/*
1222     + * Handler and Column definitions for lmXxxxSensorsTable
1223     + *
1224     + * Note that the same handler (and hence the same
1225     + * column identifiers) are used for all four tables.
1226     + * This is possible because all the table share the
1227     + * same structure and behaviour.
1228     + */
1229     +Netsnmp_Node_Handler lmSensorsTables_handler;
1230     +#define COLUMN_LMSENSORS_INDEX 1
1231     +#define COLUMN_LMSENSORS_DEVICE 2
1232     +#define COLUMN_LMSENSORS_VALUE 3
1233 jsafrane 1.1 +
1234 jsafrane 1.2 +#endif /* LM_SENSORS_MIB_H */
1235     diff -up net-snmp-5.4.1/configure.backup_patch_15 net-snmp-5.4.1/configure
1236     --- net-snmp-5.4.1/configure.backup_patch_15 2008-07-25 12:53:39.000000000 +0200
1237     +++ net-snmp-5.4.1/configure 2008-07-25 12:53:46.000000000 +0200
1238     @@ -31030,7 +31030,7 @@ fi
1239     fi
1240    
1241     # LM-SENSORS-MIB support
1242     -echo " $module_list " | grep " ucd-snmp/lmSensors " > /dev/null
1243     +echo " $module_list " | $GREP -i "ucd-snmp/lmsensor" > /dev/null
1244     if test $? -eq 0 ; then
1245     echo "$as_me:$LINENO: checking for sensors support" >&5
1246     echo $ECHO_N "checking for sensors support... $ECHO_C" >&6
1247     diff -up net-snmp-5.4.1/configure.in.backup_patch_15 net-snmp-5.4.1/configure.in
1248     --- net-snmp-5.4.1/configure.in.backup_patch_15 2008-07-25 12:53:39.000000000 +0200
1249     +++ net-snmp-5.4.1/configure.in 2008-07-25 12:53:46.000000000 +0200
1250     @@ -2880,7 +2880,7 @@ if test $? -eq 0 ; then
1251     fi
1252    
1253     # LM-SENSORS-MIB support
1254     -echo " $module_list " | grep " ucd-snmp/lmSensors " > /dev/null
1255     +echo " $module_list " | $GREP -i "ucd-snmp/lmsensor" > /dev/null
1256     if test $? -eq 0 ; then
1257     AC_MSG_CHECKING([for sensors support])
1258     case $target_os in
1259     diff -up /dev/null net-snmp-5.4.1/include/net-snmp/agent/hardware/sensors.h
1260     --- /dev/null 2008-07-23 14:59:56.660004489 +0200
1261     +++ net-snmp-5.4.1/include/net-snmp/agent/hardware/sensors.h 2008-07-25 12:53:46.000000000 +0200
1262     @@ -0,0 +1,48 @@
1263     +/*
1264     + * Hardware Abstraction Layer - Sensors module
1265     + *
1266     + * Public interface
1267     + */
1268 jsafrane 1.1 +
1269 jsafrane 1.2 +#define NETSNMP_SENSOR_TYPE_OTHER 1
1270     +#define NETSNMP_SENSOR_TYPE_VOLTAGE_AC 3
1271     +#define NETSNMP_SENSOR_TYPE_VOLTAGE_DC 4
1272     +#define NETSNMP_SENSOR_TYPE_CURRENT 5
1273     +#define NETSNMP_SENSOR_TYPE_POWER 6
1274     +#define NETSNMP_SENSOR_TYPE_FREQUENCY 7
1275     +#define NETSNMP_SENSOR_TYPE_TEMPERATURE 8
1276     +#define NETSNMP_SENSOR_TYPE_HUMIDITY 9
1277     +#define NETSNMP_SENSOR_TYPE_RPM 10
1278     +#define NETSNMP_SENSOR_TYPE_VOLUME 11
1279     +#define NETSNMP_SENSOR_TYPE_BOOLEAN 12
1280 jsafrane 1.1 +
1281     +
1282 jsafrane 1.2 +#define NETSNMP_SENSOR_FLAG_ACTIVE 0x01
1283     +#define NETSNMP_SENSOR_FLAG_NAVAIL 0x02
1284     +#define NETSNMP_SENSOR_FLAG_BROKEN 0x04
1285     +#define NETSNMP_SENSOR_FLAG_DISABLE 0x08
1286 jsafrane 1.1 +
1287 jsafrane 1.2 +#define NETSNMP_SENSOR_MASK_STATUS 0x06 /* NAVAIL|BROKEN */
1288 jsafrane 1.1 +
1289     +
1290 jsafrane 1.2 +#define NETSNMP_SENSOR_FIND_CREATE 1 /* or use one of the sensor type values */
1291     +#define NETSNMP_SENSOR_FIND_EXIST 0
1292 jsafrane 1.1 +
1293 jsafrane 1.2 +typedef struct netsnmp_sensor_info_s netsnmp_sensor_info;
1294     +struct netsnmp_sensor_info_s {
1295 jsafrane 1.1 +
1296 jsafrane 1.2 + netsnmp_index idx;
1297     + /* int idx; */
1298     + char name[256];
1299     +
1300     + int type;
1301     + float value;
1302     + char descr[256];
1303     + long flags;
1304     +};
1305 jsafrane 1.1 +
1306 jsafrane 1.2 +netsnmp_container *get_sensor_container( void );
1307     +netsnmp_cache *get_sensor_cache( void );
1308     +netsnmp_sensor_info *sensor_by_name( char *, int );
1309     +NetsnmpCacheLoad netsnmp_sensor_load;
1310     +NetsnmpCacheFree netsnmp_sensor_free;

admin@fedoraproject.org
ViewVC Help
Powered by ViewVC 1.1.2