Code

The "-e" option now accepts a comma-delimited list of expected status
[nagiosplug.git] / plugins / common.h
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 * Last Modified: $Date$
10
11 * Description:
12
13 * This file contains common include files and defines used in many of
14 * the plugins.
15
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 3 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, see <http://www.gnu.org/licenses/>.
29
30 * $Id$
31
32 *****************************************************************************/
34 #ifndef _COMMON_H_
35 #define _COMMON_H_
37 #include "config.h"
39 #ifdef HAVE_FEATURES_H
40 #include <features.h>
41 #endif
43 #include <stdio.h>                                                      /* obligatory includes */
44 #include <stdlib.h>
45 #include <errno.h>
47 /* This block provides uintmax_t - should be reported to coreutils that this should be added to fsuage.h */
48 #if HAVE_INTTYPES_H
49 # include <inttypes.h>
50 #endif
51 #if HAVE_STDINT_H
52 # include <stdint.h>
53 #endif
54 #include <unistd.h>
55 #ifndef UINTMAX_MAX
56 # define UINTMAX_MAX ((uintmax_t) -1)
57 #endif
59 #include <limits.h>     /* This is assumed true, because coreutils assume it too */
61 #ifdef HAVE_MATH_H
62 #include <math.h>
63 #endif
65 #ifdef HAVE_STRINGS_H
66 #include <strings.h>
67 #endif
68 #ifdef HAVE_STRING_H
69 #include <string.h>
70 #endif
72 #ifdef HAVE_UNISTD_H
73 #include <unistd.h>
74 #endif
76 /* GET_NUMBER_OF_CPUS is a macro to return 
77    number of CPUs, if we can get that data.
78    Use configure.in to test for various OS ways of
79    getting that data
80    Will return -1 if cannot get data
81 */
82 #ifdef HAVE_SYSCONF__SC_NPROCESSORS_CONF 
83 #define GET_NUMBER_OF_CPUS() sysconf(_SC_NPROCESSORS_CONF)
84 #else
85 #define GET_NUMBER_OF_CPUS() -1
86 #endif
88 #ifdef TIME_WITH_SYS_TIME
89 # include <sys/time.h>
90 # include <time.h>
91 #else
92 # ifdef HAVE_SYS_TIME_H
93 #  include <sys/time.h>
94 # else
95 #  include <time.h>
96 # endif
97 #endif
99 #ifdef HAVE_SYS_TYPES_H
100 #include <sys/types.h>
101 #endif
103 #ifdef HAVE_SYS_SOCKET_H
104 #include <sys/socket.h>
105 #endif
107 #ifdef HAVE_SIGNAL_H
108 #include <signal.h>
109 #endif
111 /* GNU Libraries */
112 #include <getopt.h>
113 #include "dirname.h"
115 #ifdef HAVE_LOCALE_H
116 #include <locale.h>
117 #endif
119 #ifdef HAVE_SYS_POLL_H
120 # include "sys/poll.h"
121 #endif
123 /*
124  *
125  * Missing Functions
126  *
127  */
129 #ifndef HAVE_STRTOL
130 # define strtol(a,b,c) atol((a))
131 #endif
133 #ifndef HAVE_STRTOUL
134 # define strtoul(a,b,c) (unsigned long)atol((a))
135 #endif
137 /* SSL implementations */
138 #ifdef HAVE_GNUTLS_OPENSSL_H
139 #  include <gnutls/openssl.h>
140 #else
141 #  ifdef HAVE_SSL_H
142 #    include <rsa.h>
143 #    include <crypto.h>
144 #    include <x509.h>
145 #    include <pem.h>
146 #    include <ssl.h>
147 #    include <err.h>
148 #  else
149 #    ifdef HAVE_OPENSSL_SSL_H
150 #      include <openssl/rsa.h>
151 #      include <openssl/crypto.h>
152 #      include <openssl/x509.h>
153 #      include <openssl/pem.h>
154 #      include <openssl/ssl.h>
155 #      include <openssl/err.h>
156 #    endif
157 #  endif
158 #endif
160 /*
161  *
162  * Standard Values
163  *
164  */
166 enum {
167         OK = 0,
168         ERROR = -1
169 };
171 /* AIX seems to have this defined somewhere else */
172 #ifndef FALSE
173 enum {
174         FALSE,
175         TRUE
176 };
177 #endif
179 enum {
180         STATE_OK,
181         STATE_WARNING,
182         STATE_CRITICAL,
183         STATE_UNKNOWN,
184         STATE_DEPENDENT
185 };
187 enum {
188         DEFAULT_SOCKET_TIMEOUT = 10,     /* timeout after 10 seconds */
189         MAX_INPUT_BUFFER = 8192,             /* max size of most buffers we use */
190         MAX_HOST_ADDRESS_LENGTH = 256    /* max size of a host address */
191 };
193 /*
194  *
195  * Internationalization
196  *
197  */
198 #include "gettext.h"
199 #define _(String) gettext (String)
200 #if ! ENABLE_NLS
201 # undef textdomain
202 # define textdomain(Domainname) /* empty */
203 # undef bindtextdomain
204 # define bindtextdomain(Domainname, Dirname) /* empty */
205 #endif
207 /* For non-GNU compilers to ignore __attribute__ */
208 #ifndef __GNUC__
209 # define __attribute__(x) /* do nothing */
210 #endif
212 #endif /* _COMMON_H_ */