Debian Codegraph @

agent/mibgroup/hardware/sensors/lmsensors_v2.c

raw
1 #include <net-snmp/net-snmp-config.h>
2 #include <net-snmp/net-snmp-includes.h>
3 #include <net-snmp/agent/net-snmp-agent-includes.h>
4 #include <net-snmp/agent/hardware/sensors.h>
5 #include "hw_sensors_private.h"
6
7 #include <time.h>
8 #include <sensors/sensors.h>
9
10 void netsnmp_sensor_arch_init( void ) {
11 FILE *fp = fopen("/etc/sensors.conf", "r");
12 DEBUGMSGTL(("sensors:arch", "Initialise LM Sensors module\n"));
13 sensors_init( fp );
14 }
15
16 int
17 netsnmp_sensor_arch_load(netsnmp_cache *cache, void *vp) {
18 netsnmp_sensor_info *sp;
19 const sensors_chip_name *chip;
20 const sensors_feature_data *data;
21 int chip_nr = 0;
22
23 DEBUGMSGTL(("sensors:arch", "Reload LM Sensors module\n"));
24 while ((chip = sensors_get_detected_chips(&chip_nr))) {
25 int a = 0;
26 int b = 0;
27
28 while ((data = sensors_get_all_features(*chip, &a, &b))) {
29 DEBUGMSGTL(("sensors:arch:detail", "get_all_features (%d, %d)\n", a, b));
30 char *label = NULL;
31 double val;
32 int type = NETSNMP_SENSOR_TYPE_OTHER;
33
34 if ((data->mode & SENSORS_MODE_R) &&
35 (data->mapping == SENSORS_NO_MAPPING) &&
36 !sensors_get_label(*chip, data->number, &label) &&
37 !sensors_get_feature(*chip, data->number, &val)) {
38
39 DEBUGMSGTL(("sensors:arch:detail", "%s = %f\n", label, val));
40 /*
41 * Determine the type of sensor from the description.
42 *
43 * If the text being looked for below is not in the label of a
44 * given sensor (e.g., the temp1 sensor has been labeled 'CPU'
45 * rather than 'CPU temp') it will be categorised as OTHER.
46 */
47 if (strstr(label, "V")) {
48 type = NETSNMP_SENSOR_TYPE_VOLTAGE_DC;
49 }
50 if (strstr(label, "fan") || strstr(label, "Fan")) {
51 type = NETSNMP_SENSOR_TYPE_RPM;
52 }
53 if (strstr(label, "temp") || strstr(label, "Temp")) {
54 type = NETSNMP_SENSOR_TYPE_TEMPERATURE;
55 }
56
57 /*
58 * Use this type to create a new sensor entry
59 * (inserting it in the appropriate sub-containers)
60 */
61 sp = sensor_by_name( label, type );
62 if ( sp ) {
63 sp->value = val;
64 sp->flags|= NETSNMP_SENSOR_FLAG_ACTIVE;
65 }
66 }
67 if (label) {
68 free(label);
69 label = NULL;
70 }
71 } /* end while data */
72 } /* end while chip */
73
74 return 0;
75 }