summaryrefslogtreecommitdiffstats
path: root/plugins/check_disk.d/utils_disk.h
diff options
context:
space:
mode:
authorLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2025-03-30 22:37:48 +0200
committerLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2025-03-30 22:37:48 +0200
commit908aed4e6f9072e601a189d4ceff3152bdecc49d (patch)
tree18d88bb892ca936d2da70e9fb22e518af1eafa2b /plugins/check_disk.d/utils_disk.h
parent0bca1d1aa36b13723e77672eae162352e9be99c9 (diff)
downloadmonitoring-plugins-908aed4e6f9072e601a189d4ceff3152bdecc49d.tar.gz
Refactor check_disk and library functions
Diffstat (limited to 'plugins/check_disk.d/utils_disk.h')
-rw-r--r--plugins/check_disk.d/utils_disk.h142
1 files changed, 114 insertions, 28 deletions
diff --git a/plugins/check_disk.d/utils_disk.h b/plugins/check_disk.d/utils_disk.h
index 0c69f987..a66453ea 100644
--- a/plugins/check_disk.d/utils_disk.h
+++ b/plugins/check_disk.d/utils_disk.h
@@ -1,14 +1,34 @@
1#pragma once
1/* Header file for utils_disk */ 2/* Header file for utils_disk */
2 3
3#include "../../config.h" 4#include "../../config.h"
4#include "../../gl/mountlist.h" 5#include "../../gl/mountlist.h"
5#include "../../lib/utils_base.h" 6#include "../../lib/utils_base.h"
7#include "../../lib/output.h"
6#include "regex.h" 8#include "regex.h"
7#include <stdint.h> 9#include <stdint.h>
8 10
11typedef enum : unsigned long {
12 Humanized = 0,
13 Bytes = 1,
14 KibiBytes = 1024,
15 MebiBytes = 1024 * KibiBytes,
16 GibiBytes = 1024 * MebiBytes,
17 TebiBytes = 1024 * GibiBytes,
18 PebiBytes = 1024 * TebiBytes,
19 ExbiBytes = 1024 * PebiBytes,
20 KiloBytes = 1000,
21 MegaBytes = 1000 * KiloBytes,
22 GigaBytes = 1000 * MegaBytes,
23 TeraBytes = 1000 * GigaBytes,
24 PetaBytes = 1000 * TeraBytes,
25 ExaBytes = 1000 * PetaBytes
26} byte_unit;
27
28typedef struct name_list string_list;
9struct name_list { 29struct name_list {
10 char *name; 30 char *name;
11 struct name_list *next; 31 string_list *next;
12}; 32};
13 33
14struct regex_list { 34struct regex_list {
@@ -16,54 +36,120 @@ struct regex_list {
16 struct regex_list *next; 36 struct regex_list *next;
17}; 37};
18 38
39typedef struct parameter_list parameter_list_elem;
19struct parameter_list { 40struct parameter_list {
20 char *name; 41 char *name;
21 char *group; 42 char *group;
22 43
23 thresholds *freespace_units; 44 mp_thresholds freespace_units;
24 thresholds *freespace_percent; 45 mp_thresholds freespace_percent;
25 thresholds *usedspace_units; 46 mp_thresholds freeinodes_percent;
26 thresholds *usedspace_percent;
27
28 thresholds *usedinodes_percent;
29 thresholds *freeinodes_percent;
30 47
31 struct mount_entry *best_match; 48 struct mount_entry *best_match;
32 49
33 uintmax_t total;
34 uintmax_t available;
35 uintmax_t available_to_root;
36 uintmax_t used;
37 uintmax_t inodes_free;
38 uintmax_t inodes_free_to_root; 50 uintmax_t inodes_free_to_root;
51 uintmax_t inodes_free;
39 uintmax_t inodes_used; 52 uintmax_t inodes_used;
40 uintmax_t inodes_total; 53 uintmax_t inodes_total;
41 54
42 double dfree_pct; 55 uint64_t used_bytes;
43 double dused_pct; 56 uint64_t free_bytes;
57 uint64_t total_bytes;
44 58
45 uint64_t dused_units; 59 parameter_list_elem *next;
46 uint64_t dfree_units; 60 parameter_list_elem *prev;
47 uint64_t dtotal_units; 61};
62
63typedef struct {
64 size_t length;
65 parameter_list_elem *first;
66} filesystem_list;
48 67
49 double dused_inodes_percent; 68filesystem_list filesystem_list_init();
50 double dfree_inodes_percent;
51 69
52 struct parameter_list *name_next; 70typedef struct {
53 struct parameter_list *name_prev; 71 char *name;
72 char *filesystem_type;
73 bool is_group;
74
75 mp_thresholds freespace_bytes_thresholds;
76 mp_thresholds freespace_percent_thresholds;
77 mp_thresholds freeinodes_percent_thresholds;
78
79 uintmax_t inodes_free_to_root;
80 uintmax_t inodes_free;
81 uintmax_t inodes_used;
82 uintmax_t inodes_total;
83
84 uintmax_t used_bytes;
85 uintmax_t free_bytes;
86 uintmax_t total_bytes;
87} measurement_unit;
88
89typedef struct measurement_unit_list measurement_unit_list;
90struct measurement_unit_list {
91 measurement_unit unit;
92 measurement_unit_list *next;
54}; 93};
55 94
95typedef struct {
96 // Output options
97 bool erronly;
98 bool display_mntp;
99 /* show only local filesystems. */
100 bool show_local_fs;
101 /* show only local filesystems but call stat() on remote ones. */
102 bool stat_remote_fs;
103 bool display_inodes_perfdata;
104
105 bool exact_match;
106 bool freespace_ignore_reserved;
107
108 bool ignore_missing;
109 bool path_ignored;
110
111 /* Linked list of filesystem types to omit.
112 If the list is empty, don't exclude any types. */
113 struct regex_list *fs_exclude_list;
114 /* Linked list of filesystem types to check.
115 If the list is empty, include all types. */
116 struct regex_list *fs_include_list;
117 struct name_list *device_path_exclude_list;
118 filesystem_list path_select_list;
119 /* Linked list of mounted filesystems. */
120 struct mount_entry *mount_list;
121 struct name_list *seen;
122
123 byte_unit display_unit;
124 // byte_unit unit;
125
126 bool output_format_is_set;
127 mp_output_format output_format;
128} check_disk_config;
129
56void np_add_name(struct name_list **list, const char *name); 130void np_add_name(struct name_list **list, const char *name);
57bool np_find_name(struct name_list *list, const char *name); 131bool np_find_name(struct name_list *list, const char *name);
58bool np_seen_name(struct name_list *list, const char *name); 132bool np_seen_name(struct name_list *list, const char *name);
59int np_add_regex(struct regex_list **list, const char *regex, int cflags); 133int np_add_regex(struct regex_list **list, const char *regex, int cflags);
60bool np_find_regmatch(struct regex_list *list, const char *name); 134bool np_find_regmatch(struct regex_list *list, const char *name);
61 135
62struct parameter_list *np_add_parameter(struct parameter_list **list, const char *name); 136parameter_list_elem parameter_list_init(const char *);
63struct parameter_list *np_find_parameter(struct parameter_list *list, const char *name); 137
64struct parameter_list *np_del_parameter(struct parameter_list *item, struct parameter_list *prev); 138parameter_list_elem *mp_int_fs_list_append(filesystem_list *list, const char *name);
65struct parameter_list parameter_list_init(const char *); 139parameter_list_elem *mp_int_fs_list_find(filesystem_list list, const char *name);
140parameter_list_elem *mp_int_fs_list_del(filesystem_list *list, parameter_list_elem *item);
141parameter_list_elem *mp_int_fs_list_get_next(parameter_list_elem *current);
142void mp_int_fs_list_set_best_match(filesystem_list list, struct mount_entry *mount_list, bool exact);
66 143
67int search_parameter_list(struct parameter_list *list, const char *name); 144measurement_unit measurement_unit_init();
68void np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list, bool exact); 145measurement_unit_list *add_measurement_list(measurement_unit_list *list, measurement_unit elem);
146measurement_unit add_filesystem_to_measurement_unit(measurement_unit unit, parameter_list_elem filesystem);
147measurement_unit create_measurement_unit_from_filesystem(parameter_list_elem filesystem, bool display_mntp);
148
149int search_parameter_list(parameter_list_elem *list, const char *name);
69bool np_regex_match_mount_entry(struct mount_entry *, regex_t *); 150bool np_regex_match_mount_entry(struct mount_entry *, regex_t *);
151
152char *get_unit_string(byte_unit);
153check_disk_config check_disk_config_init();
154
155char *humanize_byte_value(uintmax_t value, bool use_si_units);