summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_curl.c14
-rw-r--r--plugins/check_mrtg.c138
-rw-r--r--plugins/check_mrtg.d/config.h17
3 files changed, 121 insertions, 48 deletions
diff --git a/plugins/check_curl.c b/plugins/check_curl.c
index fc704171..ba856a11 100644
--- a/plugins/check_curl.c
+++ b/plugins/check_curl.c
@@ -672,6 +672,11 @@ redir_wrapper redir(curlhelp_write_curlbuf *header_buf, const check_curl_config
672 672
673 char *location = get_header_value(headers, nof_headers, "location"); 673 char *location = get_header_value(headers, nof_headers, "location");
674 674
675 if (location == NULL) {
676 // location header not found
677 die(STATE_UNKNOWN, "HTTP UNKNOWN - could not find \"location\" header\n");
678 }
679
675 if (verbose >= 2) { 680 if (verbose >= 2) {
676 printf(_("* Seen redirect location %s\n"), location); 681 printf(_("* Seen redirect location %s\n"), location);
677 } 682 }
@@ -1480,7 +1485,9 @@ void print_help(void) {
1480 printf(" %s\n", _("Append a port to include it in the header (eg: example.com:5000)")); 1485 printf(" %s\n", _("Append a port to include it in the header (eg: example.com:5000)"));
1481 printf(" %s\n", "-I, --IP-address=ADDRESS"); 1486 printf(" %s\n", "-I, --IP-address=ADDRESS");
1482 printf(" %s\n", 1487 printf(" %s\n",
1483 _("IP address or name (use numeric address if possible to bypass DNS lookup).")); 1488 "IP address or name (use numeric address if possible to bypass DNS lookup).");
1489 printf(" %s\n",
1490 "This overwrites the network address of the target while leaving everything else (HTTP headers) as they are");
1484 printf(" %s\n", "-p, --port=INTEGER"); 1491 printf(" %s\n", "-p, --port=INTEGER");
1485 printf(" %s", _("Port number (default: ")); 1492 printf(" %s", _("Port number (default: "));
1486 printf("%d)\n", HTTP_PORT); 1493 printf("%d)\n", HTTP_PORT);
@@ -1544,6 +1551,7 @@ void print_help(void) {
1544 printf(" %s\n", _("String to expect in the content")); 1551 printf(" %s\n", _("String to expect in the content"));
1545 printf(" %s\n", "-u, --url=PATH"); 1552 printf(" %s\n", "-u, --url=PATH");
1546 printf(" %s\n", _("URL to GET or POST (default: /)")); 1553 printf(" %s\n", _("URL to GET or POST (default: /)"));
1554 printf(" %s\n", _("This is the part after the address in a URL, so for \"https://example.com/index.html\" it would be '-u /index.html'"));
1547 printf(" %s\n", "-P, --post=STRING"); 1555 printf(" %s\n", "-P, --post=STRING");
1548 printf(" %s\n", _("URL decoded http POST data")); 1556 printf(" %s\n", _("URL decoded http POST data"));
1549 printf(" %s\n", 1557 printf(" %s\n",
@@ -1556,7 +1564,7 @@ void print_help(void) {
1556 printf(" %s\n", _("Warn if document is more than SECONDS old. the number can also be of")); 1564 printf(" %s\n", _("Warn if document is more than SECONDS old. the number can also be of"));
1557 printf(" %s\n", _("the form \"10m\" for minutes, \"10h\" for hours, or \"10d\" for days.")); 1565 printf(" %s\n", _("the form \"10m\" for minutes, \"10h\" for hours, or \"10d\" for days."));
1558 printf(" %s\n", "-T, --content-type=STRING"); 1566 printf(" %s\n", "-T, --content-type=STRING");
1559 printf(" %s\n", _("specify Content-Type header media type when POSTing\n")); 1567 printf(" %s\n", _("specify Content-Type header media type when POSTing"));
1560 printf(" %s\n", "-l, --linespan"); 1568 printf(" %s\n", "-l, --linespan");
1561 printf(" %s\n", _("Allow regex to span newlines (must precede -r or -R)")); 1569 printf(" %s\n", _("Allow regex to span newlines (must precede -r or -R)"));
1562 printf(" %s\n", "-r, --regex, --ereg=STRING"); 1570 printf(" %s\n", "-r, --regex, --ereg=STRING");
@@ -1685,7 +1693,7 @@ void print_help(void) {
1685 printf(" %s\n", _("It is recommended to use an environment proxy like:")); 1693 printf(" %s\n", _("It is recommended to use an environment proxy like:"));
1686 printf(" %s\n", 1694 printf(" %s\n",
1687 _("https_proxy=http://192.168.100.35:3128 ./check_curl -H www.verisign.com -S")); 1695 _("https_proxy=http://192.168.100.35:3128 ./check_curl -H www.verisign.com -S"));
1688 printf(" %s\n", _("legacy proxy requests in check_http style still work:")); 1696 printf(" %s\n", _("legacy proxy requests in check_http style might still work, but are frowned upon, so DONT:"));
1689 printf(" %s\n", _("check_curl -I 192.168.100.35 -p 3128 -u https://www.verisign.com/ -S -j " 1697 printf(" %s\n", _("check_curl -I 192.168.100.35 -p 3128 -u https://www.verisign.com/ -S -j "
1690 "CONNECT -H www.verisign.com ")); 1698 "CONNECT -H www.verisign.com "));
1691 printf(" %s\n", _("all these options are needed: -I <proxy> -p <proxy-port> -u <check-url> " 1699 printf(" %s\n", _("all these options are needed: -I <proxy> -p <proxy-port> -u <check-url> "
diff --git a/plugins/check_mrtg.c b/plugins/check_mrtg.c
index 4a17049a..cdc2a035 100644
--- a/plugins/check_mrtg.c
+++ b/plugins/check_mrtg.c
@@ -29,14 +29,18 @@
29 * 29 *
30 *****************************************************************************/ 30 *****************************************************************************/
31 31
32const char *progname = "check_mrtg";
33const char *copyright = "1999-2024";
34const char *email = "devel@monitoring-plugins.org";
35
36#include "common.h" 32#include "common.h"
33#include "output.h"
34#include "perfdata.h"
35#include "states.h"
36#include "thresholds.h"
37#include "utils.h" 37#include "utils.h"
38#include "check_mrtg.d/config.h" 38#include "check_mrtg.d/config.h"
39 39
40const char *progname = "check_mrtg";
41const char *copyright = "1999-2024";
42const char *email = "devel@monitoring-plugins.org";
43
40typedef struct { 44typedef struct {
41 int errorcode; 45 int errorcode;
42 check_mrtg_config config; 46 check_mrtg_config config;
@@ -62,11 +66,24 @@ int main(int argc, char **argv) {
62 66
63 const check_mrtg_config config = tmp_config.config; 67 const check_mrtg_config config = tmp_config.config;
64 68
69 if (config.output_format_is_set) {
70 mp_set_format(config.output_format);
71 }
72
73 mp_check overall = mp_check_init();
74
65 /* open the MRTG log file for reading */ 75 /* open the MRTG log file for reading */
76 mp_subcheck sc_open_mrtg_log_file = mp_subcheck_init();
66 FILE *mtrg_log_file = fopen(config.log_file, "r"); 77 FILE *mtrg_log_file = fopen(config.log_file, "r");
67 if (mtrg_log_file == NULL) { 78 if (mtrg_log_file == NULL) {
68 printf(_("Unable to open MRTG log file\n")); 79 xasprintf(&sc_open_mrtg_log_file.output, "unable to open MRTG log file");
69 return STATE_UNKNOWN; 80 sc_open_mrtg_log_file = mp_set_subcheck_state(sc_open_mrtg_log_file, STATE_UNKNOWN);
81 mp_add_subcheck_to_check(&overall, sc_open_mrtg_log_file);
82 mp_exit(overall);
83 } else {
84 xasprintf(&sc_open_mrtg_log_file.output, "opened MRTG log file");
85 sc_open_mrtg_log_file = mp_set_subcheck_state(sc_open_mrtg_log_file, STATE_OK);
86 mp_add_subcheck_to_check(&overall, sc_open_mrtg_log_file);
70 } 87 }
71 88
72 time_t timestamp = 0; 89 time_t timestamp = 0;
@@ -120,18 +137,32 @@ int main(int argc, char **argv) {
120 fclose(mtrg_log_file); 137 fclose(mtrg_log_file);
121 138
122 /* if we couldn't read enough data, return an unknown error */ 139 /* if we couldn't read enough data, return an unknown error */
140 mp_subcheck sc_process_mrtg_log_file = mp_subcheck_init();
123 if (line <= 2) { 141 if (line <= 2) {
124 printf(_("Unable to process MRTG log file\n")); 142 xasprintf(&sc_process_mrtg_log_file.output, "unable to process MRTG log file");
125 return STATE_UNKNOWN; 143 sc_process_mrtg_log_file = mp_set_subcheck_state(sc_process_mrtg_log_file, STATE_UNKNOWN);
144 mp_exit(overall);
145 } else {
146 xasprintf(&sc_process_mrtg_log_file.output, "processed MRTG log file");
147 sc_process_mrtg_log_file = mp_set_subcheck_state(sc_process_mrtg_log_file, STATE_OK);
148 mp_add_subcheck_to_check(&overall, sc_process_mrtg_log_file);
126 } 149 }
127 150
128 /* make sure the MRTG data isn't too old */ 151 /* make sure the MRTG data isn't too old */
129 time_t current_time; 152 time_t current_time;
130 time(&current_time); 153 time(&current_time);
154 mp_subcheck sc_data_expired = mp_subcheck_init();
131 if (config.expire_minutes > 0 && (current_time - timestamp) > (config.expire_minutes * 60)) { 155 if (config.expire_minutes > 0 && (current_time - timestamp) > (config.expire_minutes * 60)) {
132 printf(_("MRTG data has expired (%d minutes old)\n"), 156 xasprintf(&sc_data_expired.output, "MRTG data has expired (%d minutes old)",
133 (int)((current_time - timestamp) / 60)); 157 (int)((current_time - timestamp) / 60));
134 return STATE_WARNING; 158 sc_data_expired = mp_set_subcheck_state(sc_data_expired, STATE_WARNING);
159 mp_add_subcheck_to_check(&overall, sc_data_expired);
160 mp_exit(overall);
161 } else {
162 xasprintf(&sc_data_expired.output, "MRTG data should be valid (%d minutes old)",
163 (int)((current_time - timestamp) / 60));
164 sc_data_expired = mp_set_subcheck_state(sc_data_expired, STATE_OK);
165 mp_add_subcheck_to_check(&overall, sc_data_expired);
135 } 166 }
136 167
137 unsigned long rate = 0L; 168 unsigned long rate = 0L;
@@ -142,24 +173,27 @@ int main(int argc, char **argv) {
142 rate = maximum_value_rate; 173 rate = maximum_value_rate;
143 } 174 }
144 175
145 int result = STATE_OK; 176 mp_subcheck sc_values = mp_subcheck_init();
146 if (config.value_critical_threshold_set && rate > config.value_critical_threshold) { 177 mp_perfdata pd_value = perfdata_init();
147 result = STATE_CRITICAL; 178 pd_value = mp_set_pd_value(pd_value, rate);
148 } else if (config.value_warning_threshold_set && rate > config.value_warning_threshold) { 179 pd_value.label = config.label;
149 result = STATE_WARNING; 180 pd_value = mp_pd_set_thresholds(pd_value, config.values_threshold);
150 }
151 181
152 printf("%s. %s = %lu %s|%s\n", (config.use_average) ? _("Avg") : _("Max"), config.label, rate, 182 sc_values = mp_set_subcheck_state(sc_values, mp_get_pd_status(pd_value));
153 config.units, 183 xasprintf(&sc_values.output, "%s. %s = %lu %s", (config.use_average) ? _("Avg") : _("Max"),
154 perfdata(config.label, (long)rate, config.units, config.value_warning_threshold_set, 184 config.label, rate, config.units);
155 (long)config.value_warning_threshold, config.value_critical_threshold_set,
156 (long)config.value_critical_threshold, 0, 0, 0, 0));
157 185
158 return result; 186 mp_add_subcheck_to_check(&overall, sc_values);
187
188 mp_exit(overall);
159} 189}
160 190
161/* process command-line arguments */ 191/* process command-line arguments */
162check_mrtg_config_wrapper process_arguments(int argc, char **argv) { 192check_mrtg_config_wrapper process_arguments(int argc, char **argv) {
193 enum {
194 output_format_index,
195 };
196
163 static struct option longopts[] = {{"logfile", required_argument, 0, 'F'}, 197 static struct option longopts[] = {{"logfile", required_argument, 0, 'F'},
164 {"expires", required_argument, 0, 'e'}, 198 {"expires", required_argument, 0, 'e'},
165 {"aggregation", required_argument, 0, 'a'}, 199 {"aggregation", required_argument, 0, 'a'},
@@ -171,6 +205,7 @@ check_mrtg_config_wrapper process_arguments(int argc, char **argv) {
171 {"variable", required_argument, 0, 'v'}, 205 {"variable", required_argument, 0, 'v'},
172 {"version", no_argument, 0, 'V'}, 206 {"version", no_argument, 0, 'V'},
173 {"help", no_argument, 0, 'h'}, 207 {"help", no_argument, 0, 'h'},
208 {"output-format", required_argument, 0, output_format_index},
174 {0, 0, 0, 0}}; 209 {0, 0, 0, 0}};
175 210
176 check_mrtg_config_wrapper result = { 211 check_mrtg_config_wrapper result = {
@@ -218,14 +253,22 @@ check_mrtg_config_wrapper process_arguments(int argc, char **argv) {
218 usage4(_("Invalid variable number")); 253 usage4(_("Invalid variable number"));
219 } 254 }
220 break; 255 break;
221 case 'w': /* critical time threshold */ 256 case 'w': /* critical time threshold */ {
222 result.config.value_warning_threshold_set = true; 257 mp_range_parsed tmp = mp_parse_range_string(optarg);
223 result.config.value_warning_threshold = strtoul(optarg, NULL, 10); 258 if (tmp.error != MP_PARSING_SUCCES) {
224 break; 259 die(STATE_UNKNOWN, "failed to parse warning threshold");
225 case 'c': /* warning time threshold */ 260 }
226 result.config.value_critical_threshold_set = true; 261 result.config.values_threshold =
227 result.config.value_critical_threshold = strtoul(optarg, NULL, 10); 262 mp_thresholds_set_warn(result.config.values_threshold, tmp.range);
228 break; 263 } break;
264 case 'c': /* warning time threshold */ {
265 mp_range_parsed tmp = mp_parse_range_string(optarg);
266 if (tmp.error != MP_PARSING_SUCCES) {
267 die(STATE_UNKNOWN, "failed to parse critical threshold");
268 }
269 result.config.values_threshold =
270 mp_thresholds_set_crit(result.config.values_threshold, tmp.range);
271 } break;
229 case 'l': /* label */ 272 case 'l': /* label */
230 result.config.label = optarg; 273 result.config.label = optarg;
231 break; 274 break;
@@ -240,6 +283,17 @@ check_mrtg_config_wrapper process_arguments(int argc, char **argv) {
240 exit(STATE_UNKNOWN); 283 exit(STATE_UNKNOWN);
241 case '?': /* help */ 284 case '?': /* help */
242 usage5(); 285 usage5();
286 case output_format_index: {
287 parsed_output_format parser = mp_parse_output_format(optarg);
288 if (!parser.parsing_success) {
289 printf("Invalid output format: %s\n", optarg);
290 exit(STATE_UNKNOWN);
291 }
292
293 result.config.output_format_is_set = true;
294 result.config.output_format = parser.output_format;
295 break;
296 }
243 } 297 }
244 } 298 }
245 299
@@ -274,14 +328,22 @@ check_mrtg_config_wrapper process_arguments(int argc, char **argv) {
274 } 328 }
275 } 329 }
276 330
277 if (argc > option_char && !result.config.value_warning_threshold_set) { 331 if (argc > option_char && !result.config.values_threshold.warning_is_set) {
278 result.config.value_warning_threshold_set = true; 332 mp_range_parsed tmp = mp_parse_range_string(argv[option_char++]);
279 result.config.value_warning_threshold = strtoul(argv[option_char++], NULL, 10); 333 if (tmp.error != MP_PARSING_SUCCES) {
334 die(STATE_UNKNOWN, "failed to parse warning threshold");
335 }
336 result.config.values_threshold =
337 mp_thresholds_set_warn(result.config.values_threshold, tmp.range);
280 } 338 }
281 339
282 if (argc > option_char && !result.config.value_critical_threshold_set) { 340 if (argc > option_char && !result.config.values_threshold.critical_is_set) {
283 result.config.value_critical_threshold_set = true; 341 mp_range_parsed tmp = mp_parse_range_string(argv[option_char++]);
284 result.config.value_critical_threshold = strtoul(argv[option_char++], NULL, 10); 342 if (tmp.error != MP_PARSING_SUCCES) {
343 die(STATE_UNKNOWN, "failed to parse critical threshold");
344 }
345 result.config.values_threshold =
346 mp_thresholds_set_crit(result.config.values_threshold, tmp.range);
285 } 347 }
286 348
287 if (argc > option_char && strlen(result.config.label) == 0) { 349 if (argc > option_char && strlen(result.config.label) == 0) {
@@ -345,6 +407,8 @@ void print_help(void) {
345 printf(" %s\n", _("Option units label for data (Example: Packets/Sec, Errors/Sec,")); 407 printf(" %s\n", _("Option units label for data (Example: Packets/Sec, Errors/Sec,"));
346 printf(" %s\n", _("\"Bytes Per Second\", \"%% Utilization\")")); 408 printf(" %s\n", _("\"Bytes Per Second\", \"%% Utilization\")"));
347 409
410 printf(UT_OUTPUT_FORMAT);
411
348 printf("\n"); 412 printf("\n");
349 printf(" %s\n", 413 printf(" %s\n",
350 _("If the value exceeds the <vwl> threshold, a WARNING status is returned. If")); 414 _("If the value exceeds the <vwl> threshold, a WARNING status is returned. If"));
diff --git a/plugins/check_mrtg.d/config.h b/plugins/check_mrtg.d/config.h
index 96b849a2..4a5b5595 100644
--- a/plugins/check_mrtg.d/config.h
+++ b/plugins/check_mrtg.d/config.h
@@ -1,6 +1,8 @@
1#pragma once 1#pragma once
2 2
3#include "../../config.h" 3#include "../../config.h"
4#include "output.h"
5#include "thresholds.h"
4#include <stddef.h> 6#include <stddef.h>
5#include <stdlib.h> 7#include <stdlib.h>
6 8
@@ -12,10 +14,10 @@ typedef struct {
12 char *units; 14 char *units;
13 char *log_file; 15 char *log_file;
14 16
15 bool value_warning_threshold_set; 17 mp_thresholds values_threshold;
16 unsigned long value_warning_threshold; 18
17 bool value_critical_threshold_set; 19 bool output_format_is_set;
18 unsigned long value_critical_threshold; 20 mp_output_format output_format;
19} check_mrtg_config; 21} check_mrtg_config;
20 22
21check_mrtg_config check_mrtg_config_init() { 23check_mrtg_config check_mrtg_config_init() {
@@ -27,10 +29,9 @@ check_mrtg_config check_mrtg_config_init() {
27 .units = NULL, 29 .units = NULL,
28 .log_file = NULL, 30 .log_file = NULL,
29 31
30 .value_warning_threshold_set = false, 32 .values_threshold = mp_thresholds_init(),
31 .value_warning_threshold = 0, 33
32 .value_critical_threshold_set = false, 34 .output_format_is_set = false,
33 .value_critical_threshold = 0,
34 }; 35 };
35 return tmp; 36 return tmp;
36} 37}