~percona-toolkit-dev/percona-monitoring-plugins/upgrade-docs-fix-bug-934617

« back to all changes in this revision

Viewing changes to nagios/bin/pmp-check-mysql-pidfile

  • Committer: baron at percona
  • Date: 2012-02-20 02:39:24 UTC
  • Revision ID: baron@percona.com-20120220023924-c3ifx2si9m3wy8v6
Make the Nagios plugins more testable (fixes bug #936579)

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
STATE_CRITICAL=2
21
21
STATE_UNKNOWN=3
22
22
STATE_DEPENDENT=4
23
 
EXITSTATUS=$STATE_UNKNOWN
24
23
 
25
24
# ########################################################################
26
25
# Run the program.
45
44
   if [ -e '/etc/nagios/mysql.cnf' ]; then
46
45
      OPT_DEFT="${OPT_DEFT:-/etc/nagios/mysql.cnf}"
47
46
   fi
 
47
   if is_not_sourced; then
 
48
      if [ -n "$1" ]; then
 
49
         echo "WARN spurious command-line options: $@"
 
50
         exit 1
 
51
      fi
 
52
   fi
48
53
 
49
54
   # Set the exit status in case there are any problems.
50
 
   EXITSTATUS=$STATE_UNKNOWN
51
55
   NOTE="UNK could not determine the PID file location."
52
56
 
53
57
   # Set up files to hold one or more PID file locations.
96
100
         MISSING=1
97
101
         NOTE2="${NOTE2:+${NOTE2}; }missing ${pidfile}"
98
102
      fi
99
 
      EXITSTATUS=$STATE_OK
100
103
      NOTE="OK all PID files exist."
101
104
   done < "${FILES}"
102
105
 
103
106
   if [ "${MISSING}" ]; then
104
107
      if [ "${OPT_CRIT}" ]; then
105
108
         NOTE="CRIT ${NOTE2}"
106
 
         EXITSTATUS=$STATE_CRITICAL
107
109
      else
108
 
         EXITSTATUS=$STATE_WARNING
109
110
         NOTE="WARN ${NOTE2}"
110
111
      fi
111
112
   fi
112
113
 
113
114
   echo $NOTE
114
 
   exit $EXITSTATUS
115
115
}
116
116
 
117
117
# ########################################################################
155
155
}
156
156
 
157
157
# ########################################################################
 
158
# Determine whether this program is being executed directly, or sourced/included
 
159
# from another file.
 
160
# ########################################################################
 
161
is_not_sourced() {
 
162
   [ "${0##*/}" = "pmp-check-mysql-pidfile" ] || [ "${0##*/}" = "bash" -a "$_" = "$0" ]
 
163
}
 
164
 
 
165
# ########################################################################
158
166
# Execute the program if it was not included from another file.
159
167
# This makes it possible to include without executing, and thus test.
160
168
# ########################################################################
161
 
if    [ "${0##*/}" = "pmp-check-mysql-pidfile" ] \
162
 
   || [ "${0##*/}" = "bash" -a "$_" = "$0" ]; then
163
 
   main "$@"
 
169
if is_not_sourced; then
 
170
   OUTPUT=$(main "$@")
 
171
   EXITSTATUS=$STATE_UNKNOWN
 
172
   case "${OUTPUT}" in
 
173
      UNK*)  EXITSTATUS=$STATE_UNKNOWN;  ;;
 
174
      OK*)   EXITSTATUS=$STATE_OK;       ;;
 
175
      WARN*) EXITSTATUS=$STATE_WARNING;  ;;
 
176
      CRIT*) EXITSTATUS=$STATE_CRITICAL; ;;
 
177
   esac
 
178
   echo "${OUTPUT}"
 
179
   exit $EXITSTATUS
164
180
fi
165
181
 
166
182
# ############################################################################