1 This patch makes "load X Y Z" snmpsettable via snmpset,
3 it behaves the same as sysName.0, once written in snmpd.conf, it becames
6 Signed-off-by: Elan Ruusamäe <glen@delfi.ee>
7 Upstream-Tracker: https://sourceforge.net/tracker/?func=detail&aid=2931446&group_id=12694&atid=312694
9 --- net-snmp/agent/mibgroup/ucd-snmp/loadave.c 2010/07/29 14:58:47 19264
10 +++ net-snmp/agent/mibgroup/ucd-snmp/loadave.c 2010/08/11 22:07:58 19294
12 #include "util_funcs/header_simple_table.h"
16 +static double maxload[3];
17 +static int laConfigSet = 0;
20 +loadave_store_config(int a, int b, void *c, void *d)
22 + char line[SNMP_MAXBUF_SMALL];
23 + if (laConfigSet > 0) {
24 + snprintf(line, SNMP_MAXBUF_SMALL, "pload %.02f %.02f %.02f", maxload[0], maxload[1], maxload[2]);
25 + snmpd_store_config(line);
27 + return SNMPERR_SUCCESS;
33 var_extensible_loadave, 1, {ERRORNAME}},
34 {LOADAVE, ASN_OCTET_STR, NETSNMP_OLDAPI_RONLY,
35 var_extensible_loadave, 1, {LOADAVE}},
36 - {LOADMAXVAL, ASN_OCTET_STR, NETSNMP_OLDAPI_RONLY,
37 + {LOADMAXVAL, ASN_OCTET_STR, NETSNMP_OLDAPI_RWRITE,
38 var_extensible_loadave, 1, {LOADMAXVAL}},
39 {LOADAVEINT, ASN_INTEGER, NETSNMP_OLDAPI_RONLY,
40 var_extensible_loadave, 1, {LOADAVEINT}},
42 REGISTER_MIB("ucd-snmp/loadave", extensible_loadave_variables,
43 variable2, loadave_variables_oid);
47 snmpd_register_config_handler("load", loadave_parse_config,
49 "max1 [max5] [max15]");
51 + snmpd_register_config_handler("pload",
52 + loadave_parse_config, NULL, NULL);
56 + * we need to be called back later
58 + snmp_register_callback(SNMP_CALLBACK_LIBRARY, SNMP_CALLBACK_STORE_DATA,
59 + loadave_store_config, NULL);
68 + if (strcmp(token, "pload") == 0) {
69 + if (laConfigSet < 0) {
70 + snmp_log(LOG_WARNING,
71 + "ignoring attempted override of read-only load\n");
77 + if (laConfigSet > 0) {
78 + snmp_log(LOG_WARNING,
79 + "ignoring attempted override of read-only load\n");
81 + * Fall through and copy in this value.
87 for (i = 0; i <= 2; i++) {
89 maxload[i] = atof(cptr);
95 +write_laConfig(int action,
97 + u_char var_val_type,
99 + u_char * statP, oid * name, size_t name_len)
101 + static double laConfig = 0;
104 + case RESERVE1: /* Check values for acceptability */
105 + if (var_val_type != ASN_OCTET_STR) {
106 + DEBUGMSGTL(("ucd-snmp/loadave",
107 + "write to laConfig not ASN_OCTET_STR\n"));
108 + return SNMP_ERR_WRONGTYPE;
110 + if (var_val_len > 8 || var_val_len <= 0) {
111 + DEBUGMSGTL(("ucd-snmp/loadave",
112 + "write to laConfig: bad length\n"));
113 + return SNMP_ERR_WRONGLENGTH;
116 + if (laConfigSet < 0) {
118 + * The object is set in a read-only configuration file.
120 + return SNMP_ERR_NOTWRITABLE;
124 + case RESERVE2: /* Allocate memory and similar resources */
127 + int old_errno = errno;
131 + strncpy(buf, var_val, var_val_len);
132 + buf[var_val_len] = '\0';
133 + val = strtod(buf, &endp);
135 + if (errno == ERANGE || *endp != '\0' || val < 0 || val > 65536.00) {
137 + DEBUGMSGTL(("ucd-snmp/loadave",
138 + "write to laConfig: invalid value\n"));
139 + return SNMP_ERR_WRONGVALUE;
150 + int idx = name[name_len - 1] - 1;
151 + maxload[idx] = laConfig;
156 + return SNMP_ERR_NOERROR;
160 var_extensible_loadave(struct variable * vp,
164 long_ret = name[*length - 1];
165 return ((u_char *) (&long_ret));
167 + /* setup write method, but don't return yet */
168 + *write_method = write_laConfig;
171 sprintf(errmsg, "Load-%d", ((name[*length - 1] == 1) ? 1 :
172 ((name[*length - 1] == 2) ? 5 : 15)));