summaryrefslogtreecommitdiffstats
path: root/contrib
diff options
context:
space:
mode:
Diffstat (limited to 'contrib')
-rw-r--r--contrib/check_procr.sh147
1 files changed, 147 insertions, 0 deletions
diff --git a/contrib/check_procr.sh b/contrib/check_procr.sh
new file mode 100644
index 00000000..c99a17e1
--- /dev/null
+++ b/contrib/check_procr.sh
@@ -0,0 +1,147 @@
1#!/bin/bash
2
3#
4# Check_procr.sh
5#
6# Program: Process running check plugin for Nagios
7# License : GPL
8# Copyright (c) 2002 Jerome Tytgat (j.tytgat@sioban.net)
9#
10# check_procr.sh,v 1.0 2002/09/18 15:28
11#
12# Description :
13#
14# This plugin check if at least one process is running
15#
16# Usage :
17#
18# check_procr.sh -p process_name
19#
20# Example :
21#
22# To know if snort is running
23# check_procr.sh -p snort
24# > OK - total snort running : PID=23441
25#
26# Linux Redhat 7.3
27#
28
29help_usage() {
30 echo "Usage:"
31 echo " $0 -p <process_name>"
32 echo " $0 (-v | --version)"
33 echo " $0 (-h | --help)"
34}
35
36help_version() {
37 echo "check_procr.sh (nagios-plugins) 1.0"
38 echo "The nagios plugins come with ABSOLUTELY NO WARRANTY. You may redistribute"
39 echo "copies of the plugins under the terms of the GNU General Public License."
40 echo "For more information about these matters, see the file named COPYING."
41 echo "Copyright (c) 2002 Jerome Tytgat - j.tytgat@sioban.net"
42 echo "Greetings goes to Websurg which kindly let me took time to develop this"
43 echo " Manu Feig and Jacques Kern who were my beta testers, thanks to them !"
44}
45
46verify_dep() {
47 needed="bash cut egrep expr grep let ps sed sort tail test tr wc"
48 for i in `echo $needed`
49 do
50 type $i > /dev/null 2>&1 /dev/null
51 if [ $? -eq 1 ]
52 then
53 echo "I am missing an important component : $i"
54 echo "Cannot continue, sorry, try to find the missing one..."
55 exit 3
56 fi
57 done
58}
59
60myself=$0
61
62verify_dep
63
64if [ "$1" = "-h" -o "$1" = "--help" ]
65then
66 help_version
67 echo ""
68 echo "This plugin will check if a process is running."
69 echo ""
70 help_usage
71 echo ""
72 echo "Required Arguments:"
73 echo " -p, --process STRING"
74 echo " process name we want to verify"
75 echo ""
76 exit 3
77fi
78
79if [ "$1" = "-v" -o "$1" = "--version" ]
80then
81 help_version
82 exit 3
83fi
84
85if [ `echo $@|tr "=" " "|wc -w` -lt 2 ]
86then
87 echo "Bad arguments number (need two)!"
88 help_usage
89 exit 3
90fi
91
92tt=0
93process_name=""
94exclude_process_name=""
95wt=""
96ct=""
97
98# Test of the command lines arguments
99while test $# -gt 0
100do
101
102 case "$1" in
103 -p|--process)
104 if [ -n "$process_name" ]
105 then
106 echo "Only one --process argument is useful..."
107 help_usage
108 exit 3
109 fi
110 shift
111 process_name="`echo $1|tr \",\" \"|\"`"
112 ;;
113 *)
114 echo "Unknown argument $1"
115 help_usage
116 exit 3
117 ;;
118 esac
119 shift
120done
121
122# ps line construction set...
123for i in `ps ho pid -C $process_name`
124do
125 pid_list="$pid_list $i"
126done
127
128if [ -z "$pid_list" ]
129then
130 crit=1
131else
132 crit=0
133fi
134
135# Finally Inform Nagios of what we found...
136if [ $crit -eq 1 ]
137then
138 echo "CRITICAL - process $process_name is not running !"
139 exit 2
140else
141 echo "OK - process $process_name is running : PID=$pid_list "
142 exit 0
143fi
144
145# Hey what are we doing here ???
146exit 3
147