~ubuntu-branches/ubuntu/precise/nagios-plugins/precise-proposed

« back to all changes in this revision

Viewing changes to contrib/check_procr.sh

  • Committer: Bazaar Package Importer
  • Author(s): Guido Trotter
  • Date: 2004-06-15 15:37:48 UTC
  • Revision ID: james.westby@ubuntu.com-20040615153748-pq7702qdzghqfcns
Tags: upstream-1.3.1.0
ImportĀ upstreamĀ versionĀ 1.3.1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
29
help_usage() {
 
30
        echo "Usage:"
 
31
        echo " $0 -p <process_name>"
 
32
        echo " $0 (-v | --version)"
 
33
        echo " $0 (-h | --help)"
 
34
}
 
35
 
 
36
help_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
 
 
46
verify_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
 
 
60
myself=$0
 
61
 
 
62
verify_dep
 
63
 
 
64
if [ "$1" = "-h" -o "$1" = "--help" ]
 
65
then 
 
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
 
77
fi
 
78
 
 
79
if [ "$1" = "-v" -o "$1" = "--version" ]
 
80
then
 
81
        help_version
 
82
        exit 3
 
83
fi
 
84
 
 
85
if [ `echo $@|tr "=" " "|wc -w` -lt 2 ]
 
86
then 
 
87
        echo "Bad arguments number (need two)!"
 
88
        help_usage
 
89
        exit 3
 
90
fi
 
91
 
 
92
tt=0
 
93
process_name=""
 
94
exclude_process_name=""
 
95
wt=""
 
96
ct=""
 
97
 
 
98
# Test of the command lines arguments
 
99
while test $# -gt 0
 
100
do
 
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
 
120
done
 
121
 
 
122
# ps line construction set...
 
123
for i in `ps ho pid -C $process_name`
 
124
do
 
125
         pid_list="$pid_list $i"
 
126
done
 
127
 
 
128
if [ -z "$pid_list" ]
 
129
then
 
130
        crit=1
 
131
else
 
132
        crit=0
 
133
fi
 
134
 
 
135
# Finally Inform Nagios of what we found...
 
136
if [ $crit -eq 1 ]
 
137
then
 
138
        echo "CRITICAL - process $process_name is not running !"
 
139
        exit 2
 
140
else
 
141
        echo "OK - process $process_name is running : PID=$pid_list "
 
142
        exit 0
 
143
fi
 
144
 
 
145
# Hey what are we doing here ???
 
146
exit 3
 
147