Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # +-----------------------------------------------------------------------------------------+
- # | Dit script checked de raid status van Areca RAID kaarten op Ubuntu/Debian |
- # | Nagios script |
- # | Januari 2012 flip hess flip@nerdmetbril.nl |
- # +-----------------------------------------------------------------------------------------+
- # Global variables:
- PATH='/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin'
- SCRIPT_PATH="${0}"
- ARGS="${#}"
- ARG1="${1}"
- ARG3="${3}"
- STATE_OK="0"
- STATE_WARNING="1"
- STATE_CRITICAL="2"
- STATE_UNKNOWN="3"
- # Functions:
- # exit function
- function die()
- {
- # output
- echo -e "Error in ${SCRIPT_PATH}:\n ${1}"
- # return state unknown
- exit ${STATE_UNKNOWN}
- }
- # Shows usage function.
- function fShowUsage()
- {
- echo -e "Usage: ${SCRIPT_PATH} [status|event|help]\n
- help Show Usage
- status Check RAID status\n
- event Check RAID event\n
- Install this plugin using the installer:\n
- ./ipmi-raid-installer.sh YES\"\n
- Check Areca on Linux - flip@nerdmetbril.nl\n\nVersie 1.0"
- exit ${STATE_UNKNOWN}
- }
- # function status
- function fRunStatus()
- {
- # get cli output
- OUTPUT="$( sudo /usr/local/bin/cli vsf info vol=1 | grep -Ev '(===|GuiErrMsg|Volume Set Information)' )" || die "Failed to get CLI OUTPUT"
- # check state
- if ( echo ${OUTPUT} | grep -qE 'Volume.+State.+Normal' ) ; then
- local STATE="1"
- local STMSG="Volume State is Normal"
- else
- local STATE="0"
- local STMSG="$( echo "${OUTPUT}" | grep -E 'Volume.+State.+:' )"
- fi
- # check members
- if ( echo "${OUTPUT}" | grep -qE 'Member.Disks.+:.+2' ) ; then
- local MEMBER="1"
- local MBMSG="Member Disks is 2"
- else
- local MEMBER="0"
- local MBMSG="$( echo "${OUTPUT}" | grep 'Member.+Disks.+:' )"
- fi
- # make results
- if [ ${STATE} = 1 ] && [ ${MEMBER} = 1 ] ; then
- { echo -e "OKAY ${STMSG} and ${MBMSG}\n |\n${OUTPUT}" ; exit ${STATE_OK}; }
- elif [ ${STATE} = 0 ] && [ ${MEMBER} = 0 ] ; then
- { echo -e "CRITICAL - NOK: ${STMSG} - and NOK: ${MBMSG}\n |\n${OUTPUT}" ; exit ${STATE_CRITICAL}; }
- elif [ ${STATE} = 1 ] && [ ${MEMBER} = 0 ] ; then
- { echo -e "CRITICAL - Volume State is OKAY But Member Disks: ${MBMSG}\n |\n${OUTPUT}" ; exit ${STATE_CRITICAL}; }
- elif [ ${STATE} = 0 ] && [ ${MEMBER} = 1 ] ; then
- { echo -e "CRITICAL - Member Disks is OKAY but State: ${STMSG}\n |\n${OUTPUT}" ; exit ${STATE_CRITICAL}; }
- else
- { echo -e "WARNING - This Check is WONKY! BARK KRAK STUK!" ; exit ${STATE_WARNING}; }
- fi
- }
- # function event
- function fRunEvent()
- {
- #check state file
- [ -f /tmp/raid-events ] || \
- { fCheckReset && { echo "WARNING - check has been reset - a new /tmp/raid-events error state file is created" ; exit "${STATE_WARNING}"; };}
- # get info
- local TEMP="$(mktemp)"
- { sudo /usr/local/bin/cli event info | grep -Ev '(====|GuiErrMsg|Date-Time|Device)' > ${TEMP} ; } || die "Failed to Get event info!"
- local TOTAL="$( cat "${TEMP}" | wc -l )"
- local OLDTOTAL="$( cat /tmp/raid-events | wc -l )"
- local DELTA="$(( ${TOTAL} - ${OLDTOTAL} ))"
- local LAST="$( cat "${TEMP}" | head -1 )"
- # diff
- DIFFS="$( diff "${TEMP}" "/tmp/raid-events" |grep -E '(<|>)' |sed -e 's/^>/missing event:/g;s/^</event:/g' )"
- # make results
- if [ -z "${DIFFS}" ] ; then
- rm ${TEMP}
- echo -e "ALL OK: ${TOTAL} known RAID events are given \nLast event was: ${LAST}"
- exit ${STATE_OK}
- else
- echo -e "CRITICAL: ${DELTA} new RAID events given!\nLast event was: ${LAST} - tmp: ${TEMP}"
- echo "${DIFFS}"
- exit ${STATE_CRITICAL}
- fi
- }
- # resets
- function fCheckReset()
- {
- # Reset state old file
- if [ ! -f /tmp/raid-events ] ; then
- touch /tmp/raid-events
- sudo cli event info | grep -Ev '(====|GuiErrMsg|Date-Time|Device)' > /tmp/raid-events
- fi
- return 0
- }
- # The main function.
- function fMain()
- {
- # script o depends on:
- [ -x /usr/local/bin/cli ] || die "This script depends on CLI, please install it using the installer ipmi-raid-installer.sh"
- # check for arguments:
- [ ${ARGS} = 1 ] || fShowUsage
- # Do the Magic:
- #get options and set vars
- case ${ARG1} in
- status)
- fRunStatus
- ;;
- event)
- fRunEvent
- ;;
- help)
- fShowUsage
- ;;
- *)
- fShowUsage
- ;;
- esac
- }
- # Start the program:
- fMain
- # Exit with previous return code:
- exit "${?}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement