1 #include <net-snmp/net-snmp-config.h>
13 #if TIME_WITH_SYS_TIME
15 # include <sys/timeb.h>
17 # include <sys/time.h>
22 # include <sys/time.h>
27 #if HAVE_MACHINE_PARAM_H
28 #include <machine/param.h>
31 #include <sys/param.h>
33 #if HAVE_SYS_VMMETER_H
34 #if !(defined(bsdi2) || defined(netbsd1))
35 #include <sys/vmmeter.h>
53 #ifdef HAVE_SYS_STAT_H
56 #ifdef HAVE_SYS_VNODE_H
57 #include <sys/vnode.h>
59 #ifdef HAVE_UFS_UFS_QUOTA_H
60 #include <ufs/ufs/quota.h>
62 #ifdef HAVE_UFS_UFS_INODE_H
63 #include <ufs/ufs/inode.h>
66 #include <ufs/ffs/fs.h>
79 #include <sys/statfs.h>
81 #if HAVE_SYS_STATVFS_H
82 #include <sys/statvfs.h>
87 #if (!defined(HAVE_STATVFS)) && defined(HAVE_STATFS)
89 #include <sys/param.h>
92 #include <sys/mount.h>
95 #include <sys/sysctl.h>
97 #define statvfs statfs
102 #if HAVE_VM_SWAP_PAGER_H
103 #include <vm/swap_pager.h>
105 #if HAVE_SYS_FIXPOINT_H
106 #include <sys/fixpoint.h>
122 #include <net-snmp/net-snmp-includes.h>
123 #include <net-snmp/agent/net-snmp-agent-includes.h>
124 #include <net-snmp/agent/auto_nlist.h>
127 #include "errormib.h"
128 #include "util_funcs.h"
130 static time_t errorstatustime = 0;
131 static int errorstatusprior = 0;
132 static char errorstring[STRMAX];
135 setPerrorstatus(const char *to)
139 snprintf(buf, sizeof(buf), "%s: %s", to, strerror(errno));
140 buf[ sizeof(buf)-1 ] = 0;
142 seterrorstatus(buf, 5);
146 seterrorstatus(const char *to, int prior)
148 if (errorstatusprior <= prior ||
149 (ERRORTIMELENGTH < (time(NULL) - errorstatustime))) {
150 strncpy(errorstring, to, sizeof(errorstring));
151 errorstring[ sizeof(errorstring)-1 ] = 0;
152 errorstatusprior = prior;
153 errorstatustime = time(NULL);
162 * define the structure we're going to ask the agent to register our
165 struct variable2 extensible_error_variables[] = {
166 {MIBINDEX, ASN_INTEGER, RONLY, var_extensible_errors, 1,
168 {ERRORNAME, ASN_OCTET_STR, RONLY, var_extensible_errors, 1,
170 {ERRORFLAG, ASN_INTEGER, RONLY, var_extensible_errors, 1,
172 {ERRORMSG, ASN_OCTET_STR, RONLY, var_extensible_errors, 1,
177 * Define the OID pointer to the top of the mib tree that we're
178 * registering underneath
180 oid extensible_error_variables_oid[] =
181 { UCDAVIS_MIB, ERRORMIBNUM };
184 * register ourselves with the agent to handle our mib tree
186 REGISTER_MIB("ucd-snmp/errormib", extensible_error_variables,
187 variable2, extensible_error_variables_oid);
191 * var_extensible_errors(...
193 * vp IN - pointer to variable entry that points here
194 * name IN/OUT - IN/name requested, OUT/name found
195 * length IN/OUT - length of IN/OUT oid's
196 * exact IN - TRUE if an exact match was requested
197 * var_len OUT - length of variable or 0 if function returned
202 var_extensible_errors(struct variable *vp,
206 size_t * var_len, WriteMethod ** write_method)
209 static long long_ret;
210 static char errmsg[300];
213 if (header_generic(vp, name, length, exact, var_len, write_method))
220 long_ret = name[*length - 1];
221 return ((u_char *) (&long_ret));
223 strcpy(errmsg, "snmp");
224 *var_len = strlen(errmsg);
225 return ((u_char *) errmsg);
228 (ERRORTIMELENGTH >= time(NULL) - errorstatustime) ? 1 : 0;
229 return ((u_char *) (&long_ret));
231 if ((ERRORTIMELENGTH >= time(NULL) - errorstatustime) ? 1 : 0) {
232 strncpy(errmsg, errorstring, sizeof(errmsg));
233 errmsg[ sizeof(errmsg)-1 ] = 0;
236 *var_len = strlen(errmsg);
237 return ((u_char *) errmsg);