diff options
Diffstat (limited to 'plugins/check_mrtgtraf.c')
| -rw-r--r-- | plugins/check_mrtgtraf.c | 210 |
1 files changed, 91 insertions, 119 deletions
diff --git a/plugins/check_mrtgtraf.c b/plugins/check_mrtgtraf.c index 21791ae9..c99e4213 100644 --- a/plugins/check_mrtgtraf.c +++ b/plugins/check_mrtgtraf.c | |||
| @@ -1,63 +1,83 @@ | |||
| 1 | /****************************************************************************** | 1 | /****************************************************************************** |
| 2 | * | 2 | |
| 3 | * CHECK_MRTGTRAF.C | 3 | This program is free software; you can redistribute it and/or modify |
| 4 | * | 4 | it under the terms of the GNU General Public License as published by |
| 5 | * Program: MRTG (Multi-Router Traffic Grapher) traffic plugin for Nagios | 5 | the Free Software Foundation; either version 2 of the License, or |
| 6 | * License: GPL | 6 | (at your option) any later version. |
| 7 | * Copyright (c) 1999 Ethan Galstad (nagios@nagios.org) | 7 | |
| 8 | * | 8 | This program is distributed in the hope that it will be useful, |
| 9 | * Last Modified: $Date$ | 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * | 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * Command line: CHECK_MRTGTRAF <log_file> <expire_minutes> <AVG|MAX> <iwl> <icl> <owl> <ocl> | 11 | GNU General Public License for more details. |
| 12 | * | 12 | |
| 13 | * Description: | 13 | You should have received a copy of the GNU General Public License |
| 14 | * | 14 | along with this program; if not, write to the Free Software |
| 15 | * This plugin will check the incoming/outgoing transfer rates of a | 15 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 16 | * router, switch, etc recorded in an MRTG log. If the newest log | 16 | |
| 17 | * entry is older than <expire_minutes>, a WARNING status is returned. | 17 | ******************************************************************************/ |
| 18 | * If either the incoming or outgoing rates exceed the <icl> or <ocl> | 18 | |
| 19 | * thresholds (in Bytes/sec), a CRITICAL status results. If either of | ||
| 20 | * the rates exceed the <iwl> or <owl> thresholds (in Bytes/sec), a | ||
| 21 | * WARNING status results. | ||
| 22 | * | ||
| 23 | * Notes: | ||
| 24 | * - MRTG stands for the Multi Router Traffic Grapher. It can be | ||
| 25 | * downloaded from | ||
| 26 | * http://ee-staff.ethz.ch/~oetiker/webtools/mrtg/mrtg.html | ||
| 27 | * - While MRTG can monitor things other than traffic rates, this | ||
| 28 | * plugin probably won't work with much else without modification. | ||
| 29 | * - The calculated i/o rates are a little off from what MRTG actually | ||
| 30 | * reports. I'm not sure why this is right now, but will look into it | ||
| 31 | * for future enhancements of this plugin. | ||
| 32 | * | ||
| 33 | * License Information: | ||
| 34 | * | ||
| 35 | * This program is free software; you can redistribute it and/or modify | ||
| 36 | * it under the terms of the GNU General Public License as published by | ||
| 37 | * the Free Software Foundation; either version 2 of the License, or | ||
| 38 | * (at your option) any later version. | ||
| 39 | * | ||
| 40 | * This program is distributed in the hope that it will be useful, | ||
| 41 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 42 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 43 | * GNU General Public License for more details. | ||
| 44 | * | ||
| 45 | * You should have received a copy of the GNU General Public License | ||
| 46 | * along with this program; if not, write to the Free Software | ||
| 47 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
| 48 | * | ||
| 49 | *****************************************************************************/ | ||
| 50 | |||
| 51 | #include "config.h" | ||
| 52 | #include "common.h" | 19 | #include "common.h" |
| 53 | #include "utils.h" | 20 | #include "utils.h" |
| 54 | 21 | ||
| 55 | const char *progname = "check_mrtgtraf"; | 22 | const char *progname = "check_mrtgtraf"; |
| 23 | const char *revision = "$Revision$"; | ||
| 24 | const char *copyright = "1999-2003"; | ||
| 25 | const char *email = "nagiosplug-devel@lists.sourceforge.net"; | ||
| 56 | 26 | ||
| 27 | void | ||
| 28 | print_usage (void) | ||
| 29 | { | ||
| 30 | printf (_("\ | ||
| 31 | Usage: %s -F <log_file> -a <AVG | MAX> -v <variable> -w <warning_pair> -c <critical_pair>\n\ | ||
| 32 | [-e expire_minutes] [-t timeout] [-v]\n"), progname); | ||
| 33 | printf (_(UT_HLP_VRS), progname, progname); | ||
| 34 | } | ||
| 35 | |||
| 36 | void | ||
| 37 | print_help (void) | ||
| 38 | { | ||
| 39 | print_revision (progname, revision); | ||
| 40 | |||
| 41 | printf (_(COPYRIGHT), copyright, email); | ||
| 42 | |||
| 43 | print_usage (); | ||
| 44 | |||
| 45 | printf (_(UT_HELP_VRSN)); | ||
| 46 | |||
| 47 | printf (_("\ | ||
| 48 | -F, --filename=STRING\n\ | ||
| 49 | File to read log from\n\ | ||
| 50 | -e, --expires=INTEGER\n\ | ||
| 51 | Minutes after which log expires\n\ | ||
| 52 | -a, --aggregation=(AVG|MAX)\n\ | ||
| 53 | Test average or maximum\n\ | ||
| 54 | -w, --warning\n\ | ||
| 55 | Warning threshold pair \"<incoming>,<outgoing>\"\n\ | ||
| 56 | -c, --critical\n\ | ||
| 57 | Critical threshold pair \"<incoming>,<outgoing>\"\n")); | ||
| 58 | |||
| 59 | printf (_("\n\ | ||
| 60 | This plugin will check the incoming/outgoing transfer rates of a router,\n\ | ||
| 61 | switch, etc recorded in an MRTG log. If the newest log entry is older\n\ | ||
| 62 | than <expire_minutes>, a WARNING status is returned. If either the\n\ | ||
| 63 | incoming or outgoing rates exceed the <icl> or <ocl> thresholds (in\n\ | ||
| 64 | Bytes/sec), a CRITICAL status results. If either of the rates exceed\n\ | ||
| 65 | the <iwl> or <owl> thresholds (in Bytes/sec), a WARNING status results.\n\n")); | ||
| 66 | |||
| 67 | printf (_("Notes:\n\ | ||
| 68 | - MRTG stands for Multi Router Traffic Grapher. It can be downloaded from\n\ | ||
| 69 | http://ee-staff.ethz.ch/~oetiker/webtools/mrtg/mrtg.html\n\ | ||
| 70 | - While MRTG can monitor things other than traffic rates, this\n\ | ||
| 71 | plugin probably won't work with much else without modification.\n\ | ||
| 72 | - The calculated i/o rates are a little off from what MRTG actually\n\ | ||
| 73 | reports. I'm not sure why this is right now, but will look into it\n\ | ||
| 74 | for future enhancements of this plugin.\n")); | ||
| 75 | |||
| 76 | printf (_(UT_SUPPORT)); | ||
| 77 | } | ||
| 78 | |||
| 57 | int process_arguments (int, char **); | 79 | int process_arguments (int, char **); |
| 58 | int validate_arguments (void); | 80 | int validate_arguments (void); |
| 59 | void print_help (void); | ||
| 60 | void print_usage (void); | ||
| 61 | 81 | ||
| 62 | char *log_file = NULL; | 82 | char *log_file = NULL; |
| 63 | int expire_minutes = -1; | 83 | int expire_minutes = -1; |
| @@ -90,12 +110,12 @@ main (int argc, char **argv) | |||
| 90 | char outgoing_speed_rating[8]; | 110 | char outgoing_speed_rating[8]; |
| 91 | 111 | ||
| 92 | if (process_arguments (argc, argv) != OK) | 112 | if (process_arguments (argc, argv) != OK) |
| 93 | usage ("Invalid command arguments supplied\n"); | 113 | usage (_("Invalid command arguments supplied\n")); |
| 94 | 114 | ||
| 95 | /* open the MRTG log file for reading */ | 115 | /* open the MRTG log file for reading */ |
| 96 | fp = fopen (log_file, "r"); | 116 | fp = fopen (log_file, "r"); |
| 97 | if (fp == NULL) | 117 | if (fp == NULL) |
| 98 | usage ("Unable to open MRTG log file\n"); | 118 | usage (_("Unable to open MRTG log file\n")); |
| 99 | 119 | ||
| 100 | line = 0; | 120 | line = 0; |
| 101 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, fp)) { | 121 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, fp)) { |
| @@ -137,14 +157,14 @@ main (int argc, char **argv) | |||
| 137 | 157 | ||
| 138 | /* if we couldn't read enough data, return an unknown error */ | 158 | /* if we couldn't read enough data, return an unknown error */ |
| 139 | if (line <= 2) | 159 | if (line <= 2) |
| 140 | usage ("Unable to process MRTG log file\n"); | 160 | usage (_("Unable to process MRTG log file\n")); |
| 141 | 161 | ||
| 142 | /* make sure the MRTG data isn't too old */ | 162 | /* make sure the MRTG data isn't too old */ |
| 143 | time (¤t_time); | 163 | time (¤t_time); |
| 144 | if (expire_minutes > 0 | 164 | if (expire_minutes > 0 |
| 145 | && (current_time - timestamp) > | 165 | && (current_time - timestamp) > |
| 146 | (expire_minutes * 60)) terminate (STATE_WARNING, | 166 | (expire_minutes * 60)) terminate (STATE_WARNING, |
| 147 | "MRTG data has expired (%d minutes old)\n", | 167 | _("MRTG data has expired (%d minutes old)\n"), |
| 148 | (int) ((current_time - timestamp) / | 168 | (int) ((current_time - timestamp) / |
| 149 | 60)); | 169 | 60)); |
| 150 | 170 | ||
| @@ -197,34 +217,30 @@ main (int argc, char **argv) | |||
| 197 | if (incoming_rate > incoming_critical_threshold | 217 | if (incoming_rate > incoming_critical_threshold |
| 198 | || outgoing_rate > outgoing_critical_threshold) { | 218 | || outgoing_rate > outgoing_critical_threshold) { |
| 199 | result = STATE_CRITICAL; | 219 | result = STATE_CRITICAL; |
| 200 | asprintf (&error_message, "Traffic CRITICAL %s. In = %0.1f %s, %s. Out = %0.1f %s", | 220 | asprintf (&error_message, _("Traffic CRITICAL %s. In = %0.1f %s, %s. Out = %0.1f %s"), |
| 201 | (use_average == TRUE) ? "Avg" : "Max", adjusted_incoming_rate, | 221 | (use_average == TRUE) ? _("Avg") : _("Max"), adjusted_incoming_rate, |
| 202 | incoming_speed_rating, (use_average == TRUE) ? "Avg" : "Max", | 222 | incoming_speed_rating, (use_average == TRUE) ? "Avg" : "Max", |
| 203 | adjusted_outgoing_rate, outgoing_speed_rating); | 223 | adjusted_outgoing_rate, outgoing_speed_rating); |
| 204 | } | 224 | } |
| 205 | else if (incoming_rate > incoming_warning_threshold | 225 | else if (incoming_rate > incoming_warning_threshold |
| 206 | || outgoing_rate > outgoing_warning_threshold) { | 226 | || outgoing_rate > outgoing_warning_threshold) { |
| 207 | result = STATE_WARNING; | 227 | result = STATE_WARNING; |
| 208 | asprintf (&error_message, "Traffic WARNING %s. In = %0.1f %s, %s. Out = %0.1f %s", | 228 | asprintf (&error_message, _("Traffic WARNING %s. In = %0.1f %s, %s. Out = %0.1f %s"), |
| 209 | (use_average == TRUE) ? "Avg" : "Max", adjusted_incoming_rate, | 229 | (use_average == TRUE) ? _("Avg") : _("Max"), adjusted_incoming_rate, |
| 210 | incoming_speed_rating, (use_average == TRUE) ? "Avg" : "Max", | 230 | incoming_speed_rating, (use_average == TRUE) ? _("Avg") : _("Max"), |
| 211 | adjusted_outgoing_rate, outgoing_speed_rating); | 231 | adjusted_outgoing_rate, outgoing_speed_rating); |
| 212 | } | 232 | } |
| 213 | else if (result == STATE_OK) | 233 | else if (result == STATE_OK) |
| 214 | printf ("Traffic OK - %s. In = %0.1f %s, %s. Out = %0.1f %s\n", | 234 | printf (_("Traffic OK - %s. In = %0.1f %s, %s. Out = %0.1f %s\n"), |
| 215 | (use_average == TRUE) ? "Avg" : "Max", adjusted_incoming_rate, | 235 | (use_average == TRUE) ? _("Avg") : _("Max"), adjusted_incoming_rate, |
| 216 | incoming_speed_rating, (use_average == TRUE) ? "Avg" : "Max", | 236 | incoming_speed_rating, (use_average == TRUE) ? _("Avg") : _("Max"), |
| 217 | adjusted_outgoing_rate, outgoing_speed_rating); | 237 | adjusted_outgoing_rate, outgoing_speed_rating); |
| 218 | else | 238 | else |
| 219 | printf ("UNKNOWN %s\n", error_message); | 239 | printf (_("UNKNOWN %s\n"), error_message); |
| 220 | 240 | ||
| 221 | return result; | 241 | return result; |
| 222 | } | 242 | } |
| 223 | 243 | ||
| 224 | |||
| 225 | |||
| 226 | |||
| 227 | |||
| 228 | /* process command-line arguments */ | 244 | /* process command-line arguments */ |
| 229 | int | 245 | int |
| 230 | process_arguments (int argc, char **argv) | 246 | process_arguments (int argc, char **argv) |
| @@ -285,13 +301,13 @@ process_arguments (int argc, char **argv) | |||
| 285 | &outgoing_warning_threshold); | 301 | &outgoing_warning_threshold); |
| 286 | break; | 302 | break; |
| 287 | case 'V': /* version */ | 303 | case 'V': /* version */ |
| 288 | print_revision (progname, "$Revision$"); | 304 | print_revision (progname, revision); |
| 289 | exit (STATE_OK); | 305 | exit (STATE_OK); |
| 290 | case 'h': /* help */ | 306 | case 'h': /* help */ |
| 291 | print_help (); | 307 | print_help (); |
| 292 | exit (STATE_OK); | 308 | exit (STATE_OK); |
| 293 | case '?': /* help */ | 309 | case '?': /* help */ |
| 294 | usage ("Invalid argument\n"); | 310 | usage (_("Invalid argument\n")); |
| 295 | } | 311 | } |
| 296 | } | 312 | } |
| 297 | 313 | ||
| @@ -341,47 +357,3 @@ validate_arguments (void) | |||
| 341 | { | 357 | { |
| 342 | return OK; | 358 | return OK; |
| 343 | } | 359 | } |
| 344 | |||
| 345 | |||
| 346 | |||
| 347 | |||
| 348 | |||
| 349 | void | ||
| 350 | print_help (void) | ||
| 351 | { | ||
| 352 | print_revision (progname, "$Revision$"); | ||
| 353 | printf | ||
| 354 | ("Copyright (c) 2000 Tom Shields/Karl DeBisschop\n\n" | ||
| 355 | "This plugin tests the UPS service on the specified host.\n\n"); | ||
| 356 | print_usage (); | ||
| 357 | printf | ||
| 358 | ("\nOptions:\n" | ||
| 359 | " -F, --filename=STRING\n" | ||
| 360 | " File to read log from\n" | ||
| 361 | " -e, --expires=INTEGER\n" | ||
| 362 | " Minutes after which log expires\n" | ||
| 363 | " -a, --aggregation=(AVG|MAX)\n" | ||
| 364 | " Test average or maximum" | ||
| 365 | " -w, --warning\n" | ||
| 366 | " Warning threshold pair \"<incoming>,<outgoing>\"\n" | ||
| 367 | " -c, --critical\n" | ||
| 368 | " Critical threshold pair \"<incoming>,<outgoing>\"\n" | ||
| 369 | " -h, --help\n" | ||
| 370 | " Print detailed help screen\n" | ||
| 371 | " -V, --version\n" " Print version information\n\n"); | ||
| 372 | support (); | ||
| 373 | } | ||
| 374 | |||
| 375 | |||
| 376 | |||
| 377 | |||
| 378 | |||
| 379 | void | ||
| 380 | print_usage (void) | ||
| 381 | { | ||
| 382 | printf | ||
| 383 | ("Usage: %s -F <log_file> -a <AVG | MAX> -v <variable> -w <warning_pair> -c <critical_pair>\n" | ||
| 384 | " [-e expire_minutes] [-t timeout] [-v]\n" | ||
| 385 | " %s --help\n" | ||
| 386 | " %s --version\n", progname, progname, progname); | ||
| 387 | } | ||
