flipje

check-ipboard-gallery

Jul 15th, 2012
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.68 KB | None | 0 0
  1. #!/bin/bash
  2. # flip hess november 2011 [email protected]
  3. # nagios check ipboard gallery
  4. #==================================================
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 3 of the License.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU Library General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301, USA
  18. #
  19. # http://www.gnu.org/licenses/gpl.txt
  20. #
  21. #==================================================
  22.  
  23. # Variables
  24.  
  25.   PATH='/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin'
  26.   SCRIPT_PATH="${0}"
  27.   HOST="${1}"
  28.  
  29.   PASSFILE="/etc/nagios/.my.cnf"
  30.   DATABASE="Database"
  31.   MYSQL="mysql --defaults-file=${PASSFILE} ${DATABASE} -Be"
  32.  
  33.   STATE_OK="0"
  34.   STATE_WARNING="1"
  35.   STATE_CRITICAL="2"
  36.   STATE_UNKNOWN="3"
  37.  
  38. # Functions:
  39.  
  40.  
  41. # The main function.
  42. function fMain()
  43. {
  44.   # Check whether sufficient arguments are given:
  45.   [ ${#} = 0 ] || { fShowUsage ; exit "${STATE_UNKNOWN}"; }
  46.  
  47.   # checken binaries
  48.   { test -x /usr/bin/mysqldump  && test -x /usr/bin/mysql; } || { echo -e "This script depends on mysql-common!" ; exit "${STATE_WARNING}"; }
  49.  
  50.   # check op .my.cnf
  51.   if [ ! -f ${PASSFILE} ]; then
  52.     echo -e  "${PASSFILE} Not found!"
  53.     exit "${STATE_UNKNOWN}"
  54.   fi
  55.  
  56.   # checken op connectiviteit
  57.   ${MYSQL} "show databases" |grep -Eq '(information_schema)'
  58.   [ ${?} = 0 ] || { echo -e "Failed to connect to database!"  ; exit "${STATE_UNKNOWN}"; }
  59.  
  60.  
  61.   # get info
  62.   RESULT="$( ${MYSQL} "SELECT album_id FROM gallery_albums_main WHERE album_name = '';" | sed '1d' )" || \
  63.        { echo -e "Failed to query ${DATABASE}" ; exit "${STATE_UNKNOWN}"; }
  64.  
  65.   # make results and notify
  66.   if [ -n "${RESULT}" ]; then
  67.     echo -e  "CRITICAL: Found one or more gallery albums in ${DATABASE} without a album_name: ID: ${RESULT}\n\
  68.      Please run \"UPDATE gallery_albums_main SET album_name = 'Example' WHERE album_id = ${RESULT}\" on ${DATABASE}"
  69.     exit "${STATE_CRITICAL}"
  70.   else
  71.     echo -e "OK - No Gallery ID's found without an album_name in ${DATABASE}"
  72.     exit "${STATE_OK}"
  73.   fi
  74.  
  75. }
  76.  
  77. # Shows usage.
  78. function fShowUsage()
  79. {
  80.   echo "Usage: ${SCRIPT_PATH}"
  81.   return 0
  82. }
  83.  
  84.  
  85. # Start the program:
  86. fMain "${@}"
  87.  
  88. # Exit with previous return code:
  89. exit "${?}"
Advertisement
Add Comment
Please, Sign In to add comment