summaryrefslogtreecommitdiffstats
path: root/plugins/check_disk.c
diff options
context:
space:
mode:
authorKarl DeBisschop <kdebisschop@users.sourceforge.net>2003-03-21 14:08:01 (GMT)
committerKarl DeBisschop <kdebisschop@users.sourceforge.net>2003-03-21 14:08:01 (GMT)
commitdae56061fcd5534886863865e47359662f4bc55b (patch)
tree747cc9fc853ca48bf8c8b31562c5f9c72ddba027 /plugins/check_disk.c
parent0e138a6ba7c465b8cbbf0a04d11537b98d4b69e1 (diff)
downloadmonitoring-plugins-dae56061fcd5534886863865e47359662f4bc55b.tar.gz
checkpoint, allows selecting devices and paths now
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@444 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/check_disk.c')
-rw-r--r--plugins/check_disk.c59
1 files changed, 42 insertions, 17 deletions
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index f9a9a84..9746511 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -91,10 +91,10 @@ static int require_sync = 0;
91 91
92/* A filesystem type to display. */ 92/* A filesystem type to display. */
93 93
94struct fs_type_list 94struct name_list
95{ 95{
96 char *fs_name; 96 char *name;
97 struct fs_type_list *fs_next; 97 struct name_list *name_next;
98}; 98};
99 99
100/* Linked list of filesystem types to display. 100/* Linked list of filesystem types to display.
@@ -108,12 +108,16 @@ struct fs_type_list
108 Some filesystem types: 108 Some filesystem types:
109 4.2 4.3 ufs nfs swap ignore io vm efs dbg */ 109 4.2 4.3 ufs nfs swap ignore io vm efs dbg */
110 110
111static struct fs_type_list *fs_select_list; 111static struct name_list *fs_select_list;
112 112
113/* Linked list of filesystem types to omit. 113/* Linked list of filesystem types to omit.
114 If the list is empty, don't exclude any types. */ 114 If the list is empty, don't exclude any types. */
115 115
116static struct fs_type_list *fs_exclude_list; 116static struct name_list *fs_exclude_list;
117
118static struct name_list *path_select_list;
119
120static struct name_list *dev_select_list;
117 121
118/* Linked list of mounted filesystems. */ 122/* Linked list of mounted filesystems. */
119static struct mount_entry *mount_list; 123static struct mount_entry *mount_list;
@@ -169,28 +173,36 @@ main (int argc, char **argv)
169 struct fs_usage fsp; 173 struct fs_usage fsp;
170 char *disk; 174 char *disk;
171 175
176 mount_list = read_filesystem_list (0);
177
172 if (process_arguments (argc, argv) != OK) 178 if (process_arguments (argc, argv) != OK)
173 usage ("Could not parse arguments\n"); 179 usage ("Could not parse arguments\n");
174 180
175 mount_list = read_filesystem_list (0);
176
177 for (me = mount_list; me; me = me->me_next) { 181 for (me = mount_list; me; me = me->me_next) {
178 get_fs_usage (me->me_mountdir, me->me_devname, &fsp); 182
183 if ((dev_select_list &&
184 ! strcmp (dev_select_list->name, me->me_devname)) ||
185 (path_select_list &&
186 ! strcmp (path_select_list->name, me->me_mountdir)))
187 get_fs_usage (me->me_mountdir, me->me_devname, &fsp);
188 else if (dev_select_list || path_select_list)
189 continue;
190 else
191 get_fs_usage (me->me_mountdir, me->me_devname, &fsp);
192
179 if (fsp.fsu_blocks && strcmp ("none", me->me_mountdir)) { 193 if (fsp.fsu_blocks && strcmp ("none", me->me_mountdir)) {
180 usp = (fsp.fsu_blocks - fsp.fsu_bavail) * 100 / fsp.fsu_blocks; 194 usp = (fsp.fsu_blocks - fsp.fsu_bavail) * 100 / fsp.fsu_blocks;
181 disk_result = check_disk (usp, fsp.fsu_bavail); 195 disk_result = check_disk (usp, fsp.fsu_bavail);
182 result = max_state (disk_result, result); 196 result = max_state (disk_result, result);
183 asprintf (&output, "%s %llu of %llu kB (%2.0f%%) free (%d-byte blocks) on %s (%s) %d\n", 197 asprintf (&output, "%s %llu of %llu MB (%2.0f%%) free on %s\n",
184 output, 198 output,
185 fsp.fsu_bavail*fsp.fsu_blocksize/1024, 199 fsp.fsu_bavail*fsp.fsu_blocksize/1024/1024,
186 fsp.fsu_blocks*fsp.fsu_blocksize/1024, 200 fsp.fsu_blocks*fsp.fsu_blocksize/1024/1024,
187 (double)fsp.fsu_bavail*100/fsp.fsu_blocks, 201 (double)fsp.fsu_bavail*100/fsp.fsu_blocks,
188 fsp.fsu_blocksize, 202 display_mntp ? me->me_devname : me->me_mountdir);
189 me->me_mountdir,
190 me->me_type, usp);
191 } 203 }
192 }
193 204
205 }
194 206
195 terminate (result, "DISK %s %s\n", state_text (result), output); 207 terminate (result, "DISK %s %s\n", state_text (result), output);
196} 208}
@@ -200,6 +212,9 @@ int
200process_arguments (int argc, char **argv) 212process_arguments (int argc, char **argv)
201{ 213{
202 int c; 214 int c;
215 struct name_list *se;
216 struct name_list **pathtail = &path_select_list;
217 struct name_list **devtail = &dev_select_list;
203 218
204 int option_index = 0; 219 int option_index = 0;
205 static struct option long_options[] = { 220 static struct option long_options[] = {
@@ -213,6 +228,7 @@ process_arguments (int argc, char **argv)
213 {"errors-only", no_argument, 0, 'e'}, 228 {"errors-only", no_argument, 0, 'e'},
214 {"help", no_argument, 0, 'h'}, 229 {"help", no_argument, 0, 'h'},
215 {"mountpoint", no_argument, 0, 'm'}, 230 {"mountpoint", no_argument, 0, 'm'},
231 {"device", no_argument, 0, 'd'},
216 {"exclude_device", required_argument, 0, 'x'}, 232 {"exclude_device", required_argument, 0, 'x'},
217 {"quiet", no_argument, 0, 'q'}, 233 {"quiet", no_argument, 0, 'q'},
218 234
@@ -227,7 +243,7 @@ process_arguments (int argc, char **argv)
227 strcpy (argv[c], "-t"); 243 strcpy (argv[c], "-t");
228 244
229 while (1) { 245 while (1) {
230 c = getopt_long (argc, argv, "+?Vqhvet:c:w:p:x:m", long_options, &option_index); 246 c = getopt_long (argc, argv, "+?Vqhvet:c:w:p:d:x:m", long_options, &option_index);
231 247
232 if (c == -1 || c == EOF) 248 if (c == -1 || c == EOF)
233 break; 249 break;
@@ -274,7 +290,16 @@ process_arguments (int argc, char **argv)
274 usage ("Timeout Interval must be an integer!\n"); 290 usage ("Timeout Interval must be an integer!\n");
275 } 291 }
276 case 'p': /* path or partition */ 292 case 'p': /* path or partition */
277 path = optarg; 293 se = (struct name_list *) malloc (sizeof (struct name_list));
294 se->name = strdup (optarg);
295 *pathtail = se;
296 pathtail = &se->name_next;
297 break;
298 case 'd': /* path or partition */
299 se = (struct name_list *) malloc (sizeof (struct name_list));
300 se->name = strdup (optarg);
301 *devtail = se;
302 devtail = &se->name_next;
278 break; 303 break;
279 case 'v': /* verbose */ 304 case 'v': /* verbose */
280 verbose++; 305 verbose++;