Code

check_load can optionally divide by number of cpus
[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  *
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  * $Id$
32  *
33  *****************************************************************************/
35 #ifndef _COMMON_H_
36 #define _COMMON_H_
38 #include "config.h"
39 /* This needs to be removed for Solaris servers, where 64 bit files, but 32 bit architecture
40    This needs to be done early on because subsequent system includes use _FILE_OFFSET_BITS
41    Cannot remove from config.h because is included by regex.c from lib/ */
42 #if __sun__ && !defined(_LP64) && _FILE_OFFSET_BITS == 64
43 #undef _FILE_OFFSET_BITS
44 #endif
46 #ifdef HAVE_FEATURES_H
47 #include <features.h>
48 #endif
50 #include <stdio.h>                                                      /* obligatory includes */
51 #include <stdlib.h>
52 #include <errno.h>
54 /* This block provides uintmax_t - should be reported to coreutils that this should be added to fsuage.h */
55 #if HAVE_INTTYPES_H
56 # include <inttypes.h>
57 #endif
58 #if HAVE_STDINT_H
59 # include <stdint.h>
60 #endif
61 #include <unistd.h>
62 #ifndef UINTMAX_MAX
63 # define UINTMAX_MAX ((uintmax_t) -1)
64 #endif
66 #include <limits.h>     /* This is assumed true, because coreutils assume it too */
68 #ifdef HAVE_MATH_H
69 #include <math.h>
70 #endif
72 #ifdef HAVE_STRINGS_H
73 #include <strings.h>
74 #endif
75 #ifdef HAVE_STRING_H
76 #include <string.h>
77 #endif
79 #ifdef HAVE_UNISTD_H
80 #include <unistd.h>
81 #endif
83 /* GET_NUMBER_OF_CPUS is a macro to return 
84    number of CPUs, if we can get that data.
85    Use configure.in to test for various OS ways of
86    getting that data
87    Will return -1 if cannot get data
88 */
89 #ifdef HAVE_SYSCONF__SC_NPROCESSORS_CONF 
90 #define GET_NUMBER_OF_CPUS() sysconf(_SC_NPROCESSORS_CONF)
91 #else
92 #define GET_NUMBER_OF_CPUS() -1
93 #endif
95 #ifdef TIME_WITH_SYS_TIME
96 # include <sys/time.h>
97 # include <time.h>
98 #else
99 # ifdef HAVE_SYS_TIME_H
100 #  include <sys/time.h>
101 # else
102 #  include <time.h>
103 # endif
104 #endif
106 #ifdef HAVE_SYS_TYPES_H
107 #include <sys/types.h>
108 #endif
110 #ifdef HAVE_SYS_SOCKET_H
111 #include <sys/socket.h>
112 #endif
114 #ifdef HAVE_SIGNAL_H
115 #include <signal.h>
116 #endif
118 /* GNU Libraries */
119 #include <getopt.h>
120 #include "dirname.h"
121 #include "vasprintf.h"
122 #include "snprintf.h"
123 #include "vsnprintf.h"
125 #ifdef HAVE_LOCALE_H
126 #include <locale.h>
127 #endif
129 #ifdef HAVE_SYS_POLL_H
130 # include "sys/poll.h"
131 #endif
133 /*
134  *
135  * Missing Functions
136  *
137  */
139 #ifndef HAVE_STRTOL
140 # define strtol(a,b,c) atol((a))
141 #endif
143 #ifndef HAVE_STRTOUL
144 # define strtoul(a,b,c) (unsigned long)atol((a))
145 #endif
147 /* SSL implementations */
148 #ifdef HAVE_GNUTLS_OPENSSL_H
149 #  include <gnutls/openssl.h>
150 #else
151 #  ifdef HAVE_SSL_H
152 #    include <rsa.h>
153 #    include <crypto.h>
154 #    include <x509.h>
155 #    include <pem.h>
156 #    include <ssl.h>
157 #    include <err.h>
158 #  else
159 #    ifdef HAVE_OPENSSL_SSL_H
160 #      include <openssl/rsa.h>
161 #      include <openssl/crypto.h>
162 #      include <openssl/x509.h>
163 #      include <openssl/pem.h>
164 #      include <openssl/ssl.h>
165 #      include <openssl/err.h>
166 #    endif
167 #  endif
168 #endif
170 /*
171  *
172  * Standard Values
173  *
174  */
176 enum {
177         OK = 0,
178         ERROR = -1
179 };
181 /* AIX seems to have this defined somewhere else */
182 #ifndef FALSE
183 enum {
184         FALSE,
185         TRUE
186 };
187 #endif
189 /* Solaris does not have floorf, but floor works. Should probably be in configure */
190 #if defined(__sun) || defined(__sun__)
191 static inline float floorf (float x) { return floor(x); }
192 #endif
194 enum {
195         STATE_OK,
196         STATE_WARNING,
197         STATE_CRITICAL,
198         STATE_UNKNOWN,
199         STATE_DEPENDENT
200 };
202 enum {
203         DEFAULT_SOCKET_TIMEOUT = 10,     /* timeout after 10 seconds */
204         MAX_INPUT_BUFFER = 8192,             /* max size of most buffers we use */
205         MAX_HOST_ADDRESS_LENGTH = 256    /* max size of a host address */
206 };
208 /*
209  *
210  * Internationalization
211  *
212  */
213 #include "gettext.h"
214 #define _(String) gettext (String)
215 #if ! ENABLE_NLS
216 # undef textdomain
217 # define textdomain(Domainname) /* empty */
218 # undef bindtextdomain
219 # define bindtextdomain(Domainname, Dirname) /* empty */
220 #endif
222 /* For non-GNU compilers to ignore __attribute__ */
223 #ifndef __GNUC__
224 # define __attribute__(x) /* do nothing */
225 #endif
227 #endif /* _COMMON_H_ */