Initial commit
Benjamin Renard

Benjamin Renard commited on 2014-12-08 14:14:58
Showing 3 changed files, with 172 additions and 0 deletions.

... ...
@@ -0,0 +1,2 @@
1
+*~
2
+.*.swp
... ...
@@ -0,0 +1,47 @@
1
+Nagios plugin to check NFS services state
2
+=========================================
3
+
4
+This plugin check NFS services state.
5
+
6
+Usage
7
+-----
8
+
9
+  Usage : ./check_nfs_services [parameters]
10
+  
11
+  Check NFS services status
12
+  
13
+  Parameters :
14
+    -n               Enable check of nfsd status
15
+    -N process name  The process name of nfsd (Default : nfsd)
16
+    -m               Enable check of mountd status
17
+    -M process name  The process name of mountd (Default : rpc.mountd)
18
+    -s               Enable check of statd status
19
+    -S process name  The process name of statd (Default : rpc.statd)
20
+    -i               Enable check of idmapd status
21
+    -I process name  The process name of idmapd (Default : rpc.idmapd)
22
+    -g               Enable check of gssd status
23
+    -G process name  The process name of gssd (Default : rpc.gssd)
24
+    -d               Enable debug mode
25
+    -h               Show this message
26
+
27
+Copyright
28
+---------
29
+
30
+Copyright (c) 2014 Benjamin Renard 
31
+
32
+License
33
+-------
34
+
35
+This program is free software; you can redistribute it and/or
36
+modify it under the terms of the GNU General Public License version 2
37
+as published by the Free Software Foundation.
38
+
39
+This program is distributed in the hope that it will be useful,
40
+but WITHOUT ANY WARRANTY; without even the implied warranty of
41
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
42
+GNU General Public License for more details.
43
+
44
+You should have received a copy of the GNU General Public License
45
+along with this program; if not, write to the Free Software
46
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
47
+
... ...
@@ -0,0 +1,123 @@
1
+#!/bin/bash
2
+
3
+CHECK_NFSD=0
4
+NFSD_PROCESS_NAME=nfsd
5
+
6
+CHECK_MOUNTD=0
7
+MOUNTD_PROCESS_NAME=rpc.mountd
8
+
9
+CHECK_STATD=0
10
+STATD_PROCESS_NAME=rpc.statd
11
+
12
+CHECK_IDMAPD=0
13
+IDMAPD_PROCESS_NAME=rpc.idmapd
14
+
15
+CHECK_GSSD=0
16
+GSSD_PROCESS_NAME=rpc.gssd
17
+
18
+DEBUG=0
19
+
20
+function usage() {
21
+        echo "Usage : $0 [parameters]"
22
+        echo
23
+        echo "Check NFS services status"
24
+        echo
25
+        echo "Parameters :"
26
+        echo "  -n               Enable check of nfsd status"
27
+        echo "  -N process name  The process name of nfsd (Default : $NFSD_PROCESS_NAME)"
28
+        echo "  -m               Enable check of mountd status"
29
+        echo "  -M process name  The process name of mountd (Default : $MOUNTD_PROCESS_NAME)"
30
+        echo "  -s               Enable check of statd status"
31
+        echo "  -S process name  The process name of statd (Default : $STATD_PROCESS_NAME)"
32
+        echo "  -i               Enable check of idmapd status"
33
+        echo "  -I process name  The process name of idmapd (Default : $IDMAPD_PROCESS_NAME)"
34
+        echo "  -g               Enable check of gssd status"
35
+        echo "  -G process name  The process name of gssd (Default : $GSSD_PROCESS_NAME)"
36
+        echo "  -d               Enable debug mode"
37
+        echo "  -h               Show this message"
38
+}
39
+
40
+while getopts :nN:mM:sS:iI:gG:dh FLAG
41
+do
42
+        [ $DEBUG -eq 1 ] && echo "Parameter $FLAG present. Value : '$OPTARG'"
43
+        case $FLAG in
44
+		n)
45
+			CHECK_NFSD=1
46
+		;;
47
+		N)
48
+			NFSD_PROCESS_NAME=$OPTARG
49
+		;;
50
+		m)
51
+			CHECK_MOUNTD=1
52
+		;;
53
+		M)
54
+			MOUNTD_PROCESS_NAME=$OPTARG
55
+		;;
56
+                s)
57
+                        CHECK_STATD=1
58
+                ;;
59
+		S)
60
+			STATD_PROCESS_NAME=$OPTARG
61
+		;;
62
+		i)
63
+			CHECK_IDMAPD=1
64
+		;;
65
+		I)
66
+			IDMAPD_PROCESS_NAME=$OPTARG
67
+		;;
68
+		g)
69
+			CHECK_GSSD=1
70
+		;;
71
+		G)
72
+			GSSD_PROCESS_NAME=$OPTARG
73
+		;;
74
+                d)
75
+                        DEBUG=1
76
+                ;;
77
+                h)
78
+                        usage
79
+                        exit 0
80
+                ;;
81
+		*)
82
+			echo "Invalid parameter -$FLAG"
83
+			usage
84
+			exit 1
85
+		;;
86
+        esac
87
+done
88
+
89
+[ $CHECK_NFSD -eq 0 -a $CHECK_MOUNTD -eq 0 -a $CHECK_STATD -eq 0 -a $CHECK_IDMAPD -eq 0 -a $CHECK_GSSD -eq 0 ] && echo "You must enable check of at least one service" && usage && exit 1
90
+
91
+STATE=OK
92
+MSG=""
93
+EXIT=0
94
+
95
+function check_process() {
96
+	check="$1"
97
+	name="$2"
98
+	process="$3"
99
+
100
+	if [ "$check" == "1" ]
101
+	then
102
+		P=$( pidof "$process" )
103
+		if [ $? -ne 0 ]
104
+		then
105
+			[ $DEBUG -eq 1 ] && echo "Process $process not found."
106
+			MSG="$MSG - $name NOT running"
107
+			STATE=CRITICAL
108
+			EXIT=2
109
+		else
110
+			[ $DEBUG -eq 1 ] && echo "Process $process found. PID = $P"
111
+			MSG="$MSG - $name is running"
112
+		fi
113
+	fi
114
+}
115
+
116
+check_process $CHECK_NFSD nfsd "$NFSD_PROCESS_NAME"
117
+check_process $CHECK_MOUNTD mountd "$MOUNTD_PROCESS_NAME"
118
+check_process $CHECK_STATD statd "$STATD_PROCESS_NAME"
119
+check_process $CHECK_IDMAPD idmapd "$IDMAPD_PROCESS_NAME"
120
+check_process $CHECK_GSSD gssd "$GSSD_PROCESS_NAME"
121
+
122
+echo "${STATE}${MSG}"
123
+exit $EXIT
0 124