summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/check_load.c125
1 files changed, 58 insertions, 67 deletions
diff --git a/plugins/check_load.c b/plugins/check_load.c
index 6673b1d..bedbf16 100644
--- a/plugins/check_load.c
+++ b/plugins/check_load.c
@@ -47,7 +47,6 @@
47#define PROGNAME "check_load" 47#define PROGNAME "check_load"
48 48
49int process_arguments (int argc, char **argv); 49int process_arguments (int argc, char **argv);
50int call_getopt (int argc, char **argv);
51int validate_arguments (void); 50int validate_arguments (void);
52void print_usage (void); 51void print_usage (void);
53void print_help (void); 52void print_help (void);
@@ -152,40 +151,6 @@ main (int argc, char **argv)
152int 151int
153process_arguments (int argc, char **argv) 152process_arguments (int argc, char **argv)
154{ 153{
155 int c;
156
157 if (argc < 2)
158 return ERROR;
159
160 c = 0;
161 while (c += (call_getopt (argc - c, &argv[c]))) {
162 if (argc <= c)
163 break;
164
165 if (wload1 < 0 && is_nonnegative (argv[c]))
166 wload1 = atof (argv[c]);
167 else if (cload1 < 0 && is_nonnegative (argv[c]))
168 cload1 = atof (argv[c]);
169 else if (wload5 < 0 && is_nonnegative (argv[c]))
170 wload5 = atof (argv[c]);
171 else if (cload5 < 0 && is_nonnegative (argv[c]))
172 cload5 = atof (argv[c]);
173 else if (wload15 < 0 && is_nonnegative (argv[c]))
174 wload15 = atof (argv[c]);
175 else if (cload15 < 0 && is_nonnegative (argv[c]))
176 cload15 = atof (argv[c]);
177 }
178
179 return validate_arguments ();
180}
181
182
183
184
185
186int
187call_getopt (int argc, char **argv)
188{
189 int c, i = 0; 154 int c, i = 0;
190 155
191#ifdef HAVE_GETOPT_H 156#ifdef HAVE_GETOPT_H
@@ -199,59 +164,53 @@ call_getopt (int argc, char **argv)
199 }; 164 };
200#endif 165#endif
201 166
167#define OPTCHARS "Vhc:w:"
168
169 if (argc < 2)
170 return ERROR;
171
202 while (1) { 172 while (1) {
203#ifdef HAVE_GETOPT_H 173#ifdef HAVE_GETOPT_H
204 c = getopt_long (argc, argv, "+?Vhc:w:", long_options, &option_index); 174 c = getopt_long (argc, argv, OPTCHARS, long_options, &option_index);
205#else 175#else
206 c = getopt (argc, argv, "+?Vhc:w:"); 176 c = getopt (argc, argv, OPTCHARS);
207#endif 177#endif
208
209 i++;
210
211 if (c == -1 || c == EOF) 178 if (c == -1 || c == EOF)
212 break; 179 break;
213 180
214 switch (c) { 181 switch (c) {
215 case 'c':
216 case 'w':
217 i++;
218 }
219
220 switch (c) {
221 case 'w': /* warning time threshold */ 182 case 'w': /* warning time threshold */
222 if (is_intnonneg (optarg)) { 183 if (is_intnonneg (optarg)) {
223 if (wload1 < 0 && is_nonnegative (argv[c])) 184 wload1 = atof (optarg);
224 wload1 = atof (argv[c]); 185 wload5 = atof (optarg);
225 else if (wload5 < 0 && is_nonnegative (argv[c])) 186 wload15 = atof (optarg);
226 wload5 = atof (argv[c]);
227 else if (wload15 < 0 && is_nonnegative (argv[c]))
228 wload15 = atof (argv[c]);
229 break; 187 break;
230 } 188 }
231 else if (strstr (optarg, ",") && 189 else if (strstr (optarg, ",") &&
232 sscanf (optarg, "%f,%f,%f", &wload1, &wload5, &wload15) == 3) { 190 sscanf (optarg, "%f,%f,%f", &wload1, &wload5, &wload15) == 3)
233 break; 191 break;
234 } 192 else if (strstr (optarg, ":") &&
235 else { 193 sscanf (optarg, "%f:%f:%f", &wload1, &wload5, &wload15) == 3)
194 break;
195 else
236 usage ("Warning threshold must be float or float triplet!\n"); 196 usage ("Warning threshold must be float or float triplet!\n");
237 } 197 break;
238 case 'c': /* critical time threshold */ 198 case 'c': /* critical time threshold */
239 if (is_intnonneg (optarg)) { 199 if (is_intnonneg (optarg)) {
240 if (cload1 < 0 && is_nonnegative (argv[c])) 200 cload1 = atof (optarg);
241 cload1 = atof (argv[c]); 201 cload5 = atof (optarg);
242 else if (cload5 < 0 && is_nonnegative (argv[c])) 202 cload15 = atof (optarg);
243 cload5 = atof (argv[c]);
244 else if (cload15 < 0 && is_nonnegative (argv[c]))
245 cload15 = atof (argv[c]);
246 break; 203 break;
247 } 204 }
248 else if (strstr (optarg, ",") && 205 else if (strstr (optarg, ",") &&
249 sscanf (optarg, "%f,%f,%f", &cload1, &cload5, &cload15) == 3) { 206 sscanf (optarg, "%f,%f,%f", &cload1, &cload5, &cload15) == 3)
250 break; 207 break;
251 } 208 else if (strstr (optarg, ":") &&
252 else { 209 sscanf (optarg, "%f:%f:%f", &cload1, &cload5, &cload15) == 3)
210 break;
211 else
253 usage ("Critical threshold must be float or float triplet!\n"); 212 usage ("Critical threshold must be float or float triplet!\n");
254 } 213 break;
255 case 'V': /* version */ 214 case 'V': /* version */
256 print_revision (my_basename (argv[0]), "$Revision$"); 215 print_revision (my_basename (argv[0]), "$Revision$");
257 exit (STATE_OK); 216 exit (STATE_OK);
@@ -262,7 +221,39 @@ call_getopt (int argc, char **argv)
262 usage ("Invalid argument\n"); 221 usage ("Invalid argument\n");
263 } 222 }
264 } 223 }
265 return i; 224
225 c = optind;
226 if (c == argc)
227 return validate_arguments ();
228 if (wload1 < 0 && is_nonnegative (argv[c]))
229 wload1 = atof (argv[c]);
230
231 if (c == argc)
232 return validate_arguments ();
233 if (cload1 < 0 && is_nonnegative (argv[c]))
234 cload1 = atof (argv[c]);
235
236 if (c == argc)
237 return validate_arguments ();
238 if (wload5 < 0 && is_nonnegative (argv[c]))
239 wload5 = atof (argv[c]);
240
241 if (c == argc)
242 return validate_arguments ();
243 if (cload5 < 0 && is_nonnegative (argv[c]))
244 cload5 = atof (argv[c]);
245
246 if (c == argc)
247 return validate_arguments ();
248 if (wload15 < 0 && is_nonnegative (argv[c]))
249 wload15 = atof (argv[c]);
250
251 if (c == argc)
252 return validate_arguments ();
253 if (cload15 < 0 && is_nonnegative (argv[c]))
254 cload15 = atof (argv[c]);
255
256 return validate_arguments ();
266} 257}
267 258
268 259