summaryrefslogtreecommitdiffstats
path: root/plugins/check_curl.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_curl.c')
-rw-r--r--plugins/check_curl.c168
1 files changed, 168 insertions, 0 deletions
diff --git a/plugins/check_curl.c b/plugins/check_curl.c
new file mode 100644
index 0000000..be024fe
--- /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
36const char *progname = "check_curl";
37const char *copyright = "2006-2017";
38const 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
50int verbose = FALSE;
51CURL *curl;
52
53int process_arguments (int, char **);
54void print_help (void);
55void print_usage (void);
56void print_curl_version (void);
57
58int
59main (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
85int
86process_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
128void
129print_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
155void
156print_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
164void
165print_curl_version (void)
166{
167 printf( "%s\n", curl_version());
168}