diff -Naur nagios-plugins-1.3.0-beta2/plugins/check_mrtgtraf.c nagios-plugins-1.3.0-beta2_swl/plugins/check_mrtgtraf.c --- nagios-plugins-1.3.0-beta2/plugins/check_mrtgtraf.c 2002-11-15 02:04:51.000000000 +0100 +++ nagios-plugins-1.3.0-beta2_swl/plugins/check_mrtgtraf.c 2003-02-26 14:56:54.000000000 +0100 @@ -56,6 +56,7 @@ int process_arguments (int, char **); int validate_arguments (void); +unsigned long adjust_threshold(unsigned long val, char **c); void print_help (void); void print_usage (void); @@ -144,9 +145,9 @@ if (expire_minutes > 0 && (current_time - timestamp) > (expire_minutes * 60)) terminate (STATE_WARNING, - "MRTG data has expired (%d minutes old)\n", - (int) ((current_time - timestamp) / - 60)); + "MRTG data has expired (%d minutes old)\n", + (int) ((current_time - timestamp) / + 60)); /* else check the incoming/outgoing rates */ if (use_average == TRUE) { @@ -160,37 +161,37 @@ /* report incoming traffic in Bytes/sec */ if (incoming_rate < 1024) { - strcpy (incoming_speed_rating, "B/s"); + strcpy (incoming_speed_rating, "b/s"); adjusted_incoming_rate = (double) incoming_rate; } /* report incoming traffic in KBytes/sec */ else if (incoming_rate < (1024 * 1024)) { - strcpy (incoming_speed_rating, "KB/s"); + strcpy (incoming_speed_rating, "Kb/s"); adjusted_incoming_rate = (double) (incoming_rate / 1024.0); } /* report incoming traffic in MBytes/sec */ else { - strcpy (incoming_speed_rating, "MB/s"); + strcpy (incoming_speed_rating, "Mb/s"); adjusted_incoming_rate = (double) (incoming_rate / 1024.0 / 1024.0); } /* report outgoing traffic in Bytes/sec */ if (outgoing_rate < 1024) { - strcpy (outgoing_speed_rating, "B/s"); + strcpy (outgoing_speed_rating, "b/s"); adjusted_outgoing_rate = (double) outgoing_rate; } /* report outgoing traffic in KBytes/sec */ else if (outgoing_rate < (1024 * 1024)) { - strcpy (outgoing_speed_rating, "KB/s"); + strcpy (outgoing_speed_rating, "Kb/s"); adjusted_outgoing_rate = (double) (outgoing_rate / 1024.0); } /* report outgoing traffic in MBytes/sec */ else { - strcpy (outgoing_speed_rating, "MB/s"); + strcpy (outgoing_speed_rating, "Mb/s"); adjusted_outgoing_rate = (double) (outgoing_rate / 1024.0 / 1024.0); } @@ -231,6 +232,7 @@ process_arguments (int argc, char **argv) { int c; + char* modpos; #ifdef HAVE_GETOPT_H int option_index = 0; @@ -283,13 +285,27 @@ else use_average = TRUE; break; - case 'c': /* warning threshold */ - sscanf (optarg, "%lu,%lu", &incoming_critical_threshold, - &outgoing_critical_threshold); + case 'c': /* critical threshold */ + incoming_critical_threshold = strtoul (optarg, &modpos, 10); + if(*modpos != ',') + incoming_critical_threshold = adjust_threshold(incoming_critical_threshold,&modpos); + + modpos++; + + outgoing_critical_threshold = strtoul (modpos, &modpos, 10); + outgoing_critical_threshold = adjust_threshold(outgoing_critical_threshold,&modpos); + break; - case 'w': /* critical threshold */ - sscanf (optarg, "%lu,%lu", &incoming_warning_threshold, - &outgoing_warning_threshold); + case 'w': /* warning threshold */ + incoming_warning_threshold = strtoul (optarg, &modpos, 10); + if(*modpos != ',') + incoming_warning_threshold = adjust_threshold(incoming_warning_threshold,&modpos); + + modpos++; + + outgoing_warning_threshold = strtoul (modpos, &modpos, 10); + outgoing_warning_threshold = adjust_threshold(outgoing_warning_threshold,&modpos); + break; case 'V': /* version */ print_revision (PROGNAME, "$Revision: 1.2 $"); @@ -321,25 +337,48 @@ } if (argc > c && incoming_warning_threshold == 0) { - incoming_warning_threshold = strtoul (argv[c++], NULL, 10); + incoming_warning_threshold = strtoul (argv[c++], &modpos, 10); + incoming_warning_threshold = adjust_threshold(incoming_warning_threshold,&modpos); } if (argc > c && incoming_critical_threshold == 0) { - incoming_critical_threshold = strtoul (argv[c++], NULL, 10); + incoming_critical_threshold = strtoul (argv[c++], &modpos, 10); + incoming_critical_threshold = adjust_threshold(incoming_critical_threshold,&modpos); } if (argc > c && outgoing_warning_threshold == 0) { - outgoing_warning_threshold = strtoul (argv[c++], NULL, 10); + outgoing_warning_threshold = strtoul (argv[c++], &modpos, 10); + outgoing_warning_threshold = adjust_threshold(outgoing_warning_threshold,&modpos); } if (argc > c && outgoing_critical_threshold == 0) { - outgoing_critical_threshold = strtoul (argv[c++], NULL, 10); + outgoing_critical_threshold = strtoul (argv[c++], &modpos, 10); + outgoing_critical_threshold = adjust_threshold(outgoing_critical_threshold,&modpos); } return validate_arguments (); } - +unsigned long adjust_threshold(unsigned long val, char **pos) +{ + switch(**pos) + { + case 'K': + case 'k': + (*pos)++; + return (val*1024L); + case 'M': + case 'm': + (*pos)++; + return val*1024L*1024L; + case 'G': + case 'm': + (*pos)++; + return val*1024L*1024L*1024L; + default: + return val; + } +}