diff options
-rw-r--r-- | plugins/check_mrtg.c | 54 |
1 files changed, 29 insertions, 25 deletions
diff --git a/plugins/check_mrtg.c b/plugins/check_mrtg.c index 5d429d7..5924f17 100644 --- a/plugins/check_mrtg.c +++ b/plugins/check_mrtg.c | |||
@@ -35,8 +35,8 @@ int use_average = TRUE; | |||
35 | int variable_number = -1; | 35 | int variable_number = -1; |
36 | unsigned long value_warning_threshold = 0L; | 36 | unsigned long value_warning_threshold = 0L; |
37 | unsigned long value_critical_threshold = 0L; | 37 | unsigned long value_critical_threshold = 0L; |
38 | char *value_label; | 38 | char *label; |
39 | char *units_label; | 39 | char *units; |
40 | 40 | ||
41 | int | 41 | int |
42 | main (int argc, char **argv) | 42 | main (int argc, char **argv) |
@@ -47,11 +47,11 @@ main (int argc, char **argv) | |||
47 | char input_buffer[MAX_INPUT_BUFFER]; | 47 | char input_buffer[MAX_INPUT_BUFFER]; |
48 | char *temp_buffer; | 48 | char *temp_buffer; |
49 | time_t current_time; | 49 | time_t current_time; |
50 | char error_message[MAX_INPUT_BUFFER]; | 50 | char* message; |
51 | time_t timestamp = 0L; | 51 | time_t timestamp = 0L; |
52 | unsigned long average_value_rate = 0L; | 52 | unsigned long average_value_rate = 0L; |
53 | unsigned long maximum_value_rate = 0L; | 53 | unsigned long maximum_value_rate = 0L; |
54 | unsigned long value_rate = 0L; | 54 | unsigned long rate = 0L; |
55 | 55 | ||
56 | setlocale (LC_ALL, ""); | 56 | setlocale (LC_ALL, ""); |
57 | bindtextdomain (PACKAGE, LOCALEDIR); | 57 | bindtextdomain (PACKAGE, LOCALEDIR); |
@@ -111,7 +111,7 @@ main (int argc, char **argv) | |||
111 | /* if we couldn't read enough data, return an unknown error */ | 111 | /* if we couldn't read enough data, return an unknown error */ |
112 | if (line <= 2) { | 112 | if (line <= 2) { |
113 | result = STATE_UNKNOWN; | 113 | result = STATE_UNKNOWN; |
114 | sprintf (error_message, _("Unable to process MRTG log file\n")); | 114 | asprintf (&message, _("Unable to process MRTG log file\n")); |
115 | } | 115 | } |
116 | 116 | ||
117 | /* make sure the MRTG data isn't too old */ | 117 | /* make sure the MRTG data isn't too old */ |
@@ -120,29 +120,33 @@ main (int argc, char **argv) | |||
120 | if (expire_minutes > 0 | 120 | if (expire_minutes > 0 |
121 | && (current_time - timestamp) > (expire_minutes * 60)) { | 121 | && (current_time - timestamp) > (expire_minutes * 60)) { |
122 | result = STATE_WARNING; | 122 | result = STATE_WARNING; |
123 | sprintf (error_message, _("MRTG data has expired (%d minutes old)\n"), | 123 | asprintf (&message, _("MRTG data has expired (%d minutes old)\n"), |
124 | (int) ((current_time - timestamp) / 60)); | 124 | (int) ((current_time - timestamp) / 60)); |
125 | } | 125 | } |
126 | } | 126 | } |
127 | 127 | ||
128 | /* else check the incoming/outgoing rates */ | 128 | /* else check the incoming/outgoing rates */ |
129 | if (result == STATE_OK) { | 129 | if (result == STATE_OK) { |
130 | |||
131 | if (use_average == TRUE) | 130 | if (use_average == TRUE) |
132 | value_rate = average_value_rate; | 131 | rate = average_value_rate; |
133 | else | 132 | else |
134 | value_rate = maximum_value_rate; | 133 | rate = maximum_value_rate; |
135 | 134 | ||
136 | if (value_rate > value_critical_threshold) | 135 | if (rate > value_critical_threshold) |
137 | result = STATE_CRITICAL; | 136 | result = STATE_CRITICAL; |
138 | else if (value_rate > value_warning_threshold) | 137 | else if (rate > value_warning_threshold) |
139 | result = STATE_WARNING; | 138 | result = STATE_WARNING; |
139 | |||
140 | asprintf (&message, "%s. %s = %lu %s|%s", | ||
141 | (use_average == TRUE) ? _("Avg") : _("Max"), | ||
142 | label, rate, units, | ||
143 | perfdata(label, rate, units, | ||
144 | value_warning_threshold, value_warning_threshold, | ||
145 | value_critical_threshold, value_critical_threshold, | ||
146 | 0, 0, 0, 0)); | ||
140 | } | 147 | } |
141 | 148 | ||
142 | sprintf (error_message, "%s. %s = %lu %s", | 149 | printf ("%s\n", message); |
143 | (use_average == TRUE) ? _("Ave") : _("Max"), value_label, value_rate, | ||
144 | units_label); | ||
145 | printf ("%s\n", error_message); | ||
146 | 150 | ||
147 | return result; | 151 | return result; |
148 | } | 152 | } |
@@ -213,10 +217,10 @@ process_arguments (int argc, char **argv) | |||
213 | value_critical_threshold = strtoul (optarg, NULL, 10); | 217 | value_critical_threshold = strtoul (optarg, NULL, 10); |
214 | break; | 218 | break; |
215 | case 'l': /* label */ | 219 | case 'l': /* label */ |
216 | value_label = optarg; | 220 | label = optarg; |
217 | break; | 221 | break; |
218 | case 'u': /* timeout */ | 222 | case 'u': /* timeout */ |
219 | units_label = optarg; | 223 | units = optarg; |
220 | break; | 224 | break; |
221 | case 'V': /* version */ | 225 | case 'V': /* version */ |
222 | print_revision (progname, revision); | 226 | print_revision (progname, revision); |
@@ -268,12 +272,12 @@ process_arguments (int argc, char **argv) | |||
268 | value_critical_threshold = strtoul (argv[c++], NULL, 10); | 272 | value_critical_threshold = strtoul (argv[c++], NULL, 10); |
269 | } | 273 | } |
270 | 274 | ||
271 | if (argc > c && strlen (value_label) == 0) { | 275 | if (argc > c && strlen (label) == 0) { |
272 | value_label = argv[c++]; | 276 | label = argv[c++]; |
273 | } | 277 | } |
274 | 278 | ||
275 | if (argc > c && strlen (units_label) == 0) { | 279 | if (argc > c && strlen (units) == 0) { |
276 | units_label = argv[c++]; | 280 | units = argv[c++]; |
277 | } | 281 | } |
278 | 282 | ||
279 | return validate_arguments (); | 283 | return validate_arguments (); |
@@ -285,11 +289,11 @@ validate_arguments (void) | |||
285 | if (variable_number == -1) | 289 | if (variable_number == -1) |
286 | usage (_("You must supply the variable number\n")); | 290 | usage (_("You must supply the variable number\n")); |
287 | 291 | ||
288 | if (value_label == NULL) | 292 | if (label == NULL) |
289 | value_label = strdup (""); | 293 | label = strdup ("value"); |
290 | 294 | ||
291 | if (units_label == NULL) | 295 | if (units == NULL) |
292 | units_label = strdup (""); | 296 | units = strdup (""); |
293 | 297 | ||
294 | return OK; | 298 | return OK; |
295 | } | 299 | } |