diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/Makefile.am | 5 | ||||
-rw-r--r-- | plugins/check_curl.c | 168 |
2 files changed, 172 insertions, 1 deletions
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 | } | ||