Nagios configuration for Liberia
ThatOneNeji
2020-07-16 7ce05af8af539f631d1dae6f893a3b005cc71c6f
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/bin/bash
##################################################################################
# NAME:    ./check_facts_ldr_procs
# PURPOSE: This script is a Nagios Plugin to test FACTS Loader processes
#          It checks Java if certain Java processes are running or not.
# USAGE: ./check_facts_ldr_procs [ -p {proc_list} ] [ -P {pidfile_list} ]
#       -p {proc_list}    = Comma seperated list of Process names to grep for
#   -P {pidfile_list} = Comma seperated lsit of PID Files. PIDs in files will
#                       be looked for.
#
# REVISIONS:
# Ver     Date        Author           Description
# ----- ----------  ----------  ------------------------------------
# 2.0   2010-05-07  JD Loots    1. Modified the script for MTN FACTS purposes.
#                                  Removed PORT checks.
# 2.1   2010-06-02  JD Loots    2. There was a bug in checking PIDs in Linux.
#                                  Bug was fixed by introducing a PS variable.
# 2.2   2011-05-31  JD Loots    3. Added ability to specify the processes and
#                                  PID files on command line (-p and -P) instead
#                                  of having the processes specified inside
#                                  script. Also removed Warning level procs tests.
# 2.3   2011-05-09  JD Loots    4. Added exit to printUsage sub.
##################################################################################
 
##################################################################################
#
# PID Files to check
PIDLIST=""           # Will be populated from -p argument
# Processes to check
PROCLIST=""          # Will be populated from -P argument
 
PATH="/usr/bin:/usr/sbin:/bin:/sbin"
 
if [ "`uname -s`" = "SunOS" ]
then
  PSAUXWWW="/usr/ucb/ps -auxwww"
  PS=/usr/bin/ps
elif [ "`uname -s`" = "Linux" ]
then
  PSAUXWWW="/bin/ps auxwww"
  PS=/bin/ps
else
  PSAUXWWW="/bin/ps -auxwww"
  PS=/bin/ps
fi
 
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
STATE_DEPENDENT=4
 
print_gpl() {
    echo "This program is free software; you can redistribute it and/or modify"
    echo "it under the terms of the GNU General Public License as published by"
    echo "the Free Software Foundation; either version 2 of the License, or"
    echo "(at your option) any later version."
    echo ""
    echo "This program is distributed in the hope that it will be useful,"
    echo "but WITHOUT ANY WARRANTY; without even the implied warranty of"
    echo "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the"
    echo "GNU General Public License for more details."
    echo ""
    echo "You should have received a copy of the GNU General Public License"
    echo "along with this program; if not, write to the Free Software"
    echo "Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA"
}
 
printUsage(){
    echo ""
    echo "FACTS Loader process and port check script for Nagios."
        echo ""
    echo "USAGE: $0  [ -p {proc_list} ] [ -P {pidfile_list} ]"
    echo "-p {proc_list}    = Comma seperated list of Process names to grep for"
    echo "-P {pidfile_list} = Comma seperated lsit of PID Files. PIDs in files will"
    echo "                    be looked for."
        echo ""
        echo "EXAMPLE: $0 -p StatsGW,NotificationManager,DownloadManager,serviceManager,ViewManager,factsbi/cs/jboss \\"
        echo "   -P /app/factsbi/es/tmp/es.pid,/app/factsbi/en1/tmp/en.pid"
        print_gpl
    exit 1
}
 
check_processes()
{
        PROCESS="0"
        ERROR_PROCS=""
        for PROC in `echo $PROCLIST`
        do
          if [ `${PSAUXWWW} | grep $PROC | grep -v grep | wc -l` -lt 1 ]
          then
            PROCESS=1
            ERROR_PROCS="$ERROR_PROCS""$PROC ";
          fi
        done
 
        if [ $PROCESS -eq "1" ]
        then
          exit_proc=$STATE_CRITICAL
            elif [ $PROCESS -eq "0" ]
            then
                  exit_proc=$STATE_OK
        fi
}
 
check_pids()
{
  PROCESS="0"
  ERROR_PIDS=""
  for PIDFILE in `echo $PIDLIST`
  do
    if [ ! -r ${PIDFILE} ]
    then
      PROCESS=1
      ERROR_PIDS="${ERROR_PIDS} ${PIDFILE}"
    else
      PID=`cat ${PIDFILE} | head -1`
      ${PS} -p ${PID} > /dev/null 2>&1
      CODE=$?
      if [ ${CODE} -gt 0 ]
      then
        PROCESS=1
        ERROR_PIDS="${ERROR_PIDS} ${PIDFILE}"
      fi
    fi
  done
 
  if [ $PROCESS -eq "1" ]
  then
    exit_pid=$STATE_CRITICAL
  elif [ $PROCESS -eq "0" ]
  then
    exit_pid=$STATE_OK
  fi
}
#
# MAIN
#
 
if [ "$1" = "" ]
then
  echo "ERROR:No argument specified." >&2
  printUsage
fi
 
# Decode command-line arguments
while [ "$1" != "" ]
do
  case "$1" in
    '-p' ) PROCLIST=$2
           shift 2
           ;;
    '-P' ) PIDLIST=$2
           shift 2
           ;;
    '-h' ) printUsage
           shift
           ;;
     *)    # In case all parameters were passed as one, decode with awk
           if [ "$1" != "" ] && [ "$2" = "" ]
           then
             NF=`echo $1 | awk '{print NF}'`
             let i=1
             while [ $i -lt $NF ]
             do
               let j=i+1        # Make j 1 more than i
               ONE=`echo $1 | awk '{print $'${i}'}'`
               TWO=`echo $1 | awk '{print $'${j}'}'`
               case "${ONE}" in
                 '-p' ) PROCLIST=$TWO
                        let i=i+2       # shift 2
                        ;;
                 '-P' ) PIDLIST=`echo "scale=0;$TWO * ${SCALE} / 1" |bc`
                        let i=i+2       # shift 2
                        ;;
                 '-h' ) printUsage
                        let i=i+1       # shift
                        ;;
                 *)     echo "Unknown argument: \"$ONE\"" >&2
                        printUsage
                        ;;
               esac
             done
             shift
           else
             echo "Unknown argument: \"$1\"" >&2
             printUsage
           fi
           ;;
  esac
done
 
# At this stage, PROCLIST and PIDLIST are Comma Seperated Lists.
# Replace Comma's with spaces in these values.
PIDLIST=`echo ${PIDLIST} | sed 's/,/ /g'`
PROCLIST=`echo ${PROCLIST} | sed 's/,/ /g'`
 
# Do the Process checks
check_processes
check_pids
 
final_exit=`expr $exit_proc + $exit_pid`
 
if [ $final_exit -eq "0" ]
then
  echo "SYSTEM OK - All monitored resources OK. Processes: ${PROCLIST}. PID Files: ${PIDLIST}."
  exitstatus=$STATE_OK
else
  echo "SYSTEM CRITICAL - Processes DOWN! Processes: ${ERROR_PROCS} ${ERROR_PIDS}."
  exitstatus=$STATE_CRITICAL
fi
 
exit $exitstatus