blob: 8c162e6dbd78888c0ae21175d2ef8cea58d15e4b [file] [log] [blame]
Wes Hardakerc3c403c1997-03-07 08:06:34 +00001#include <config.h>
2
3#if HAVE_STDLIB_H
4#include <stdlib.h>
5#endif
6#if HAVE_UNISTD_H
7#include <unistd.h>
8#endif
9#if HAVE_FCNTL_H
10#include <fcntl.h>
11#endif
12#include <signal.h>
Wes Hardakere74d0f91997-04-22 13:02:56 +000013#if TIME_WITH_SYS_TIME
14# include <sys/time.h>
15# include <time.h>
16#else
17# if HAVE_SYS_TIME_H
18# include <sys/time.h>
19# else
20# include <time.h>
21# endif
22#endif
Wes Hardakerc3c403c1997-03-07 08:06:34 +000023#if HAVE_MACHINE_PARAM_H
24#include <machine/param.h>
25#endif
Wes Hardakera1a822e1998-03-26 15:22:30 +000026#if HAVE_SYS_PARAM_H
27#include <sys/param.h>
28#endif
Wes Hardakerc3c403c1997-03-07 08:06:34 +000029#if HAVE_SYS_VMMETER_H
Wes Hardaker4e5278b1997-10-29 19:20:54 +000030#if !(defined(bsdi2) || defined(netbsd1))
Wes Hardakerc3c403c1997-03-07 08:06:34 +000031#include <sys/vmmeter.h>
32#endif
33#endif
34#if HAVE_SYS_CONF_H
35#include <sys/conf.h>
36#endif
Wes Hardakerf1f58741999-01-20 23:17:17 +000037#if HAVE_ASM_PAGE_H
38#include <asm/page.h>
39#endif
Wes Hardakerc3c403c1997-03-07 08:06:34 +000040#if HAVE_SYS_SWAP_H
41#include <sys/swap.h>
42#endif
43#if HAVE_SYS_FS_H
44#include <sys/fs.h>
45#else
46#if HAVE_UFS_FS_H
47#include <ufs/fs.h>
48#else
Wes Hardakerc3adf701997-07-01 13:41:44 +000049#ifdef HAVE_SYS_STAT_H
50#include <sys/stat.h>
51#endif
52#ifdef HAVE_SYS_VNODE_H
53#include <sys/vnode.h>
54#endif
55#ifdef HAVE_UFS_UFS_QUOTA_H
56#include <ufs/ufs/quota.h>
57#endif
58#ifdef HAVE_UFS_UFS_INODE_H
59#include <ufs/ufs/inode.h>
60#endif
Wes Hardakerc3c403c1997-03-07 08:06:34 +000061#if HAVE_UFS_FFS_FS_H
62#include <ufs/ffs/fs.h>
63#endif
64#endif
65#endif
66#if HAVE_MTAB_H
67#include <mtab.h>
68#endif
69#include <sys/stat.h>
70#include <errno.h>
71#if HAVE_FSTAB_H
72#include <fstab.h>
73#endif
Wes Hardaker7a2cb581997-08-14 14:38:17 +000074#if HAVE_SYS_STATFS_H
75#include <sys/statfs.h>
76#endif
Wes Hardakerc3c403c1997-03-07 08:06:34 +000077#if HAVE_SYS_STATVFS_H
78#include <sys/statvfs.h>
79#endif
80#if HAVE_SYS_VFS_H
81#include <sys/vfs.h>
82#endif
83#if (!defined(HAVE_STATVFS)) && defined(HAVE_STATFS)
84#if HAVE_SYS_PARAM_H
85#include <sys/param.h>
86#endif
87#if HAVE_SYS_MOUNT_H
88#include <sys/mount.h>
89#endif
90#if HAVE_SYS_SYSCTL_H
91#include <sys/sysctl.h>
92#endif
93#define statvfs statfs
94#endif
Michael Slifcak316513a1999-11-04 13:13:05 +000095#if HAVE_VM_VM_H
96#include <vm/vm.h>
97#endif
Wes Hardakerc3c403c1997-03-07 08:06:34 +000098#if HAVE_VM_SWAP_PAGER_H
99#include <vm/swap_pager.h>
100#endif
101#if HAVE_SYS_FIXPOINT_H
102#include <sys/fixpoint.h>
103#endif
104#if HAVE_MALLOC_H
105#include <malloc.h>
106#endif
Michael Slifcak5dc0a731999-11-04 12:14:28 +0000107#if HAVE_STRING_H
Wes Hardakerc3c403c1997-03-07 08:06:34 +0000108#include <string.h>
109#endif
110
Niels Baggesen4416a541999-10-25 21:13:57 +0000111#if HAVE_DMALLOC_H
112#include <dmalloc.h>
113#endif
114
Wes Hardakerc3c403c1997-03-07 08:06:34 +0000115#include "mibincl.h"
Wes Hardakere7e82b41998-01-21 19:12:34 +0000116#include "struct.h"
Wes Hardakerc3c403c1997-03-07 08:06:34 +0000117#include "errormib.h"
Wes Hardakerb41e8f81997-03-07 08:59:28 +0000118#include "util_funcs.h"
Wes Hardaker7510f2e1998-02-09 19:03:02 +0000119#include "auto_nlist.h"
Wes Hardakerc3c403c1997-03-07 08:06:34 +0000120
121static time_t errorstatustime=0;
122static int errorstatusprior=0;
123static char errorstring[STRMAX];
124
125void
Niels Baggesen34058af1999-04-26 19:13:52 +0000126setPerrorstatus(const char *to)
Wes Hardakerc3c403c1997-03-07 08:06:34 +0000127{
128 char buf[STRMAX];
Wes Hardakerc3c403c1997-03-07 08:06:34 +0000129
Wes Hardaker4e5278b1997-10-29 19:20:54 +0000130 sprintf(buf,"%s: %s",to,strerror(errno));
Niels Baggesence215d81999-08-18 16:31:09 +0000131 snmp_log_perror(to);
Wes Hardakerc3c403c1997-03-07 08:06:34 +0000132 seterrorstatus(buf,5);
133}
134
135void
Niels Baggesen34058af1999-04-26 19:13:52 +0000136seterrorstatus(const char *to, int prior)
Wes Hardakerc3c403c1997-03-07 08:06:34 +0000137{
138 if (errorstatusprior <= prior ||
139 (ERRORTIMELENGTH < (time(NULL) - errorstatustime))) {
140 strcpy(errorstring,to);
141 errorstatusprior = prior;
142 errorstatustime = time(NULL);
143 }
144}
Wes Hardaker3af42a81999-01-15 23:24:03 +0000145
Wes Hardaker40b2bf11999-01-18 18:47:36 +0000146void init_errormib(void)
147{
Wes Hardaker3af42a81999-01-15 23:24:03 +0000148
149 /* define the structure we're going to ask the agent to register our
150 information at */
151 struct variable2 extensible_error_variables[] = {
152 {MIBINDEX, ASN_INTEGER, RONLY, var_extensible_errors, 1, {MIBINDEX}},
153 {ERRORNAME, ASN_OCTET_STR, RONLY, var_extensible_errors, 1, {ERRORNAME}},
154 {ERRORFLAG, ASN_INTEGER, RONLY, var_extensible_errors, 1, {ERRORFLAG}},
155 {ERRORMSG, ASN_OCTET_STR, RONLY, var_extensible_errors, 1, {ERRORMSG}}
156 };
157
158 /* Define the OID pointer to the top of the mib tree that we're
159 registering underneath */
160 oid extensible_error_variables_oid[] = { EXTENSIBLEMIB,ERRORMIBNUM };
161
162 /* register ourselves with the agent to handle our mib tree */
Dave Shield88da1f71999-07-27 13:38:09 +0000163 REGISTER_MIB("ucd-snmp/errormib", extensible_error_variables, \
Wes Hardaker3af42a81999-01-15 23:24:03 +0000164 variable2, extensible_error_variables_oid);
165}
166
Wes Hardaker40b2bf11999-01-18 18:47:36 +0000167/*
168 var_extensible_errors(...
169 Arguments:
170 vp IN - pointer to variable entry that points here
171 name IN/OUT - IN/name requested, OUT/name found
172 length IN/OUT - length of IN/OUT oid's
173 exact IN - TRUE if an exact match was requested
174 var_len OUT - length of variable or 0 if function returned
175 write_method
Wes Hardakerc3c403c1997-03-07 08:06:34 +0000176
Wes Hardaker40b2bf11999-01-18 18:47:36 +0000177*/
Niels Baggesenbc881471999-05-04 07:51:16 +0000178u_char *var_extensible_errors(struct variable *vp,
Wes Hardaker40b2bf11999-01-18 18:47:36 +0000179 oid *name,
Niels Baggesen0045e2f1999-05-03 22:40:11 +0000180 size_t *length,
Wes Hardaker40b2bf11999-01-18 18:47:36 +0000181 int exact,
Niels Baggesen0045e2f1999-05-03 22:40:11 +0000182 size_t *var_len,
Wes Hardaker5ae6c981999-02-09 07:22:33 +0000183 WriteMethod **write_method)
Wes Hardakerc3c403c1997-03-07 08:06:34 +0000184{
185
Wes Hardakerc3c403c1997-03-07 08:06:34 +0000186 static long long_ret;
187 static char errmsg[300];
188
189
Wes Hardakerabbf6911998-05-06 21:58:23 +0000190 if (header_generic(vp,name,length,exact,var_len,write_method))
Wes Hardakerc3c403c1997-03-07 08:06:34 +0000191 return(NULL);
192
193 errmsg[0] = 0;
194
195 switch (vp->magic) {
196 case MIBINDEX:
Wes Hardakerabbf6911998-05-06 21:58:23 +0000197 long_ret = name[*length - 1];
Wes Hardakerc3c403c1997-03-07 08:06:34 +0000198 return((u_char *) (&long_ret));
199 case ERRORNAME:
200 strcpy(errmsg,"snmp");
201 *var_len = strlen(errmsg);
202 return((u_char *) errmsg);
203 case ERRORFLAG:
204 long_ret = (ERRORTIMELENGTH >= time(NULL)-errorstatustime) ? 1 : 0;
205 return((u_char *) (&long_ret));
206 case ERRORMSG:
207 if ((ERRORTIMELENGTH >= time(NULL)-errorstatustime) ? 1 : 0)
208 strcpy(errmsg,errorstring);
209 else
210 errmsg[0] = 0;
211 *var_len = strlen(errmsg);
212 return((u_char *) errmsg);
213 }
214 return NULL;
215}
216