diff options
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | configure.ac | 15 | ||||
| -rw-r--r-- | m4/libcurl.m4 | 272 | ||||
| -rw-r--r-- | plugins/Makefile.am | 5 | ||||
| -rw-r--r-- | plugins/check_curl.c | 168 |
5 files changed, 460 insertions, 1 deletions
| @@ -142,6 +142,7 @@ NP-VERSION-FILE | |||
| 142 | /plugins/check_by_ssh | 142 | /plugins/check_by_ssh |
| 143 | /plugins/check_clamd | 143 | /plugins/check_clamd |
| 144 | /plugins/check_cluster | 144 | /plugins/check_cluster |
| 145 | /plugins/check_curl | ||
| 145 | /plugins/check_dbi | 146 | /plugins/check_dbi |
| 146 | /plugins/check_dig | 147 | /plugins/check_dig |
| 147 | /plugins/check_disk | 148 | /plugins/check_disk |
diff --git a/configure.ac b/configure.ac index bf129956..04ec5bde 100644 --- a/configure.ac +++ b/configure.ac | |||
| @@ -385,6 +385,20 @@ if test "$ac_cv_header_wtsapi32_h" = "yes"; then | |||
| 385 | AC_SUBST(WTSAPI32LIBS) | 385 | AC_SUBST(WTSAPI32LIBS) |
| 386 | fi | 386 | fi |
| 387 | 387 | ||
| 388 | dnl Check for cURL library | ||
| 389 | LIBCURL_CHECK_CONFIG(yes, 7.15.2, [ | ||
| 390 | EXTRAS="$EXTRAS check_curl\$(EXEEXT)" | ||
| 391 | LIBCURLINCLUDE="$LIBCURL_CPPFLAGS" | ||
| 392 | LIBCURLLIBS="$LIBCURL" | ||
| 393 | LIBCURLCFLAGS="$LIBCURL_CPPFLAGS" | ||
| 394 | AC_SUBST(LIBCURLINCLUDE) | ||
| 395 | AC_SUBST(LIBCURLLIBS) | ||
| 396 | AC_SUBST(LIBCURLCFLAGS) | ||
| 397 | ], [ | ||
| 398 | AC_MSG_WARN([Skipping curl plugin]) | ||
| 399 | AC_MSG_WARN([install libcurl libs to compile this plugin (see REQUIREMENTS).]) | ||
| 400 | ]) | ||
| 401 | |||
| 388 | dnl Fallback to who(1) if the system doesn't provide an utmpx(5) interface | 402 | dnl Fallback to who(1) if the system doesn't provide an utmpx(5) interface |
| 389 | if test "$ac_cv_header_utmpx_h" = "no" -a "$ac_cv_header_wtsapi32_h" = "no" | 403 | if test "$ac_cv_header_utmpx_h" = "no" -a "$ac_cv_header_wtsapi32_h" = "no" |
| 390 | then | 404 | then |
| @@ -1882,4 +1896,5 @@ ACX_FEATURE([enable],[perl-modules]) | |||
| 1882 | ACX_FEATURE([with],[cgiurl]) | 1896 | ACX_FEATURE([with],[cgiurl]) |
| 1883 | ACX_FEATURE([with],[trusted-path]) | 1897 | ACX_FEATURE([with],[trusted-path]) |
| 1884 | ACX_FEATURE([enable],[libtap]) | 1898 | ACX_FEATURE([enable],[libtap]) |
| 1899 | ACX_FEATURE([with],[libcurl]) | ||
| 1885 | 1900 | ||
diff --git a/m4/libcurl.m4 b/m4/libcurl.m4 new file mode 100644 index 00000000..53d694d0 --- /dev/null +++ b/m4/libcurl.m4 | |||
| @@ -0,0 +1,272 @@ | |||
| 1 | #*************************************************************************** | ||
| 2 | # _ _ ____ _ | ||
| 3 | # Project ___| | | | _ \| | | ||
| 4 | # / __| | | | |_) | | | ||
| 5 | # | (__| |_| | _ <| |___ | ||
| 6 | # \___|\___/|_| \_\_____| | ||
| 7 | # | ||
| 8 | # Copyright (C) 2006, David Shaw <dshaw@jabberwocky.com> | ||
| 9 | # | ||
| 10 | # This software is licensed as described in the file COPYING, which | ||
| 11 | # you should have received as part of this distribution. The terms | ||
| 12 | # are also available at https://curl.haxx.se/docs/copyright.html. | ||
| 13 | # | ||
| 14 | # You may opt to use, copy, modify, merge, publish, distribute and/or sell | ||
| 15 | # copies of the Software, and permit persons to whom the Software is | ||
| 16 | # furnished to do so, under the terms of the COPYING file. | ||
| 17 | # | ||
| 18 | # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
| 19 | # KIND, either express or implied. | ||
| 20 | # | ||
| 21 | ########################################################################### | ||
| 22 | # LIBCURL_CHECK_CONFIG ([DEFAULT-ACTION], [MINIMUM-VERSION], | ||
| 23 | # [ACTION-IF-YES], [ACTION-IF-NO]) | ||
| 24 | # ---------------------------------------------------------- | ||
| 25 | # David Shaw <dshaw@jabberwocky.com> May-09-2006 | ||
| 26 | # | ||
| 27 | # Checks for libcurl. DEFAULT-ACTION is the string yes or no to | ||
| 28 | # specify whether to default to --with-libcurl or --without-libcurl. | ||
| 29 | # If not supplied, DEFAULT-ACTION is yes. MINIMUM-VERSION is the | ||
| 30 | # minimum version of libcurl to accept. Pass the version as a regular | ||
| 31 | # version number like 7.10.1. If not supplied, any version is | ||
| 32 | # accepted. ACTION-IF-YES is a list of shell commands to run if | ||
| 33 | # libcurl was successfully found and passed the various tests. | ||
| 34 | # ACTION-IF-NO is a list of shell commands that are run otherwise. | ||
| 35 | # Note that using --without-libcurl does run ACTION-IF-NO. | ||
| 36 | # | ||
| 37 | # This macro #defines HAVE_LIBCURL if a working libcurl setup is | ||
| 38 | # found, and sets @LIBCURL@ and @LIBCURL_CPPFLAGS@ to the necessary | ||
| 39 | # values. Other useful defines are LIBCURL_FEATURE_xxx where xxx are | ||
| 40 | # the various features supported by libcurl, and LIBCURL_PROTOCOL_yyy | ||
| 41 | # where yyy are the various protocols supported by libcurl. Both xxx | ||
| 42 | # and yyy are capitalized. See the list of AH_TEMPLATEs at the top of | ||
| 43 | # the macro for the complete list of possible defines. Shell | ||
| 44 | # variables $libcurl_feature_xxx and $libcurl_protocol_yyy are also | ||
| 45 | # defined to 'yes' for those features and protocols that were found. | ||
| 46 | # Note that xxx and yyy keep the same capitalization as in the | ||
| 47 | # curl-config list (e.g. it's "HTTP" and not "http"). | ||
| 48 | # | ||
| 49 | # Users may override the detected values by doing something like: | ||
| 50 | # LIBCURL="-lcurl" LIBCURL_CPPFLAGS="-I/usr/myinclude" ./configure | ||
| 51 | # | ||
| 52 | # For the sake of sanity, this macro assumes that any libcurl that is | ||
| 53 | # found is after version 7.7.2, the first version that included the | ||
| 54 | # curl-config script. Note that it is very important for people | ||
| 55 | # packaging binary versions of libcurl to include this script! | ||
| 56 | # Without curl-config, we can only guess what protocols are available, | ||
| 57 | # or use curl_version_info to figure it out at runtime. | ||
| 58 | |||
| 59 | AC_DEFUN([LIBCURL_CHECK_CONFIG], | ||
| 60 | [ | ||
| 61 | AH_TEMPLATE([LIBCURL_FEATURE_SSL],[Defined if libcurl supports SSL]) | ||
| 62 | AH_TEMPLATE([LIBCURL_FEATURE_KRB4],[Defined if libcurl supports KRB4]) | ||
| 63 | AH_TEMPLATE([LIBCURL_FEATURE_IPV6],[Defined if libcurl supports IPv6]) | ||
| 64 | AH_TEMPLATE([LIBCURL_FEATURE_LIBZ],[Defined if libcurl supports libz]) | ||
| 65 | AH_TEMPLATE([LIBCURL_FEATURE_ASYNCHDNS],[Defined if libcurl supports AsynchDNS]) | ||
| 66 | AH_TEMPLATE([LIBCURL_FEATURE_IDN],[Defined if libcurl supports IDN]) | ||
| 67 | AH_TEMPLATE([LIBCURL_FEATURE_SSPI],[Defined if libcurl supports SSPI]) | ||
| 68 | AH_TEMPLATE([LIBCURL_FEATURE_NTLM],[Defined if libcurl supports NTLM]) | ||
| 69 | |||
| 70 | AH_TEMPLATE([LIBCURL_PROTOCOL_HTTP],[Defined if libcurl supports HTTP]) | ||
| 71 | AH_TEMPLATE([LIBCURL_PROTOCOL_HTTPS],[Defined if libcurl supports HTTPS]) | ||
| 72 | AH_TEMPLATE([LIBCURL_PROTOCOL_FTP],[Defined if libcurl supports FTP]) | ||
| 73 | AH_TEMPLATE([LIBCURL_PROTOCOL_FTPS],[Defined if libcurl supports FTPS]) | ||
| 74 | AH_TEMPLATE([LIBCURL_PROTOCOL_FILE],[Defined if libcurl supports FILE]) | ||
| 75 | AH_TEMPLATE([LIBCURL_PROTOCOL_TELNET],[Defined if libcurl supports TELNET]) | ||
| 76 | AH_TEMPLATE([LIBCURL_PROTOCOL_LDAP],[Defined if libcurl supports LDAP]) | ||
| 77 | AH_TEMPLATE([LIBCURL_PROTOCOL_DICT],[Defined if libcurl supports DICT]) | ||
| 78 | AH_TEMPLATE([LIBCURL_PROTOCOL_TFTP],[Defined if libcurl supports TFTP]) | ||
| 79 | AH_TEMPLATE([LIBCURL_PROTOCOL_RTSP],[Defined if libcurl supports RTSP]) | ||
| 80 | AH_TEMPLATE([LIBCURL_PROTOCOL_POP3],[Defined if libcurl supports POP3]) | ||
| 81 | AH_TEMPLATE([LIBCURL_PROTOCOL_IMAP],[Defined if libcurl supports IMAP]) | ||
| 82 | AH_TEMPLATE([LIBCURL_PROTOCOL_SMTP],[Defined if libcurl supports SMTP]) | ||
| 83 | |||
| 84 | AC_ARG_WITH(libcurl, | ||
| 85 | AS_HELP_STRING([--with-libcurl=PREFIX],[look for the curl library in PREFIX/lib and headers in PREFIX/include]), | ||
| 86 | [_libcurl_with=$withval],[_libcurl_with=ifelse([$1],,[yes],[$1])]) | ||
| 87 | |||
| 88 | if test "$_libcurl_with" != "no" ; then | ||
| 89 | |||
| 90 | AC_PROG_AWK | ||
| 91 | |||
| 92 | _libcurl_version_parse="eval $AWK '{split(\$NF,A,\".\"); X=256*256*A[[1]]+256*A[[2]]+A[[3]]; print X;}'" | ||
| 93 | |||
| 94 | _libcurl_try_link=yes | ||
| 95 | |||
| 96 | if test -d "$_libcurl_with" ; then | ||
| 97 | LIBCURL_CPPFLAGS="-I$withval/include" | ||
| 98 | _libcurl_ldflags="-L$withval/lib" | ||
| 99 | AC_PATH_PROG([_libcurl_config],[curl-config],[], | ||
| 100 | ["$withval/bin"]) | ||
| 101 | else | ||
| 102 | AC_PATH_PROG([_libcurl_config],[curl-config],[],[$PATH]) | ||
| 103 | fi | ||
| 104 | |||
| 105 | if test x$_libcurl_config != "x" ; then | ||
| 106 | AC_CACHE_CHECK([for the version of libcurl], | ||
| 107 | [libcurl_cv_lib_curl_version], | ||
| 108 | [libcurl_cv_lib_curl_version=`$_libcurl_config --version | $AWK '{print $[]2}'`]) | ||
| 109 | |||
| 110 | _libcurl_version=`echo $libcurl_cv_lib_curl_version | $_libcurl_version_parse` | ||
| 111 | _libcurl_wanted=`echo ifelse([$2],,[0],[$2]) | $_libcurl_version_parse` | ||
| 112 | |||
| 113 | if test $_libcurl_wanted -gt 0 ; then | ||
| 114 | AC_CACHE_CHECK([for libcurl >= version $2], | ||
| 115 | [libcurl_cv_lib_version_ok], | ||
| 116 | [ | ||
| 117 | if test $_libcurl_version -ge $_libcurl_wanted ; then | ||
| 118 | libcurl_cv_lib_version_ok=yes | ||
| 119 | else | ||
| 120 | libcurl_cv_lib_version_ok=no | ||
| 121 | fi | ||
| 122 | ]) | ||
| 123 | fi | ||
| 124 | |||
| 125 | if test $_libcurl_wanted -eq 0 || test x$libcurl_cv_lib_version_ok = xyes ; then | ||
| 126 | if test x"$LIBCURL_CPPFLAGS" = "x" ; then | ||
| 127 | LIBCURL_CPPFLAGS=`$_libcurl_config --cflags` | ||
| 128 | fi | ||
| 129 | if test x"$LIBCURL" = "x" ; then | ||
| 130 | LIBCURL=`$_libcurl_config --libs` | ||
| 131 | |||
| 132 | # This is so silly, but Apple actually has a bug in their | ||
| 133 | # curl-config script. Fixed in Tiger, but there are still | ||
| 134 | # lots of Panther installs around. | ||
| 135 | case "${host}" in | ||
| 136 | powerpc-apple-darwin7*) | ||
| 137 | LIBCURL=`echo $LIBCURL | sed -e 's|-arch i386||g'` | ||
| 138 | ;; | ||
| 139 | esac | ||
| 140 | fi | ||
| 141 | |||
| 142 | # All curl-config scripts support --feature | ||
| 143 | _libcurl_features=`$_libcurl_config --feature` | ||
| 144 | |||
| 145 | # Is it modern enough to have --protocols? (7.12.4) | ||
| 146 | if test $_libcurl_version -ge 461828 ; then | ||
| 147 | _libcurl_protocols=`$_libcurl_config --protocols` | ||
| 148 | fi | ||
| 149 | else | ||
| 150 | _libcurl_try_link=no | ||
| 151 | fi | ||
| 152 | |||
| 153 | unset _libcurl_wanted | ||
| 154 | fi | ||
| 155 | |||
| 156 | if test $_libcurl_try_link = yes ; then | ||
| 157 | |||
| 158 | # we didn't find curl-config, so let's see if the user-supplied | ||
| 159 | # link line (or failing that, "-lcurl") is enough. | ||
| 160 | LIBCURL=${LIBCURL-"$_libcurl_ldflags -lcurl"} | ||
| 161 | |||
| 162 | AC_CACHE_CHECK([whether libcurl is usable], | ||
| 163 | [libcurl_cv_lib_curl_usable], | ||
| 164 | [ | ||
| 165 | _libcurl_save_cppflags=$CPPFLAGS | ||
| 166 | CPPFLAGS="$LIBCURL_CPPFLAGS $CPPFLAGS" | ||
| 167 | _libcurl_save_libs=$LIBS | ||
| 168 | LIBS="$LIBCURL $LIBS" | ||
| 169 | |||
| 170 | AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <curl/curl.h>]],[[ | ||
| 171 | /* Try and use a few common options to force a failure if we are | ||
| 172 | missing symbols or can't link. */ | ||
| 173 | int x; | ||
| 174 | curl_easy_setopt(NULL,CURLOPT_URL,NULL); | ||
| 175 | x=CURL_ERROR_SIZE; | ||
| 176 | x=CURLOPT_WRITEFUNCTION; | ||
| 177 | x=CURLOPT_WRITEDATA; | ||
| 178 | x=CURLOPT_ERRORBUFFER; | ||
| 179 | x=CURLOPT_STDERR; | ||
| 180 | x=CURLOPT_VERBOSE; | ||
| 181 | if (x) {;} | ||
| 182 | ]])],libcurl_cv_lib_curl_usable=yes,libcurl_cv_lib_curl_usable=no) | ||
| 183 | |||
| 184 | CPPFLAGS=$_libcurl_save_cppflags | ||
| 185 | LIBS=$_libcurl_save_libs | ||
| 186 | unset _libcurl_save_cppflags | ||
| 187 | unset _libcurl_save_libs | ||
| 188 | ]) | ||
| 189 | |||
| 190 | if test $libcurl_cv_lib_curl_usable = yes ; then | ||
| 191 | |||
| 192 | # Does curl_free() exist in this version of libcurl? | ||
| 193 | # If not, fake it with free() | ||
| 194 | |||
| 195 | _libcurl_save_cppflags=$CPPFLAGS | ||
| 196 | CPPFLAGS="$CPPFLAGS $LIBCURL_CPPFLAGS" | ||
| 197 | _libcurl_save_libs=$LIBS | ||
| 198 | LIBS="$LIBS $LIBCURL" | ||
| 199 | |||
| 200 | AC_CHECK_FUNC(curl_free,, | ||
| 201 | AC_DEFINE(curl_free,free, | ||
| 202 | [Define curl_free() as free() if our version of curl lacks curl_free.])) | ||
| 203 | |||
| 204 | CPPFLAGS=$_libcurl_save_cppflags | ||
| 205 | LIBS=$_libcurl_save_libs | ||
| 206 | unset _libcurl_save_cppflags | ||
| 207 | unset _libcurl_save_libs | ||
| 208 | |||
| 209 | AC_DEFINE(HAVE_LIBCURL,1, | ||
| 210 | [Define to 1 if you have a functional curl library.]) | ||
| 211 | AC_SUBST(LIBCURL_CPPFLAGS) | ||
| 212 | AC_SUBST(LIBCURL) | ||
| 213 | |||
| 214 | for _libcurl_feature in $_libcurl_features ; do | ||
| 215 | AC_DEFINE_UNQUOTED(AS_TR_CPP(libcurl_feature_$_libcurl_feature),[1]) | ||
| 216 | eval AS_TR_SH(libcurl_feature_$_libcurl_feature)=yes | ||
| 217 | done | ||
| 218 | |||
| 219 | if test "x$_libcurl_protocols" = "x" ; then | ||
| 220 | |||
| 221 | # We don't have --protocols, so just assume that all | ||
| 222 | # protocols are available | ||
| 223 | _libcurl_protocols="HTTP FTP FILE TELNET LDAP DICT TFTP" | ||
| 224 | |||
| 225 | if test x$libcurl_feature_SSL = xyes ; then | ||
| 226 | _libcurl_protocols="$_libcurl_protocols HTTPS" | ||
| 227 | |||
| 228 | # FTPS wasn't standards-compliant until version | ||
| 229 | # 7.11.0 (0x070b00 == 461568) | ||
| 230 | if test $_libcurl_version -ge 461568; then | ||
| 231 | _libcurl_protocols="$_libcurl_protocols FTPS" | ||
| 232 | fi | ||
| 233 | fi | ||
| 234 | |||
| 235 | # RTSP, IMAP, POP3 and SMTP were added in | ||
| 236 | # 7.20.0 (0x071400 == 463872) | ||
| 237 | if test $_libcurl_version -ge 463872; then | ||
| 238 | _libcurl_protocols="$_libcurl_protocols RTSP IMAP POP3 SMTP" | ||
| 239 | fi | ||
| 240 | fi | ||
| 241 | |||
| 242 | for _libcurl_protocol in $_libcurl_protocols ; do | ||
| 243 | AC_DEFINE_UNQUOTED(AS_TR_CPP(libcurl_protocol_$_libcurl_protocol),[1]) | ||
| 244 | eval AS_TR_SH(libcurl_protocol_$_libcurl_protocol)=yes | ||
| 245 | done | ||
| 246 | else | ||
| 247 | unset LIBCURL | ||
| 248 | unset LIBCURL_CPPFLAGS | ||
| 249 | fi | ||
| 250 | fi | ||
| 251 | |||
| 252 | unset _libcurl_try_link | ||
| 253 | unset _libcurl_version_parse | ||
| 254 | unset _libcurl_config | ||
| 255 | unset _libcurl_feature | ||
| 256 | unset _libcurl_features | ||
| 257 | unset _libcurl_protocol | ||
| 258 | unset _libcurl_protocols | ||
| 259 | unset _libcurl_version | ||
| 260 | unset _libcurl_ldflags | ||
| 261 | fi | ||
| 262 | |||
| 263 | if test x$_libcurl_with = xno || test x$libcurl_cv_lib_curl_usable != xyes ; then | ||
| 264 | # This is the IF-NO path | ||
| 265 | ifelse([$4],,:,[$4]) | ||
| 266 | else | ||
| 267 | # This is the IF-YES path | ||
| 268 | ifelse([$3],,:,[$3]) | ||
| 269 | fi | ||
| 270 | |||
| 271 | unset _libcurl_with | ||
| 272 | ])dnl | ||
diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 0ddf9bd1..2c87b4e1 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am | |||
| @@ -38,7 +38,7 @@ check_tcp_programs = check_ftp check_imap check_nntp check_pop \ | |||
| 38 | EXTRA_PROGRAMS = check_mysql check_radius check_pgsql check_snmp check_hpjd \ | 38 | EXTRA_PROGRAMS = check_mysql check_radius check_pgsql check_snmp check_hpjd \ |
| 39 | check_swap check_fping check_ldap check_game check_dig \ | 39 | check_swap check_fping check_ldap check_game check_dig \ |
| 40 | check_nagios check_by_ssh check_dns check_nt check_ide_smart \ | 40 | check_nagios check_by_ssh check_dns check_nt check_ide_smart \ |
| 41 | check_procs check_mysql_query check_apt check_dbi | 41 | check_procs check_mysql_query check_apt check_dbi check_curl |
| 42 | 42 | ||
| 43 | EXTRA_DIST = t tests | 43 | EXTRA_DIST = t tests |
| 44 | 44 | ||
| @@ -69,6 +69,9 @@ test-debug: | |||
| 69 | 69 | ||
| 70 | check_apt_LDADD = $(BASEOBJS) | 70 | check_apt_LDADD = $(BASEOBJS) |
| 71 | check_cluster_LDADD = $(BASEOBJS) | 71 | check_cluster_LDADD = $(BASEOBJS) |
| 72 | check_curl_CFLAGS = $(AM_CFLAGS) $(LIBCURLCFLAGS) | ||
| 73 | check_curl_CPPFLAGS = $(AM_CPPFLAGS) $(LIBCURLINCLUDE) | ||
| 74 | check_curl_LDADD = $(NETLIBS) $(LIBCURLLIBS) | ||
| 72 | check_dbi_LDADD = $(NETLIBS) $(DBILIBS) | 75 | check_dbi_LDADD = $(NETLIBS) $(DBILIBS) |
| 73 | check_dig_LDADD = $(NETLIBS) | 76 | check_dig_LDADD = $(NETLIBS) |
| 74 | check_disk_LDADD = $(BASEOBJS) | 77 | check_disk_LDADD = $(BASEOBJS) |
diff --git a/plugins/check_curl.c b/plugins/check_curl.c new file mode 100644 index 00000000..be024feb --- /dev/null +++ b/plugins/check_curl.c | |||
| @@ -0,0 +1,168 @@ | |||
| 1 | /***************************************************************************** | ||
| 2 | * | ||
| 3 | * Monitoring check_curl plugin | ||
| 4 | * | ||
| 5 | * License: GPL | ||
| 6 | * Copyright (c) 1999-2017 Monitoring Plugins Development Team | ||
| 7 | * | ||
| 8 | * Description: | ||
| 9 | * | ||
| 10 | * This file contains the check_curl plugin | ||
| 11 | * | ||
| 12 | * This plugin tests the HTTP service on the specified host. It can test | ||
| 13 | * normal (http) and secure (https) servers, follow redirects, search for | ||
| 14 | * strings and regular expressions, check connection times, and report on | ||
| 15 | * certificate expiration times. | ||
| 16 | * | ||
| 17 | * This plugin uses functions from the curl library, see | ||
| 18 | * http://curl.haxx.se | ||
| 19 | * | ||
| 20 | * This program is free software: you can redistribute it and/or modify | ||
| 21 | * it under the terms of the GNU General Public License as published by | ||
| 22 | * the Free Software Foundation, either version 3 of the License, or | ||
| 23 | * (at your option) any later version. | ||
| 24 | * | ||
| 25 | * This program is distributed in the hope that it will be useful, | ||
| 26 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 27 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 28 | * GNU General Public License for more details. | ||
| 29 | * | ||
| 30 | * You should have received a copy of the GNU General Public License | ||
| 31 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 32 | * | ||
| 33 | * | ||
| 34 | *****************************************************************************/ | ||
| 35 | |||
| 36 | const char *progname = "check_curl"; | ||
| 37 | const char *copyright = "2006-2017"; | ||
| 38 | const char *email = "devel@monitoring-plugins.org"; | ||
| 39 | |||
| 40 | #include "common.h" | ||
| 41 | #include "utils.h" | ||
| 42 | |||
| 43 | #ifndef LIBCURL_PROTOCOL_HTTP | ||
| 44 | #error libcurl compiled without HTTP support, compiling check_curl plugin makes not much sense | ||
| 45 | #endif | ||
| 46 | |||
| 47 | #include "curl/curl.h" | ||
| 48 | #include "curl/easy.h" | ||
| 49 | |||
| 50 | int verbose = FALSE; | ||
| 51 | CURL *curl; | ||
| 52 | |||
| 53 | int process_arguments (int, char **); | ||
| 54 | void print_help (void); | ||
| 55 | void print_usage (void); | ||
| 56 | void print_curl_version (void); | ||
| 57 | |||
| 58 | int | ||
| 59 | main (int argc, char **argv) | ||
| 60 | { | ||
| 61 | int result = STATE_UNKNOWN; | ||
| 62 | |||
| 63 | setlocale (LC_ALL, ""); | ||
| 64 | bindtextdomain (PACKAGE, LOCALEDIR); | ||
| 65 | textdomain (PACKAGE); | ||
| 66 | |||
| 67 | /* Parse extra opts if any */ | ||
| 68 | argv=np_extra_opts (&argc, argv, progname); | ||
| 69 | |||
| 70 | if (process_arguments (argc, argv) == ERROR) | ||
| 71 | usage4 (_("Could not parse arguments")); | ||
| 72 | |||
| 73 | if (curl_global_init (CURL_GLOBAL_DEFAULT) != CURLE_OK) | ||
| 74 | die (STATE_UNKNOWN, "HTTP UNKNOWN - curl_global_init failed\n"); | ||
| 75 | |||
| 76 | if ((curl = curl_easy_init()) == NULL) | ||
| 77 | die (STATE_UNKNOWN, "HTTP UNKNOWN - curl_easy_init failed\n"); | ||
| 78 | |||
| 79 | curl_easy_cleanup (curl); | ||
| 80 | curl_global_cleanup (); | ||
| 81 | |||
| 82 | return result; | ||
| 83 | } | ||
| 84 | |||
| 85 | int | ||
| 86 | process_arguments (int argc, char **argv) | ||
| 87 | { | ||
| 88 | int c; | ||
| 89 | int option=0; | ||
| 90 | static struct option longopts[] = { | ||
| 91 | {"version", no_argument, 0, 'V'}, | ||
| 92 | {"help", no_argument, 0, 'h'}, | ||
| 93 | {"verbose", no_argument, 0, 'v'}, | ||
| 94 | {0, 0, 0, 0} | ||
| 95 | }; | ||
| 96 | |||
| 97 | if (argc < 2) | ||
| 98 | usage ("\n"); | ||
| 99 | |||
| 100 | while (1) { | ||
| 101 | c = getopt_long (argc, argv, "Vhv", longopts, &option); | ||
| 102 | if (c == -1 || c == EOF || c == 1) | ||
| 103 | break; | ||
| 104 | |||
| 105 | switch (c) { | ||
| 106 | case 'h': | ||
| 107 | print_help(); | ||
| 108 | exit(STATE_UNKNOWN); | ||
| 109 | break; | ||
| 110 | case 'V': | ||
| 111 | print_revision(progname, NP_VERSION); | ||
| 112 | print_curl_version(); | ||
| 113 | exit(STATE_UNKNOWN); | ||
| 114 | break; | ||
| 115 | case 'v': | ||
| 116 | verbose++; | ||
| 117 | break; | ||
| 118 | case '?': | ||
| 119 | /* print short usage statement if args not parsable */ | ||
| 120 | usage5 (); | ||
| 121 | break; | ||
| 122 | } | ||
| 123 | } | ||
| 124 | |||
| 125 | return 0; | ||
| 126 | } | ||
| 127 | |||
| 128 | void | ||
| 129 | print_help (void) | ||
| 130 | { | ||
| 131 | print_revision(progname, NP_VERSION); | ||
| 132 | |||
| 133 | printf ("Copyright (c) 2017 Andreas Baumann <abaumann@yahoo.com>\n"); | ||
| 134 | printf (COPYRIGHT, copyright, email); | ||
| 135 | |||
| 136 | printf ("%s\n", _("This plugin tests the HTTP(S) service on the specified host.")); | ||
| 137 | printf ("%s\n", _("It makes use of libcurl to do so.")); | ||
| 138 | |||
| 139 | printf ("\n\n"); | ||
| 140 | |||
| 141 | print_usage(); | ||
| 142 | printf (_("NOTE: One or both of -H and -I must be specified")); | ||
| 143 | |||
| 144 | printf ("\n"); | ||
| 145 | |||
| 146 | printf (UT_HELP_VRSN); | ||
| 147 | printf (UT_VERBOSE); | ||
| 148 | |||
| 149 | printf (UT_SUPPORT); | ||
| 150 | |||
| 151 | printf ("%s\n", _("WARNING: check_curl is experimental. Please use")); | ||
| 152 | printf ("%s\n\n", _("check_http if you need a stable version.")); | ||
| 153 | } | ||
| 154 | |||
| 155 | void | ||
| 156 | print_usage (void) | ||
| 157 | { | ||
| 158 | printf ("%s\n", _("WARNING: check_curl is experimental. Please use")); | ||
| 159 | printf ("%s\n\n", _("check_http if you need a stable version.")); | ||
| 160 | printf ("%s\n", _("Usage:")); | ||
| 161 | printf (" %s [-v verbose]\n", progname); | ||
| 162 | } | ||
| 163 | |||
| 164 | void | ||
| 165 | print_curl_version (void) | ||
| 166 | { | ||
| 167 | printf( "%s\n", curl_version()); | ||
| 168 | } | ||
