forked from jonschipp/nagios-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_nfs_stale
62 lines (53 loc) · 1.17 KB
/
check_nfs_stale
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <iso646.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#define VERSION_STRING "0.1"
#define OK 0
#define WARNING 1
#define CRITICAL 2
#define UNKNOWN 3
static void usage(void)
{
printf("check_nfs_stale Version: %s\n", VERSION_STRING);
puts(
"Nagios plugin to check for stale NFS mounts\n"
"Options:\n\n"
" -p <mount> Mount point of NFS share\n"
" -h Print help\n\n"
"Usage: check_nfs_stale [-h] [-p mount_point]\n"
"Please report bugs to <jonschipp@gmail.com>");
exit(OK);
}
int main(int argc, char **argv) {
struct stat file_stat;
int ret, c;
const char *mpoint = NULL;
if ( argc == 1 ) {
puts("Requires an argument, try ``-h''");
exit(UNKNOWN);
}
while ((c = getopt (argc, argv, "hp:")) != -1)
switch (c) {
case 'h':
usage();
break;
case 'p':
mpoint = optarg;
break;
case '?':
usage();
break;
}
ret = stat(mpoint, &file_stat);
if (ret == -1 && errno == ESTALE) {
printf("%s is stale\n", mpoint);
exit(CRITICAL);
}
else
printf("%s is fine\n", mpoint);
exit(OK);
}