2 * This file was generated by mib2c and is intended for use as a mib module
3 * for the ucd-snmp snmpd agent.
8 * This should always be included first before anything else
10 #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>
16 * minimal include directives
18 #include "util_funcs.h"
22 #include <sensors/sensors.h>
24 #include "lmSensors.h"
28 #define MAX_SENSORS (32)
31 * lmSensors_variables_oid:
32 * this is the top level oid that we want to register under. This
33 * is essentially a prefix, with the suffix appearing in the
38 oid lmSensors_variables_oid[] =
39 { 1, 3, 6, 1, 4, 1, 2021, 13, 16 };
42 * variable4 lmSensors_variables:
43 * this variable defines function callbacks and type return information
44 * for the lmSensors mib section
47 struct variable4 lmSensors_variables[] = {
49 * magic number , variable type , ro/rw , callback fn , L, oidsuffix
51 #define LMTEMPSENSORSINDEX 3
52 {LMTEMPSENSORSINDEX, ASN_INTEGER, RONLY, var_lmSensorsTable, 3,
54 #define LMTEMPSENSORSDEVICE 4
55 {LMTEMPSENSORSDEVICE, ASN_OCTET_STR, RONLY, var_lmSensorsTable, 3,
57 #define LMTEMPSENSORSVALUE 5
58 {LMTEMPSENSORSVALUE, ASN_GAUGE, RONLY, var_lmSensorsTable, 3,
60 #define LMFANSENSORSINDEX 8
61 {LMFANSENSORSINDEX, ASN_INTEGER, RONLY, var_lmSensorsTable, 3,
63 #define LMFANSENSORSDEVICE 9
64 {LMFANSENSORSDEVICE, ASN_OCTET_STR, RONLY, var_lmSensorsTable, 3,
66 #define LMFANSENSORSVALUE 10
67 {LMFANSENSORSVALUE, ASN_GAUGE, RONLY, var_lmSensorsTable, 3,
69 #define LMVOLTSENSORSINDEX 13
70 {LMVOLTSENSORSINDEX, ASN_INTEGER, RONLY, var_lmSensorsTable, 3,
72 #define LMVOLTSENSORSDEVICE 14
73 {LMVOLTSENSORSDEVICE, ASN_OCTET_STR, RONLY, var_lmSensorsTable, 3,
75 #define LMVOLTSENSORSVALUE 15
76 {LMVOLTSENSORSVALUE, ASN_GAUGE, RONLY, var_lmSensorsTable, 3,
78 #define LMMISCSENSORSINDEX 18
79 {LMMISCSENSORSINDEX, ASN_INTEGER, RONLY, var_lmSensorsTable, 3,
81 #define LMMISCSENSORSDEVICE 19
82 {LMMISCSENSORSDEVICE, ASN_OCTET_STR, RONLY, var_lmSensorsTable, 3,
84 #define LMMISCSENSORSVALUE 20
85 {LMMISCSENSORSVALUE, ASN_GAUGE, RONLY, var_lmSensorsTable, 3,
96 _sensor sensor[MAX_SENSORS];
99 static _sensor_array sensor_array[N_TYPES];
100 static clock_t timestamp;
103 static int sensor_init(void);
104 static void sensor_load(void);
105 static void _sensor_load(clock_t t);
107 #define CONFIG_FILE_NAME "/etc/sensors.conf"
111 * Initialization routine. This is called when the agent starts up.
112 * At a minimum, registration of your variables should take place here.
120 * register ourselves with the agent to handle our mib tree
122 REGISTER_MIB("lmSensors", lmSensors_variables, variable4,
123 lmSensors_variables_oid);
127 * var_lmSensorsTable():
128 * Handle this table separately from the scalar value case.
129 * The workings of this are basically the same as for var_lmSensors above.
132 var_lmSensorsTable(struct variable *vp,
136 size_t * var_len, WriteMethod ** write_method)
138 static long long_ret;
139 static unsigned char string[SPRINT_MAX_LEN];
142 int s_index = name[*length - 1] - 1;
151 case LMTEMPSENSORSINDEX:
152 case LMTEMPSENSORSDEVICE:
153 case LMTEMPSENSORSVALUE:
155 n_sensors = sensor_array[0].n;
158 case LMFANSENSORSINDEX:
159 case LMFANSENSORSDEVICE:
160 case LMFANSENSORSVALUE:
162 n_sensors = sensor_array[1].n;
165 case LMVOLTSENSORSINDEX:
166 case LMVOLTSENSORSDEVICE:
167 case LMVOLTSENSORSVALUE:
169 n_sensors = sensor_array[2].n;
172 case LMMISCSENSORSINDEX:
173 case LMMISCSENSORSDEVICE:
174 case LMMISCSENSORSVALUE:
176 n_sensors = sensor_array[3].n;
184 if (header_simple_table(vp, name, length, exact,
185 var_len, write_method,
186 n_sensors) == MATCH_FAILED)
192 s = sensor_array[s_type].sensor[s_index];
195 case LMTEMPSENSORSINDEX:
196 case LMFANSENSORSINDEX:
197 case LMVOLTSENSORSINDEX:
198 case LMMISCSENSORSINDEX:
200 return (unsigned char *) &long_ret;
202 case LMTEMPSENSORSDEVICE:
203 case LMFANSENSORSDEVICE:
204 case LMVOLTSENSORSDEVICE:
205 case LMMISCSENSORSDEVICE:
206 strncpy(string, s.name, SPRINT_MAX_LEN - 1);
207 *var_len = strlen(string);
208 return (unsigned char *) string;
210 case LMTEMPSENSORSVALUE:
211 case LMFANSENSORSVALUE:
212 case LMVOLTSENSORSVALUE:
213 case LMMISCSENSORSVALUE:
215 return (unsigned char *) &long_ret;
218 ERROR_MSG("Unable to handle table request");
228 char filename[] = CONFIG_FILE_NAME;
231 FILE *fp = fopen(filename, "r");
235 if (res = sensors_init(fp))
247 if (t > timestamp + 60)
254 _sensor_load(clock_t t)
256 const sensors_chip_name *chip;
257 const sensors_feature_data *data;
263 for (i = 0; i < N_TYPES; i++)
264 sensor_array[i].n = 0;
266 while (chip = sensors_get_detected_chips(&chip_nr)) {
267 while (data = sensors_get_all_features(*chip, &a, &b)) {
271 if ((data->mode & SENSORS_MODE_R) &&
272 (data->mapping == SENSORS_NO_MAPPING) &&
273 !sensors_get_label(*chip, data->number, &label) &&
274 !sensors_get_feature(*chip, data->number, &val)) {
277 _sensor_array *array;
279 if (strstr(label, "temp")) {
282 } else if (strstr(label, "fan")) {
285 } else if (strstr(label, "V")) {
293 array = &sensor_array[type];
295 strncpy(array->sensor[array->n].name, label, MAX_NAME);
296 array->sensor[array->n].value = (int) (val * mul);