summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_disk.c61
1 files changed, 56 insertions, 5 deletions
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index 9421d060..1afc7620 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -36,6 +36,14 @@
36#include "utils.h" 36#include "utils.h"
37#include <stdarg.h> 37#include <stdarg.h>
38 38
39#ifdef _AIX
40 #pragma alloca
41#endif
42
43#if HAVE_INTTYPES_H
44# include <inttypes.h>
45#endif
46
39#define REVISION "$Revision$" 47#define REVISION "$Revision$"
40#define COPYRIGHT "2000-2002" 48#define COPYRIGHT "2000-2002"
41 49
@@ -73,9 +81,52 @@ main (int argc, char **argv)
73 char mntp[MAX_INPUT_BUFFER]; 81 char mntp[MAX_INPUT_BUFFER];
74 char *output = ""; 82 char *output = "";
75 83
84#ifdef HAVE_STRUCT_STATFS
85#ifdef HAVE_SYS_VFS_H
86#include <sys/vfs.h>
87#else
88#include <sys/param.h>
89#include <sys/mount.h>
90#endif
91 struct statfs buf;
92#endif
93
76 if (process_arguments (argc, argv) != OK) 94 if (process_arguments (argc, argv) != OK)
77 usage ("Could not parse arguments\n"); 95 usage ("Could not parse arguments\n");
78 96
97#ifdef HAVE_STRUCT_STATFS
98
99 if (statfs (path, &buf) == -1) {
100 switch (errno)
101 {
102 case ENOTDIR:
103 terminate (STATE_UNKNOWN, "A component of the path prefix is not a directory.\n");
104 case ENAMETOOLONG:
105 terminate (STATE_UNKNOWN, "path is too long.\n");
106 case ENOENT:
107 terminate (STATE_UNKNOWN, "The file referred to by path does not exist.\n");
108 case EACCES:
109 terminate (STATE_UNKNOWN, "Search permission is denied for a component of the path prefix of path.\n");
110 case ELOOP:
111 terminate (STATE_UNKNOWN, "Too many symbolic links were encountered in translating path.\n");
112 case EFAULT:
113 terminate (STATE_UNKNOWN, "Buf or path points to an invalid address.\n");
114 case EIO:
115 terminate (STATE_UNKNOWN, "An I/O error occurred while reading from or writing to the file system.\n");
116 case ENOMEM:
117 terminate (STATE_UNKNOWN, "Insufficient kernel memory was available.\n");
118 case ENOSYS:
119 terminate (STATE_UNKNOWN, "The filesystem path is on does not support statfs.\n");
120 }
121 }
122 usp = (buf.f_blocks - buf.f_bavail) / buf.f_blocks;
123 disk_result = check_disk (usp, buf.f_bavail);
124 result = disk_result;
125 asprintf (&output, "%ld of %ld kB free (%ld-byte blocks)",
126 buf.f_bavail*buf.f_bsize/1024, buf.f_blocks*buf.f_bsize/1024, buf.f_bsize);
127
128#else
129
79 asprintf (&command_line, "%s %s", DF_COMMAND, path); 130 asprintf (&command_line, "%s %s", DF_COMMAND, path);
80 131
81 if (verbose>0) 132 if (verbose>0)
@@ -151,13 +202,13 @@ main (int argc, char **argv)
151 result = STATE_WARNING; 202 result = STATE_WARNING;
152 203
153 if (usp < 0) 204 if (usp < 0)
154 printf ("Disk \"%s\" not mounted or nonexistant\n", path); 205 terminate (result, "Disk \"%s\" not mounted or nonexistant\n", path);
155 else if (result == STATE_UNKNOWN) 206 else if (result == STATE_UNKNOWN)
156 printf ("Unable to read output\n%s\n%s\n", command_line, input_buffer); 207 terminate (result, "Unable to read output\n%s\n%s\n", command_line, input_buffer);
157 else
158 printf ("DISK %s%s\n", state_text (result), output);
159 208
160 return result; 209#endif
210
211 terminate (result, "DISK %s %s\n", state_text (result), output);
161} 212}
162 213
163/* process command-line arguments */ 214/* process command-line arguments */