summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristian Schuster <116557017+KriSchu@users.noreply.github.com>2023-03-06 13:03:10 (GMT)
committerKristian Schuster <116557017+KriSchu@users.noreply.github.com>2023-03-06 13:03:10 (GMT)
commit3e7da5f970d73df91fad32f4dce259d30cdbbd65 (patch)
tree2ac87394ea7897939621fb19de2e72501922dd82
parente102b8a49e857a474db516455d2e871e6834ae34 (diff)
downloadmonitoring-plugins-3e7da5f.tar.gz
check_disk: use cleaner code for ignore-missing optionrefs/pull/1801/head
- use datatype bool for new vars ignore_missing and path_ignored instead of int - directly initialize preamble and ignored_preamble with their strings
-rw-r--r--plugins/check_disk.c34
1 files changed, 16 insertions, 18 deletions
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index c52d1df..bd84c82 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -141,7 +141,7 @@ int verbose = 0;
141int erronly = FALSE; 141int erronly = FALSE;
142int display_mntp = FALSE; 142int display_mntp = FALSE;
143int exact_match = FALSE; 143int exact_match = FALSE;
144int ignore_missing = FALSE; 144bool ignore_missing = false;
145int freespace_ignore_reserved = FALSE; 145int freespace_ignore_reserved = FALSE;
146int display_inodes_perfdata = FALSE; 146int display_inodes_perfdata = FALSE;
147char *warn_freespace_units = NULL; 147char *warn_freespace_units = NULL;
@@ -157,7 +157,7 @@ char *crit_usedinodes_percent = NULL;
157char *warn_freeinodes_percent = NULL; 157char *warn_freeinodes_percent = NULL;
158char *crit_freeinodes_percent = NULL; 158char *crit_freeinodes_percent = NULL;
159int path_selected = FALSE; 159int path_selected = FALSE;
160int path_ignored = FALSE; 160bool path_ignored = false;
161char *group = NULL; 161char *group = NULL;
162struct stat *stat_buf; 162struct stat *stat_buf;
163struct name_list *seen = NULL; 163struct name_list *seen = NULL;
@@ -173,8 +173,8 @@ main (int argc, char **argv)
173 char *details; 173 char *details;
174 char *perf; 174 char *perf;
175 char *perf_ilabel; 175 char *perf_ilabel;
176 char *preamble; 176 char *preamble = " - free space:";
177 char *ignored_preamble; 177 char *ignored_preamble = " - ignored paths:";
178 char *flag_header; 178 char *flag_header;
179 int temp_result; 179 int temp_result;
180 180
@@ -186,8 +186,6 @@ main (int argc, char **argv)
186 char mountdir[32]; 186 char mountdir[32];
187#endif 187#endif
188 188
189 preamble = strdup (" - free space:");
190 ignored_preamble = strdup (" - ignored paths:");
191 output = strdup (""); 189 output = strdup ("");
192 ignored = strdup (""); 190 ignored = strdup ("");
193 details = strdup (""); 191 details = strdup ("");
@@ -210,7 +208,7 @@ main (int argc, char **argv)
210 /* If a list of paths has not been selected, find entire 208 /* If a list of paths has not been selected, find entire
211 mount list and create list of paths 209 mount list and create list of paths
212 */ 210 */
213 if (path_selected == FALSE && path_ignored == FALSE) { 211 if (path_selected == FALSE && path_ignored == false) {
214 for (me = mount_list; me; me = me->me_next) { 212 for (me = mount_list; me; me = me->me_next) {
215 if (! (path = np_find_parameter(path_select_list, me->me_mountdir))) { 213 if (! (path = np_find_parameter(path_select_list, me->me_mountdir))) {
216 path = np_add_parameter(&path_select_list, me->me_mountdir); 214 path = np_add_parameter(&path_select_list, me->me_mountdir);
@@ -221,7 +219,7 @@ main (int argc, char **argv)
221 } 219 }
222 } 220 }
223 221
224 if (path_ignored == FALSE) { 222 if (path_ignored == false) {
225 np_set_best_match(path_select_list, mount_list, exact_match); 223 np_set_best_match(path_select_list, mount_list, exact_match);
226 } 224 }
227 225
@@ -229,7 +227,7 @@ main (int argc, char **argv)
229 temp_list = path_select_list; 227 temp_list = path_select_list;
230 228
231 while (path_select_list) { 229 while (path_select_list) {
232 if (! path_select_list->best_match && ignore_missing == 1) { 230 if (! path_select_list->best_match && ignore_missing == true) {
233 /* If the first element will be deleted, the temp_list must be updated with the new start address as well */ 231 /* If the first element will be deleted, the temp_list must be updated with the new start address as well */
234 if (path_select_list == temp_list) { 232 if (path_select_list == temp_list) {
235 temp_list = path_select_list->name_next; 233 temp_list = path_select_list->name_next;
@@ -249,7 +247,7 @@ main (int argc, char **argv)
249 247
250 path_select_list = temp_list; 248 path_select_list = temp_list;
251 249
252 if (! path_select_list && ignore_missing == 1) { 250 if (! path_select_list && ignore_missing == true) {
253 result = STATE_OK; 251 result = STATE_OK;
254 if (verbose >= 2) { 252 if (verbose >= 2) {
255 printf ("None of the provided paths were found\n"); 253 printf ("None of the provided paths were found\n");
@@ -295,7 +293,7 @@ main (int argc, char **argv)
295 /* Skip remote filesystems if we're not interested in them */ 293 /* Skip remote filesystems if we're not interested in them */
296 if (me->me_remote && show_local_fs) { 294 if (me->me_remote && show_local_fs) {
297 if (stat_remote_fs) { 295 if (stat_remote_fs) {
298 if (!stat_path(path) && ignore_missing == 1) { 296 if (!stat_path(path) && ignore_missing == true) {
299 result = STATE_OK; 297 result = STATE_OK;
300 xasprintf (&ignored, "%s %s;", ignored, path->name); 298 xasprintf (&ignored, "%s %s;", ignored, path->name);
301 } 299 }
@@ -319,7 +317,7 @@ main (int argc, char **argv)
319 } 317 }
320 318
321 if (!stat_path(path)) { 319 if (!stat_path(path)) {
322 if (ignore_missing == 1) { 320 if (ignore_missing == true) {
323 result = STATE_OK; 321 result = STATE_OK;
324 xasprintf (&ignored, "%s %s;", ignored, path->name); 322 xasprintf (&ignored, "%s %s;", ignored, path->name);
325 } 323 }
@@ -682,8 +680,8 @@ process_arguments (int argc, char **argv)
682 if (! (se = np_find_parameter(path_select_list, optarg))) { 680 if (! (se = np_find_parameter(path_select_list, optarg))) {
683 se = np_add_parameter(&path_select_list, optarg); 681 se = np_add_parameter(&path_select_list, optarg);
684 682
685 if (stat(optarg, &stat_buf[0]) && ignore_missing == 1) { 683 if (stat(optarg, &stat_buf[0]) && ignore_missing == true) {
686 path_ignored = TRUE; 684 path_ignored = true;
687 break; 685 break;
688 } 686 }
689 } 687 }
@@ -775,7 +773,7 @@ process_arguments (int argc, char **argv)
775 break; 773 break;
776 774
777 case IGNORE_MISSING: 775 case IGNORE_MISSING:
778 ignore_missing = 1; 776 ignore_missing = true;
779 break; 777 break;
780 case 'A': 778 case 'A':
781 optarg = strdup(".*"); 779 optarg = strdup(".*");
@@ -812,8 +810,8 @@ process_arguments (int argc, char **argv)
812 } 810 }
813 } 811 }
814 812
815 if (!fnd && ignore_missing == 1) { 813 if (!fnd && ignore_missing == true) {
816 path_ignored = TRUE; 814 path_ignored = true;
817 /* path_selected = TRUE;*/ 815 /* path_selected = TRUE;*/
818 break; 816 break;
819 } else if (!fnd) 817 } else if (!fnd)
@@ -1031,7 +1029,7 @@ stat_path (struct parameter_list *p)
1031 if (stat (p->name, &stat_buf[0])) { 1029 if (stat (p->name, &stat_buf[0])) {
1032 if (verbose >= 3) 1030 if (verbose >= 3)
1033 printf("stat failed on %s\n", p->name); 1031 printf("stat failed on %s\n", p->name);
1034 if (ignore_missing == 1) { 1032 if (ignore_missing == true) {
1035 return false; 1033 return false;
1036 } else { 1034 } else {
1037 printf("DISK %s - ", _("CRITICAL")); 1035 printf("DISK %s - ", _("CRITICAL"));