diff options
Diffstat (limited to 'plugins/common.h')
| -rw-r--r-- | plugins/common.h | 186 |
1 files changed, 186 insertions, 0 deletions
diff --git a/plugins/common.h b/plugins/common.h new file mode 100644 index 00000000..56d53761 --- /dev/null +++ b/plugins/common.h | |||
| @@ -0,0 +1,186 @@ | |||
| 1 | /****************************************************************************** | ||
| 2 | * | ||
| 3 | * Nagios plugins common include file | ||
| 4 | * | ||
| 5 | * License: GPL | ||
| 6 | * Copyright (c) 1999 Ethan Galstad (nagios@nagios.org) | ||
| 7 | * | ||
| 8 | * Last Modified: 11-05-1999 | ||
| 9 | * | ||
| 10 | * Description: | ||
| 11 | * | ||
| 12 | * This file contains common include files and defines used in many of | ||
| 13 | * the plugins. | ||
| 14 | * | ||
| 15 | * License Information: | ||
| 16 | * | ||
| 17 | * This program is free software; you can redistribute it and/or modify | ||
| 18 | * it under the terms of the GNU General Public License as published by | ||
| 19 | * the Free Software Foundation; either version 2 of the License, or | ||
| 20 | * (at your option) any later version. | ||
| 21 | * | ||
| 22 | * This program is distributed in the hope that it will be useful, | ||
| 23 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 25 | * GNU General Public License for more details. | ||
| 26 | * | ||
| 27 | * You should have received a copy of the GNU General Public License | ||
| 28 | * along with this program; if not, write to the Free Software | ||
| 29 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
| 30 | * | ||
| 31 | *****************************************************************************/ | ||
| 32 | |||
| 33 | #include <stdio.h> /* obligatory includes */ | ||
| 34 | #include <stdlib.h> | ||
| 35 | #include <errno.h> | ||
| 36 | |||
| 37 | #include "config.h" | ||
| 38 | |||
| 39 | #ifdef HAVE_STRINGS_H | ||
| 40 | #include <strings.h> | ||
| 41 | #endif | ||
| 42 | #ifdef HAVE_STRING_H | ||
| 43 | #include <string.h> | ||
| 44 | #endif | ||
| 45 | |||
| 46 | #ifdef HAVE_UNISTD_H | ||
| 47 | #include <unistd.h> | ||
| 48 | #endif | ||
| 49 | |||
| 50 | #ifdef TIME_WITH_SYS_TIME | ||
| 51 | # include <sys/time.h> | ||
| 52 | # include <time.h> | ||
| 53 | #else | ||
| 54 | # ifdef HAVE_SYS_TIME_H | ||
| 55 | # include <sys/time.h> | ||
| 56 | # else | ||
| 57 | # include <time.h> | ||
| 58 | # endif | ||
| 59 | #endif | ||
| 60 | |||
| 61 | #ifdef HAVE_SYS_TYPES_H | ||
| 62 | #include <sys/types.h> | ||
| 63 | #endif | ||
| 64 | |||
| 65 | #ifdef HAVE_SYS_SOCKET_H | ||
| 66 | #include <sys/socket.h> | ||
| 67 | #endif | ||
| 68 | |||
| 69 | #ifdef HAVE_SIGNAL_H | ||
| 70 | #include <signal.h> | ||
| 71 | #endif | ||
| 72 | |||
| 73 | /* TODO: define can be removed when all ifdef in each plugin has been removed */ | ||
| 74 | #define HAVE_GETOPT_H | ||
| 75 | #include <getopt.h> | ||
| 76 | |||
| 77 | #include <ctype.h> | ||
| 78 | |||
| 79 | #if HAVE_LWRES_NETDB_H | ||
| 80 | #include <lwres/netdb.h> | ||
| 81 | #elif !HAVE_GETADDRINFO | ||
| 82 | #include "getaddrinfo.h" | ||
| 83 | #else | ||
| 84 | #include <netdb.h> | ||
| 85 | #endif | ||
| 86 | |||
| 87 | /* | ||
| 88 | * | ||
| 89 | * Missing Functions | ||
| 90 | * | ||
| 91 | */ | ||
| 92 | |||
| 93 | #ifndef HAVE_STRTOL | ||
| 94 | # define strtol(a,b,c) atol((a)) | ||
| 95 | #endif | ||
| 96 | |||
| 97 | #ifndef HAVE_STRTOUL | ||
| 98 | # define strtoul(a,b,c) (unsigned long)atol((a)) | ||
| 99 | #endif | ||
| 100 | |||
| 101 | #ifndef HAVE_ASPRINTF | ||
| 102 | int asprintf(char **strp, const char *fmt, ...); | ||
| 103 | #endif | ||
| 104 | |||
| 105 | #ifndef HAVE_VASPRINTF | ||
| 106 | /* int vasprintf(char **strp, const char *fmt, va_list ap); */ | ||
| 107 | #endif | ||
| 108 | |||
| 109 | #ifndef HAVE_SNPRINTF | ||
| 110 | int snprintf(char *str, size_t size, const char *format, ...); | ||
| 111 | #endif | ||
| 112 | |||
| 113 | #ifndef HAVE_VSNPRINTF | ||
| 114 | int vsnprintf(char *str, size_t size, const char *format, va_list ap); | ||
| 115 | #endif | ||
| 116 | |||
| 117 | /* | ||
| 118 | * | ||
| 119 | * Standard Values | ||
| 120 | * | ||
| 121 | */ | ||
| 122 | |||
| 123 | #define OK 0 | ||
| 124 | #define ERROR -1 | ||
| 125 | |||
| 126 | #define TRUE 1 | ||
| 127 | #define FALSE 0 | ||
| 128 | |||
| 129 | #define STATE_CRITICAL 2 /* service state return codes */ | ||
| 130 | #define STATE_WARNING 1 | ||
| 131 | #define STATE_OK 0 | ||
| 132 | #define STATE_UNKNOWN 3 | ||
| 133 | #define STATE_DEPENDENT 4 | ||
| 134 | |||
| 135 | #define DEFAULT_SOCKET_TIMEOUT 10 /* timeout after 10 seconds */ | ||
| 136 | |||
| 137 | #define MAX_INPUT_BUFFER 1024 /* max size of most buffers we use */ | ||
| 138 | |||
| 139 | #define MAX_HOST_ADDRESS_LENGTH 256 /* max size of a host address */ | ||
| 140 | |||
| 141 | |||
| 142 | #ifndef HAVE_SNPRINTF | ||
| 143 | /* | ||
| 144 | int snprintf (char *str, size_t n, const char *fmt, ...); | ||
| 145 | int snprintf (char *str, size_t n, const char *fmt, ...) | ||
| 146 | { | ||
| 147 | char *buf; | ||
| 148 | int i; | ||
| 149 | int j=0; | ||
| 150 | va_list ap; | ||
| 151 | int d; | ||
| 152 | char c, *p, *s; | ||
| 153 | |||
| 154 | if((buf=malloc(n))==NULL){ | ||
| 155 | puts("could not malloc snprintf buffer\n"); | ||
| 156 | exit(-1); | ||
| 157 | } | ||
| 158 | va_start(ap,fmt); | ||
| 159 | i=strlen(fmt); | ||
| 160 | while((jj=index(&fmt[j],'%'))){ | ||
| 161 | j+=jj+1; | ||
| 162 | switch fmt[j] | ||
| 163 | { | ||
| 164 | case 's': | ||
| 165 | s = va_arg(ap, char *); | ||
| 166 | i+=strlen(s); | ||
| 167 | break; | ||
| 168 | case 'd': | ||
| 169 | d = va_arg(ap, int); | ||
| 170 | i++; | ||
| 171 | if (d<0) i++; | ||
| 172 | while((d=d/10)>0) i++; | ||
| 173 | break; | ||
| 174 | case 'c': | ||
| 175 | c = va_arg(ap, char); | ||
| 176 | i++; | ||
| 177 | break; | ||
| 178 | } | ||
| 179 | } | ||
| 180 | va_end(ap); | ||
| 181 | vsprintf(buf,fmt,ap); | ||
| 182 | strcpy(str,buf[1:n-1]); | ||
| 183 | exit(result); | ||
| 184 | } | ||
| 185 | */ | ||
| 186 | #endif | ||
