summaryrefslogtreecommitdiffstats
path: root/plugins/check_mrtgtraf.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_mrtgtraf.c')
-rw-r--r--plugins/check_mrtgtraf.c632
1 files changed, 354 insertions, 278 deletions
diff --git a/plugins/check_mrtgtraf.c b/plugins/check_mrtgtraf.c
index bd25d47d..46b94f57 100644
--- a/plugins/check_mrtgtraf.c
+++ b/plugins/check_mrtgtraf.c
@@ -1,381 +1,457 @@
1/***************************************************************************** 1/*****************************************************************************
2* 2 *
3* Monitoring check_mrtgtraf plugin 3 * Monitoring check_mrtgtraf 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_mtrgtraf plugin 10 * This file contains the check_mtrgtraf plugin
11* 11 *
12* This plugin will check the incoming/outgoing transfer rates of a router 12 * This plugin will check the incoming/outgoing transfer rates of a router
13* switch, etc recorded in an MRTG log. 13 * switch, etc recorded in an MRTG log.
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 31
32#include "check_mrtgtraf.d/config.h"
32#include "common.h" 33#include "common.h"
34#include "output.h"
35#include "perfdata.h"
36#include "states.h"
37#include "thresholds.h"
33#include "utils.h" 38#include "utils.h"
34 39
35const char *progname = "check_mrtgtraf"; 40const char *progname = "check_mrtgtraf";
36const char *copyright = "1999-2007"; 41const char *copyright = "1999-2024";
37const char *email = "devel@monitoring-plugins.org"; 42const char *email = "devel@monitoring-plugins.org";
38 43
39int process_arguments (int, char **); 44typedef struct {
40int validate_arguments (void); 45 int errorcode;
41void print_help(void); 46 check_mrtgtraf_config config;
42void print_usage(void); 47} check_mrtgtraf_config_wrapper;
43 48
44char *log_file = NULL; 49static check_mrtgtraf_config_wrapper process_arguments(int /*argc*/, char ** /*argv*/);
45int expire_minutes = -1; 50static void print_help(void);
46bool use_average = true; 51void print_usage(void);
47unsigned long incoming_warning_threshold = 0L;
48unsigned long incoming_critical_threshold = 0L;
49unsigned long outgoing_warning_threshold = 0L;
50unsigned long outgoing_critical_threshold = 0L;
51
52
53int
54main (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 char *error_message;
63 time_t timestamp = 0L;
64 unsigned long average_incoming_rate = 0L;
65 unsigned long average_outgoing_rate = 0L;
66 unsigned long maximum_incoming_rate = 0L;
67 unsigned long maximum_outgoing_rate = 0L;
68 unsigned long incoming_rate = 0L;
69 unsigned long outgoing_rate = 0L;
70 double adjusted_incoming_rate = 0.0;
71 double adjusted_outgoing_rate = 0.0;
72 char incoming_speed_rating[8];
73 char outgoing_speed_rating[8];
74 52
75 setlocale (LC_ALL, ""); 53int main(int argc, char **argv) {
76 bindtextdomain (PACKAGE, LOCALEDIR); 54 setlocale(LC_ALL, "");
77 textdomain (PACKAGE); 55 bindtextdomain(PACKAGE, LOCALEDIR);
56 textdomain(PACKAGE);
78 57
79 /* Parse extra opts if any */ 58 /* Parse extra opts if any */
80 argv=np_extra_opts (&argc, argv, progname); 59 argv = np_extra_opts(&argc, argv, progname);
81 60
82 if (process_arguments (argc, argv) == ERROR) 61 check_mrtgtraf_config_wrapper tmp_config = process_arguments(argc, argv);
83 usage4 (_("Could not parse arguments")); 62 if (tmp_config.errorcode == ERROR) {
63 usage4(_("Could not parse arguments"));
64 }
84 65
85 /* open the MRTG log file for reading */ 66 const check_mrtgtraf_config config = tmp_config.config;
86 fp = fopen (log_file, "r"); 67
87 if (fp == NULL) 68 if (config.output_format_is_set) {
88 usage4 (_("Unable to open MRTG log file")); 69 mp_set_format(config.output_format);
70 }
89 71
90 line = 0; 72 mp_check overall = mp_check_init();
91 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, fp)) { 73 mp_subcheck sc_open_mrtg_log_file = mp_subcheck_init();
92 74
75 /* open the MRTG log file for reading */
76 FILE *mrtg_log_file_ptr = fopen(config.log_file, "r");
77 if (mrtg_log_file_ptr == NULL) {
78 sc_open_mrtg_log_file = mp_set_subcheck_state(sc_open_mrtg_log_file, STATE_UNKNOWN);
79 xasprintf(&sc_open_mrtg_log_file.output, "unable to open MRTG log file");
80 mp_add_subcheck_to_check(&overall, sc_open_mrtg_log_file);
81 mp_exit(overall);
82 } else {
83 sc_open_mrtg_log_file = mp_set_subcheck_state(sc_open_mrtg_log_file, STATE_OK);
84 xasprintf(&sc_open_mrtg_log_file.output, "opened MRTG log file");
85 mp_add_subcheck_to_check(&overall, sc_open_mrtg_log_file);
86 }
87
88 time_t timestamp = 0L;
89 char input_buffer[MAX_INPUT_BUFFER];
90 unsigned long average_incoming_rate = 0L;
91 unsigned long average_outgoing_rate = 0L;
92 unsigned long maximum_incoming_rate = 0L;
93 unsigned long maximum_outgoing_rate = 0L;
94 int line = 0;
95 while (fgets(input_buffer, MAX_INPUT_BUFFER - 1, mrtg_log_file_ptr)) {
93 line++; 96 line++;
94 97
95 /* skip the first line of the log file */ 98 /* skip the first line of the log file */
96 if (line == 1) 99 if (line == 1) {
97 continue; 100 continue;
101 }
98 102
99 /* break out of read loop */ 103 /* break out of read loop */
100 /* if we've passed the number of entries we want to read */ 104 /* if we've passed the number of entries we want to read */
101 if (line > 2) 105 if (line > 2) {
102 break; 106 break;
107 }
103 108
104 /* grab the timestamp */ 109 /* grab the timestamp */
105 temp_buffer = strtok (input_buffer, " "); 110 char *temp_buffer = strtok(input_buffer, " ");
106 timestamp = strtoul (temp_buffer, NULL, 10); 111 timestamp = strtoul(temp_buffer, NULL, 10);
107 112
108 /* grab the average incoming transfer rate */ 113 /* grab the average incoming transfer rate */
109 temp_buffer = strtok (NULL, " "); 114 temp_buffer = strtok(NULL, " ");
110 average_incoming_rate = strtoul (temp_buffer, NULL, 10); 115 average_incoming_rate = strtoul(temp_buffer, NULL, 10);
111 116
112 /* grab the average outgoing transfer rate */ 117 /* grab the average outgoing transfer rate */
113 temp_buffer = strtok (NULL, " "); 118 temp_buffer = strtok(NULL, " ");
114 average_outgoing_rate = strtoul (temp_buffer, NULL, 10); 119 average_outgoing_rate = strtoul(temp_buffer, NULL, 10);
115 120
116 /* grab the maximum incoming transfer rate */ 121 /* grab the maximum incoming transfer rate */
117 temp_buffer = strtok (NULL, " "); 122 temp_buffer = strtok(NULL, " ");
118 maximum_incoming_rate = strtoul (temp_buffer, NULL, 10); 123 maximum_incoming_rate = strtoul(temp_buffer, NULL, 10);
119 124
120 /* grab the maximum outgoing transfer rate */ 125 /* grab the maximum outgoing transfer rate */
121 temp_buffer = strtok (NULL, " "); 126 temp_buffer = strtok(NULL, " ");
122 maximum_outgoing_rate = strtoul (temp_buffer, NULL, 10); 127 maximum_outgoing_rate = strtoul(temp_buffer, NULL, 10);
123 } 128 }
124 129
125 /* close the log file */ 130 /* close the log file */
126 fclose (fp); 131 fclose(mrtg_log_file_ptr);
127 132
128 /* if we couldn't read enough data, return an unknown error */ 133 /* if we couldn't read enough data, return an unknown error */
129 if (line <= 2) 134 if (line <= 2) {
130 usage4 (_("Unable to process MRTG log file")); 135 usage4(_("Unable to process MRTG log file"));
136 }
131 137
132 /* make sure the MRTG data isn't too old */ 138 /* make sure the MRTG data isn't too old */
133 time (&current_time); 139 time_t current_time;
134 if ((expire_minutes > 0) && 140 time(&current_time);
135 (current_time - timestamp) > (expire_minutes * 60)) 141 mp_subcheck sc_expired = mp_subcheck_init();
136 die (STATE_WARNING, _("MRTG data has expired (%d minutes old)\n"), 142 if ((config.expire_minutes > 0) && (current_time - timestamp) > (config.expire_minutes * 60)) {
137 (int) ((current_time - timestamp) / 60)); 143 xasprintf(&sc_expired.output, "MRTG data has expired (%d minutes old)",
144 (int)((current_time - timestamp) / 60));
145 sc_expired = mp_set_subcheck_state(sc_expired, STATE_WARNING);
146 mp_add_subcheck_to_check(&overall, sc_expired);
147 mp_exit(overall);
148 }
149
150 xasprintf(&sc_expired.output, "MRTG data should be valid (%d minutes old)",
151 (int)((current_time - timestamp) / 60));
152 sc_expired = mp_set_subcheck_state(sc_expired, STATE_WARNING);
153 mp_add_subcheck_to_check(&overall, sc_expired);
138 154
155 unsigned long incoming_rate = 0L;
156 unsigned long outgoing_rate = 0L;
139 /* else check the incoming/outgoing rates */ 157 /* else check the incoming/outgoing rates */
140 if (use_average) { 158 if (config.use_average) {
141 incoming_rate = average_incoming_rate; 159 incoming_rate = average_incoming_rate;
142 outgoing_rate = average_outgoing_rate; 160 outgoing_rate = average_outgoing_rate;
143 } 161 } else {
144 else {
145 incoming_rate = maximum_incoming_rate; 162 incoming_rate = maximum_incoming_rate;
146 outgoing_rate = maximum_outgoing_rate; 163 outgoing_rate = maximum_outgoing_rate;
147 } 164 }
148 165
166 double adjusted_incoming_rate = 0.0;
167 char incoming_speed_rating[8];
149 /* report incoming traffic in Bytes/sec */ 168 /* report incoming traffic in Bytes/sec */
150 if (incoming_rate < 1024) { 169 if (incoming_rate < 1024) {
151 strcpy (incoming_speed_rating, "B"); 170 strcpy(incoming_speed_rating, "B");
152 adjusted_incoming_rate = (double) incoming_rate; 171 adjusted_incoming_rate = (double)incoming_rate;
153 } 172 }
154 173
155 /* report incoming traffic in KBytes/sec */ 174 /* report incoming traffic in KBytes/sec */
156 else if (incoming_rate < (1024 * 1024)) { 175 else if (incoming_rate < (1024 * 1024)) {
157 strcpy (incoming_speed_rating, "KB"); 176 strcpy(incoming_speed_rating, "KB");
158 adjusted_incoming_rate = (double) (incoming_rate / 1024.0); 177 adjusted_incoming_rate = ((double)incoming_rate / 1024.0);
159 } 178 }
160 179
161 /* report incoming traffic in MBytes/sec */ 180 /* report incoming traffic in MBytes/sec */
162 else { 181 else {
163 strcpy (incoming_speed_rating, "MB"); 182 strcpy(incoming_speed_rating, "MB");
164 adjusted_incoming_rate = (double) (incoming_rate / 1024.0 / 1024.0); 183 adjusted_incoming_rate = ((double)incoming_rate / 1024.0 / 1024.0);
165 } 184 }
166 185
167 /* report outgoing traffic in Bytes/sec */ 186 double adjusted_outgoing_rate = 0.0;
187 char outgoing_speed_rating[8];
168 if (outgoing_rate < 1024) { 188 if (outgoing_rate < 1024) {
169 strcpy (outgoing_speed_rating, "B"); 189 /* report outgoing traffic in Bytes/sec */
170 adjusted_outgoing_rate = (double) outgoing_rate; 190 strcpy(outgoing_speed_rating, "B");
171 } 191 adjusted_outgoing_rate = (double)outgoing_rate;
172 192 } else if (outgoing_rate < (1024 * 1024)) {
173 /* report outgoing traffic in KBytes/sec */ 193 /* report outgoing traffic in KBytes/sec */
174 else if (outgoing_rate < (1024 * 1024)) { 194 strcpy(outgoing_speed_rating, "KB");
175 strcpy (outgoing_speed_rating, "KB"); 195 adjusted_outgoing_rate = ((double)outgoing_rate / 1024.0);
176 adjusted_outgoing_rate = (double) (outgoing_rate / 1024.0); 196 } else {
177 } 197 /* report outgoing traffic in MBytes/sec */
178 198 strcpy(outgoing_speed_rating, "MB");
179 /* report outgoing traffic in MBytes/sec */ 199 adjusted_outgoing_rate = ((double)outgoing_rate / 1024.0 / 1024.0);
180 else {
181 strcpy (outgoing_speed_rating, "MB");
182 adjusted_outgoing_rate = (double) (outgoing_rate / 1024.0 / 1024.0);
183 }
184
185 if (incoming_rate > incoming_critical_threshold
186 || outgoing_rate > outgoing_critical_threshold) {
187 result = STATE_CRITICAL;
188 }
189 else if (incoming_rate > incoming_warning_threshold
190 || outgoing_rate > outgoing_warning_threshold) {
191 result = STATE_WARNING;
192 } 200 }
193 201
194 xasprintf (&error_message, _("%s. In = %0.1f %s/s, %s. Out = %0.1f %s/s|%s %s\n"), 202 mp_perfdata pd_rate_in = perfdata_init();
195 (use_average) ? _("Avg") : _("Max"), adjusted_incoming_rate, 203 pd_rate_in.label = "in";
196 incoming_speed_rating, (use_average) ? _("Avg") : _("Max"), 204 pd_rate_in = mp_set_pd_value(pd_rate_in, incoming_rate);
197 adjusted_outgoing_rate, outgoing_speed_rating, 205 pd_rate_in.uom = "B";
198 fperfdata("in", adjusted_incoming_rate, incoming_speed_rating, 206 pd_rate_in = mp_pd_set_thresholds(pd_rate_in, config.incoming_thresholds);
199 (int)incoming_warning_threshold, incoming_warning_threshold, 207
200 (int)incoming_critical_threshold, incoming_critical_threshold, 208 mp_perfdata pd_rate_out = perfdata_init();
201 true, 0, false, 0), 209 pd_rate_out.label = "out";
202 fperfdata("out", adjusted_outgoing_rate, outgoing_speed_rating, 210 pd_rate_out = mp_set_pd_value(pd_rate_out, outgoing_rate);
203 (int)outgoing_warning_threshold, outgoing_warning_threshold, 211 pd_rate_out.uom = "B";
204 (int)outgoing_critical_threshold, outgoing_critical_threshold, 212 pd_rate_out = mp_pd_set_thresholds(pd_rate_out, config.outgoing_thresholds);
205 true, 0, false, 0)); 213
206 214 mp_subcheck sc_rate_in = mp_subcheck_init();
207 printf (_("Traffic %s - %s\n"), state_text(result), error_message); 215 sc_rate_in = mp_set_subcheck_state(sc_rate_in, mp_get_pd_status(pd_rate_in));
208 216 mp_add_perfdata_to_subcheck(&sc_rate_in, pd_rate_in);
209 return result; 217 xasprintf(&sc_rate_in.output, "%s. In = %0.1f %s/s", (config.use_average) ? _("Avg") : _("Max"),
218 adjusted_incoming_rate, incoming_speed_rating);
219
220 mp_subcheck sc_rate_out = mp_subcheck_init();
221 sc_rate_out = mp_set_subcheck_state(sc_rate_out, mp_get_pd_status(pd_rate_out));
222 mp_add_perfdata_to_subcheck(&sc_rate_out, pd_rate_out);
223 xasprintf(&sc_rate_out.output, "%s. Out = %0.1f %s/s",
224 (config.use_average) ? _("Avg") : _("Max"), adjusted_outgoing_rate,
225 outgoing_speed_rating);
226
227 mp_subcheck sc_rate = mp_subcheck_init();
228 xasprintf(&sc_rate.output, "Traffic");
229 mp_add_subcheck_to_subcheck(&sc_rate, sc_rate_in);
230 mp_add_subcheck_to_subcheck(&sc_rate, sc_rate_out);
231
232 mp_add_subcheck_to_check(&overall, sc_rate);
233
234 mp_exit(overall);
210} 235}
211 236
212
213
214/* process command-line arguments */ 237/* process command-line arguments */
215int 238check_mrtgtraf_config_wrapper process_arguments(int argc, char **argv) {
216process_arguments (int argc, char **argv) 239 enum {
217{ 240 output_format_index = CHAR_MAX + 1,
218 int c;
219
220 int option = 0;
221 static struct option longopts[] = {
222 {"filename", required_argument, 0, 'F'},
223 {"expires", required_argument, 0, 'e'},
224 {"aggregation", required_argument, 0, 'a'},
225 {"critical", required_argument, 0, 'c'},
226 {"warning", required_argument, 0, 'w'},
227 {"version", no_argument, 0, 'V'},
228 {"help", no_argument, 0, 'h'},
229 {0, 0, 0, 0}
230 }; 241 };
231 242
232 if (argc < 2) 243 static struct option longopts[] = {{"filename", required_argument, 0, 'F'},
233 return ERROR; 244 {"expires", required_argument, 0, 'e'},
234 245 {"aggregation", required_argument, 0, 'a'},
235 for (c = 1; c < argc; c++) { 246 {"critical", required_argument, 0, 'c'},
236 if (strcmp ("-to", argv[c]) == 0) 247 {"warning", required_argument, 0, 'w'},
237 strcpy (argv[c], "-t"); 248 {"version", no_argument, 0, 'V'},
238 else if (strcmp ("-wt", argv[c]) == 0) 249 {"help", no_argument, 0, 'h'},
239 strcpy (argv[c], "-w"); 250 {"output-format", required_argument, 0, output_format_index},
240 else if (strcmp ("-ct", argv[c]) == 0) 251 {0, 0, 0, 0}};
241 strcpy (argv[c], "-c"); 252
253 check_mrtgtraf_config_wrapper result = {
254 .errorcode = OK,
255 .config = check_mrtgtraf_config_init(),
256 };
257 if (argc < 2) {
258 result.errorcode = ERROR;
259 return result;
242 } 260 }
243 261
244 while (1) { 262 for (int i = 1; i < argc; i++) {
245 c = getopt_long (argc, argv, "hVF:e:a:c:w:", longopts, &option); 263 if (strcmp("-to", argv[i]) == 0) {
264 strcpy(argv[i], "-t");
265 } else if (strcmp("-wt", argv[i]) == 0) {
266 strcpy(argv[i], "-w");
267 } else if (strcmp("-ct", argv[i]) == 0) {
268 strcpy(argv[i], "-c");
269 }
270 }
246 271
247 if (c == -1 || c == EOF) 272 int option_char;
273 int option = 0;
274 unsigned long incoming_warning_threshold = 0;
275 unsigned long incoming_critical_threshold = 0;
276 unsigned long outgoing_warning_threshold = 0;
277 unsigned long outgoing_critical_threshold = 0;
278 bool incoming_warning_set = false;
279 bool incoming_critical_set = false;
280 bool outgoing_warning_set = false;
281 bool outgoing_critical_set = false;
282 while (true) {
283 option_char = getopt_long(argc, argv, "hVF:e:a:c:w:", longopts, &option);
284
285 if (option_char == -1 || option_char == EOF) {
248 break; 286 break;
287 }
249 288
250 switch (c) { 289 switch (option_char) {
251 case 'F': /* input file */ 290 case 'F': /* input file */
252 log_file = optarg; 291 result.config.log_file = optarg;
292 break;
293 case 'e': /* expiration time */
294 result.config.expire_minutes = atoi(optarg);
253 break; 295 break;
254 case 'e': /* expiration time */ 296 case 'a': /* aggregation (AVE or MAX) */
255 expire_minutes = atoi (optarg); 297 result.config.use_average = (bool)(strcmp(optarg, "MAX"));
256 break; 298 break;
257 case 'a': /* aggregation (AVE or MAX) */ 299 case 'c': /* critical threshold */
258 if (!strcmp (optarg, "MAX")) 300 sscanf(optarg, "%lu,%lu", &incoming_critical_threshold, &outgoing_critical_threshold);
259 use_average = false; 301 incoming_critical_set = true;
260 else 302 outgoing_critical_set = true;
261 use_average = true;
262 break; 303 break;
263 case 'c': /* warning threshold */ 304 case 'w': /* warning threshold */
264 sscanf (optarg, "%lu,%lu", &incoming_critical_threshold, 305 sscanf(optarg, "%lu,%lu", &incoming_warning_threshold, &outgoing_warning_threshold);
265 &outgoing_critical_threshold); 306 incoming_warning_set = true;
307 incoming_critical_set = true;
266 break; 308 break;
267 case 'w': /* critical threshold */ 309 case 'V': /* version */
268 sscanf (optarg, "%lu,%lu", &incoming_warning_threshold, 310 print_revision(progname, NP_VERSION);
269 &outgoing_warning_threshold); 311 exit(STATE_UNKNOWN);
312 case 'h': /* help */
313 print_help();
314 exit(STATE_UNKNOWN);
315 case '?': /* help */
316 usage5();
317 case output_format_index: {
318 parsed_output_format parser = mp_parse_output_format(optarg);
319 if (!parser.parsing_success) {
320 printf("Invalid output format: %s\n", optarg);
321 exit(STATE_UNKNOWN);
322 }
323
324 result.config.output_format_is_set = true;
325 result.config.output_format = parser.output_format;
270 break; 326 break;
271 case 'V': /* version */ 327 }
272 print_revision (progname, NP_VERSION);
273 exit (STATE_UNKNOWN);
274 case 'h': /* help */
275 print_help ();
276 exit (STATE_UNKNOWN);
277 case '?': /* help */
278 usage5 ();
279 } 328 }
280 } 329 }
281 330
282 c = optind; 331 option_char = optind;
283 if (argc > c && log_file == NULL) { 332 if (argc > option_char && result.config.log_file == NULL) {
284 log_file = argv[c++]; 333 result.config.log_file = argv[option_char++];
285 } 334 }
286 335
287 if (argc > c && expire_minutes == -1) { 336 if (argc > option_char && result.config.expire_minutes == -1) {
288 expire_minutes = atoi (argv[c++]); 337 result.config.expire_minutes = atoi(argv[option_char++]);
289 } 338 }
290 339
291 if (argc > c && strcmp (argv[c], "MAX") == 0) { 340 if (argc > option_char && strcmp(argv[option_char], "MAX") == 0) {
292 use_average = false; 341 result.config.use_average = false;
293 c++; 342 option_char++;
343 } else if (argc > option_char && strcmp(argv[option_char], "AVG") == 0) {
344 result.config.use_average = true;
345 option_char++;
294 } 346 }
295 else if (argc > c && strcmp (argv[c], "AVG") == 0) { 347
296 use_average = true; 348 if (argc > option_char && incoming_warning_threshold == 0) {
297 c++; 349 incoming_warning_threshold = strtoul(argv[option_char++], NULL, 10);
350 incoming_warning_set = true;
298 } 351 }
299 352
300 if (argc > c && incoming_warning_threshold == 0) { 353 if (argc > option_char && incoming_critical_threshold == 0) {
301 incoming_warning_threshold = strtoul (argv[c++], NULL, 10); 354 incoming_critical_threshold = strtoul(argv[option_char++], NULL, 10);
355 incoming_critical_set = true;
302 } 356 }
303 357
304 if (argc > c && incoming_critical_threshold == 0) { 358 if (argc > option_char && outgoing_warning_threshold == 0) {
305 incoming_critical_threshold = strtoul (argv[c++], NULL, 10); 359 outgoing_warning_threshold = strtoul(argv[option_char++], NULL, 10);
360 outgoing_warning_set = true;
306 } 361 }
307 362
308 if (argc > c && outgoing_warning_threshold == 0) { 363 if (argc > option_char && outgoing_critical_threshold == 0) {
309 outgoing_warning_threshold = strtoul (argv[c++], NULL, 10); 364 outgoing_critical_threshold = strtoul(argv[option_char++], NULL, 10);
365 outgoing_critical_set = true;
310 } 366 }
311 367
312 if (argc > c && outgoing_critical_threshold == 0) { 368 mp_range incoming_warning = mp_range_init();
313 outgoing_critical_threshold = strtoul (argv[c++], NULL, 10); 369 if (incoming_warning_set) {
370 incoming_warning =
371 mp_range_set_end(incoming_warning, mp_create_pd_value(incoming_warning_threshold));
314 } 372 }
315 373
316 return validate_arguments (); 374 result.config.incoming_thresholds =
317} 375 mp_thresholds_set_warn(result.config.incoming_thresholds, incoming_warning);
318 376
377 mp_range incoming_critical = mp_range_init();
378 if (incoming_critical_set) {
379 incoming_critical =
380 mp_range_set_end(incoming_critical, mp_create_pd_value(incoming_critical_threshold));
381 }
319 382
320int 383 result.config.incoming_thresholds =
321validate_arguments (void) 384 mp_thresholds_set_crit(result.config.incoming_thresholds, incoming_critical);
322{
323 return OK;
324}
325 385
386 mp_range outgoing_warning = mp_range_init();
387 if (outgoing_warning_set) {
388 outgoing_warning =
389 mp_range_set_end(outgoing_warning, mp_create_pd_value(outgoing_warning_threshold));
390 }
326 391
327void 392 result.config.outgoing_thresholds =
328print_help (void) 393 mp_thresholds_set_warn(result.config.outgoing_thresholds, outgoing_warning);
329{ 394
330 print_revision (progname, NP_VERSION); 395 mp_range outgoing_critical = mp_range_init();
331 396 if (outgoing_critical_set) {
332 printf ("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n"); 397 outgoing_critical =
333 printf (COPYRIGHT, copyright, email); 398 mp_range_set_end(outgoing_critical, mp_create_pd_value(outgoing_critical_threshold));
334 399 }
335 printf ("%s\n", _("This plugin will check the incoming/outgoing transfer rates of a router,"));
336 printf ("%s\n", _("switch, etc recorded in an MRTG log. If the newest log entry is older"));
337 printf ("%s\n", _("than <expire_minutes>, a WARNING status is returned. If either the"));
338 printf ("%s\n", _("incoming or outgoing rates exceed the <icl> or <ocl> thresholds (in"));
339 printf ("%s\n", _("Bytes/sec), a CRITICAL status results. If either of the rates exceed"));
340 printf ("%s\n", _("the <iwl> or <owl> thresholds (in Bytes/sec), a WARNING status results."));
341
342 printf ("\n\n");
343
344 print_usage ();
345
346 printf (UT_HELP_VRSN);
347 printf (UT_EXTRA_OPTS);
348
349 printf (" %s\n", "-F, --filename=STRING");
350 printf (" %s\n", _("File to read log from"));
351 printf (" %s\n", "-e, --expires=INTEGER");
352 printf (" %s\n", _("Minutes after which log expires"));
353 printf (" %s\n", "-a, --aggregation=(AVG|MAX)");
354 printf (" %s\n", _("Test average or maximum"));
355 printf (" %s\n", "-w, --warning");
356 printf (" %s\n", _("Warning threshold pair <incoming>,<outgoing>"));
357 printf (" %s\n", "-c, --critical");
358 printf (" %s\n", _("Critical threshold pair <incoming>,<outgoing>"));
359
360 printf ("\n");
361 printf ("%s\n", _("Notes:"));
362 printf (" %s\n", _("- MRTG stands for Multi Router Traffic Grapher. It can be downloaded from"));
363 printf (" %s\n", " http://ee-staff.ethz.ch/~oetiker/webtools/mrtg/mrtg.html");
364 printf (" %s\n", _("- While MRTG can monitor things other than traffic rates, this"));
365 printf (" %s\n", _(" plugin probably won't work with much else without modification."));
366 printf (" %s\n", _("- The calculated i/o rates are a little off from what MRTG actually"));
367 printf (" %s\n", _(" reports. I'm not sure why this is right now, but will look into it"));
368 printf (" %s\n", _(" for future enhancements of this plugin."));
369
370 printf (UT_SUPPORT);
371}
372 400
401 result.config.outgoing_thresholds =
402 mp_thresholds_set_crit(result.config.outgoing_thresholds, outgoing_critical);
373 403
404 return result;
405}
406
407void print_help(void) {
408 print_revision(progname, NP_VERSION);
409
410 printf("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n");
411 printf(COPYRIGHT, copyright, email);
412
413 printf("%s\n", _("This plugin will check the incoming/outgoing transfer rates of a router,"));
414 printf("%s\n", _("switch, etc recorded in an MRTG log. If the newest log entry is older"));
415 printf("%s\n", _("than <expire_minutes>, a WARNING status is returned. If either the"));
416 printf("%s\n", _("incoming or outgoing rates exceed the <icl> or <ocl> thresholds (in"));
417 printf("%s\n", _("Bytes/sec), a CRITICAL status results. If either of the rates exceed"));
418 printf("%s\n", _("the <iwl> or <owl> thresholds (in Bytes/sec), a WARNING status results."));
419
420 printf("\n\n");
421
422 print_usage();
423
424 printf(UT_HELP_VRSN);
425 printf(UT_EXTRA_OPTS);
426
427 printf(" %s\n", "-F, --filename=STRING");
428 printf(" %s\n", _("File to read log from"));
429 printf(" %s\n", "-e, --expires=INTEGER");
430 printf(" %s\n", _("Minutes after which log expires"));
431 printf(" %s\n", "-a, --aggregation=(AVG|MAX)");
432 printf(" %s\n", _("Test average or maximum"));
433 printf(" %s\n", "-w, --warning");
434 printf(" %s\n", _("Warning threshold pair <incoming>,<outgoing>"));
435 printf(" %s\n", "-c, --critical");
436 printf(" %s\n", _("Critical threshold pair <incoming>,<outgoing>"));
437
438 printf(UT_OUTPUT_FORMAT);
439
440 printf("\n");
441 printf("%s\n", _("Notes:"));
442 printf(" %s\n", _("- MRTG stands for Multi Router Traffic Grapher. It can be downloaded from"));
443 printf(" %s\n", " http://ee-staff.ethz.ch/~oetiker/webtools/mrtg/mrtg.html");
444 printf(" %s\n", _("- While MRTG can monitor things other than traffic rates, this"));
445 printf(" %s\n", _(" plugin probably won't work with much else without modification."));
446 printf(" %s\n", _("- The calculated i/o rates are a little off from what MRTG actually"));
447 printf(" %s\n", _(" reports. I'm not sure why this is right now, but will look into it"));
448 printf(" %s\n", _(" for future enhancements of this plugin."));
449
450 printf(UT_SUPPORT);
451}
374 452
375void 453void print_usage(void) {
376print_usage (void) 454 printf(_("Usage"));
377{ 455 printf(" %s -F <log_file> -a <AVG | MAX> -w <warning_pair>\n", progname);
378 printf (_("Usage")); 456 printf("-c <critical_pair> [-e expire_minutes]\n");
379 printf (" %s -F <log_file> -a <AVG | MAX> -w <warning_pair>\n",progname);
380 printf ("-c <critical_pair> [-e expire_minutes]\n");
381} 457}