diff options
Diffstat (limited to 'plugins/check_mrtg.c')
| -rw-r--r-- | plugins/check_mrtg.c | 632 |
1 files changed, 349 insertions, 283 deletions
diff --git a/plugins/check_mrtg.c b/plugins/check_mrtg.c index 826b77e9..cdc2a035 100644 --- a/plugins/check_mrtg.c +++ b/plugins/check_mrtg.c | |||
| @@ -1,385 +1,451 @@ | |||
| 1 | /***************************************************************************** | 1 | /***************************************************************************** |
| 2 | * | 2 | * |
| 3 | * Monitoring check_mrtg plugin | 3 | * Monitoring check_mrtg plugin |
| 4 | * | 4 | * |
| 5 | * License: GPL | 5 | * License: GPL |
| 6 | * Copyright (c) 1999-2007 Monitoring Plugins Development Team | 6 | * Copyright (c) 1999-2024 Monitoring Plugins Development Team |
| 7 | * | 7 | * |
| 8 | * Description: | 8 | * Description: |
| 9 | * | 9 | * |
| 10 | * This file contains the check_mrtg plugin | 10 | * This file contains the check_mrtg plugin |
| 11 | * | 11 | * |
| 12 | * This plugin will check either the average or maximum value of one of the | 12 | * This plugin will check either the average or maximum value of one of the |
| 13 | * two variables recorded in an MRTG log file. | 13 | * two variables recorded in an MRTG log file. |
| 14 | * | 14 | * |
| 15 | * | 15 | * |
| 16 | * This program is free software: you can redistribute it and/or modify | 16 | * This program is free software: you can redistribute it and/or modify |
| 17 | * it under the terms of the GNU General Public License as published by | 17 | * it under the terms of the GNU General Public License as published by |
| 18 | * the Free Software Foundation, either version 3 of the License, or | 18 | * the Free Software Foundation, either version 3 of the License, or |
| 19 | * (at your option) any later version. | 19 | * (at your option) any later version. |
| 20 | * | 20 | * |
| 21 | * This program is distributed in the hope that it will be useful, | 21 | * This program is distributed in the hope that it will be useful, |
| 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 24 | * GNU General Public License for more details. | 24 | * GNU General Public License for more details. |
| 25 | * | 25 | * |
| 26 | * You should have received a copy of the GNU General Public License | 26 | * You should have received a copy of the GNU General Public License |
| 27 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 27 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 28 | * | 28 | * |
| 29 | * | 29 | * |
| 30 | *****************************************************************************/ | 30 | *****************************************************************************/ |
| 31 | |||
| 32 | #include "common.h" | ||
| 33 | #include "output.h" | ||
| 34 | #include "perfdata.h" | ||
| 35 | #include "states.h" | ||
| 36 | #include "thresholds.h" | ||
| 37 | #include "utils.h" | ||
| 38 | #include "check_mrtg.d/config.h" | ||
| 31 | 39 | ||
| 32 | const char *progname = "check_mrtg"; | 40 | const char *progname = "check_mrtg"; |
| 33 | const char *copyright = "1999-2007"; | 41 | const char *copyright = "1999-2024"; |
| 34 | const char *email = "devel@monitoring-plugins.org"; | 42 | const char *email = "devel@monitoring-plugins.org"; |
| 35 | 43 | ||
| 36 | #include "common.h" | 44 | typedef struct { |
| 37 | #include "utils.h" | 45 | int errorcode; |
| 46 | check_mrtg_config config; | ||
| 47 | } check_mrtg_config_wrapper; | ||
| 48 | static check_mrtg_config_wrapper process_arguments(int /*argc*/, char ** /*argv*/); | ||
| 49 | static check_mrtg_config_wrapper validate_arguments(check_mrtg_config_wrapper /*config_wrapper*/); | ||
| 38 | 50 | ||
| 39 | int process_arguments (int, char **); | 51 | static void print_help(void); |
| 40 | int validate_arguments (void); | 52 | void print_usage(void); |
| 41 | void print_help (void); | ||
| 42 | void print_usage (void); | ||
| 43 | |||
| 44 | char *log_file = NULL; | ||
| 45 | int expire_minutes = 0; | ||
| 46 | bool use_average = true; | ||
| 47 | int variable_number = -1; | ||
| 48 | unsigned long value_warning_threshold = 0L; | ||
| 49 | unsigned long value_critical_threshold = 0L; | ||
| 50 | char *label; | ||
| 51 | char *units; | ||
| 52 | |||
| 53 | int | ||
| 54 | main (int argc, char **argv) | ||
| 55 | { | ||
| 56 | int result = STATE_OK; | ||
| 57 | FILE *fp; | ||
| 58 | int line; | ||
| 59 | char input_buffer[MAX_INPUT_BUFFER]; | ||
| 60 | char *temp_buffer; | ||
| 61 | time_t current_time; | ||
| 62 | time_t timestamp = 0L; | ||
| 63 | unsigned long average_value_rate = 0L; | ||
| 64 | unsigned long maximum_value_rate = 0L; | ||
| 65 | unsigned long rate = 0L; | ||
| 66 | 53 | ||
| 67 | setlocale (LC_ALL, ""); | 54 | int main(int argc, char **argv) { |
| 68 | bindtextdomain (PACKAGE, LOCALEDIR); | 55 | setlocale(LC_ALL, ""); |
| 69 | textdomain (PACKAGE); | 56 | bindtextdomain(PACKAGE, LOCALEDIR); |
| 57 | textdomain(PACKAGE); | ||
| 70 | 58 | ||
| 71 | /* Parse extra opts if any */ | 59 | /* Parse extra opts if any */ |
| 72 | argv=np_extra_opts (&argc, argv, progname); | 60 | argv = np_extra_opts(&argc, argv, progname); |
| 61 | |||
| 62 | check_mrtg_config_wrapper tmp_config = process_arguments(argc, argv); | ||
| 63 | if (tmp_config.errorcode == ERROR) { | ||
| 64 | usage4(_("Could not parse arguments\n")); | ||
| 65 | } | ||
| 73 | 66 | ||
| 74 | if (process_arguments (argc, argv) == ERROR) | 67 | const check_mrtg_config config = tmp_config.config; |
| 75 | usage4 (_("Could not parse arguments\n")); | ||
| 76 | 68 | ||
| 77 | /* open the MRTG log file for reading */ | 69 | if (config.output_format_is_set) { |
| 78 | fp = fopen (log_file, "r"); | 70 | mp_set_format(config.output_format); |
| 79 | if (fp == NULL) { | ||
| 80 | printf (_("Unable to open MRTG log file\n")); | ||
| 81 | return STATE_UNKNOWN; | ||
| 82 | } | 71 | } |
| 83 | 72 | ||
| 84 | line = 0; | 73 | mp_check overall = mp_check_init(); |
| 85 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, fp)) { | ||
| 86 | 74 | ||
| 75 | /* open the MRTG log file for reading */ | ||
| 76 | mp_subcheck sc_open_mrtg_log_file = mp_subcheck_init(); | ||
| 77 | FILE *mtrg_log_file = fopen(config.log_file, "r"); | ||
| 78 | if (mtrg_log_file == NULL) { | ||
| 79 | xasprintf(&sc_open_mrtg_log_file.output, "unable to open MRTG log file"); | ||
| 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); | ||
| 87 | } | ||
| 88 | |||
| 89 | time_t timestamp = 0; | ||
| 90 | unsigned long average_value_rate = 0; | ||
| 91 | unsigned long maximum_value_rate = 0; | ||
| 92 | char input_buffer[MAX_INPUT_BUFFER]; | ||
| 93 | int line = 0; | ||
| 94 | while (fgets(input_buffer, MAX_INPUT_BUFFER - 1, mtrg_log_file)) { | ||
| 87 | line++; | 95 | line++; |
| 88 | 96 | ||
| 89 | /* skip the first line of the log file */ | 97 | /* skip the first line of the log file */ |
| 90 | if (line == 1) | 98 | if (line == 1) { |
| 91 | continue; | 99 | continue; |
| 100 | } | ||
| 92 | 101 | ||
| 93 | /* break out of read loop if we've passed the number of entries we want to read */ | 102 | /* break out of read loop if we've passed the number of entries we want to read */ |
| 94 | if (line > 2) | 103 | if (line > 2) { |
| 95 | break; | 104 | break; |
| 105 | } | ||
| 96 | 106 | ||
| 97 | /* grab the timestamp */ | 107 | /* grab the timestamp */ |
| 98 | temp_buffer = strtok (input_buffer, " "); | 108 | char *temp_buffer = strtok(input_buffer, " "); |
| 99 | timestamp = strtoul (temp_buffer, NULL, 10); | 109 | timestamp = strtoul(temp_buffer, NULL, 10); |
| 100 | 110 | ||
| 101 | /* grab the average value 1 rate */ | 111 | /* grab the average value 1 rate */ |
| 102 | temp_buffer = strtok (NULL, " "); | 112 | temp_buffer = strtok(NULL, " "); |
| 103 | if (variable_number == 1) | 113 | if (config.variable_number == 1) { |
| 104 | average_value_rate = strtoul (temp_buffer, NULL, 10); | 114 | average_value_rate = strtoul(temp_buffer, NULL, 10); |
| 115 | } | ||
| 105 | 116 | ||
| 106 | /* grab the average value 2 rate */ | 117 | /* grab the average value 2 rate */ |
| 107 | temp_buffer = strtok (NULL, " "); | 118 | temp_buffer = strtok(NULL, " "); |
| 108 | if (variable_number == 2) | 119 | if (config.variable_number == 2) { |
| 109 | average_value_rate = strtoul (temp_buffer, NULL, 10); | 120 | average_value_rate = strtoul(temp_buffer, NULL, 10); |
| 121 | } | ||
| 110 | 122 | ||
| 111 | /* grab the maximum value 1 rate */ | 123 | /* grab the maximum value 1 rate */ |
| 112 | temp_buffer = strtok (NULL, " "); | 124 | temp_buffer = strtok(NULL, " "); |
| 113 | if (variable_number == 1) | 125 | if (config.variable_number == 1) { |
| 114 | maximum_value_rate = strtoul (temp_buffer, NULL, 10); | 126 | maximum_value_rate = strtoul(temp_buffer, NULL, 10); |
| 127 | } | ||
| 115 | 128 | ||
| 116 | /* grab the maximum value 2 rate */ | 129 | /* grab the maximum value 2 rate */ |
| 117 | temp_buffer = strtok (NULL, " "); | 130 | temp_buffer = strtok(NULL, " "); |
| 118 | if (variable_number == 2) | 131 | if (config.variable_number == 2) { |
| 119 | maximum_value_rate = strtoul (temp_buffer, NULL, 10); | 132 | maximum_value_rate = strtoul(temp_buffer, NULL, 10); |
| 133 | } | ||
| 120 | } | 134 | } |
| 121 | 135 | ||
| 122 | /* close the log file */ | 136 | /* close the log file */ |
| 123 | fclose (fp); | 137 | fclose(mtrg_log_file); |
| 124 | 138 | ||
| 125 | /* 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(); | ||
| 126 | if (line <= 2) { | 141 | if (line <= 2) { |
| 127 | printf (_("Unable to process MRTG log file\n")); | 142 | xasprintf(&sc_process_mrtg_log_file.output, "unable to process MRTG log file"); |
| 128 | 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); | ||
| 129 | } | 149 | } |
| 130 | 150 | ||
| 131 | /* make sure the MRTG data isn't too old */ | 151 | /* make sure the MRTG data isn't too old */ |
| 132 | time (¤t_time); | 152 | time_t current_time; |
| 133 | if (expire_minutes > 0 | 153 | time(¤t_time); |
| 134 | && (current_time - timestamp) > (expire_minutes * 60)) { | 154 | mp_subcheck sc_data_expired = mp_subcheck_init(); |
| 135 | printf (_("MRTG data has expired (%d minutes old)\n"), | 155 | if (config.expire_minutes > 0 && (current_time - timestamp) > (config.expire_minutes * 60)) { |
| 136 | (int) ((current_time - timestamp) / 60)); | 156 | xasprintf(&sc_data_expired.output, "MRTG data has expired (%d minutes old)", |
| 137 | return STATE_WARNING; | 157 | (int)((current_time - timestamp) / 60)); |
| 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); | ||
| 138 | } | 166 | } |
| 139 | 167 | ||
| 168 | unsigned long rate = 0L; | ||
| 140 | /* else check the incoming/outgoing rates */ | 169 | /* else check the incoming/outgoing rates */ |
| 141 | if (use_average) | 170 | if (config.use_average) { |
| 142 | rate = average_value_rate; | 171 | rate = average_value_rate; |
| 143 | else | 172 | } else { |
| 144 | rate = maximum_value_rate; | 173 | rate = maximum_value_rate; |
| 174 | } | ||
| 145 | 175 | ||
| 146 | if (rate > value_critical_threshold) | 176 | mp_subcheck sc_values = mp_subcheck_init(); |
| 147 | result = STATE_CRITICAL; | 177 | mp_perfdata pd_value = perfdata_init(); |
| 148 | else if (rate > value_warning_threshold) | 178 | pd_value = mp_set_pd_value(pd_value, rate); |
| 149 | result = STATE_WARNING; | 179 | pd_value.label = config.label; |
| 150 | 180 | pd_value = mp_pd_set_thresholds(pd_value, config.values_threshold); | |
| 151 | printf("%s. %s = %lu %s|%s\n", | ||
| 152 | (use_average) ? _("Avg") : _("Max"), | ||
| 153 | label, rate, units, | ||
| 154 | perfdata(label, (long) rate, units, | ||
| 155 | (int) value_warning_threshold, (long) value_warning_threshold, | ||
| 156 | (int) value_critical_threshold, (long) value_critical_threshold, | ||
| 157 | 0, 0, 0, 0)); | ||
| 158 | 181 | ||
| 159 | return result; | 182 | sc_values = mp_set_subcheck_state(sc_values, mp_get_pd_status(pd_value)); |
| 160 | } | 183 | xasprintf(&sc_values.output, "%s. %s = %lu %s", (config.use_average) ? _("Avg") : _("Max"), |
| 184 | config.label, rate, config.units); | ||
| 161 | 185 | ||
| 186 | mp_add_subcheck_to_check(&overall, sc_values); | ||
| 162 | 187 | ||
| 188 | mp_exit(overall); | ||
| 189 | } | ||
| 163 | 190 | ||
| 164 | /* process command-line arguments */ | 191 | /* process command-line arguments */ |
| 165 | int | 192 | check_mrtg_config_wrapper process_arguments(int argc, char **argv) { |
| 166 | process_arguments (int argc, char **argv) | 193 | enum { |
| 167 | { | 194 | output_format_index, |
| 168 | int c; | 195 | }; |
| 169 | 196 | ||
| 170 | int option = 0; | 197 | static struct option longopts[] = {{"logfile", required_argument, 0, 'F'}, |
| 171 | static struct option longopts[] = { | 198 | {"expires", required_argument, 0, 'e'}, |
| 172 | {"logfile", required_argument, 0, 'F'}, | 199 | {"aggregation", required_argument, 0, 'a'}, |
| 173 | {"expires", required_argument, 0, 'e'}, | 200 | {"variable", required_argument, 0, 'v'}, |
| 174 | {"aggregation", required_argument, 0, 'a'}, | 201 | {"critical", required_argument, 0, 'c'}, |
| 175 | {"variable", required_argument, 0, 'v'}, | 202 | {"warning", required_argument, 0, 'w'}, |
| 176 | {"critical", required_argument, 0, 'c'}, | 203 | {"label", required_argument, 0, 'l'}, |
| 177 | {"warning", required_argument, 0, 'w'}, | 204 | {"units", required_argument, 0, 'u'}, |
| 178 | {"label", required_argument, 0, 'l'}, | 205 | {"variable", required_argument, 0, 'v'}, |
| 179 | {"units", required_argument, 0, 'u'}, | 206 | {"version", no_argument, 0, 'V'}, |
| 180 | {"variable", required_argument, 0, 'v'}, | 207 | {"help", no_argument, 0, 'h'}, |
| 181 | {"version", no_argument, 0, 'V'}, | 208 | {"output-format", required_argument, 0, output_format_index}, |
| 182 | {"help", no_argument, 0, 'h'}, | 209 | {0, 0, 0, 0}}; |
| 183 | {0, 0, 0, 0} | 210 | |
| 211 | check_mrtg_config_wrapper result = { | ||
| 212 | .errorcode = OK, | ||
| 213 | .config = check_mrtg_config_init(), | ||
| 184 | }; | 214 | }; |
| 185 | 215 | ||
| 186 | if (argc < 2) | 216 | if (argc < 2) { |
| 187 | return ERROR; | 217 | result.errorcode = ERROR; |
| 218 | return result; | ||
| 219 | } | ||
| 188 | 220 | ||
| 189 | for (c = 1; c < argc; c++) { | 221 | for (int i = 1; i < argc; i++) { |
| 190 | if (strcmp ("-to", argv[c]) == 0) | 222 | if (strcmp("-to", argv[i]) == 0) { |
| 191 | strcpy (argv[c], "-t"); | 223 | strcpy(argv[i], "-t"); |
| 192 | else if (strcmp ("-wt", argv[c]) == 0) | 224 | } else if (strcmp("-wt", argv[i]) == 0) { |
| 193 | strcpy (argv[c], "-w"); | 225 | strcpy(argv[i], "-w"); |
| 194 | else if (strcmp ("-ct", argv[c]) == 0) | 226 | } else if (strcmp("-ct", argv[i]) == 0) { |
| 195 | strcpy (argv[c], "-c"); | 227 | strcpy(argv[i], "-c"); |
| 228 | } | ||
| 196 | } | 229 | } |
| 197 | 230 | ||
| 231 | int option_char; | ||
| 232 | int option = 0; | ||
| 198 | while (1) { | 233 | while (1) { |
| 199 | c = getopt_long (argc, argv, "hVF:e:a:v:c:w:l:u:", longopts, | 234 | option_char = getopt_long(argc, argv, "hVF:e:a:v:c:w:l:u:", longopts, &option); |
| 200 | &option); | ||
| 201 | 235 | ||
| 202 | if (c == -1 || c == EOF) | 236 | if (option_char == -1 || option_char == EOF) { |
| 203 | break; | 237 | break; |
| 238 | } | ||
| 204 | 239 | ||
| 205 | switch (c) { | 240 | switch (option_char) { |
| 206 | case 'F': /* input file */ | 241 | case 'F': /* input file */ |
| 207 | log_file = optarg; | 242 | result.config.log_file = optarg; |
| 208 | break; | 243 | break; |
| 209 | case 'e': /* ups name */ | 244 | case 'e': /* ups name */ |
| 210 | expire_minutes = atoi (optarg); | 245 | result.config.expire_minutes = atoi(optarg); |
| 211 | break; | 246 | break; |
| 212 | case 'a': /* port */ | 247 | case 'a': /* port */ |
| 213 | if (!strcmp (optarg, "MAX")) | 248 | result.config.use_average = (bool)(strcmp(optarg, "MAX")); |
| 214 | use_average = false; | ||
| 215 | else | ||
| 216 | use_average = true; | ||
| 217 | break; | 249 | break; |
| 218 | case 'v': | 250 | case 'v': |
| 219 | variable_number = atoi (optarg); | 251 | result.config.variable_number = atoi(optarg); |
| 220 | if (variable_number < 1 || variable_number > 2) | 252 | if (result.config.variable_number < 1 || result.config.variable_number > 2) { |
| 221 | usage4 (_("Invalid variable number")); | 253 | usage4(_("Invalid variable number")); |
| 222 | break; | 254 | } |
| 223 | case 'w': /* critical time threshold */ | ||
| 224 | value_warning_threshold = strtoul (optarg, NULL, 10); | ||
| 225 | break; | 255 | break; |
| 226 | case 'c': /* warning time threshold */ | 256 | case 'w': /* critical time threshold */ { |
| 227 | value_critical_threshold = strtoul (optarg, NULL, 10); | 257 | mp_range_parsed tmp = mp_parse_range_string(optarg); |
| 258 | if (tmp.error != MP_PARSING_SUCCES) { | ||
| 259 | die(STATE_UNKNOWN, "failed to parse warning threshold"); | ||
| 260 | } | ||
| 261 | result.config.values_threshold = | ||
| 262 | mp_thresholds_set_warn(result.config.values_threshold, tmp.range); | ||
| 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; | ||
| 272 | case 'l': /* label */ | ||
| 273 | result.config.label = optarg; | ||
| 228 | break; | 274 | break; |
| 229 | case 'l': /* label */ | 275 | case 'u': /* timeout */ |
| 230 | label = optarg; | 276 | result.config.units = optarg; |
| 231 | break; | 277 | break; |
| 232 | case 'u': /* timeout */ | 278 | case 'V': /* version */ |
| 233 | units = optarg; | 279 | print_revision(progname, NP_VERSION); |
| 280 | exit(STATE_UNKNOWN); | ||
| 281 | case 'h': /* help */ | ||
| 282 | print_help(); | ||
| 283 | exit(STATE_UNKNOWN); | ||
| 284 | case '?': /* help */ | ||
| 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; | ||
| 234 | break; | 295 | break; |
| 235 | case 'V': /* version */ | 296 | } |
| 236 | print_revision (progname, NP_VERSION); | ||
| 237 | exit (STATE_UNKNOWN); | ||
| 238 | case 'h': /* help */ | ||
| 239 | print_help (); | ||
| 240 | exit (STATE_UNKNOWN); | ||
| 241 | case '?': /* help */ | ||
| 242 | usage5 (); | ||
| 243 | } | 297 | } |
| 244 | } | 298 | } |
| 245 | 299 | ||
| 246 | c = optind; | 300 | option_char = optind; |
| 247 | if (log_file == NULL && argc > c) { | 301 | if (result.config.log_file == NULL && argc > option_char) { |
| 248 | log_file = argv[c++]; | 302 | result.config.log_file = argv[option_char++]; |
| 249 | } | 303 | } |
| 250 | 304 | ||
| 251 | if (expire_minutes <= 0 && argc > c) { | 305 | if (result.config.expire_minutes <= 0 && argc > option_char) { |
| 252 | if (is_intpos (argv[c])) | 306 | if (is_intpos(argv[option_char])) { |
| 253 | expire_minutes = atoi (argv[c++]); | 307 | result.config.expire_minutes = atoi(argv[option_char++]); |
| 254 | else | 308 | } else { |
| 255 | die (STATE_UNKNOWN, | 309 | die(STATE_UNKNOWN, |
| 256 | _("%s is not a valid expiration time\nUse '%s -h' for additional help\n"), | 310 | _("%s is not a valid expiration time\nUse '%s -h' for additional help\n"), |
| 257 | argv[c], progname); | 311 | argv[option_char], progname); |
| 312 | } | ||
| 258 | } | 313 | } |
| 259 | 314 | ||
| 260 | if (argc > c && strcmp (argv[c], "MAX") == 0) { | 315 | if (argc > option_char && strcmp(argv[option_char], "MAX") == 0) { |
| 261 | use_average = false; | 316 | result.config.use_average = false; |
| 262 | c++; | 317 | option_char++; |
| 263 | } | 318 | } else if (argc > option_char && strcmp(argv[option_char], "AVG") == 0) { |
| 264 | else if (argc > c && strcmp (argv[c], "AVG") == 0) { | 319 | result.config.use_average = true; |
| 265 | use_average = true; | 320 | option_char++; |
| 266 | c++; | ||
| 267 | } | 321 | } |
| 268 | 322 | ||
| 269 | if (argc > c && variable_number == -1) { | 323 | if (argc > option_char && result.config.variable_number == -1) { |
| 270 | variable_number = atoi (argv[c++]); | 324 | result.config.variable_number = atoi(argv[option_char++]); |
| 271 | if (variable_number < 1 || variable_number > 2) { | 325 | if (result.config.variable_number < 1 || result.config.variable_number > 2) { |
| 272 | printf ("%s :", argv[c]); | 326 | printf("%s :", argv[option_char]); |
| 273 | usage (_("Invalid variable number\n")); | 327 | usage(_("Invalid variable number\n")); |
| 274 | } | 328 | } |
| 275 | } | 329 | } |
| 276 | 330 | ||
| 277 | if (argc > c && value_warning_threshold == 0) { | 331 | if (argc > option_char && !result.config.values_threshold.warning_is_set) { |
| 278 | value_warning_threshold = strtoul (argv[c++], NULL, 10); | 332 | mp_range_parsed tmp = mp_parse_range_string(argv[option_char++]); |
| 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); | ||
| 279 | } | 338 | } |
| 280 | 339 | ||
| 281 | if (argc > c && value_critical_threshold == 0) { | 340 | if (argc > option_char && !result.config.values_threshold.critical_is_set) { |
| 282 | value_critical_threshold = strtoul (argv[c++], NULL, 10); | 341 | mp_range_parsed tmp = mp_parse_range_string(argv[option_char++]); |
| 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); | ||
| 283 | } | 347 | } |
| 284 | 348 | ||
| 285 | if (argc > c && strlen (label) == 0) { | 349 | if (argc > option_char && strlen(result.config.label) == 0) { |
| 286 | label = argv[c++]; | 350 | result.config.label = argv[option_char++]; |
| 287 | } | 351 | } |
| 288 | 352 | ||
| 289 | if (argc > c && strlen (units) == 0) { | 353 | if (argc > option_char && strlen(result.config.units) == 0) { |
| 290 | units = argv[c++]; | 354 | result.config.units = argv[option_char++]; |
| 291 | } | 355 | } |
| 292 | 356 | ||
| 293 | return validate_arguments (); | 357 | return validate_arguments(result); |
| 294 | } | 358 | } |
| 295 | 359 | ||
| 296 | int | 360 | check_mrtg_config_wrapper validate_arguments(check_mrtg_config_wrapper config_wrapper) { |
| 297 | validate_arguments (void) | 361 | if (config_wrapper.config.variable_number == -1) { |
| 298 | { | 362 | usage4(_("You must supply the variable number")); |
| 299 | if (variable_number == -1) | 363 | } |
| 300 | usage4 (_("You must supply the variable number")); | ||
| 301 | 364 | ||
| 302 | if (label == NULL) | 365 | if (config_wrapper.config.label == NULL) { |
| 303 | label = strdup ("value"); | 366 | config_wrapper.config.label = strdup("value"); |
| 367 | } | ||
| 304 | 368 | ||
| 305 | if (units == NULL) | 369 | if (config_wrapper.config.units == NULL) { |
| 306 | units = strdup (""); | 370 | config_wrapper.config.units = strdup(""); |
| 371 | } | ||
| 307 | 372 | ||
| 308 | return OK; | 373 | return config_wrapper; |
| 309 | } | 374 | } |
| 310 | 375 | ||
| 311 | 376 | void print_help(void) { | |
| 312 | 377 | print_revision(progname, NP_VERSION); | |
| 313 | void | 378 | |
| 314 | print_help (void) | 379 | printf("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n"); |
| 315 | { | 380 | printf(COPYRIGHT, copyright, email); |
| 316 | print_revision (progname, NP_VERSION); | 381 | |
| 317 | 382 | printf("%s\n", _("This plugin will check either the average or maximum value of one of the")); | |
| 318 | printf ("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n"); | 383 | printf("%s\n", _("two variables recorded in an MRTG log file.")); |
| 319 | printf (COPYRIGHT, copyright, email); | 384 | |
| 320 | 385 | printf("\n\n"); | |
| 321 | printf ("%s\n", _("This plugin will check either the average or maximum value of one of the")); | 386 | |
| 322 | printf ("%s\n", _("two variables recorded in an MRTG log file.")); | 387 | print_usage(); |
| 323 | 388 | ||
| 324 | printf ("\n\n"); | 389 | printf(UT_HELP_VRSN); |
| 325 | 390 | printf(UT_EXTRA_OPTS); | |
| 326 | print_usage (); | 391 | |
| 327 | 392 | printf(" %s\n", "-F, --logfile=FILE"); | |
| 328 | printf (UT_HELP_VRSN); | 393 | printf(" %s\n", _("The MRTG log file containing the data you want to monitor")); |
| 329 | printf (UT_EXTRA_OPTS); | 394 | printf(" %s\n", "-e, --expires=MINUTES"); |
| 330 | 395 | printf(" %s\n", _("Minutes before MRTG data is considered to be too old")); | |
| 331 | printf (" %s\n", "-F, --logfile=FILE"); | 396 | printf(" %s\n", "-a, --aggregation=AVG|MAX"); |
| 332 | printf (" %s\n", _("The MRTG log file containing the data you want to monitor")); | 397 | printf(" %s\n", _("Should we check average or maximum values?")); |
| 333 | printf (" %s\n", "-e, --expires=MINUTES"); | 398 | printf(" %s\n", "-v, --variable=INTEGER"); |
| 334 | printf (" %s\n", _("Minutes before MRTG data is considered to be too old")); | 399 | printf(" %s\n", _("Which variable set should we inspect? (1 or 2)")); |
| 335 | printf (" %s\n", "-a, --aggregation=AVG|MAX"); | 400 | printf(" %s\n", "-w, --warning=INTEGER"); |
| 336 | printf (" %s\n", _("Should we check average or maximum values?")); | 401 | printf(" %s\n", _("Threshold value for data to result in WARNING status")); |
| 337 | printf (" %s\n", "-v, --variable=INTEGER"); | 402 | printf(" %s\n", "-c, --critical=INTEGER"); |
| 338 | printf (" %s\n", _("Which variable set should we inspect? (1 or 2)")); | 403 | printf(" %s\n", _("Threshold value for data to result in CRITICAL status")); |
| 339 | printf (" %s\n", "-w, --warning=INTEGER"); | 404 | printf(" %s\n", "-l, --label=STRING"); |
| 340 | printf (" %s\n", _("Threshold value for data to result in WARNING status")); | 405 | printf(" %s\n", _("Type label for data (Examples: Conns, \"Processor Load\", In, Out)")); |
| 341 | printf (" %s\n", "-c, --critical=INTEGER"); | 406 | printf(" %s\n", "-u, --units=STRING"); |
| 342 | printf (" %s\n", _("Threshold value for data to result in CRITICAL status")); | 407 | printf(" %s\n", _("Option units label for data (Example: Packets/Sec, Errors/Sec,")); |
| 343 | printf (" %s\n", "-l, --label=STRING"); | 408 | printf(" %s\n", _("\"Bytes Per Second\", \"%% Utilization\")")); |
| 344 | printf (" %s\n", _("Type label for data (Examples: Conns, \"Processor Load\", In, Out)")); | 409 | |
| 345 | printf (" %s\n", "-u, --units=STRING"); | 410 | printf(UT_OUTPUT_FORMAT); |
| 346 | printf (" %s\n", _("Option units label for data (Example: Packets/Sec, Errors/Sec,")); | 411 | |
| 347 | printf (" %s\n", _("\"Bytes Per Second\", \"%% Utilization\")")); | 412 | printf("\n"); |
| 348 | 413 | printf(" %s\n", | |
| 349 | printf ("\n"); | 414 | _("If the value exceeds the <vwl> threshold, a WARNING status is returned. If")); |
| 350 | printf (" %s\n", _("If the value exceeds the <vwl> threshold, a WARNING status is returned. If")); | 415 | printf(" %s\n", _("the value exceeds the <vcl> threshold, a CRITICAL status is returned. If")); |
| 351 | printf (" %s\n", _("the value exceeds the <vcl> threshold, a CRITICAL status is returned. If")); | 416 | printf(" %s\n", _("the data in the log file is older than <expire_minutes> old, a WARNING")); |
| 352 | printf (" %s\n", _("the data in the log file is older than <expire_minutes> old, a WARNING")); | 417 | printf(" %s\n", _("status is returned and a warning message is printed.")); |
| 353 | printf (" %s\n", _("status is returned and a warning message is printed.")); | 418 | |
| 354 | 419 | printf("\n"); | |
| 355 | printf ("\n"); | 420 | printf(" %s\n", |
| 356 | printf (" %s\n", _("This plugin is useful for monitoring MRTG data that does not correspond to")); | 421 | _("This plugin is useful for monitoring MRTG data that does not correspond to")); |
| 357 | printf (" %s\n", _("bandwidth usage. (Use the check_mrtgtraf plugin for monitoring bandwidth).")); | 422 | printf(" %s\n", |
| 358 | printf (" %s\n", _("It can be used to monitor any kind of data that MRTG is monitoring - errors,")); | 423 | _("bandwidth usage. (Use the check_mrtgtraf plugin for monitoring bandwidth).")); |
| 359 | printf (" %s\n", _("packets/sec, etc. I use MRTG in conjunction with the Novell NLM that allows")); | 424 | printf(" %s\n", |
| 360 | printf (" %s\n", _("me to track processor utilization, user connections, drive space, etc and")); | 425 | _("It can be used to monitor any kind of data that MRTG is monitoring - errors,")); |
| 361 | printf (" %s\n\n", _("this plugin works well for monitoring that kind of data as well.")); | 426 | printf(" %s\n", |
| 362 | 427 | _("packets/sec, etc. I use MRTG in conjunction with the Novell NLM that allows")); | |
| 363 | printf ("%s\n", _("Notes:")); | 428 | printf(" %s\n", _("me to track processor utilization, user connections, drive space, etc and")); |
| 364 | printf (" %s\n", _("- This plugin only monitors one of the two variables stored in the MRTG log")); | 429 | printf(" %s\n\n", _("this plugin works well for monitoring that kind of data as well.")); |
| 365 | printf (" %s\n", _("file. If you want to monitor both values you will have to define two")); | 430 | |
| 366 | printf (" %s\n", _("commands with different values for the <variable> argument. Of course,")); | 431 | printf("%s\n", _("Notes:")); |
| 367 | printf (" %s\n", _("you can always hack the code to make this plugin work for you...")); | 432 | printf(" %s\n", |
| 368 | printf (" %s\n", _("- MRTG stands for the Multi Router Traffic Grapher. It can be downloaded from")); | 433 | _("- This plugin only monitors one of the two variables stored in the MRTG log")); |
| 369 | printf (" %s\n", "http://ee-staff.ethz.ch/~oetiker/webtools/mrtg/mrtg.html"); | 434 | printf(" %s\n", _("file. If you want to monitor both values you will have to define two")); |
| 370 | 435 | printf(" %s\n", _("commands with different values for the <variable> argument. Of course,")); | |
| 371 | printf (UT_SUPPORT); | 436 | printf(" %s\n", _("you can always hack the code to make this plugin work for you...")); |
| 437 | printf(" %s\n", | ||
| 438 | _("- MRTG stands for the Multi Router Traffic Grapher. It can be downloaded from")); | ||
| 439 | printf(" %s\n", "http://ee-staff.ethz.ch/~oetiker/webtools/mrtg/mrtg.html"); | ||
| 440 | |||
| 441 | printf(UT_SUPPORT); | ||
| 372 | } | 442 | } |
| 373 | 443 | ||
| 374 | |||
| 375 | |||
| 376 | /* original command line: | 444 | /* original command line: |
| 377 | <log_file> <expire_minutes> <AVG|MAX> <variable> <vwl> <vcl> <label> [units] */ | 445 | <log_file> <expire_minutes> <AVG|MAX> <variable> <vwl> <vcl> <label> [units] */ |
| 378 | 446 | ||
| 379 | void | 447 | void print_usage(void) { |
| 380 | print_usage (void) | 448 | printf("%s\n", _("Usage:")); |
| 381 | { | 449 | printf("%s -F log_file -a <AVG | MAX> -v variable -w warning -c critical\n", progname); |
| 382 | printf ("%s\n", _("Usage:")); | 450 | printf("[-l label] [-u units] [-e expire_minutes] [-t timeout] [-v]\n"); |
| 383 | printf ("%s -F log_file -a <AVG | MAX> -v variable -w warning -c critical\n",progname); | ||
| 384 | printf ("[-l label] [-u units] [-e expire_minutes] [-t timeout] [-v]\n"); | ||
| 385 | } | 451 | } |
