1 --- net-snmp-5.4.2.1/agent/mibgroup/ucd-snmp/loadave.c~ 2009-12-21 21:00:10.094254079 +0200
2 +++ net-snmp-5.4.2.1/agent/mibgroup/ucd-snmp/loadave.c 2009-12-21 22:02:45.398903148 +0200
4 #include "util_funcs.h"
8 +static double maxload[3];
9 +static int laConfigSet = 0;
12 +loadave_store_config(int a, int b, void *c, void *d)
14 + char line[SNMP_MAXBUF_SMALL];
15 + if (laConfigSet > 0) {
16 + snprintf(line, SNMP_MAXBUF_SMALL, "pload %.02f %.02f %.02f", maxload[0], maxload[1], maxload[2]);
17 + snmpd_store_config(line);
19 + return SNMPERR_SUCCESS;
26 {LOADAVE, ASN_OCTET_STR, RONLY, var_extensible_loadave, 1,
28 - {LOADMAXVAL, ASN_OCTET_STR, RONLY, var_extensible_loadave, 1,
29 + {LOADMAXVAL, ASN_OCTET_STR, RWRITE, var_extensible_loadave, 1,
31 {LOADAVEINT, ASN_INTEGER, RONLY, var_extensible_loadave, 1,
34 REGISTER_MIB("ucd-snmp/loadave", extensible_loadave_variables,
35 variable2, loadave_variables_oid);
39 snmpd_register_config_handler("load", loadave_parse_config,
41 "max1 [max5] [max15]");
43 + snmpd_register_config_handler("pload",
44 + loadave_parse_config, NULL, NULL);
48 + * we need to be called back later
50 + snmp_register_callback(SNMP_CALLBACK_LIBRARY, SNMP_CALLBACK_STORE_DATA,
51 + loadave_store_config, NULL);
60 + if (strcmp(token, "pload") == 0) {
61 + if (laConfigSet < 0) {
62 + snmp_log(LOG_WARNING,
63 + "ignoring attempted override of read-only load\n");
69 + if (laConfigSet > 0) {
70 + snmp_log(LOG_WARNING,
71 + "ignoring attempted override of read-only load\n");
73 + * Fall through and copy in this value.
79 for (i = 0; i <= 2; i++) {
81 maxload[i] = atof(cptr);
87 +write_laConfig(int action,
89 + u_char var_val_type,
91 + u_char * statP, oid * name, size_t name_len)
93 + static double laConfig = 0;
96 + case RESERVE1: /* Check values for acceptability */
97 + if (var_val_type != ASN_OCTET_STR) {
98 + DEBUGMSGTL(("ucd-snmp/loadave",
99 + "write to laConfig not ASN_OCTET_STR\n"));
100 + return SNMP_ERR_WRONGTYPE;
102 + if (var_val_len > 8 || var_val_len <= 0) {
103 + DEBUGMSGTL(("ucd-snmp/loadave",
104 + "write to laConfig: bad length\n"));
105 + return SNMP_ERR_WRONGLENGTH;
108 + if (laConfigSet < 0) {
110 + * The object is set in a read-only configuration file.
112 + return SNMP_ERR_NOTWRITABLE;
116 + case RESERVE2: /* Allocate memory and similar resources */
119 + int old_errno = errno;
123 + strncpy(buf, var_val, var_val_len);
124 + buf[var_val_len] = '\0';
125 + val = strtod(buf, &endp);
127 + if (errno == ERANGE || *endp != '\0' || val < 0 || val > 65536.00) {
129 + DEBUGMSGTL(("ucd-snmp/loadave",
130 + "write to laConfig: invalid value\n"));
131 + return SNMP_ERR_WRONGVALUE;
142 + int idx = name[name_len - 1] - 1;
143 + maxload[idx] = laConfig;
148 + return SNMP_ERR_NOERROR;
152 var_extensible_loadave(struct variable * vp,
156 long_ret = name[*length - 1];
157 return ((u_char *) (&long_ret));
159 + /* setup write method, but don't return yet */
160 + *write_method = write_laConfig;
163 sprintf(errmsg, "Load-%d", ((name[*length - 1] == 1) ? 1 :
164 ((name[*length - 1] == 2) ? 5 : 15)));