diff options
author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-03-18 14:37:49 +0100 |
---|---|---|
committer | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-03-18 14:37:49 +0100 |
commit | 29d946b9b516662a0f625b7d229ee41962cac264 (patch) | |
tree | 03a18f4cdaa57d0692e06f02cf5ef02d9da47cde | |
parent | 8ccff07bed03046a97637a54d45a9ffe77edc235 (diff) | |
download | monitoring-plugins-29d946b9b516662a0f625b7d229ee41962cac264.tar.gz |
Refactor check_disk, no more global variables
-rw-r--r-- | plugins/check_disk.c | 530 | ||||
-rw-r--r-- | plugins/check_disk.d/config.h | 92 |
2 files changed, 358 insertions, 264 deletions
diff --git a/plugins/check_disk.c b/plugins/check_disk.c index f67f3d57..2df89aa3 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c | |||
@@ -43,13 +43,15 @@ const char *email = "devel@monitoring-plugins.org"; | |||
43 | #endif | 43 | #endif |
44 | 44 | ||
45 | #include <assert.h> | 45 | #include <assert.h> |
46 | #include "popen.h" | ||
47 | #include "utils.h" | ||
48 | #include "utils_disk.h" | ||
49 | #include <stdarg.h> | 46 | #include <stdarg.h> |
50 | #include "fsusage.h" | 47 | #include <stdint.h> |
51 | #include "mountlist.h" | ||
52 | #include <float.h> | 48 | #include <float.h> |
49 | #include "./popen.h" | ||
50 | #include "./utils.h" | ||
51 | #include "./check_disk.d/utils_disk.h" | ||
52 | #include "../gl/fsusage.h" | ||
53 | #include "../gl/mountlist.h" | ||
54 | #include "check_disk.d/config.h" | ||
53 | 55 | ||
54 | #if HAVE_LIMITS_H | 56 | #if HAVE_LIMITS_H |
55 | # include <limits.h> | 57 | # include <limits.h> |
@@ -63,27 +65,6 @@ const char *email = "devel@monitoring-plugins.org"; | |||
63 | # define ERROR -1 | 65 | # define ERROR -1 |
64 | #endif | 66 | #endif |
65 | 67 | ||
66 | /* If nonzero, show only local filesystems. */ | ||
67 | static bool show_local_fs = false; | ||
68 | |||
69 | /* If nonzero, show only local filesystems but call stat() on remote ones. */ | ||
70 | static bool stat_remote_fs = false; | ||
71 | |||
72 | /* Linked list of filesystem types to omit. | ||
73 | If the list is empty, don't exclude any types. */ | ||
74 | static struct regex_list *fs_exclude_list = NULL; | ||
75 | |||
76 | /* Linked list of filesystem types to check. | ||
77 | If the list is empty, include all types. */ | ||
78 | static struct regex_list *fs_include_list; | ||
79 | |||
80 | static struct name_list *dp_exclude_list; | ||
81 | |||
82 | static struct parameter_list *path_select_list = NULL; | ||
83 | |||
84 | /* Linked list of mounted filesystems. */ | ||
85 | static struct mount_entry *mount_list; | ||
86 | |||
87 | /* For long options that have no equivalent short option, use a | 68 | /* For long options that have no equivalent short option, use a |
88 | non-character as a pseudo short option, starting with CHAR_MAX + 1. */ | 69 | non-character as a pseudo short option, starting with CHAR_MAX + 1. */ |
89 | enum { | 70 | enum { |
@@ -96,40 +77,27 @@ enum { | |||
96 | # pragma alloca | 77 | # pragma alloca |
97 | #endif | 78 | #endif |
98 | 79 | ||
99 | static int process_arguments(int /*argc*/, char ** /*argv*/); | 80 | typedef struct { |
100 | static void set_all_thresholds(struct parameter_list *path); | 81 | int errorcode; |
82 | check_disk_config config; | ||
83 | } check_disk_config_wrapper; | ||
84 | static check_disk_config_wrapper process_arguments(int /*argc*/, char ** /*argv*/); | ||
85 | static void set_all_thresholds(struct parameter_list *path, char * /*warn_freespace_units*/, char * /*crit_freespace_units*/, | ||
86 | char * /*warn_freespace_percent*/, char * /*crit_freespace_percent*/, char * /*warn_usedspace_units*/, | ||
87 | char * /*crit_usedspace_units*/, char * /*warn_usedspace_percent*/, char * /*crit_usedspace_percent*/, | ||
88 | char * /*warn_usedinodes_percent*/, char * /*crit_usedinodes_percent*/, char * /*warn_freeinodes_percent*/, | ||
89 | char * /*crit_freeinodes_percent*/); | ||
101 | static void print_help(void); | 90 | static void print_help(void); |
102 | void print_usage(void); | 91 | void print_usage(void); |
103 | static double calculate_percent(uintmax_t /*value*/, uintmax_t /*total*/); | 92 | static double calculate_percent(uintmax_t /*value*/, uintmax_t /*total*/); |
104 | static bool stat_path(struct parameter_list * /*parameters*/); | 93 | static bool stat_path(struct parameter_list * /*parameters*/, bool /*ignore_missing*/); |
105 | static void get_stats(struct parameter_list * /*parameters*/, struct fs_usage *fsp); | 94 | static void get_stats(struct parameter_list * /*parameters*/, struct fs_usage *fsp, bool /*ignore_missing*/, |
106 | static void get_path_stats(struct parameter_list * /*parameters*/, struct fs_usage *fsp); | 95 | bool /*freespace_ignore_reserved*/, uintmax_t /*mult*/, struct parameter_list * /*path_select_list*/, |
96 | struct name_list * /*seen*/); | ||
97 | static void get_path_stats(struct parameter_list * /*parameters*/, struct fs_usage *fsp, bool /*freespace_ignore_reserved*/, | ||
98 | uintmax_t /*mult*/, struct name_list * /*seen*/); | ||
107 | 99 | ||
108 | static char *units; | ||
109 | static uintmax_t mult = 1024 * 1024; | ||
110 | static int verbose = 0; | 100 | static int verbose = 0; |
111 | static bool erronly = false; | ||
112 | static bool display_mntp = false; | ||
113 | static bool exact_match = false; | ||
114 | static bool ignore_missing = false; | ||
115 | static bool freespace_ignore_reserved = false; | ||
116 | static bool display_inodes_perfdata = false; | ||
117 | static char *warn_freespace_units = NULL; | ||
118 | static char *crit_freespace_units = NULL; | ||
119 | static char *warn_freespace_percent = NULL; | ||
120 | static char *crit_freespace_percent = NULL; | ||
121 | static char *warn_usedspace_units = NULL; | ||
122 | static char *crit_usedspace_units = NULL; | ||
123 | static char *warn_usedspace_percent = NULL; | ||
124 | static char *crit_usedspace_percent = NULL; | ||
125 | static char *warn_usedinodes_percent = NULL; | ||
126 | static char *crit_usedinodes_percent = NULL; | ||
127 | static char *warn_freeinodes_percent = NULL; | ||
128 | static char *crit_freeinodes_percent = NULL; | ||
129 | static bool path_selected = false; | ||
130 | static bool path_ignored = false; | ||
131 | static char *group = NULL; | ||
132 | static struct name_list *seen = NULL; | ||
133 | 101 | ||
134 | int main(int argc, char **argv) { | 102 | int main(int argc, char **argv) { |
135 | setlocale(LC_ALL, ""); | 103 | setlocale(LC_ALL, ""); |
@@ -140,74 +108,78 @@ int main(int argc, char **argv) { | |||
140 | char mountdir[32]; | 108 | char mountdir[32]; |
141 | #endif | 109 | #endif |
142 | 110 | ||
143 | mount_list = read_file_system_list(false); | ||
144 | |||
145 | /* Parse extra opts if any */ | 111 | /* Parse extra opts if any */ |
146 | argv = np_extra_opts(&argc, argv, progname); | 112 | argv = np_extra_opts(&argc, argv, progname); |
147 | 113 | ||
148 | if (process_arguments(argc, argv) == ERROR) { | 114 | check_disk_config_wrapper tmp_config = process_arguments(argc, argv); |
115 | if (tmp_config.errorcode == ERROR) { | ||
149 | usage4(_("Could not parse arguments")); | 116 | usage4(_("Could not parse arguments")); |
150 | } | 117 | } |
151 | 118 | ||
119 | check_disk_config config = tmp_config.config; | ||
120 | |||
152 | /* If a list of paths has not been selected, find entire | 121 | /* If a list of paths has not been selected, find entire |
153 | mount list and create list of paths | 122 | mount list and create list of paths |
154 | */ | 123 | */ |
155 | if (!path_selected && !path_ignored) { | 124 | if (!config.path_selected && !config.path_ignored) { |
156 | for (struct mount_entry *me = mount_list; me; me = me->me_next) { | 125 | for (struct mount_entry *me = config.mount_list; me; me = me->me_next) { |
157 | struct parameter_list *path = NULL; | 126 | struct parameter_list *path = NULL; |
158 | if (!(path = np_find_parameter(path_select_list, me->me_mountdir))) { | 127 | if (!(path = np_find_parameter(config.path_select_list, me->me_mountdir))) { |
159 | path = np_add_parameter(&path_select_list, me->me_mountdir); | 128 | path = np_add_parameter(&config.path_select_list, me->me_mountdir); |
160 | } | 129 | } |
161 | path->best_match = me; | 130 | path->best_match = me; |
162 | path->group = group; | 131 | path->group = config.group; |
163 | set_all_thresholds(path); | 132 | set_all_thresholds(path, config.warn_freespace_units, config.crit_freespace_units, config.warn_freespace_percent, |
133 | config.crit_freespace_percent, config.warn_usedspace_units, config.crit_usedspace_units, | ||
134 | config.warn_usedspace_percent, config.crit_usedspace_percent, config.warn_usedinodes_percent, | ||
135 | config.crit_usedinodes_percent, config.warn_freeinodes_percent, config.crit_freeinodes_percent); | ||
164 | } | 136 | } |
165 | } | 137 | } |
166 | 138 | ||
167 | if (!path_ignored) { | 139 | if (!config.path_ignored) { |
168 | np_set_best_match(path_select_list, mount_list, exact_match); | 140 | np_set_best_match(config.path_select_list, config.mount_list, config.exact_match); |
169 | } | 141 | } |
170 | 142 | ||
171 | /* Error if no match found for specified paths */ | 143 | /* Error if no match found for specified paths */ |
172 | struct parameter_list *temp_list = path_select_list; | 144 | struct parameter_list *temp_list = config.path_select_list; |
173 | 145 | ||
174 | char *ignored = strdup(""); | 146 | char *ignored = strdup(""); |
175 | while (path_select_list) { | 147 | while (config.path_select_list) { |
176 | if (!path_select_list->best_match && ignore_missing) { | 148 | if (!config.path_select_list->best_match && config.ignore_missing) { |
177 | /* If the first element will be deleted, the temp_list must be updated with the new start address as well */ | 149 | /* If the first element will be deleted, the temp_list must be updated with the new start address as well */ |
178 | if (path_select_list == temp_list) { | 150 | if (config.path_select_list == temp_list) { |
179 | temp_list = path_select_list->name_next; | 151 | temp_list = config.path_select_list->name_next; |
180 | } | 152 | } |
181 | /* Add path argument to list of ignored paths to inform about missing paths being ignored and not alerted */ | 153 | /* Add path argument to list of ignored paths to inform about missing paths being ignored and not alerted */ |
182 | xasprintf(&ignored, "%s %s;", ignored, path_select_list->name); | 154 | xasprintf(&ignored, "%s %s;", ignored, config.path_select_list->name); |
183 | /* Delete the path from the list so that it is not stat-checked later in the code. */ | 155 | /* Delete the path from the list so that it is not stat-checked later in the code. */ |
184 | path_select_list = np_del_parameter(path_select_list, path_select_list->name_prev); | 156 | config.path_select_list = np_del_parameter(config.path_select_list, config.path_select_list->name_prev); |
185 | } else if (!path_select_list->best_match) { | 157 | } else if (!config.path_select_list->best_match) { |
186 | /* Without --ignore-missing option, exit with Critical state. */ | 158 | /* Without --ignore-missing option, exit with Critical state. */ |
187 | die(STATE_CRITICAL, _("DISK %s: %s not found\n"), _("CRITICAL"), path_select_list->name); | 159 | die(STATE_CRITICAL, _("DISK %s: %s not found\n"), _("CRITICAL"), config.path_select_list->name); |
188 | } else { | 160 | } else { |
189 | /* Continue jumping through the list */ | 161 | /* Continue jumping through the list */ |
190 | path_select_list = path_select_list->name_next; | 162 | config.path_select_list = config.path_select_list->name_next; |
191 | } | 163 | } |
192 | } | 164 | } |
193 | 165 | ||
194 | path_select_list = temp_list; | 166 | config.path_select_list = temp_list; |
195 | 167 | ||
196 | int result = STATE_UNKNOWN; | 168 | mp_state_enum result = STATE_UNKNOWN; |
197 | if (!path_select_list && ignore_missing) { | 169 | if (!config.path_select_list && config.ignore_missing) { |
198 | result = STATE_OK; | 170 | result = STATE_OK; |
199 | if (verbose >= 2) { | 171 | if (verbose >= 2) { |
200 | printf("None of the provided paths were found\n"); | 172 | printf("None of the provided paths were found\n"); |
201 | } | 173 | } |
202 | } | 174 | } |
203 | 175 | ||
204 | mp_state_enum disk_result = STATE_UNKNOWN; | 176 | mp_state_enum filesystem_result = STATE_UNKNOWN; |
205 | char *perf = strdup(""); | 177 | char *perf = strdup(""); |
206 | char *perf_ilabel = strdup(""); | 178 | char *perf_ilabel = strdup(""); |
207 | char *output = strdup(""); | 179 | char *output = strdup(""); |
208 | struct parameter_list *path = NULL; | 180 | struct parameter_list *path = NULL; |
209 | /* Process for every path in list */ | 181 | /* Process for every path in list */ |
210 | for (path = path_select_list; path; path = path->name_next) { | 182 | for (path = config.path_select_list; path; path = path->name_next) { |
211 | if (verbose >= 3 && path->freespace_percent->warning != NULL && path->freespace_percent->critical != NULL) { | 183 | if (verbose >= 3 && path->freespace_percent->warning != NULL && path->freespace_percent->critical != NULL) { |
212 | printf("Thresholds(pct) for %s warn: %f crit %f\n", path->name, path->freespace_percent->warning->end, | 184 | printf("Thresholds(pct) for %s warn: %f crit %f\n", path->name, path->freespace_percent->warning->end, |
213 | path->freespace_percent->critical->end); | 185 | path->freespace_percent->critical->end); |
@@ -217,8 +189,8 @@ int main(int argc, char **argv) { | |||
217 | printf("Group of %s: %s\n", path->name, path->group); | 189 | printf("Group of %s: %s\n", path->name, path->group); |
218 | } | 190 | } |
219 | 191 | ||
220 | // reset disk result | 192 | // reset filesystem result |
221 | disk_result = STATE_UNKNOWN; | 193 | filesystem_result = STATE_UNKNOWN; |
222 | 194 | ||
223 | struct mount_entry *mount_entry = path->best_match; | 195 | struct mount_entry *mount_entry = path->best_match; |
224 | 196 | ||
@@ -238,16 +210,16 @@ int main(int argc, char **argv) { | |||
238 | /* Filters */ | 210 | /* Filters */ |
239 | 211 | ||
240 | /* Remove filesystems already seen */ | 212 | /* Remove filesystems already seen */ |
241 | if (np_seen_name(seen, mount_entry->me_mountdir)) { | 213 | if (np_seen_name(config.seen, mount_entry->me_mountdir)) { |
242 | continue; | 214 | continue; |
243 | } | 215 | } |
244 | np_add_name(&seen, mount_entry->me_mountdir); | 216 | np_add_name(&config.seen, mount_entry->me_mountdir); |
245 | 217 | ||
246 | if (path->group == NULL) { | 218 | if (path->group == NULL) { |
247 | /* Skip remote filesystems if we're not interested in them */ | 219 | /* Skip remote filesystems if we're not interested in them */ |
248 | if (mount_entry->me_remote && show_local_fs) { | 220 | if (mount_entry->me_remote && config.show_local_fs) { |
249 | if (stat_remote_fs) { | 221 | if (config.stat_remote_fs) { |
250 | if (!stat_path(path) && ignore_missing) { | 222 | if (!stat_path(path, config.ignore_missing) && config.ignore_missing) { |
251 | result = STATE_OK; | 223 | result = STATE_OK; |
252 | xasprintf(&ignored, "%s %s;", ignored, path->name); | 224 | xasprintf(&ignored, "%s %s;", ignored, path->name); |
253 | } | 225 | } |
@@ -255,22 +227,22 @@ int main(int argc, char **argv) { | |||
255 | continue; | 227 | continue; |
256 | /* Skip pseudo fs's if we haven't asked for all fs's */ | 228 | /* Skip pseudo fs's if we haven't asked for all fs's */ |
257 | } | 229 | } |
258 | if (fs_exclude_list && np_find_regmatch(fs_exclude_list, mount_entry->me_type)) { | 230 | if (config.fs_exclude_list && np_find_regmatch(config.fs_exclude_list, mount_entry->me_type)) { |
259 | continue; | 231 | continue; |
260 | /* Skip excluded fs's */ | 232 | /* Skip excluded fs's */ |
261 | } | 233 | } |
262 | if (dp_exclude_list && | 234 | if (config.device_path_exclude_list && (np_find_name(config.device_path_exclude_list, mount_entry->me_devname) || |
263 | (np_find_name(dp_exclude_list, mount_entry->me_devname) || np_find_name(dp_exclude_list, mount_entry->me_mountdir))) { | 235 | np_find_name(config.device_path_exclude_list, mount_entry->me_mountdir))) { |
264 | continue; | 236 | continue; |
265 | /* Skip not included fstypes */ | 237 | /* Skip not included fstypes */ |
266 | } | 238 | } |
267 | if (fs_include_list && !np_find_regmatch(fs_include_list, mount_entry->me_type)) { | 239 | if (config.fs_include_list && !np_find_regmatch(config.fs_include_list, mount_entry->me_type)) { |
268 | continue; | 240 | continue; |
269 | } | 241 | } |
270 | } | 242 | } |
271 | 243 | ||
272 | if (!stat_path(path)) { | 244 | if (!stat_path(path, config.ignore_missing)) { |
273 | if (ignore_missing) { | 245 | if (config.ignore_missing) { |
274 | result = STATE_OK; | 246 | result = STATE_OK; |
275 | xasprintf(&ignored, "%s %s;", ignored, path->name); | 247 | xasprintf(&ignored, "%s %s;", ignored, path->name); |
276 | } | 248 | } |
@@ -281,13 +253,14 @@ int main(int argc, char **argv) { | |||
281 | get_fs_usage(mount_entry->me_mountdir, mount_entry->me_devname, &fsp); | 253 | get_fs_usage(mount_entry->me_mountdir, mount_entry->me_devname, &fsp); |
282 | 254 | ||
283 | if (fsp.fsu_blocks && strcmp("none", mount_entry->me_mountdir)) { | 255 | if (fsp.fsu_blocks && strcmp("none", mount_entry->me_mountdir)) { |
284 | get_stats(path, &fsp); | 256 | get_stats(path, &fsp, config.ignore_missing, config.freespace_ignore_reserved, config.mult, config.path_select_list, |
257 | config.seen); | ||
285 | 258 | ||
286 | if (verbose >= 3) { | 259 | if (verbose >= 3) { |
287 | printf("For %s, used_pct=%f free_pct=%f used_units=%lu free_units=%lu total_units=%lu used_inodes_pct=%f " | 260 | printf("For %s, used_pct=%f free_pct=%f used_units=%lu free_units=%lu total_units=%lu used_inodes_pct=%f " |
288 | "free_inodes_pct=%f fsp.fsu_blocksize=%lu mult=%lu\n", | 261 | "free_inodes_pct=%f fsp.fsu_blocksize=%lu mult=%lu\n", |
289 | mount_entry->me_mountdir, path->dused_pct, path->dfree_pct, path->dused_units, path->dfree_units, path->dtotal_units, | 262 | mount_entry->me_mountdir, path->dused_pct, path->dfree_pct, path->dused_units, path->dfree_units, path->dtotal_units, |
290 | path->dused_inodes_percent, path->dfree_inodes_percent, fsp.fsu_blocksize, mult); | 263 | path->dused_inodes_percent, path->dfree_inodes_percent, fsp.fsu_blocksize, config.mult); |
291 | } | 264 | } |
292 | 265 | ||
293 | /* Threshold comparisons */ | 266 | /* Threshold comparisons */ |
@@ -296,39 +269,39 @@ int main(int argc, char **argv) { | |||
296 | if (verbose >= 3) { | 269 | if (verbose >= 3) { |
297 | printf("Freespace_units result=%d\n", temp_result); | 270 | printf("Freespace_units result=%d\n", temp_result); |
298 | } | 271 | } |
299 | disk_result = max_state(disk_result, temp_result); | 272 | filesystem_result = max_state(filesystem_result, temp_result); |
300 | 273 | ||
301 | temp_result = get_status(path->dfree_pct, path->freespace_percent); | 274 | temp_result = get_status(path->dfree_pct, path->freespace_percent); |
302 | if (verbose >= 3) { | 275 | if (verbose >= 3) { |
303 | printf("Freespace%% result=%d\n", temp_result); | 276 | printf("Freespace%% result=%d\n", temp_result); |
304 | } | 277 | } |
305 | disk_result = max_state(disk_result, temp_result); | 278 | filesystem_result = max_state(filesystem_result, temp_result); |
306 | 279 | ||
307 | temp_result = get_status(path->dused_units, path->usedspace_units); | 280 | temp_result = get_status(path->dused_units, path->usedspace_units); |
308 | if (verbose >= 3) { | 281 | if (verbose >= 3) { |
309 | printf("Usedspace_units result=%d\n", temp_result); | 282 | printf("Usedspace_units result=%d\n", temp_result); |
310 | } | 283 | } |
311 | disk_result = max_state(disk_result, temp_result); | 284 | filesystem_result = max_state(filesystem_result, temp_result); |
312 | 285 | ||
313 | temp_result = get_status(path->dused_pct, path->usedspace_percent); | 286 | temp_result = get_status(path->dused_pct, path->usedspace_percent); |
314 | if (verbose >= 3) { | 287 | if (verbose >= 3) { |
315 | printf("Usedspace_percent result=%d\n", temp_result); | 288 | printf("Usedspace_percent result=%d\n", temp_result); |
316 | } | 289 | } |
317 | disk_result = max_state(disk_result, temp_result); | 290 | filesystem_result = max_state(filesystem_result, temp_result); |
318 | 291 | ||
319 | temp_result = get_status(path->dused_inodes_percent, path->usedinodes_percent); | 292 | temp_result = get_status(path->dused_inodes_percent, path->usedinodes_percent); |
320 | if (verbose >= 3) { | 293 | if (verbose >= 3) { |
321 | printf("Usedinodes_percent result=%d\n", temp_result); | 294 | printf("Usedinodes_percent result=%d\n", temp_result); |
322 | } | 295 | } |
323 | disk_result = max_state(disk_result, temp_result); | 296 | filesystem_result = max_state(filesystem_result, temp_result); |
324 | 297 | ||
325 | temp_result = get_status(path->dfree_inodes_percent, path->freeinodes_percent); | 298 | temp_result = get_status(path->dfree_inodes_percent, path->freeinodes_percent); |
326 | if (verbose >= 3) { | 299 | if (verbose >= 3) { |
327 | printf("Freeinodes_percent result=%d\n", temp_result); | 300 | printf("Freeinodes_percent result=%d\n", temp_result); |
328 | } | 301 | } |
329 | disk_result = max_state(disk_result, temp_result); | 302 | filesystem_result = max_state(filesystem_result, temp_result); |
330 | 303 | ||
331 | result = max_state(result, disk_result); | 304 | result = max_state(result, filesystem_result); |
332 | 305 | ||
333 | /* What a mess of units. The output shows free space, the perf data shows used space. Yikes! | 306 | /* What a mess of units. The output shows free space, the perf data shows used space. Yikes! |
334 | Hack here. Trying to get warn/crit levels from freespace_(units|percent) for perf | 307 | Hack here. Trying to get warn/crit levels from freespace_(units|percent) for perf |
@@ -339,31 +312,32 @@ int main(int argc, char **argv) { | |||
339 | uint64_t warning_high_tide = UINT64_MAX; | 312 | uint64_t warning_high_tide = UINT64_MAX; |
340 | 313 | ||
341 | if (path->freespace_units->warning != NULL) { | 314 | if (path->freespace_units->warning != NULL) { |
342 | warning_high_tide = (path->dtotal_units - path->freespace_units->warning->end) * mult; | 315 | warning_high_tide = (path->dtotal_units - path->freespace_units->warning->end) * config.mult; |
343 | } | 316 | } |
344 | if (path->freespace_percent->warning != NULL) { | 317 | if (path->freespace_percent->warning != NULL) { |
345 | warning_high_tide = | 318 | warning_high_tide = min(warning_high_tide, (uint64_t)((1.0 - path->freespace_percent->warning->end / 100) * |
346 | min(warning_high_tide, (uint64_t)((1.0 - path->freespace_percent->warning->end / 100) * (path->dtotal_units * mult))); | 319 | (path->dtotal_units * config.mult))); |
347 | } | 320 | } |
348 | 321 | ||
349 | uint64_t critical_high_tide = UINT64_MAX; | 322 | uint64_t critical_high_tide = UINT64_MAX; |
350 | 323 | ||
351 | if (path->freespace_units->critical != NULL) { | 324 | if (path->freespace_units->critical != NULL) { |
352 | critical_high_tide = (path->dtotal_units - path->freespace_units->critical->end) * mult; | 325 | critical_high_tide = (path->dtotal_units - path->freespace_units->critical->end) * config.mult; |
353 | } | 326 | } |
354 | if (path->freespace_percent->critical != NULL) { | 327 | if (path->freespace_percent->critical != NULL) { |
355 | critical_high_tide = | 328 | critical_high_tide = min(critical_high_tide, (uint64_t)((1.0 - path->freespace_percent->critical->end / 100) * |
356 | min(critical_high_tide, (uint64_t)((1.0 - path->freespace_percent->critical->end / 100) * (path->dtotal_units * mult))); | 329 | (path->dtotal_units * config.mult))); |
357 | } | 330 | } |
358 | 331 | ||
359 | /* Nb: *_high_tide are unset when == UINT64_MAX */ | 332 | /* Nb: *_high_tide are unset when == UINT64_MAX */ |
360 | xasprintf(&perf, "%s %s", perf, | 333 | xasprintf(&perf, "%s %s", perf, |
361 | perfdata_uint64((!strcmp(mount_entry->me_mountdir, "none") || display_mntp) ? mount_entry->me_devname | 334 | perfdata_uint64((!strcmp(mount_entry->me_mountdir, "none") || config.display_mntp) ? mount_entry->me_devname |
362 | : mount_entry->me_mountdir, | 335 | : mount_entry->me_mountdir, |
363 | path->dused_units * mult, "B", (warning_high_tide != UINT64_MAX), warning_high_tide, | 336 | path->dused_units * config.mult, "B", (warning_high_tide != UINT64_MAX), warning_high_tide, |
364 | (critical_high_tide != UINT64_MAX), critical_high_tide, true, 0, true, path->dtotal_units * mult)); | 337 | (critical_high_tide != UINT64_MAX), critical_high_tide, true, 0, true, |
338 | path->dtotal_units * config.mult)); | ||
365 | 339 | ||
366 | if (display_inodes_perfdata) { | 340 | if (config.display_inodes_perfdata) { |
367 | /* *_high_tide must be reinitialized at each run */ | 341 | /* *_high_tide must be reinitialized at each run */ |
368 | warning_high_tide = UINT64_MAX; | 342 | warning_high_tide = UINT64_MAX; |
369 | critical_high_tide = UINT64_MAX; | 343 | critical_high_tide = UINT64_MAX; |
@@ -378,43 +352,46 @@ int main(int argc, char **argv) { | |||
378 | } | 352 | } |
379 | 353 | ||
380 | xasprintf(&perf_ilabel, "%s (inodes)", | 354 | xasprintf(&perf_ilabel, "%s (inodes)", |
381 | (!strcmp(mount_entry->me_mountdir, "none") || display_mntp) ? mount_entry->me_devname : mount_entry->me_mountdir); | 355 | (!strcmp(mount_entry->me_mountdir, "none") || config.display_mntp) ? mount_entry->me_devname |
356 | : mount_entry->me_mountdir); | ||
382 | /* Nb: *_high_tide are unset when == UINT64_MAX */ | 357 | /* Nb: *_high_tide are unset when == UINT64_MAX */ |
383 | xasprintf(&perf, "%s %s", perf, | 358 | xasprintf(&perf, "%s %s", perf, |
384 | perfdata_uint64(perf_ilabel, path->inodes_used, "", (warning_high_tide != UINT64_MAX), warning_high_tide, | 359 | perfdata_uint64(perf_ilabel, path->inodes_used, "", (warning_high_tide != UINT64_MAX), warning_high_tide, |
385 | (critical_high_tide != UINT64_MAX), critical_high_tide, true, 0, true, path->inodes_total)); | 360 | (critical_high_tide != UINT64_MAX), critical_high_tide, true, 0, true, path->inodes_total)); |
386 | } | 361 | } |
387 | 362 | ||
388 | if (disk_result == STATE_OK && erronly && !verbose) { | 363 | if (filesystem_result == STATE_OK && config.erronly && !verbose) { |
389 | continue; | 364 | continue; |
390 | } | 365 | } |
391 | 366 | ||
392 | char *flag_header = NULL; | 367 | char *flag_header = NULL; |
393 | if (disk_result && verbose >= 1) { | 368 | if (filesystem_result && verbose >= 1) { |
394 | xasprintf(&flag_header, " %s [", state_text(disk_result)); | 369 | xasprintf(&flag_header, " %s [", state_text(filesystem_result)); |
395 | } else { | 370 | } else { |
396 | xasprintf(&flag_header, ""); | 371 | xasprintf(&flag_header, ""); |
397 | } | 372 | } |
398 | xasprintf(&output, "%s%s %s %llu%s (%.1f%%", output, flag_header, | 373 | xasprintf(&output, "%s%s %s %llu%s (%.1f%%", output, flag_header, |
399 | (!strcmp(mount_entry->me_mountdir, "none") || display_mntp) ? mount_entry->me_devname : mount_entry->me_mountdir, | 374 | (!strcmp(mount_entry->me_mountdir, "none") || config.display_mntp) ? mount_entry->me_devname |
400 | path->dfree_units, units, path->dfree_pct); | 375 | : mount_entry->me_mountdir, |
376 | path->dfree_units, config.units, path->dfree_pct); | ||
401 | if (path->dused_inodes_percent < 0) { | 377 | if (path->dused_inodes_percent < 0) { |
402 | xasprintf(&output, "%s inode=-)%s;", output, (disk_result ? "]" : "")); | 378 | xasprintf(&output, "%s inode=-)%s;", output, (filesystem_result ? "]" : "")); |
403 | } else { | 379 | } else { |
404 | xasprintf(&output, "%s inode=%.0f%%)%s;", output, path->dfree_inodes_percent, ((disk_result && verbose >= 1) ? "]" : "")); | 380 | xasprintf(&output, "%s inode=%.0f%%)%s;", output, path->dfree_inodes_percent, |
381 | ((filesystem_result && verbose >= 1) ? "]" : "")); | ||
405 | } | 382 | } |
406 | free(flag_header); | 383 | free(flag_header); |
407 | } | 384 | } |
408 | } | 385 | } |
409 | 386 | ||
410 | char *preamble = " - free space:"; | 387 | char *preamble = " - free space:"; |
411 | if (strcmp(output, "") == 0 && !erronly) { | 388 | if (strcmp(output, "") == 0 && !config.erronly) { |
412 | preamble = ""; | 389 | preamble = ""; |
413 | xasprintf(&output, " - No disks were found for provided parameters"); | 390 | xasprintf(&output, " - No disks were found for provided parameters"); |
414 | } | 391 | } |
415 | 392 | ||
416 | char *ignored_preamble = " - ignored paths:"; | 393 | char *ignored_preamble = " - ignored paths:"; |
417 | printf("DISK %s%s%s%s%s|%s\n", state_text(result), ((erronly && result == STATE_OK)) ? "" : preamble, output, | 394 | printf("DISK %s%s%s%s%s|%s\n", state_text(result), (config.erronly && (result == STATE_OK)) ? "" : preamble, output, |
418 | (strcmp(ignored, "") == 0) ? "" : ignored_preamble, ignored, perf); | 395 | (strcmp(ignored, "") == 0) ? "" : ignored_preamble, ignored, perf); |
419 | return result; | 396 | return result; |
420 | } | 397 | } |
@@ -428,9 +405,16 @@ double calculate_percent(uintmax_t value, uintmax_t total) { | |||
428 | } | 405 | } |
429 | 406 | ||
430 | /* process command-line arguments */ | 407 | /* process command-line arguments */ |
431 | int process_arguments(int argc, char **argv) { | 408 | check_disk_config_wrapper process_arguments(int argc, char **argv) { |
409 | |||
410 | check_disk_config_wrapper result = { | ||
411 | .errorcode = OK, | ||
412 | .config = check_disk_config_init(), | ||
413 | }; | ||
414 | |||
432 | if (argc < 2) { | 415 | if (argc < 2) { |
433 | return ERROR; | 416 | result.errorcode = ERROR; |
417 | return result; | ||
434 | } | 418 | } |
435 | 419 | ||
436 | static struct option longopts[] = {{"timeout", required_argument, 0, 't'}, | 420 | static struct option longopts[] = {{"timeout", required_argument, 0, 't'}, |
@@ -480,8 +464,9 @@ int process_arguments(int argc, char **argv) { | |||
480 | 464 | ||
481 | int cflags = REG_NOSUB | REG_EXTENDED; | 465 | int cflags = REG_NOSUB | REG_EXTENDED; |
482 | int default_cflags = cflags; | 466 | int default_cflags = cflags; |
467 | result.config.mount_list = read_file_system_list(false); | ||
483 | 468 | ||
484 | np_add_regex(&fs_exclude_list, "iso9660", REG_EXTENDED); | 469 | np_add_regex(&result.config.fs_exclude_list, "iso9660", REG_EXTENDED); |
485 | 470 | ||
486 | while (true) { | 471 | while (true) { |
487 | int option = 0; | 472 | int option = 0; |
@@ -508,15 +493,15 @@ int process_arguments(int argc, char **argv) { | |||
508 | 493 | ||
509 | if (strstr(optarg, "%")) { | 494 | if (strstr(optarg, "%")) { |
510 | if (*optarg == '@') { | 495 | if (*optarg == '@') { |
511 | warn_freespace_percent = optarg; | 496 | result.config.warn_freespace_percent = optarg; |
512 | } else { | 497 | } else { |
513 | xasprintf(&warn_freespace_percent, "@%s", optarg); | 498 | xasprintf(&result.config.warn_freespace_percent, "@%s", optarg); |
514 | } | 499 | } |
515 | } else { | 500 | } else { |
516 | if (*optarg == '@') { | 501 | if (*optarg == '@') { |
517 | warn_freespace_units = optarg; | 502 | result.config.warn_freespace_units = optarg; |
518 | } else { | 503 | } else { |
519 | xasprintf(&warn_freespace_units, "@%s", optarg); | 504 | xasprintf(&result.config.warn_freespace_units, "@%s", optarg); |
520 | } | 505 | } |
521 | } | 506 | } |
522 | break; | 507 | break; |
@@ -533,149 +518,149 @@ int process_arguments(int argc, char **argv) { | |||
533 | 518 | ||
534 | if (strstr(optarg, "%")) { | 519 | if (strstr(optarg, "%")) { |
535 | if (*optarg == '@') { | 520 | if (*optarg == '@') { |
536 | crit_freespace_percent = optarg; | 521 | result.config.crit_freespace_percent = optarg; |
537 | } else { | 522 | } else { |
538 | xasprintf(&crit_freespace_percent, "@%s", optarg); | 523 | xasprintf(&result.config.crit_freespace_percent, "@%s", optarg); |
539 | } | 524 | } |
540 | } else { | 525 | } else { |
541 | if (*optarg == '@') { | 526 | if (*optarg == '@') { |
542 | crit_freespace_units = optarg; | 527 | result.config.crit_freespace_units = optarg; |
543 | } else { | 528 | } else { |
544 | xasprintf(&crit_freespace_units, "@%s", optarg); | 529 | xasprintf(&result.config.crit_freespace_units, "@%s", optarg); |
545 | } | 530 | } |
546 | } | 531 | } |
547 | break; | 532 | break; |
548 | 533 | ||
549 | case 'W': /* warning inode threshold */ | 534 | case 'W': /* warning inode threshold */ |
550 | if (*optarg == '@') { | 535 | if (*optarg == '@') { |
551 | warn_freeinodes_percent = optarg; | 536 | result.config.warn_freeinodes_percent = optarg; |
552 | } else { | 537 | } else { |
553 | xasprintf(&warn_freeinodes_percent, "@%s", optarg); | 538 | xasprintf(&result.config.warn_freeinodes_percent, "@%s", optarg); |
554 | } | 539 | } |
555 | break; | 540 | break; |
556 | case 'K': /* critical inode threshold */ | 541 | case 'K': /* critical inode threshold */ |
557 | if (*optarg == '@') { | 542 | if (*optarg == '@') { |
558 | crit_freeinodes_percent = optarg; | 543 | result.config.crit_freeinodes_percent = optarg; |
559 | } else { | 544 | } else { |
560 | xasprintf(&crit_freeinodes_percent, "@%s", optarg); | 545 | xasprintf(&result.config.crit_freeinodes_percent, "@%s", optarg); |
561 | } | 546 | } |
562 | break; | 547 | break; |
563 | case 'u': | 548 | case 'u': |
564 | if (units) { | 549 | free(result.config.units); |
565 | free(units); | ||
566 | } | ||
567 | if (!strcasecmp(optarg, "bytes")) { | 550 | if (!strcasecmp(optarg, "bytes")) { |
568 | mult = (uintmax_t)1; | 551 | result.config.mult = (uintmax_t)1; |
569 | units = strdup("B"); | 552 | result.config.units = strdup("B"); |
570 | } else if (!strcmp(optarg, "KiB")) { | 553 | } else if (!strcmp(optarg, "KiB")) { |
571 | mult = (uintmax_t)1024; | 554 | result.config.mult = (uintmax_t)1024; |
572 | units = strdup("KiB"); | 555 | result.config.units = strdup("KiB"); |
573 | } else if (!strcmp(optarg, "kB")) { | 556 | } else if (!strcmp(optarg, "kB")) { |
574 | mult = (uintmax_t)1000; | 557 | result.config.mult = (uintmax_t)1000; |
575 | units = strdup("kB"); | 558 | result.config.units = strdup("kB"); |
576 | } else if (!strcmp(optarg, "MiB")) { | 559 | } else if (!strcmp(optarg, "MiB")) { |
577 | mult = (uintmax_t)1024 * 1024; | 560 | result.config.mult = (uintmax_t)1024 * 1024; |
578 | units = strdup("MiB"); | 561 | result.config.units = strdup("MiB"); |
579 | } else if (!strcmp(optarg, "MB")) { | 562 | } else if (!strcmp(optarg, "MB")) { |
580 | mult = (uintmax_t)1000 * 1000; | 563 | result.config.mult = (uintmax_t)1000 * 1000; |
581 | units = strdup("MB"); | 564 | result.config.units = strdup("MB"); |
582 | } else if (!strcmp(optarg, "GiB")) { | 565 | } else if (!strcmp(optarg, "GiB")) { |
583 | mult = (uintmax_t)1024 * 1024 * 1024; | 566 | result.config.mult = (uintmax_t)1024 * 1024 * 1024; |
584 | units = strdup("GiB"); | 567 | result.config.units = strdup("GiB"); |
585 | } else if (!strcmp(optarg, "GB")) { | 568 | } else if (!strcmp(optarg, "GB")) { |
586 | mult = (uintmax_t)1000 * 1000 * 1000; | 569 | result.config.mult = (uintmax_t)1000 * 1000 * 1000; |
587 | units = strdup("GB"); | 570 | result.config.units = strdup("GB"); |
588 | } else if (!strcmp(optarg, "TiB")) { | 571 | } else if (!strcmp(optarg, "TiB")) { |
589 | mult = (uintmax_t)1024 * 1024 * 1024 * 1024; | 572 | result.config.mult = (uintmax_t)1024 * 1024 * 1024 * 1024; |
590 | units = strdup("TiB"); | 573 | result.config.units = strdup("TiB"); |
591 | } else if (!strcmp(optarg, "TB")) { | 574 | } else if (!strcmp(optarg, "TB")) { |
592 | mult = (uintmax_t)1000 * 1000 * 1000 * 1000; | 575 | result.config.mult = (uintmax_t)1000 * 1000 * 1000 * 1000; |
593 | units = strdup("TB"); | 576 | result.config.units = strdup("TB"); |
594 | } else if (!strcmp(optarg, "PiB")) { | 577 | } else if (!strcmp(optarg, "PiB")) { |
595 | mult = (uintmax_t)1024 * 1024 * 1024 * 1024 * 1024; | 578 | result.config.mult = (uintmax_t)1024 * 1024 * 1024 * 1024 * 1024; |
596 | units = strdup("PiB"); | 579 | result.config.units = strdup("PiB"); |
597 | } else if (!strcmp(optarg, "PB")) { | 580 | } else if (!strcmp(optarg, "PB")) { |
598 | mult = (uintmax_t)1000 * 1000 * 1000 * 1000 * 1000; | 581 | result.config.mult = (uintmax_t)1000 * 1000 * 1000 * 1000 * 1000; |
599 | units = strdup("PB"); | 582 | result.config.units = strdup("PB"); |
600 | } else { | 583 | } else { |
601 | die(STATE_UNKNOWN, _("unit type %s not known\n"), optarg); | 584 | die(STATE_UNKNOWN, _("unit type %s not known\n"), optarg); |
602 | } | 585 | } |
603 | if (units == NULL) { | 586 | if (result.config.units == NULL) { |
604 | die(STATE_UNKNOWN, _("failed allocating storage for '%s'\n"), "units"); | 587 | die(STATE_UNKNOWN, _("failed allocating storage for '%s'\n"), "units"); |
605 | } | 588 | } |
606 | break; | 589 | break; |
607 | case 'k': /* display mountpoint */ | 590 | case 'k': /* display mountpoint */ |
608 | mult = 1024; | 591 | result.config.mult = 1024; |
609 | if (units) { | 592 | free(result.config.units); |
610 | free(units); | 593 | result.config.units = strdup("kiB"); |
611 | } | ||
612 | units = strdup("kiB"); | ||
613 | break; | 594 | break; |
614 | case 'm': /* display mountpoint */ | 595 | case 'm': /* display mountpoint */ |
615 | mult = 1024 * 1024; | 596 | result.config.mult = 1024 * 1024; |
616 | if (units) { | 597 | free(result.config.units); |
617 | free(units); | 598 | result.config.units = strdup("MiB"); |
618 | } | ||
619 | units = strdup("MiB"); | ||
620 | break; | 599 | break; |
621 | case 'L': | 600 | case 'L': |
622 | stat_remote_fs = true; | 601 | result.config.stat_remote_fs = true; |
623 | /* fallthrough */ | 602 | /* fallthrough */ |
624 | case 'l': | 603 | case 'l': |
625 | show_local_fs = true; | 604 | result.config.show_local_fs = true; |
626 | break; | 605 | break; |
627 | case 'P': | 606 | case 'P': |
628 | display_inodes_perfdata = true; | 607 | result.config.display_inodes_perfdata = true; |
629 | break; | 608 | break; |
630 | case 'p': /* select path */ { | 609 | case 'p': /* select path */ { |
631 | if (!(warn_freespace_units || crit_freespace_units || warn_freespace_percent || crit_freespace_percent || | 610 | if (!(result.config.warn_freespace_units || result.config.crit_freespace_units || result.config.warn_freespace_percent || |
632 | warn_usedspace_units || crit_usedspace_units || warn_usedspace_percent || crit_usedspace_percent || | 611 | result.config.crit_freespace_percent || result.config.warn_usedspace_units || result.config.crit_usedspace_units || |
633 | warn_usedinodes_percent || crit_usedinodes_percent || warn_freeinodes_percent || crit_freeinodes_percent)) { | 612 | result.config.warn_usedspace_percent || result.config.crit_usedspace_percent || result.config.warn_usedinodes_percent || |
613 | result.config.crit_usedinodes_percent || result.config.warn_freeinodes_percent || | ||
614 | result.config.crit_freeinodes_percent)) { | ||
634 | die(STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set a threshold value before using -p\n")); | 615 | die(STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set a threshold value before using -p\n")); |
635 | } | 616 | } |
636 | 617 | ||
637 | /* add parameter if not found. overwrite thresholds if path has already been added */ | 618 | /* add parameter if not found. overwrite thresholds if path has already been added */ |
638 | struct parameter_list *se; | 619 | struct parameter_list *se; |
639 | if (!(se = np_find_parameter(path_select_list, optarg))) { | 620 | if (!(se = np_find_parameter(result.config.path_select_list, optarg))) { |
640 | se = np_add_parameter(&path_select_list, optarg); | 621 | se = np_add_parameter(&result.config.path_select_list, optarg); |
641 | 622 | ||
642 | struct stat stat_buf = {}; | 623 | struct stat stat_buf = {}; |
643 | if (stat(optarg, &stat_buf) && ignore_missing) { | 624 | if (stat(optarg, &stat_buf) && result.config.ignore_missing) { |
644 | path_ignored = true; | 625 | result.config.path_ignored = true; |
645 | break; | 626 | break; |
646 | } | 627 | } |
647 | } | 628 | } |
648 | se->group = group; | 629 | se->group = result.config.group; |
649 | set_all_thresholds(se); | 630 | set_all_thresholds( |
631 | se, result.config.warn_freespace_units, result.config.crit_freespace_units, result.config.warn_freespace_percent, | ||
632 | result.config.crit_freespace_percent, result.config.warn_usedspace_units, result.config.crit_usedspace_units, | ||
633 | result.config.warn_usedspace_percent, result.config.crit_usedspace_percent, result.config.warn_usedinodes_percent, | ||
634 | result.config.crit_usedinodes_percent, result.config.warn_freeinodes_percent, result.config.crit_freeinodes_percent); | ||
650 | 635 | ||
651 | /* With autofs, it is required to stat() the path before re-populating the mount_list */ | 636 | /* With autofs, it is required to stat() the path before re-populating the mount_list */ |
652 | if (!stat_path(se)) { | 637 | if (!stat_path(se, result.config.ignore_missing)) { |
653 | break; | 638 | break; |
654 | } | 639 | } |
655 | /* NB: We can't free the old mount_list "just like that": both list pointers and struct | 640 | /* NB: We can't free the old mount_list "just like that": both list pointers and struct |
656 | * pointers are copied around. One of the reason it wasn't done yet is that other parts | 641 | * pointers are copied around. One of the reason it wasn't done yet is that other parts |
657 | * of check_disk need the same kind of cleanup so it'd better be done as a whole */ | 642 | * of check_disk need the same kind of cleanup so it'd better be done as a whole */ |
658 | mount_list = read_file_system_list(false); | 643 | result.config.mount_list = read_file_system_list(false); |
659 | np_set_best_match(se, mount_list, exact_match); | 644 | np_set_best_match(se, result.config.mount_list, result.config.exact_match); |
660 | 645 | ||
661 | path_selected = true; | 646 | result.config.path_selected = true; |
662 | } break; | 647 | } break; |
663 | case 'x': /* exclude path or partition */ | 648 | case 'x': /* exclude path or partition */ |
664 | np_add_name(&dp_exclude_list, optarg); | 649 | np_add_name(&result.config.device_path_exclude_list, optarg); |
665 | break; | 650 | break; |
666 | case 'X': /* exclude file system type */ { | 651 | case 'X': /* exclude file system type */ { |
667 | int err = np_add_regex(&fs_exclude_list, optarg, REG_EXTENDED); | 652 | int err = np_add_regex(&result.config.fs_exclude_list, optarg, REG_EXTENDED); |
668 | if (err != 0) { | 653 | if (err != 0) { |
669 | char errbuf[MAX_INPUT_BUFFER]; | 654 | char errbuf[MAX_INPUT_BUFFER]; |
670 | regerror(err, &fs_exclude_list->regex, errbuf, MAX_INPUT_BUFFER); | 655 | regerror(err, &result.config.fs_exclude_list->regex, errbuf, MAX_INPUT_BUFFER); |
671 | die(STATE_UNKNOWN, "DISK %s: %s - %s\n", _("UNKNOWN"), _("Could not compile regular expression"), errbuf); | 656 | die(STATE_UNKNOWN, "DISK %s: %s - %s\n", _("UNKNOWN"), _("Could not compile regular expression"), errbuf); |
672 | } | 657 | } |
673 | break; | 658 | break; |
674 | case 'N': /* include file system type */ | 659 | case 'N': /* include file system type */ |
675 | err = np_add_regex(&fs_include_list, optarg, REG_EXTENDED); | 660 | err = np_add_regex(&result.config.fs_include_list, optarg, REG_EXTENDED); |
676 | if (err != 0) { | 661 | if (err != 0) { |
677 | char errbuf[MAX_INPUT_BUFFER]; | 662 | char errbuf[MAX_INPUT_BUFFER]; |
678 | regerror(err, &fs_exclude_list->regex, errbuf, MAX_INPUT_BUFFER); | 663 | regerror(err, &result.config.fs_exclude_list->regex, errbuf, MAX_INPUT_BUFFER); |
679 | die(STATE_UNKNOWN, "DISK %s: %s - %s\n", _("UNKNOWN"), _("Could not compile regular expression"), errbuf); | 664 | die(STATE_UNKNOWN, "DISK %s: %s - %s\n", _("UNKNOWN"), _("Could not compile regular expression"), errbuf); |
680 | } | 665 | } |
681 | } break; | 666 | } break; |
@@ -684,31 +669,31 @@ int process_arguments(int argc, char **argv) { | |||
684 | break; | 669 | break; |
685 | case 'q': /* TODO: this function should eventually go away (removed 2007-09-20) */ | 670 | case 'q': /* TODO: this function should eventually go away (removed 2007-09-20) */ |
686 | /* verbose--; **replaced by line below**. -q was only a broken way of implementing -e */ | 671 | /* verbose--; **replaced by line below**. -q was only a broken way of implementing -e */ |
687 | erronly = true; | 672 | result.config.erronly = true; |
688 | break; | 673 | break; |
689 | case 'e': | 674 | case 'e': |
690 | erronly = true; | 675 | result.config.erronly = true; |
691 | break; | 676 | break; |
692 | case 'E': | 677 | case 'E': |
693 | if (path_selected) { | 678 | if (result.config.path_selected) { |
694 | die(STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set -E before selecting paths\n")); | 679 | die(STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set -E before selecting paths\n")); |
695 | } | 680 | } |
696 | exact_match = true; | 681 | result.config.exact_match = true; |
697 | break; | 682 | break; |
698 | case 'f': | 683 | case 'f': |
699 | freespace_ignore_reserved = true; | 684 | result.config.freespace_ignore_reserved = true; |
700 | break; | 685 | break; |
701 | case 'g': | 686 | case 'g': |
702 | if (path_selected) { | 687 | if (result.config.path_selected) { |
703 | die(STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set group value before selecting paths\n")); | 688 | die(STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set group value before selecting paths\n")); |
704 | } | 689 | } |
705 | group = optarg; | 690 | result.config.group = optarg; |
706 | break; | 691 | break; |
707 | case 'I': | 692 | case 'I': |
708 | cflags |= REG_ICASE; | 693 | cflags |= REG_ICASE; |
709 | // Intentional fallthrough | 694 | // Intentional fallthrough |
710 | case 'i': { | 695 | case 'i': { |
711 | if (!path_selected) { | 696 | if (!result.config.path_selected) { |
712 | die(STATE_UNKNOWN, "DISK %s: %s\n", _("UNKNOWN"), | 697 | die(STATE_UNKNOWN, "DISK %s: %s\n", _("UNKNOWN"), |
713 | _("Paths need to be selected before using -i/-I. Use -A to select all paths explicitly")); | 698 | _("Paths need to be selected before using -i/-I. Use -A to select all paths explicitly")); |
714 | } | 699 | } |
@@ -720,7 +705,7 @@ int process_arguments(int argc, char **argv) { | |||
720 | die(STATE_UNKNOWN, "DISK %s: %s - %s\n", _("UNKNOWN"), _("Could not compile regular expression"), errbuf); | 705 | die(STATE_UNKNOWN, "DISK %s: %s - %s\n", _("UNKNOWN"), _("Could not compile regular expression"), errbuf); |
721 | } | 706 | } |
722 | 707 | ||
723 | struct parameter_list *temp_list = path_select_list; | 708 | struct parameter_list *temp_list = result.config.path_select_list; |
724 | struct parameter_list *previous = NULL; | 709 | struct parameter_list *previous = NULL; |
725 | while (temp_list) { | 710 | while (temp_list) { |
726 | if (temp_list->best_match) { | 711 | if (temp_list->best_match) { |
@@ -733,7 +718,7 @@ int process_arguments(int argc, char **argv) { | |||
733 | temp_list = np_del_parameter(temp_list, previous); | 718 | temp_list = np_del_parameter(temp_list, previous); |
734 | /* pointer to first element needs to be updated if first item gets deleted */ | 719 | /* pointer to first element needs to be updated if first item gets deleted */ |
735 | if (previous == NULL) { | 720 | if (previous == NULL) { |
736 | path_select_list = temp_list; | 721 | result.config.path_select_list = temp_list; |
737 | } | 722 | } |
738 | } else { | 723 | } else { |
739 | previous = temp_list; | 724 | previous = temp_list; |
@@ -748,7 +733,7 @@ int process_arguments(int argc, char **argv) { | |||
748 | cflags = default_cflags; | 733 | cflags = default_cflags; |
749 | } break; | 734 | } break; |
750 | case 'n': | 735 | case 'n': |
751 | ignore_missing = true; | 736 | result.config.ignore_missing = true; |
752 | break; | 737 | break; |
753 | case 'A': | 738 | case 'A': |
754 | optarg = strdup(".*"); | 739 | optarg = strdup(".*"); |
@@ -757,9 +742,11 @@ int process_arguments(int argc, char **argv) { | |||
757 | cflags |= REG_ICASE; | 742 | cflags |= REG_ICASE; |
758 | // Intentional fallthrough | 743 | // Intentional fallthrough |
759 | case 'r': { | 744 | case 'r': { |
760 | if (!(warn_freespace_units || crit_freespace_units || warn_freespace_percent || crit_freespace_percent || | 745 | if (!(result.config.warn_freespace_units || result.config.crit_freespace_units || result.config.warn_freespace_percent || |
761 | warn_usedspace_units || crit_usedspace_units || warn_usedspace_percent || crit_usedspace_percent || | 746 | result.config.crit_freespace_percent || result.config.warn_usedspace_units || result.config.crit_usedspace_units || |
762 | warn_usedinodes_percent || crit_usedinodes_percent || warn_freeinodes_percent || crit_freeinodes_percent)) { | 747 | result.config.warn_usedspace_percent || result.config.crit_usedspace_percent || result.config.warn_usedinodes_percent || |
748 | result.config.crit_usedinodes_percent || result.config.warn_freeinodes_percent || | ||
749 | result.config.crit_freeinodes_percent)) { | ||
763 | die(STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), | 750 | die(STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), |
764 | _("Must set a threshold value before using -r/-R/-A (--ereg-path/--eregi-path/--all)\n")); | 751 | _("Must set a threshold value before using -r/-R/-A (--ereg-path/--eregi-path/--all)\n")); |
765 | } | 752 | } |
@@ -773,7 +760,7 @@ int process_arguments(int argc, char **argv) { | |||
773 | } | 760 | } |
774 | 761 | ||
775 | bool found = false; | 762 | bool found = false; |
776 | for (struct mount_entry *me = mount_list; me; me = me->me_next) { | 763 | for (struct mount_entry *me = result.config.mount_list; me; me = me->me_next) { |
777 | if (np_regex_match_mount_entry(me, ®ex)) { | 764 | if (np_regex_match_mount_entry(me, ®ex)) { |
778 | found = true; | 765 | found = true; |
779 | if (verbose >= 3) { | 766 | if (verbose >= 3) { |
@@ -782,60 +769,69 @@ int process_arguments(int argc, char **argv) { | |||
782 | 769 | ||
783 | /* add parameter if not found. overwrite thresholds if path has already been added */ | 770 | /* add parameter if not found. overwrite thresholds if path has already been added */ |
784 | struct parameter_list *se = NULL; | 771 | struct parameter_list *se = NULL; |
785 | if (!(se = np_find_parameter(path_select_list, me->me_mountdir))) { | 772 | if (!(se = np_find_parameter(result.config.path_select_list, me->me_mountdir))) { |
786 | se = np_add_parameter(&path_select_list, me->me_mountdir); | 773 | se = np_add_parameter(&result.config.path_select_list, me->me_mountdir); |
787 | } | 774 | } |
788 | se->group = group; | 775 | se->group = result.config.group; |
789 | set_all_thresholds(se); | 776 | set_all_thresholds(se, result.config.warn_freespace_units, result.config.crit_freespace_units, |
777 | result.config.warn_freespace_percent, result.config.crit_freespace_percent, | ||
778 | result.config.warn_usedspace_units, result.config.crit_usedspace_units, | ||
779 | result.config.warn_usedspace_percent, result.config.crit_usedspace_percent, | ||
780 | result.config.warn_usedinodes_percent, result.config.crit_usedinodes_percent, | ||
781 | result.config.warn_freeinodes_percent, result.config.crit_freeinodes_percent); | ||
790 | } | 782 | } |
791 | } | 783 | } |
792 | 784 | ||
793 | if (!found && ignore_missing) { | 785 | if (!found && result.config.ignore_missing) { |
794 | path_ignored = true; | 786 | result.config.path_ignored = true; |
795 | path_selected = true; | 787 | result.config.path_selected = true; |
796 | break; | 788 | break; |
797 | } | 789 | } |
798 | if (!found) { | 790 | if (!found) { |
799 | die(STATE_UNKNOWN, "DISK %s: %s - %s\n", _("UNKNOWN"), _("Regular expression did not match any path or disk"), optarg); | 791 | die(STATE_UNKNOWN, "DISK %s: %s - %s\n", _("UNKNOWN"), _("Regular expression did not match any path or disk"), optarg); |
800 | } | 792 | } |
801 | 793 | ||
802 | found = false; | 794 | result.config.path_selected = true; |
803 | path_selected = true; | 795 | np_set_best_match(result.config.path_select_list, result.config.mount_list, result.config.exact_match); |
804 | np_set_best_match(path_select_list, mount_list, exact_match); | ||
805 | cflags = default_cflags; | 796 | cflags = default_cflags; |
806 | 797 | ||
807 | } break; | 798 | } break; |
808 | case 'M': /* display mountpoint */ | 799 | case 'M': /* display mountpoint */ |
809 | display_mntp = true; | 800 | result.config.display_mntp = true; |
810 | break; | 801 | break; |
811 | case 'C': { | 802 | case 'C': { |
812 | /* add all mount entries to path_select list if no partitions have been explicitly defined using -p */ | 803 | /* add all mount entries to path_select list if no partitions have been explicitly defined using -p */ |
813 | if (!path_selected) { | 804 | if (!result.config.path_selected) { |
814 | struct parameter_list *path; | 805 | struct parameter_list *path; |
815 | for (struct mount_entry *me = mount_list; me; me = me->me_next) { | 806 | for (struct mount_entry *me = result.config.mount_list; me; me = me->me_next) { |
816 | if (!(path = np_find_parameter(path_select_list, me->me_mountdir))) { | 807 | if (!(path = np_find_parameter(result.config.path_select_list, me->me_mountdir))) { |
817 | path = np_add_parameter(&path_select_list, me->me_mountdir); | 808 | path = np_add_parameter(&result.config.path_select_list, me->me_mountdir); |
818 | } | 809 | } |
819 | path->best_match = me; | 810 | path->best_match = me; |
820 | path->group = group; | 811 | path->group = result.config.group; |
821 | set_all_thresholds(path); | 812 | set_all_thresholds(path, result.config.warn_freespace_units, result.config.crit_freespace_units, |
813 | result.config.warn_freespace_percent, result.config.crit_freespace_percent, | ||
814 | result.config.warn_usedspace_units, result.config.crit_usedspace_units, | ||
815 | result.config.warn_usedspace_percent, result.config.crit_usedspace_percent, | ||
816 | result.config.warn_usedinodes_percent, result.config.crit_usedinodes_percent, | ||
817 | result.config.warn_freeinodes_percent, result.config.crit_freeinodes_percent); | ||
822 | } | 818 | } |
823 | } | 819 | } |
824 | warn_freespace_units = NULL; | 820 | result.config.warn_freespace_units = NULL; |
825 | crit_freespace_units = NULL; | 821 | result.config.crit_freespace_units = NULL; |
826 | warn_usedspace_units = NULL; | 822 | result.config.warn_usedspace_units = NULL; |
827 | crit_usedspace_units = NULL; | 823 | result.config.crit_usedspace_units = NULL; |
828 | warn_freespace_percent = NULL; | 824 | result.config.warn_freespace_percent = NULL; |
829 | crit_freespace_percent = NULL; | 825 | result.config.crit_freespace_percent = NULL; |
830 | warn_usedspace_percent = NULL; | 826 | result.config.warn_usedspace_percent = NULL; |
831 | crit_usedspace_percent = NULL; | 827 | result.config.crit_usedspace_percent = NULL; |
832 | warn_usedinodes_percent = NULL; | 828 | result.config.warn_usedinodes_percent = NULL; |
833 | crit_usedinodes_percent = NULL; | 829 | result.config.crit_usedinodes_percent = NULL; |
834 | warn_freeinodes_percent = NULL; | 830 | result.config.warn_freeinodes_percent = NULL; |
835 | crit_freeinodes_percent = NULL; | 831 | result.config.crit_freeinodes_percent = NULL; |
836 | 832 | ||
837 | path_selected = false; | 833 | result.config.path_selected = false; |
838 | group = NULL; | 834 | result.config.group = NULL; |
839 | } break; | 835 | } break; |
840 | case 'V': /* version */ | 836 | case 'V': /* version */ |
841 | print_revision(progname, NP_VERSION); | 837 | print_revision(progname, NP_VERSION); |
@@ -847,45 +843,49 @@ int process_arguments(int argc, char **argv) { | |||
847 | usage(_("Unknown argument")); | 843 | usage(_("Unknown argument")); |
848 | } | 844 | } |
849 | } | 845 | } |
850 | if (verbose > 0) { | ||
851 | printf("ping\n"); | ||
852 | } | ||
853 | 846 | ||
854 | /* Support for "check_disk warn crit [fs]" with thresholds at used% level */ | 847 | /* Support for "check_disk warn crit [fs]" with thresholds at used% level */ |
855 | int index = optind; | 848 | int index = optind; |
856 | 849 | ||
857 | if (warn_usedspace_percent == NULL && argc > index && is_intnonneg(argv[index])) { | 850 | if (result.config.warn_usedspace_percent == NULL && argc > index && is_intnonneg(argv[index])) { |
858 | if (verbose > 0) { | 851 | if (verbose > 0) { |
859 | printf("Got an positional warn threshold: %s\n", argv[index]); | 852 | printf("Got an positional warn threshold: %s\n", argv[index]); |
860 | } | 853 | } |
861 | warn_usedspace_percent = argv[index++]; | 854 | result.config.warn_usedspace_percent = argv[index++]; |
862 | } | 855 | } |
863 | 856 | ||
864 | if (crit_usedspace_percent == NULL && argc > index && is_intnonneg(argv[index])) { | 857 | if (result.config.crit_usedspace_percent == NULL && argc > index && is_intnonneg(argv[index])) { |
865 | if (verbose > 0) { | 858 | if (verbose > 0) { |
866 | printf("Got an positional crit threshold: %s\n", argv[index]); | 859 | printf("Got an positional crit threshold: %s\n", argv[index]); |
867 | } | 860 | } |
868 | crit_usedspace_percent = argv[index++]; | 861 | result.config.crit_usedspace_percent = argv[index++]; |
869 | } | 862 | } |
870 | 863 | ||
871 | if (argc > index) { | 864 | if (argc > index) { |
872 | if (verbose > 0) { | 865 | if (verbose > 0) { |
873 | printf("Got an positional filesystem: %s\n", argv[index]); | 866 | printf("Got an positional filesystem: %s\n", argv[index]); |
874 | } | 867 | } |
875 | struct parameter_list *se = np_add_parameter(&path_select_list, strdup(argv[index++])); | 868 | struct parameter_list *se = np_add_parameter(&result.config.path_select_list, strdup(argv[index++])); |
876 | path_selected = true; | 869 | result.config.path_selected = true; |
877 | set_all_thresholds(se); | 870 | set_all_thresholds(se, result.config.warn_freespace_units, result.config.crit_freespace_units, result.config.warn_freespace_percent, |
871 | result.config.crit_freespace_percent, result.config.warn_usedspace_units, result.config.crit_usedspace_units, | ||
872 | result.config.warn_usedspace_percent, result.config.crit_usedspace_percent, | ||
873 | result.config.warn_usedinodes_percent, result.config.crit_usedinodes_percent, | ||
874 | result.config.warn_freeinodes_percent, result.config.crit_freeinodes_percent); | ||
878 | } | 875 | } |
879 | 876 | ||
880 | if (units == NULL) { | 877 | if (result.config.units == NULL) { |
881 | units = strdup("MiB"); | 878 | result.config.units = strdup("MiB"); |
882 | mult = (uintmax_t)1024 * 1024; | 879 | result.config.mult = (uintmax_t)1024 * 1024; |
883 | } | 880 | } |
884 | 881 | ||
885 | return 0; | 882 | return result; |
886 | } | 883 | } |
887 | 884 | ||
888 | void set_all_thresholds(struct parameter_list *path) { | 885 | void set_all_thresholds(struct parameter_list *path, char *warn_freespace_units, char *crit_freespace_units, char *warn_freespace_percent, |
886 | char *crit_freespace_percent, char *warn_usedspace_units, char *crit_usedspace_units, char *warn_usedspace_percent, | ||
887 | char *crit_usedspace_percent, char *warn_usedinodes_percent, char *crit_usedinodes_percent, | ||
888 | char *warn_freeinodes_percent, char *crit_freeinodes_percent) { | ||
889 | if (path->freespace_units != NULL) { | 889 | if (path->freespace_units != NULL) { |
890 | free(path->freespace_units); | 890 | free(path->freespace_units); |
891 | } | 891 | } |
@@ -1022,7 +1022,7 @@ void print_usage(void) { | |||
1022 | printf("[-t timeout] [-u unit] [-v] [-X type_regex] [-N type]\n"); | 1022 | printf("[-t timeout] [-u unit] [-v] [-X type_regex] [-N type]\n"); |
1023 | } | 1023 | } |
1024 | 1024 | ||
1025 | bool stat_path(struct parameter_list *parameters) { | 1025 | bool stat_path(struct parameter_list *parameters, bool ignore_missing) { |
1026 | /* Stat entry to check that dir exists and is accessible */ | 1026 | /* Stat entry to check that dir exists and is accessible */ |
1027 | if (verbose >= 3) { | 1027 | if (verbose >= 3) { |
1028 | printf("calling stat on %s\n", parameters->name); | 1028 | printf("calling stat on %s\n", parameters->name); |
@@ -1043,12 +1043,13 @@ bool stat_path(struct parameter_list *parameters) { | |||
1043 | return true; | 1043 | return true; |
1044 | } | 1044 | } |
1045 | 1045 | ||
1046 | void get_stats(struct parameter_list *parameters, struct fs_usage *fsp) { | 1046 | void get_stats(struct parameter_list *parameters, struct fs_usage *fsp, bool ignore_missing, bool freespace_ignore_reserved, uintmax_t mult, |
1047 | struct parameter_list *path_select_list, struct name_list *seen) { | ||
1047 | struct fs_usage tmpfsp; | 1048 | struct fs_usage tmpfsp; |
1048 | bool first = true; | 1049 | bool first = true; |
1049 | 1050 | ||
1050 | if (parameters->group == NULL) { | 1051 | if (parameters->group == NULL) { |
1051 | get_path_stats(parameters, fsp); | 1052 | get_path_stats(parameters, fsp, freespace_ignore_reserved, mult, seen); |
1052 | } else { | 1053 | } else { |
1053 | /* find all group members */ | 1054 | /* find all group members */ |
1054 | for (struct parameter_list *p_list = path_select_list; p_list; p_list = p_list->name_next) { | 1055 | for (struct parameter_list *p_list = path_select_list; p_list; p_list = p_list->name_next) { |
@@ -1060,11 +1061,11 @@ void get_stats(struct parameter_list *parameters, struct fs_usage *fsp) { | |||
1060 | #endif | 1061 | #endif |
1061 | 1062 | ||
1062 | if (p_list->group && !(strcmp(p_list->group, parameters->group))) { | 1063 | if (p_list->group && !(strcmp(p_list->group, parameters->group))) { |
1063 | if (!stat_path(p_list)) { | 1064 | if (!stat_path(p_list, ignore_missing)) { |
1064 | continue; | 1065 | continue; |
1065 | } | 1066 | } |
1066 | get_fs_usage(p_list->best_match->me_mountdir, p_list->best_match->me_devname, &tmpfsp); | 1067 | get_fs_usage(p_list->best_match->me_mountdir, p_list->best_match->me_devname, &tmpfsp); |
1067 | get_path_stats(p_list, &tmpfsp); | 1068 | get_path_stats(p_list, &tmpfsp, freespace_ignore_reserved, mult, seen); |
1068 | if (verbose >= 3) { | 1069 | if (verbose >= 3) { |
1069 | printf("Group %s: adding %lu blocks sized %lu, (%s) used_units=%lu free_units=%lu total_units=%lu mult=%lu\n", | 1070 | printf("Group %s: adding %lu blocks sized %lu, (%s) used_units=%lu free_units=%lu total_units=%lu mult=%lu\n", |
1070 | p_list->group, tmpfsp.fsu_blocks, tmpfsp.fsu_blocksize, p_list->best_match->me_mountdir, p_list->dused_units, | 1071 | p_list->group, tmpfsp.fsu_blocks, tmpfsp.fsu_blocksize, p_list->best_match->me_mountdir, p_list->dused_units, |
@@ -1105,7 +1106,8 @@ void get_stats(struct parameter_list *parameters, struct fs_usage *fsp) { | |||
1105 | parameters->dfree_inodes_percent = 100 - parameters->dused_inodes_percent; | 1106 | parameters->dfree_inodes_percent = 100 - parameters->dused_inodes_percent; |
1106 | } | 1107 | } |
1107 | 1108 | ||
1108 | void get_path_stats(struct parameter_list *parameters, struct fs_usage *fsp) { | 1109 | void get_path_stats(struct parameter_list *parameters, struct fs_usage *fsp, bool freespace_ignore_reserved, uintmax_t mult, |
1110 | struct name_list *seen) { | ||
1109 | parameters->available = fsp->fsu_bavail; | 1111 | parameters->available = fsp->fsu_bavail; |
1110 | parameters->available_to_root = fsp->fsu_bfree; | 1112 | parameters->available_to_root = fsp->fsu_bfree; |
1111 | parameters->used = fsp->fsu_blocks - fsp->fsu_bfree; | 1113 | parameters->used = fsp->fsu_blocks - fsp->fsu_bfree; |
diff --git a/plugins/check_disk.d/config.h b/plugins/check_disk.d/config.h new file mode 100644 index 00000000..d890fc1a --- /dev/null +++ b/plugins/check_disk.d/config.h | |||
@@ -0,0 +1,92 @@ | |||
1 | #pragma once | ||
2 | |||
3 | #include "../../config.h" | ||
4 | #include <stddef.h> | ||
5 | #include <stdint.h> | ||
6 | |||
7 | typedef struct { | ||
8 | // Output options | ||
9 | bool erronly; | ||
10 | bool display_mntp; | ||
11 | /* show only local filesystems. */ | ||
12 | bool show_local_fs; | ||
13 | /* show only local filesystems but call stat() on remote ones. */ | ||
14 | bool stat_remote_fs; | ||
15 | bool display_inodes_perfdata; | ||
16 | |||
17 | bool exact_match; | ||
18 | bool ignore_missing; | ||
19 | bool path_ignored; | ||
20 | bool path_selected; | ||
21 | bool freespace_ignore_reserved; | ||
22 | |||
23 | char *warn_freespace_units; | ||
24 | char *crit_freespace_units; | ||
25 | char *warn_freespace_percent; | ||
26 | char *crit_freespace_percent; | ||
27 | char *warn_usedspace_units; | ||
28 | char *crit_usedspace_units; | ||
29 | char *warn_usedspace_percent; | ||
30 | char *crit_usedspace_percent; | ||
31 | char *warn_usedinodes_percent; | ||
32 | char *crit_usedinodes_percent; | ||
33 | char *warn_freeinodes_percent; | ||
34 | char *crit_freeinodes_percent; | ||
35 | |||
36 | /* Linked list of filesystem types to omit. | ||
37 | If the list is empty, don't exclude any types. */ | ||
38 | struct regex_list *fs_exclude_list; | ||
39 | /* Linked list of filesystem types to check. | ||
40 | If the list is empty, include all types. */ | ||
41 | struct regex_list *fs_include_list; | ||
42 | struct name_list *device_path_exclude_list; | ||
43 | struct parameter_list *path_select_list; | ||
44 | /* Linked list of mounted filesystems. */ | ||
45 | struct mount_entry *mount_list; | ||
46 | struct name_list *seen; | ||
47 | |||
48 | char *units; | ||
49 | uintmax_t mult; | ||
50 | char *group; | ||
51 | } check_disk_config; | ||
52 | |||
53 | check_disk_config check_disk_config_init() { | ||
54 | check_disk_config tmp = { | ||
55 | .erronly = false, | ||
56 | .display_mntp = false, | ||
57 | .show_local_fs = false, | ||
58 | .stat_remote_fs = false, | ||
59 | .display_inodes_perfdata = false, | ||
60 | |||
61 | .exact_match = false, | ||
62 | .ignore_missing = false, | ||
63 | .path_ignored = false, | ||
64 | .path_selected = false, | ||
65 | .freespace_ignore_reserved = false, | ||
66 | |||
67 | .warn_freespace_units = NULL, | ||
68 | .crit_freespace_units = NULL, | ||
69 | .warn_freespace_percent = NULL, | ||
70 | .crit_freespace_percent = NULL, | ||
71 | .warn_usedspace_units = NULL, | ||
72 | .crit_usedspace_units = NULL, | ||
73 | .warn_usedspace_percent = NULL, | ||
74 | .crit_usedspace_percent = NULL, | ||
75 | .warn_usedinodes_percent = NULL, | ||
76 | .crit_usedinodes_percent = NULL, | ||
77 | .warn_freeinodes_percent = NULL, | ||
78 | .crit_freeinodes_percent = NULL, | ||
79 | |||
80 | .fs_exclude_list = NULL, | ||
81 | .fs_include_list = NULL, | ||
82 | .device_path_exclude_list = NULL, | ||
83 | .path_select_list = NULL, | ||
84 | .mount_list = NULL, | ||
85 | .seen = NULL, | ||
86 | |||
87 | .units = NULL, | ||
88 | .mult = 1024 * 1024, | ||
89 | .group = NULL, | ||
90 | }; | ||
91 | return tmp; | ||
92 | } | ||