diff options
author | Holger Weiss <holger@zedat.fu-berlin.de> | 2013-09-29 22:03:24 (GMT) |
---|---|---|
committer | Holger Weiss <holger@zedat.fu-berlin.de> | 2013-09-29 22:03:24 (GMT) |
commit | 0b6423f9c99d9edf8c96fefd0f6c453859395aa1 (patch) | |
tree | 1c2b6b21704a294940f87c7892676998d8371707 /web/attachments/94817-check_disk-patch | |
download | site-0b6423f9c99d9edf8c96fefd0f6c453859395aa1.tar.gz |
Import Nagios Plugins site
Import the Nagios Plugins web site, Cronjobs, infrastructure scripts,
and configuration files.
Diffstat (limited to 'web/attachments/94817-check_disk-patch')
-rw-r--r-- | web/attachments/94817-check_disk-patch | 243 |
1 files changed, 243 insertions, 0 deletions
diff --git a/web/attachments/94817-check_disk-patch b/web/attachments/94817-check_disk-patch new file mode 100644 index 0000000..e583220 --- /dev/null +++ b/web/attachments/94817-check_disk-patch | |||
@@ -0,0 +1,243 @@ | |||
1 | --- ../tmp/nagios-plugins-1.4.0alpha1/plugins/check_disk.c Thu Jul 22 16:59:52 2004 | ||
2 | +++ plugins/check_disk.c Thu Jul 22 16:56:15 2004 | ||
3 | @@ -21,6 +21,10 @@ | ||
4 | const char *copyright = "1999-2003"; | ||
5 | const char *email = "nagiosplug-devel@lists.sourceforge.net"; | ||
6 | |||
7 | +/* | ||
8 | + * Additional inode code by Jorgen Lundman <lundman@lundman.net> | ||
9 | + */ | ||
10 | + | ||
11 | #include "common.h" | ||
12 | #if HAVE_INTTYPES_H | ||
13 | # include <inttypes.h> | ||
14 | @@ -65,6 +69,8 @@ | ||
15 | uintmax_t c_df; | ||
16 | double w_dfp; | ||
17 | double c_dfp; | ||
18 | + double w_idfp; | ||
19 | + double c_idfp; | ||
20 | struct name_list *name_next; | ||
21 | }; | ||
22 | |||
23 | @@ -110,8 +116,8 @@ | ||
24 | |||
25 | int process_arguments (int, char **); | ||
26 | void print_path (const char *mypath); | ||
27 | -int validate_arguments (uintmax_t, uintmax_t, double, double, char *); | ||
28 | -int check_disk (double usp, uintmax_t free_disk); | ||
29 | +int validate_arguments (uintmax_t, uintmax_t, double, double, double, double, char *); | ||
30 | +int check_disk (double usp, uintmax_t free_disk, double uisp); | ||
31 | int walk_name_list (struct name_list *list, const char *name); | ||
32 | void print_help (void); | ||
33 | void print_usage (void); | ||
34 | @@ -120,6 +126,8 @@ | ||
35 | uintmax_t c_df = 0; | ||
36 | double w_dfp = -1.0; | ||
37 | double c_dfp = -1.0; | ||
38 | +double w_idfp = -1.0; | ||
39 | +double c_idfp = -1.0; | ||
40 | char *path; | ||
41 | char *exclude_device; | ||
42 | char *units; | ||
43 | @@ -136,7 +144,7 @@ | ||
44 | int | ||
45 | main (int argc, char **argv) | ||
46 | { | ||
47 | - double usp = -1.0; | ||
48 | + double usp = -1.0, uisp = -1.0; | ||
49 | int result = STATE_UNKNOWN; | ||
50 | int disk_result = STATE_UNKNOWN; | ||
51 | char file_system[MAX_INPUT_BUFFER]; | ||
52 | @@ -144,7 +152,7 @@ | ||
53 | char *details; | ||
54 | char *perf; | ||
55 | uintmax_t psize; | ||
56 | - float free_space, free_space_pct, total_space; | ||
57 | + float free_space, free_space_pct, total_space, inode_space_pct; | ||
58 | |||
59 | struct mount_entry *me; | ||
60 | struct fs_usage fsp; | ||
61 | @@ -181,20 +189,26 @@ | ||
62 | (walk_name_list (dp_exclude_list, me->me_devname) || | ||
63 | walk_name_list (dp_exclude_list, me->me_mountdir))) | ||
64 | continue; | ||
65 | - else | ||
66 | + else | ||
67 | get_fs_usage (me->me_mountdir, me->me_devname, &fsp); | ||
68 | |||
69 | if (fsp.fsu_blocks && strcmp ("none", me->me_mountdir)) { | ||
70 | usp = (double)(fsp.fsu_blocks - fsp.fsu_bavail) * 100 / fsp.fsu_blocks; | ||
71 | - disk_result = check_disk (usp, fsp.fsu_bavail); | ||
72 | + uisp = (double)(fsp.fsu_files - fsp.fsu_ffree) * 100 / fsp.fsu_files; | ||
73 | + disk_result = check_disk (usp, fsp.fsu_bavail, uisp); | ||
74 | result = max_state (disk_result, result); | ||
75 | psize = fsp.fsu_blocks*fsp.fsu_blocksize/mult; | ||
76 | + | ||
77 | + /* Moved this computation up here so we can add it | ||
78 | + * to perf */ | ||
79 | + inode_space_pct = (float)fsp.fsu_ffree*100/fsp.fsu_files; | ||
80 | + | ||
81 | asprintf (&perf, "%s %s", perf, | ||
82 | perfdata ((!strcmp(file_system, "none") || display_mntp) ? me->me_devname : me->me_mountdir, | ||
83 | fsp.fsu_bavail*fsp.fsu_blocksize/mult, units, | ||
84 | TRUE, min ((uintmax_t)psize-(uintmax_t)w_df, (uintmax_t)((1.0-w_dfp/100.0)*psize)), | ||
85 | TRUE, min ((uintmax_t)psize-(uintmax_t)c_df, (uintmax_t)((1.0-c_dfp/100.0)*psize)), | ||
86 | - TRUE, 0, | ||
87 | + TRUE, inode_space_pct, | ||
88 | TRUE, psize)); | ||
89 | if (disk_result==STATE_OK && erronly && !verbose) | ||
90 | continue; | ||
91 | @@ -203,17 +217,20 @@ | ||
92 | free_space_pct = (float)fsp.fsu_bavail*100/fsp.fsu_blocks; | ||
93 | total_space = (float)fsp.fsu_blocks*fsp.fsu_blocksize/mult; | ||
94 | if (disk_result!=STATE_OK || verbose>=0) | ||
95 | - asprintf (&output, ("%s %s %.0f %s (%.0f%%);"), | ||
96 | + asprintf (&output, ("%s %s %.0f %s (%.0f%% inode=%.0f%%);"), | ||
97 | output, | ||
98 | (!strcmp(file_system, "none") || display_mntp) ? me->me_devname : me->me_mountdir, | ||
99 | free_space, | ||
100 | units, | ||
101 | - free_space_pct); | ||
102 | + free_space_pct, | ||
103 | + inode_space_pct); | ||
104 | + | ||
105 | asprintf (&details, _("%s\n\ | ||
106 | -%.0f of %.0f %s (%.0f%%) free on %s (type %s mounted on %s) warn:%lu crit:%lu warn%%:%.0f%% crit%%:%.0f%%"), | ||
107 | - details, free_space, total_space, units, free_space_pct, | ||
108 | +%.0f of %.0f %s (%.0f%% inode=%.0f%%) free on %s (type %s mounted on %s) warn:%lu crit:%lu warn%%:%.0f%% crit%%:%.0f%%"), | ||
109 | + details, free_space, total_space, units, free_space_pct, inode_space_pct, | ||
110 | me->me_devname, me->me_type, me->me_mountdir, | ||
111 | (unsigned long)w_df, (unsigned long)c_df, w_dfp, c_dfp); | ||
112 | + | ||
113 | } | ||
114 | |||
115 | } | ||
116 | @@ -259,6 +276,9 @@ | ||
117 | {"timeout", required_argument, 0, 't'}, | ||
118 | {"warning", required_argument, 0, 'w'}, | ||
119 | {"critical", required_argument, 0, 'c'}, | ||
120 | + {"iwarning", required_argument, 0, 'W'}, | ||
121 | + /* Dang, -C is taken. We might want to reshuffle this. */ | ||
122 | + {"icritical", required_argument, 0, 'K'}, | ||
123 | {"local", required_argument, 0, 'l'}, | ||
124 | {"kilobytes", required_argument, 0, 'k'}, | ||
125 | {"megabytes", required_argument, 0, 'm'}, | ||
126 | @@ -291,7 +311,7 @@ | ||
127 | strcpy (argv[c], "-t"); | ||
128 | |||
129 | while (1) { | ||
130 | - c = getopt_long (argc, argv, "+?VqhveCt:c:w:u:p:x:X:mklM", longopts, &option); | ||
131 | + c = getopt_long (argc, argv, "+?VqhveCt:c:w:K:W:u:p:x:X:mklM", longopts, &option); | ||
132 | |||
133 | if (c == -1 || c == EOF) | ||
134 | break; | ||
135 | @@ -339,6 +359,24 @@ | ||
136 | else { | ||
137 | usage (_("Critical threshold must be integer or percentage!\n")); | ||
138 | } | ||
139 | + | ||
140 | + | ||
141 | + case 'W': /* warning inode threshold */ | ||
142 | + if (strstr (optarg, "%") && sscanf (optarg, "%lf%%", &w_idfp) == 1) { | ||
143 | + break; | ||
144 | + } | ||
145 | + else { | ||
146 | + usage (_("Warning inode threshold must be percentage!\n")); | ||
147 | + } | ||
148 | + case 'K': /* kritical inode threshold */ | ||
149 | + if (strstr (optarg, "%") && sscanf (optarg, "%lf%%", &c_idfp) == 1) { | ||
150 | + break; | ||
151 | + } | ||
152 | + else { | ||
153 | + usage (_("Critical inode threshold must be percentage!\n")); | ||
154 | + } | ||
155 | + | ||
156 | + | ||
157 | case 'u': | ||
158 | if (units) | ||
159 | free(units); | ||
160 | @@ -459,6 +497,8 @@ | ||
161 | temp_list->c_df, | ||
162 | temp_list->w_dfp, | ||
163 | temp_list->c_dfp, | ||
164 | + temp_list->w_idfp, | ||
165 | + temp_list->c_idfp, | ||
166 | temp_list->name) == ERROR) | ||
167 | result = ERROR; | ||
168 | temp_list = temp_list->name_next; | ||
169 | @@ -465,7 +505,7 @@ | ||
170 | } | ||
171 | return result; | ||
172 | } else { | ||
173 | - return validate_arguments (w_df, c_df, w_dfp, c_dfp, NULL); | ||
174 | + return validate_arguments (w_df, c_df, w_dfp, c_dfp, w_idfp, c_idfp, NULL); | ||
175 | } | ||
176 | } | ||
177 | |||
178 | @@ -482,7 +522,7 @@ | ||
179 | } | ||
180 | |||
181 | int | ||
182 | -validate_arguments (uintmax_t w, uintmax_t c, double wp, double cp, char *mypath) | ||
183 | +validate_arguments (uintmax_t w, uintmax_t c, double wp, double cp, double iwp, double icp, char *mypath) | ||
184 | { | ||
185 | if (w == 0 && c == 0 && wp < 0.0 && cp < 0.0) { | ||
186 | printf (_("INPUT ERROR: No thresholds specified")); | ||
187 | @@ -497,6 +537,14 @@ | ||
188 | print_path (mypath); | ||
189 | return ERROR; | ||
190 | } | ||
191 | + else if ((iwp >= 0.0 || icp >= 0.0) && | ||
192 | + (iwp < 0.0 || icp < 0.0 || iwp > 100.0 || icp > 100.0 || icp > iwp)) { | ||
193 | + printf (_("\ | ||
194 | +INPUT ERROR: C_IDFP (%f) should be less than W_IDFP (%.1f) and both should be between zero and 100 percent, inclusive"), | ||
195 | + icp, iwp); | ||
196 | + print_path (mypath); | ||
197 | + return ERROR; | ||
198 | + } | ||
199 | else if ((w > 0 || c > 0) && (w == 0 || c == 0 || c > w)) { | ||
200 | printf (_("\ | ||
201 | INPUT ERROR: C_DF (%lu) should be less than W_DF (%lu) and both should be greater than zero"), | ||
202 | @@ -516,16 +564,20 @@ | ||
203 | |||
204 | |||
205 | int | ||
206 | -check_disk (double usp, uintmax_t free_disk) | ||
207 | +check_disk (double usp, uintmax_t free_disk, double uisp) | ||
208 | { | ||
209 | int result = STATE_UNKNOWN; | ||
210 | /* check the percent used space against thresholds */ | ||
211 | if (usp >= 0.0 && c_dfp >=0.0 && usp >= (100.0 - c_dfp)) | ||
212 | result = STATE_CRITICAL; | ||
213 | + else if (uisp >= 0.0 && c_idfp >=0.0 && uisp >= (100.0 - c_idfp)) | ||
214 | + result = STATE_CRITICAL; | ||
215 | else if (c_df > 0 && free_disk <= c_df) | ||
216 | result = STATE_CRITICAL; | ||
217 | else if (usp >= 0.0 && w_dfp >=0.0 && usp >= (100.0 - w_dfp)) | ||
218 | result = STATE_WARNING; | ||
219 | + else if (uisp >= 0.0 && w_idfp >=0.0 && uisp >= (100.0 - w_idfp)) | ||
220 | + result = STATE_WARNING; | ||
221 | else if (w_df > 0 && free_disk <= w_df) | ||
222 | result = STATE_WARNING; | ||
223 | else if (usp >= 0.0) | ||
224 | @@ -579,6 +631,10 @@ | ||
225 | Exit with WARNING status if less than INTEGER kilobytes of disk are free\n\ | ||
226 | -w, --warning=PERCENT%%\n\ | ||
227 | Exit with WARNING status if less than PERCENT of disk space is free\n\ | ||
228 | + -W, --iwarning=PERCENT%%\n\ | ||
229 | + Exit with WARNING status if less than PERCENT of inode space is free\n\ | ||
230 | + -K, --icritical=PERCENT%%\n\ | ||
231 | + Exit with CRITICAL status if less than PERCENT of inode space is free\n\ | ||
232 | -c, --critical=INTEGER\n\ | ||
233 | Exit with CRITICAL status if less than INTEGER kilobytes of disk are free\n\ | ||
234 | -c, --critical=PERCENT%%\n\ | ||
235 | @@ -628,7 +684,7 @@ | ||
236 | print_usage (void) | ||
237 | { | ||
238 | printf (_("\ | ||
239 | -Usage: %s -w limit -c limit [-p path | -x device] [-t timeout] [-m] [-e]\n\ | ||
240 | +Usage: %s -w limit -c limit [-p path | -x device] [-t timeout] [-m] [-e] [-W limit] [-K limit]\n\ | ||
241 | [-v] [-q]\n\ | ||
242 | %s (-h|--help)\n\ | ||
243 | %s (-V|--version)\n"), | ||