summaryrefslogtreecommitdiffstats
path: root/contrib/check_rbl.c
diff options
context:
space:
mode:
authorHolger Weiss <holger@zedat.fu-berlin.de>2013-09-02 13:16:24 +0200
committerHolger Weiss <holger@zedat.fu-berlin.de>2013-09-02 13:16:24 +0200
commitb15adb7762b6caaecaa83637abfcf5fdb4802092 (patch)
tree64eddbe2aa1a7f98a140be0f7973f05d7a781ae0 /contrib/check_rbl.c
parentc4d5882b9e1d07c7b61091062b7d085fa5f00284 (diff)
downloadmonitoring-plugins-b15adb7762b6caaecaa83637abfcf5fdb4802092.tar.gz
Remove "contrib" plugins
These days, sites such as "Nagios Exchange" are a much better place for publishing plugins not maintained by the Plugins Development Team.
Diffstat (limited to 'contrib/check_rbl.c')
-rw-r--r--contrib/check_rbl.c328
1 files changed, 0 insertions, 328 deletions
diff --git a/contrib/check_rbl.c b/contrib/check_rbl.c
deleted file mode 100644
index eec84ad8..00000000
--- a/contrib/check_rbl.c
+++ /dev/null
@@ -1,328 +0,0 @@
1/******************************************************************************
2*
3* check_rbl.c
4*
5* Modified by Tim Bell <bhat@trinity.unimelb.edu.au> 2002-06-05
6* based on:
7*
8* * check_dig.c
9* *
10* * Program: dig plugin for NetSaint
11* * License: GPL
12* * Copyright (c) 2000
13* *
14* * $Id: check_rbl.c 970 2004-12-02 00:30:32Z opensides $
15*
16*****************************************************************************/
17
18#include "config.h"
19#include "common.h"
20#include "utils.h"
21#include "popen.h"
22#include "string.h"
23
24const char progname = "check_rbl";
25const char *revision = "$Revision: 970 $";
26//const char *copyright = "2000-2003";
27//const char *email = "nagiosplug-devel@lists.sourceforge.net";
28
29int process_arguments(int, char **);
30int call_getopt(int, char **);
31int validate_arguments(void);
32int check_disk(int usp,int free_disk);
33void print_help(void);
34void print_usage(void);
35char *reverse_ipaddr(char *ipaddr);
36
37char *query_address=NULL;
38char *query_address_rev=NULL;
39char *dns_server=NULL;
40char *rbl_name=NULL;
41int verbose=FALSE;
42
43int main(int argc, char **argv){
44 char input_buffer[MAX_INPUT_BUFFER];
45 char *command_line=NULL;
46 char *output=NULL;
47 int result=STATE_OK;
48
49 /* Set signal handling and alarm */
50 if (signal(SIGALRM,popen_timeout_alarm_handler)==SIG_ERR)
51 usage("Cannot catch SIGALRM\n");
52
53 if (process_arguments(argc,argv)!=OK)
54 usage (_("check_rbl: could not parse arguments\n"));
55
56 /* reverse the octets in the IP address */
57 query_address_rev = reverse_ipaddr(query_address);
58
59 /* build the command to run */
60 if (dns_server) {
61 command_line=ssprintf(command_line,"%s @%s %s.%s",
62 PATH_TO_DIG,dns_server,
63 query_address_rev, rbl_name);
64 } else {
65 command_line=ssprintf(command_line,"%s %s.%s",
66 PATH_TO_DIG,
67 query_address_rev, rbl_name);
68 }
69 alarm(timeout_interval);
70 time(&start_time);
71
72 if (verbose)
73 printf("%s\n",command_line);
74 /* run the command */
75 child_process=spopen(command_line);
76 if (child_process==NULL) {
77 printf("Could not open pipe: %s\n",command_line);
78 return STATE_UNKNOWN;
79 }
80
81 child_stderr=fdopen(child_stderr_array[fileno(child_process)],"r");
82 if(child_stderr==NULL)
83 printf("Could not open stderr for %s\n",command_line);
84
85 output=strscpy(output,"");
86
87 while (fgets(input_buffer,MAX_INPUT_BUFFER-1,child_process)) {
88
89 /* the server is responding, we just got the host name... */
90 if (strstr(input_buffer,";; ANSWER SECTION:")) {
91
92 /* get the host address */
93 if (!fgets(input_buffer,MAX_INPUT_BUFFER-1,child_process))
94 break;
95
96 if (strpbrk(input_buffer,"\r\n"))
97 input_buffer[strcspn(input_buffer,"\r\n")] = '\0';
98
99 if (strstr(input_buffer,query_address_rev)==input_buffer) {
100 output=strscpy(output,input_buffer);
101 /* we found it, which means it's listed! */
102 result=STATE_CRITICAL;
103 } else {
104 strcpy(output,"Server not RBL listed.");
105 result=STATE_OK;
106 }
107
108 continue;
109 }
110
111 }
112
113 /*
114 if (result!=STATE_OK) {
115 strcpy(output,"No ANSWER SECTION found");
116 }
117 */
118
119 while (fgets(input_buffer,MAX_INPUT_BUFFER-1,child_stderr)) {
120 /* If we get anything on STDERR, at least set warning */
121 result=error_set(result,STATE_WARNING);
122 printf("%s",input_buffer);
123 if (!strcmp(output,""))
124 strcpy(output,1+index(input_buffer,':'));
125 }
126
127 (void)fclose(child_stderr);
128
129 /* close the pipe */
130 if (spclose(child_process)) {
131 result=error_set(result,STATE_WARNING);
132 if (!strcmp(output,""))
133 strcpy(output,"nslookup returned an error status");
134 }
135
136 (void)time(&end_time);
137
138 if (result==STATE_OK)
139 printf("RBL check okay - not listed.\n");
140 else if (result==STATE_WARNING)
141 printf("RBL WARNING - %s\n",!strcmp(output,"")?" Probably a non-existent host/domain":output);
142 else if (result==STATE_CRITICAL)
143 printf("RBL CRITICAL - %s is listed on %s\n",query_address, rbl_name);
144 else
145 printf("DNS problem - %s\n",!strcmp(output,"")?" Probably a non-existent host/domain":output);
146
147 return result;
148}
149
150
151
152/* reverse the ipaddr */
153char *reverse_ipaddr(char *ipaddr)
154{
155 static char revip[MAX_HOST_ADDRESS_LENGTH];
156 int a, b, c, d;
157
158 if (strlen(ipaddr) >= MAX_HOST_ADDRESS_LENGTH ||
159 sscanf(ipaddr, "%d.%d.%d.%d", &a, &b, &c, &d) != 4) {
160 usage("IP address invalid or too long");
161 }
162 sprintf(revip, "%d.%d.%d.%d", d, c, b, a);
163
164 return revip;
165}
166
167
168
169/* process command-line arguments */
170int process_arguments(int argc, char **argv)
171{
172 int c;
173
174 if(argc<2)
175 return ERROR;
176
177
178 c=0;
179 while((c+=(call_getopt(argc-c,&argv[c])))<argc){
180
181 if (is_option(argv[c]))
182 continue;
183
184 if (query_address==NULL) {
185 if (is_host(argv[c])) {
186 query_address=argv[c];
187 } else {
188 usage("Invalid host name");
189 }
190 }
191 }
192
193 return validate_arguments();
194}
195
196
197
198int call_getopt(int argc, char **argv)
199{
200 int c,i=0;
201
202#ifdef HAVE_GETOPT_H
203 int option_index = 0;
204 static struct option long_options[] =
205 {
206 {"hostname", required_argument,0,'H'},
207 {"server", required_argument,0,'s'},
208 {"rblname", required_argument,0,'r'},
209 {"verbose", no_argument, 0,'v'},
210 {"version", no_argument, 0,'V'},
211 {"help", no_argument, 0,'h'},
212 {0,0,0,0}
213 };
214#endif
215
216 while (1){
217#ifdef HAVE_GETOPT_H
218 c = getopt_long(argc,argv,"+hVvt:s:H:r:",long_options,&option_index);
219#else
220 c = getopt(argc,argv,"+?hVvt:s:H:r:");
221#endif
222
223 i++;
224
225 if(c==-1||c==EOF||c==1)
226 break;
227
228 switch (c)
229 {
230 case 't':
231 case 'l':
232 case 'H':
233 i++;
234 }
235
236 switch (c)
237 {
238 case 'H': /* hostname */
239 if (is_host(optarg)) {
240 query_address=optarg;
241 } else {
242 usage("Invalid host name (-H)\n");
243 }
244 break;
245 case 's': /* server */
246 if (is_host(optarg)) {
247 dns_server=optarg;
248 } else {
249 usage("Invalid host name (-s)\n");
250 }
251 break;
252 case 'r': /* rblname */
253 rbl_name=optarg;
254 break;
255 case 'v': /* verbose */
256 verbose=TRUE;
257 break;
258 case 't': /* timeout */
259 if (is_intnonneg(optarg)) {
260 timeout_interval=atoi(optarg);
261 } else {
262 usage("Time interval must be a nonnegative integer\n");
263 }
264 break;
265 case 'V': /* version */
266 print_revision(progname,"$Revision: 970 $");
267 exit(STATE_OK);
268 case 'h': /* help */
269 print_help();
270 exit(STATE_OK);
271 case '?': /* help */
272 printf (_("%s: Unknown argument: %s\n\n"), progname, optarg);
273 print_usage ();
274 exit (STATE_UNKNOWN);
275 }
276 }
277 return i;
278}
279
280
281
282int validate_arguments(void)
283{
284 if (query_address == NULL || rbl_name == NULL)
285 return ERROR;
286 else
287 return OK;
288}
289
290
291
292void print_help(void)
293{
294 print_revision(progname,"$Revision: 970 $");
295 printf
296 ("Copyright (c) 2000 Karl DeBisschop\n\n"
297 "This plugin uses dig to test whether the specified host is on any RBL lists.\n\n");
298 print_usage();
299 printf
300 ("\nOptions:\n"
301 " -H, --hostname=IPADDRESS\n"
302 " Check status of indicated host\n"
303 " -s, --server=STRING or IPADDRESS\n"
304 " DNS server to use\n"
305 " -r, --rblname=STRING\n"
306 " RBL domain name to use (e.g. relays.ordb.org)\n"
307 " -t, --timeout=INTEGER\n"
308 " Seconds before connection attempt times out (default: %d)\n"
309 " -v, --verbose\n"
310 " Print extra information (command-line use only)\n"
311 " -h, --help\n"
312 " Print detailed help screen\n"
313 " -V, --version\n"
314 " Print version information\n\n",
315 DEFAULT_SOCKET_TIMEOUT);
316 support();
317}
318
319
320
321void print_usage(void)
322{
323 printf
324 ("Usage: %s -H hostip -r rblname [-s server] [-t timeout] [-v]\n"
325 " %s --help\n"
326 " %s --version\n",
327 progname, progname, progname);
328}