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