Merge branch 'master' of https://github.com/cern-mig/nagios-plugins
[monitoring-plugins.git] / plugins / common.h
blobc0dc2f41935a5ba2b71fca58d727b32fd85e96ae
1 /*****************************************************************************
2 *
3 * Nagios plugins common include file
4 *
5 * License: GPL
6 * Copyright (c) 1999 Ethan Galstad (nagios@nagios.org)
7 * Copyright (c) 2003-2007 Nagios Plugins Development Team
8 *
9 * Description:
11 * This file contains common include files and defines used in many of
12 * the plugins.
15 * This program is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation, either version 3 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program. If not, see <http://www.gnu.org/licenses/>.
29 *****************************************************************************/
31 #ifndef _COMMON_H_
32 #define _COMMON_H_
34 #include "config.h"
36 #ifdef HAVE_FEATURES_H
37 #include <features.h>
38 #endif
40 #include <stdio.h> /* obligatory includes */
41 #include <stdlib.h>
42 #include <errno.h>
44 /* This block provides uintmax_t - should be reported to coreutils that this should be added to fsuage.h */
45 #if HAVE_INTTYPES_H
46 # include <inttypes.h>
47 #endif
48 #if HAVE_STDINT_H
49 # include <stdint.h>
50 #endif
51 #include <unistd.h>
52 #ifndef UINTMAX_MAX
53 # define UINTMAX_MAX ((uintmax_t) -1)
54 #endif
56 #include <limits.h> /* This is assumed true, because coreutils assume it too */
58 #ifdef HAVE_MATH_H
59 #include <math.h>
60 #endif
62 #ifdef _AIX
63 #ifdef HAVE_MP_H
64 #include <mp.h>
65 #endif
66 #endif
68 #ifdef HAVE_STRINGS_H
69 #include <strings.h>
70 #endif
71 #ifdef HAVE_STRING_H
72 #include <string.h>
73 #endif
75 #ifdef HAVE_UNISTD_H
76 #include <unistd.h>
77 #endif
79 /* GET_NUMBER_OF_CPUS is a macro to return
80 number of CPUs, if we can get that data.
81 Use configure.in to test for various OS ways of
82 getting that data
83 Will return -1 if cannot get data
85 #ifdef HAVE_SYSCONF__SC_NPROCESSORS_CONF
86 #define GET_NUMBER_OF_CPUS() sysconf(_SC_NPROCESSORS_CONF)
87 #else
88 #define GET_NUMBER_OF_CPUS() -1
89 #endif
91 #ifdef TIME_WITH_SYS_TIME
92 # include <sys/time.h>
93 # include <time.h>
94 #else
95 # ifdef HAVE_SYS_TIME_H
96 # include <sys/time.h>
97 # else
98 # include <time.h>
99 # endif
100 #endif
102 #ifdef HAVE_SYS_TYPES_H
103 #include <sys/types.h>
104 #endif
106 #ifdef HAVE_SYS_SOCKET_H
107 #include <sys/socket.h>
108 #endif
110 #ifdef HAVE_SIGNAL_H
111 #include <signal.h>
112 #endif
114 /* GNU Libraries */
115 #include <getopt.h>
116 #include "dirname.h"
118 #ifdef HAVE_LOCALE_H
119 #include <locale.h>
120 #endif
122 #ifdef HAVE_SYS_POLL_H
123 # include "sys/poll.h"
124 #endif
128 * Missing Functions
132 #ifndef HAVE_STRTOL
133 # define strtol(a,b,c) atol((a))
134 #endif
136 #ifndef HAVE_STRTOUL
137 # define strtoul(a,b,c) (unsigned long)atol((a))
138 #endif
140 /* SSL implementations */
141 #ifdef HAVE_GNUTLS_OPENSSL_H
142 # include <gnutls/openssl.h>
143 #else
144 # define OPENSSL_LOAD_CONF /* See the OPENSSL_config(3) man page. */
145 # ifdef HAVE_SSL_H
146 # include <rsa.h>
147 # include <crypto.h>
148 # include <x509.h>
149 # include <pem.h>
150 # include <ssl.h>
151 # include <err.h>
152 # else
153 # ifdef HAVE_OPENSSL_SSL_H
154 # include <openssl/rsa.h>
155 # include <openssl/crypto.h>
156 # include <openssl/x509.h>
157 # include <openssl/pem.h>
158 # include <openssl/ssl.h>
159 # include <openssl/err.h>
160 # endif
161 # endif
162 #endif
166 * Standard Values
170 enum {
171 OK = 0,
172 ERROR = -1
175 /* AIX seems to have this defined somewhere else */
176 #ifndef FALSE
177 enum {
178 FALSE,
179 TRUE
181 #endif
183 enum {
184 STATE_OK,
185 STATE_WARNING,
186 STATE_CRITICAL,
187 STATE_UNKNOWN,
188 STATE_DEPENDENT
191 enum {
192 DEFAULT_SOCKET_TIMEOUT = 10, /* timeout after 10 seconds */
193 MAX_INPUT_BUFFER = 8192, /* max size of most buffers we use */
194 MAX_HOST_ADDRESS_LENGTH = 256 /* max size of a host address */
199 * Internationalization
202 #include "gettext.h"
203 #define _(String) gettext (String)
204 #if ! ENABLE_NLS
205 # undef textdomain
206 # define textdomain(Domainname) /* empty */
207 # undef bindtextdomain
208 # define bindtextdomain(Domainname, Dirname) /* empty */
209 #endif
211 /* For non-GNU compilers to ignore __attribute__ */
212 #ifndef __GNUC__
213 # define __attribute__(x) /* do nothing */
214 #endif
216 #endif /* _COMMON_H_ */