Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # flip hess november 2011 [email protected]
- # nagios check ipboard gallery
- #==================================================
- #
- # This program is free software; you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation; either version 3 of the License.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU Library General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program; if not, write to the Free Software
- # Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301, USA
- #
- # http://www.gnu.org/licenses/gpl.txt
- #
- #==================================================
- # Variables
- PATH='/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin'
- SCRIPT_PATH="${0}"
- HOST="${1}"
- PASSFILE="/etc/nagios/.my.cnf"
- DATABASE="Database"
- MYSQL="mysql --defaults-file=${PASSFILE} ${DATABASE} -Be"
- STATE_OK="0"
- STATE_WARNING="1"
- STATE_CRITICAL="2"
- STATE_UNKNOWN="3"
- # Functions:
- # The main function.
- function fMain()
- {
- # Check whether sufficient arguments are given:
- [ ${#} = 0 ] || { fShowUsage ; exit "${STATE_UNKNOWN}"; }
- # checken binaries
- { test -x /usr/bin/mysqldump && test -x /usr/bin/mysql; } || { echo -e "This script depends on mysql-common!" ; exit "${STATE_WARNING}"; }
- # check op .my.cnf
- if [ ! -f ${PASSFILE} ]; then
- echo -e "${PASSFILE} Not found!"
- exit "${STATE_UNKNOWN}"
- fi
- # checken op connectiviteit
- ${MYSQL} "show databases" |grep -Eq '(information_schema)'
- [ ${?} = 0 ] || { echo -e "Failed to connect to database!" ; exit "${STATE_UNKNOWN}"; }
- # get info
- RESULT="$( ${MYSQL} "SELECT album_id FROM gallery_albums_main WHERE album_name = '';" | sed '1d' )" || \
- { echo -e "Failed to query ${DATABASE}" ; exit "${STATE_UNKNOWN}"; }
- # make results and notify
- if [ -n "${RESULT}" ]; then
- echo -e "CRITICAL: Found one or more gallery albums in ${DATABASE} without a album_name: ID: ${RESULT}\n\
- Please run \"UPDATE gallery_albums_main SET album_name = 'Example' WHERE album_id = ${RESULT}\" on ${DATABASE}"
- exit "${STATE_CRITICAL}"
- else
- echo -e "OK - No Gallery ID's found without an album_name in ${DATABASE}"
- exit "${STATE_OK}"
- fi
- }
- # Shows usage.
- function fShowUsage()
- {
- echo "Usage: ${SCRIPT_PATH}"
- return 0
- }
- # Start the program:
- fMain "${@}"
- # Exit with previous return code:
- exit "${?}"
Advertisement
Add Comment
Please, Sign In to add comment