diff options
Diffstat (limited to 'plugins/check_mrtgtraf.c')
| -rw-r--r-- | plugins/check_mrtgtraf.c | 50 |
1 files changed, 29 insertions, 21 deletions
diff --git a/plugins/check_mrtgtraf.c b/plugins/check_mrtgtraf.c index c9e26099..10ce936f 100644 --- a/plugins/check_mrtgtraf.c +++ b/plugins/check_mrtgtraf.c | |||
| @@ -33,16 +33,16 @@ const char *progname = "check_mrtgtraf"; | |||
| 33 | const char *copyright = "1999-2024"; | 33 | const char *copyright = "1999-2024"; |
| 34 | const char *email = "devel@monitoring-plugins.org"; | 34 | const char *email = "devel@monitoring-plugins.org"; |
| 35 | 35 | ||
| 36 | #include "check_mrtgraf.d/config.h" | 36 | #include "check_mrtgtraf.d/config.h" |
| 37 | #include "common.h" | 37 | #include "common.h" |
| 38 | #include "utils.h" | 38 | #include "utils.h" |
| 39 | 39 | ||
| 40 | typedef struct { | 40 | typedef struct { |
| 41 | int errorcode; | 41 | int errorcode; |
| 42 | check_mrtgraf_config config; | 42 | check_mrtgtraf_config config; |
| 43 | } check_mrtgraf_config_wrapper; | 43 | } check_mrtgtraf_config_wrapper; |
| 44 | 44 | ||
| 45 | static check_mrtgraf_config_wrapper process_arguments(int /*argc*/, char ** /*argv*/); | 45 | static check_mrtgtraf_config_wrapper process_arguments(int /*argc*/, char ** /*argv*/); |
| 46 | static void print_help(void); | 46 | static void print_help(void); |
| 47 | void print_usage(void); | 47 | void print_usage(void); |
| 48 | 48 | ||
| @@ -54,12 +54,12 @@ int main(int argc, char **argv) { | |||
| 54 | /* Parse extra opts if any */ | 54 | /* Parse extra opts if any */ |
| 55 | argv = np_extra_opts(&argc, argv, progname); | 55 | argv = np_extra_opts(&argc, argv, progname); |
| 56 | 56 | ||
| 57 | check_mrtgraf_config_wrapper tmp_config = process_arguments(argc, argv); | 57 | check_mrtgtraf_config_wrapper tmp_config = process_arguments(argc, argv); |
| 58 | if (tmp_config.errorcode == ERROR) { | 58 | if (tmp_config.errorcode == ERROR) { |
| 59 | usage4(_("Could not parse arguments")); | 59 | usage4(_("Could not parse arguments")); |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | const check_mrtgraf_config config = tmp_config.config; | 62 | const check_mrtgtraf_config config = tmp_config.config; |
| 63 | 63 | ||
| 64 | /* open the MRTG log file for reading */ | 64 | /* open the MRTG log file for reading */ |
| 65 | FILE *mrtg_log_file_ptr = fopen(config.log_file, "r"); | 65 | FILE *mrtg_log_file_ptr = fopen(config.log_file, "r"); |
| @@ -122,7 +122,8 @@ int main(int argc, char **argv) { | |||
| 122 | time_t current_time; | 122 | time_t current_time; |
| 123 | time(¤t_time); | 123 | time(¤t_time); |
| 124 | if ((config.expire_minutes > 0) && (current_time - timestamp) > (config.expire_minutes * 60)) { | 124 | if ((config.expire_minutes > 0) && (current_time - timestamp) > (config.expire_minutes * 60)) { |
| 125 | die(STATE_WARNING, _("MRTG data has expired (%d minutes old)\n"), (int)((current_time - timestamp) / 60)); | 125 | die(STATE_WARNING, _("MRTG data has expired (%d minutes old)\n"), |
| 126 | (int)((current_time - timestamp) / 60)); | ||
| 126 | } | 127 | } |
| 127 | 128 | ||
| 128 | unsigned long incoming_rate = 0L; | 129 | unsigned long incoming_rate = 0L; |
| @@ -177,21 +178,26 @@ int main(int argc, char **argv) { | |||
| 177 | } | 178 | } |
| 178 | 179 | ||
| 179 | int result = STATE_OK; | 180 | int result = STATE_OK; |
| 180 | if (incoming_rate > config.incoming_critical_threshold || outgoing_rate > config.outgoing_critical_threshold) { | 181 | if (incoming_rate > config.incoming_critical_threshold || |
| 182 | outgoing_rate > config.outgoing_critical_threshold) { | ||
| 181 | result = STATE_CRITICAL; | 183 | result = STATE_CRITICAL; |
| 182 | } else if (incoming_rate > config.incoming_warning_threshold || outgoing_rate > config.outgoing_warning_threshold) { | 184 | } else if (incoming_rate > config.incoming_warning_threshold || |
| 185 | outgoing_rate > config.outgoing_warning_threshold) { | ||
| 183 | result = STATE_WARNING; | 186 | result = STATE_WARNING; |
| 184 | } | 187 | } |
| 185 | 188 | ||
| 186 | char *error_message; | 189 | char *error_message; |
| 187 | xasprintf(&error_message, _("%s. In = %0.1f %s/s, %s. Out = %0.1f %s/s|%s %s\n"), (config.use_average) ? _("Avg") : _("Max"), | 190 | xasprintf(&error_message, _("%s. In = %0.1f %s/s, %s. Out = %0.1f %s/s|%s %s\n"), |
| 188 | adjusted_incoming_rate, incoming_speed_rating, (config.use_average) ? _("Avg") : _("Max"), adjusted_outgoing_rate, | 191 | (config.use_average) ? _("Avg") : _("Max"), adjusted_incoming_rate, |
| 189 | outgoing_speed_rating, | 192 | incoming_speed_rating, (config.use_average) ? _("Avg") : _("Max"), |
| 190 | fperfdata("in", adjusted_incoming_rate, incoming_speed_rating, (int)config.incoming_warning_threshold, | 193 | adjusted_outgoing_rate, outgoing_speed_rating, |
| 191 | config.incoming_warning_threshold, (int)config.incoming_critical_threshold, config.incoming_critical_threshold, | 194 | fperfdata("in", adjusted_incoming_rate, incoming_speed_rating, |
| 195 | (int)config.incoming_warning_threshold, config.incoming_warning_threshold, | ||
| 196 | (int)config.incoming_critical_threshold, config.incoming_critical_threshold, | ||
| 192 | true, 0, false, 0), | 197 | true, 0, false, 0), |
| 193 | fperfdata("out", adjusted_outgoing_rate, outgoing_speed_rating, (int)config.outgoing_warning_threshold, | 198 | fperfdata("out", adjusted_outgoing_rate, outgoing_speed_rating, |
| 194 | config.outgoing_warning_threshold, (int)config.outgoing_critical_threshold, config.outgoing_critical_threshold, | 199 | (int)config.outgoing_warning_threshold, config.outgoing_warning_threshold, |
| 200 | (int)config.outgoing_critical_threshold, config.outgoing_critical_threshold, | ||
| 195 | true, 0, false, 0)); | 201 | true, 0, false, 0)); |
| 196 | 202 | ||
| 197 | printf(_("Traffic %s - %s\n"), state_text(result), error_message); | 203 | printf(_("Traffic %s - %s\n"), state_text(result), error_message); |
| @@ -200,7 +206,7 @@ int main(int argc, char **argv) { | |||
| 200 | } | 206 | } |
| 201 | 207 | ||
| 202 | /* process command-line arguments */ | 208 | /* process command-line arguments */ |
| 203 | check_mrtgraf_config_wrapper process_arguments(int argc, char **argv) { | 209 | check_mrtgtraf_config_wrapper process_arguments(int argc, char **argv) { |
| 204 | static struct option longopts[] = {{"filename", required_argument, 0, 'F'}, | 210 | static struct option longopts[] = {{"filename", required_argument, 0, 'F'}, |
| 205 | {"expires", required_argument, 0, 'e'}, | 211 | {"expires", required_argument, 0, 'e'}, |
| 206 | {"aggregation", required_argument, 0, 'a'}, | 212 | {"aggregation", required_argument, 0, 'a'}, |
| @@ -210,9 +216,9 @@ check_mrtgraf_config_wrapper process_arguments(int argc, char **argv) { | |||
| 210 | {"help", no_argument, 0, 'h'}, | 216 | {"help", no_argument, 0, 'h'}, |
| 211 | {0, 0, 0, 0}}; | 217 | {0, 0, 0, 0}}; |
| 212 | 218 | ||
| 213 | check_mrtgraf_config_wrapper result = { | 219 | check_mrtgtraf_config_wrapper result = { |
| 214 | .errorcode = OK, | 220 | .errorcode = OK, |
| 215 | .config = check_mrtgraf_config_init(), | 221 | .config = check_mrtgtraf_config_init(), |
| 216 | }; | 222 | }; |
| 217 | if (argc < 2) { | 223 | if (argc < 2) { |
| 218 | result.errorcode = ERROR; | 224 | result.errorcode = ERROR; |
| @@ -249,10 +255,12 @@ check_mrtgraf_config_wrapper process_arguments(int argc, char **argv) { | |||
| 249 | result.config.use_average = (bool)(strcmp(optarg, "MAX")); | 255 | result.config.use_average = (bool)(strcmp(optarg, "MAX")); |
| 250 | break; | 256 | break; |
| 251 | case 'c': /* warning threshold */ | 257 | case 'c': /* warning threshold */ |
| 252 | sscanf(optarg, "%lu,%lu", &result.config.incoming_critical_threshold, &result.config.outgoing_critical_threshold); | 258 | sscanf(optarg, "%lu,%lu", &result.config.incoming_critical_threshold, |
| 259 | &result.config.outgoing_critical_threshold); | ||
| 253 | break; | 260 | break; |
| 254 | case 'w': /* critical threshold */ | 261 | case 'w': /* critical threshold */ |
| 255 | sscanf(optarg, "%lu,%lu", &result.config.incoming_warning_threshold, &result.config.outgoing_warning_threshold); | 262 | sscanf(optarg, "%lu,%lu", &result.config.incoming_warning_threshold, |
| 263 | &result.config.outgoing_warning_threshold); | ||
| 256 | break; | 264 | break; |
| 257 | case 'V': /* version */ | 265 | case 'V': /* version */ |
| 258 | print_revision(progname, NP_VERSION); | 266 | print_revision(progname, NP_VERSION); |
