diff options
| author | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2002-11-09 04:22:22 +0000 |
|---|---|---|
| committer | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2002-11-09 04:22:22 +0000 |
| commit | 6fa04c4a4954c34bd212a0f383fd1337d29a6cde (patch) | |
| tree | 58fd91d3392a9ef0790d5ca4051798c0d275b025 /plugins/check_dig.c | |
| parent | 62291c185489730733ac0902484bf7d385da0806 (diff) | |
| download | monitoring-plugins-6fa04c4a4954c34bd212a0f383fd1337d29a6cde.tar.gz | |
remove call_getopt
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@181 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/check_dig.c')
| -rw-r--r-- | plugins/check_dig.c | 115 |
1 files changed, 52 insertions, 63 deletions
diff --git a/plugins/check_dig.c b/plugins/check_dig.c index 384b380b..fcd5d0dd 100644 --- a/plugins/check_dig.c +++ b/plugins/check_dig.c | |||
| @@ -1,14 +1,24 @@ | |||
| 1 | /****************************************************************************** | 1 | /****************************************************************************** |
| 2 | * | 2 | * |
| 3 | * check_dig.c | 3 | * Program: SNMP plugin for Nagios |
| 4 | * | 4 | * License: GPL |
| 5 | * Program: dig plugin for Nagios | 5 | * |
| 6 | * License: GPL | 6 | * License Information: |
| 7 | * Copyright (c) 2000 | 7 | * |
| 8 | * | 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * $Id$ | 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * | 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | *****************************************************************************/ | 11 | * (at your option) any later version. |
| 12 | * | ||
| 13 | * This program is distributed in the hope that it will be useful, | ||
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 16 | * GNU General Public License for more details. | ||
| 17 | * | ||
| 18 | * You should have received a copy of the GNU General Public License | ||
| 19 | * along with this program; if not, write to the Free Software | ||
| 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
| 21 | *****************************************************************************/ | ||
| 12 | 22 | ||
| 13 | #include "config.h" | 23 | #include "config.h" |
| 14 | #include "common.h" | 24 | #include "common.h" |
| @@ -16,6 +26,11 @@ | |||
| 16 | #include "popen.h" | 26 | #include "popen.h" |
| 17 | 27 | ||
| 18 | #define PROGNAME "check_dig" | 28 | #define PROGNAME "check_dig" |
| 29 | #define REVISION "$Revision$" | ||
| 30 | #define COPYRIGHT "2000-2002" | ||
| 31 | #define AUTHOR "Karl DeBisschop" | ||
| 32 | #define EMAIL "karl@debisschop.net" | ||
| 33 | #define SUMMARY "Test the DNS service on the specified host using dig\n" | ||
| 19 | 34 | ||
| 20 | int process_arguments (int, char **); | 35 | int process_arguments (int, char **); |
| 21 | int call_getopt (int, char **); | 36 | int call_getopt (int, char **); |
| @@ -140,42 +155,6 @@ process_arguments (int argc, char **argv) | |||
| 140 | { | 155 | { |
| 141 | int c; | 156 | int c; |
| 142 | 157 | ||
| 143 | if (argc < 2) | ||
| 144 | return ERROR; | ||
| 145 | |||
| 146 | |||
| 147 | c = 0; | ||
| 148 | while ((c += (call_getopt (argc - c, &argv[c]))) < argc) { | ||
| 149 | |||
| 150 | if (is_option (argv[c])) | ||
| 151 | continue; | ||
| 152 | |||
| 153 | if (dns_server == NULL) { | ||
| 154 | if (is_host (argv[c])) { | ||
| 155 | dns_server = argv[c]; | ||
| 156 | } | ||
| 157 | else { | ||
| 158 | usage ("Invalid host name"); | ||
| 159 | } | ||
| 160 | } | ||
| 161 | } | ||
| 162 | |||
| 163 | if (dns_server == NULL) | ||
| 164 | dns_server = strscpy (NULL, "127.0.0.1"); | ||
| 165 | |||
| 166 | return validate_arguments (); | ||
| 167 | } | ||
| 168 | |||
| 169 | |||
| 170 | |||
| 171 | |||
| 172 | |||
| 173 | |||
| 174 | int | ||
| 175 | call_getopt (int argc, char **argv) | ||
| 176 | { | ||
| 177 | int c, i = 0; | ||
| 178 | |||
| 179 | #ifdef HAVE_GETOPT_H | 158 | #ifdef HAVE_GETOPT_H |
| 180 | int option_index = 0; | 159 | int option_index = 0; |
| 181 | static struct option long_options[] = { | 160 | static struct option long_options[] = { |
| @@ -188,26 +167,22 @@ call_getopt (int argc, char **argv) | |||
| 188 | }; | 167 | }; |
| 189 | #endif | 168 | #endif |
| 190 | 169 | ||
| 170 | if (argc < 2) | ||
| 171 | return ERROR; | ||
| 172 | |||
| 191 | while (1) { | 173 | while (1) { |
| 192 | #ifdef HAVE_GETOPT_H | 174 | #ifdef HAVE_GETOPT_H |
| 193 | c = getopt_long (argc, argv, "+hVvt:l:H:", long_options, &option_index); | 175 | c = getopt_long (argc, argv, "hVvt:l:H:", long_options, &option_index); |
| 194 | #else | 176 | #else |
| 195 | c = getopt (argc, argv, "+?hVvt:l:H:"); | 177 | c = getopt (argc, argv, "hVvt:l:H:"); |
| 196 | #endif | 178 | #endif |
| 197 | 179 | ||
| 198 | i++; | 180 | if (c == -1 || c == EOF) |
| 199 | |||
| 200 | if (c == -1 || c == EOF || c == 1) | ||
| 201 | break; | 181 | break; |
| 202 | 182 | ||
| 203 | switch (c) { | 183 | switch (c) { |
| 204 | case 't': | 184 | case '?': /* help */ |
| 205 | case 'l': | 185 | usage3 ("Unknown argument", optopt); |
| 206 | case 'H': | ||
| 207 | i++; | ||
| 208 | } | ||
| 209 | |||
| 210 | switch (c) { | ||
| 211 | case 'H': /* hostname */ | 186 | case 'H': /* hostname */ |
| 212 | if (is_host (optarg)) { | 187 | if (is_host (optarg)) { |
| 213 | dns_server = optarg; | 188 | dns_server = optarg; |
| @@ -236,11 +211,25 @@ call_getopt (int argc, char **argv) | |||
| 236 | case 'h': /* help */ | 211 | case 'h': /* help */ |
| 237 | print_help (); | 212 | print_help (); |
| 238 | exit (STATE_OK); | 213 | exit (STATE_OK); |
| 239 | case '?': /* help */ | ||
| 240 | usage ("Invalid argument\n"); | ||
| 241 | } | 214 | } |
| 242 | } | 215 | } |
| 243 | return i; | 216 | |
| 217 | c = optind; | ||
| 218 | if (dns_server == NULL) { | ||
| 219 | if (c < argc) { | ||
| 220 | if (is_host (argv[c])) { | ||
| 221 | dns_server = argv[c]; | ||
| 222 | } | ||
| 223 | else { | ||
| 224 | usage ("Invalid host name"); | ||
| 225 | } | ||
| 226 | } | ||
| 227 | else { | ||
| 228 | dns_server = strscpy (NULL, "127.0.0.1"); | ||
| 229 | } | ||
| 230 | } | ||
| 231 | |||
| 232 | return validate_arguments (); | ||
| 244 | } | 233 | } |
| 245 | 234 | ||
| 246 | 235 | ||
| @@ -262,8 +251,8 @@ print_help (void) | |||
| 262 | { | 251 | { |
| 263 | print_revision (PROGNAME, "$Revision$"); | 252 | print_revision (PROGNAME, "$Revision$"); |
| 264 | printf | 253 | printf |
| 265 | ("Copyright (c) 2000 Karl DeBisschop\n\n" | 254 | ("Copyright (c) %s %s <%s>\n\n%s\n", |
| 266 | "This plugin use dig to test the DNS service on the specified host.\n\n"); | 255 | COPYRIGHT, AUTHOR, EMAIL, SUMMARY); |
| 267 | print_usage (); | 256 | print_usage (); |
| 268 | printf | 257 | printf |
| 269 | ("\nOptions:\n" | 258 | ("\nOptions:\n" |
