├── README.md ├── LICENSE └── check_glusterfs /README.md: -------------------------------------------------------------------------------- 1 | nagios-nrpe-check_glusterfs 2 | =========================== 3 | 4 | Fork of Mark Ruys' check_glusterfs from http://exchange.nagios.org/directory/Plugins/System-Metrics/File-System/GlusterFS-checks/details 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014, Doug Wilson 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | -------------------------------------------------------------------------------- /check_glusterfs: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ## Fork of MarkR’s GlusterFS-checks at: 4 | ## http://exchange.nagios.org/directory/Plugins/System-Metrics/File-System/GlusterFS-checks/details 5 | 6 | ### CHANGELOG 7 | ## 1.0.2 8 | # * 07/01/2014 9 | # * Modified by Doug Wilson 10 | # * includes carrillm’s fix to support TB sized volumes 11 | # * outputs all errors on a critical alarm, not just free space 12 | 13 | # This Nagios script was written against version 3.3 & 3.4 of Gluster. Older 14 | # versions will most likely not work at all with this monitoring script. 15 | # 16 | # Gluster currently requires elevated permissions to do anything. In order to 17 | # accommodate this, you need to allow your Nagios user some additional 18 | # permissions via sudo. The line you want to add will look something like the 19 | # following in /etc/sudoers (or something equivalent): 20 | # 21 | # Defaults:nagios !requiretty 22 | # nagios ALL=(root) NOPASSWD:/usr/sbin/gluster volume status [[\:graph\:]]* detail,/usr/sbin/gluster volume heal [[\:graph\:]]* info 23 | # 24 | # That should give us all the access we need to check the status of any 25 | # currently defined peers and volumes. 26 | 27 | # Inspired by a script of Mark Nipper 28 | # 29 | # 2013, Mark Ruys, mark.ruys@peercode.nl 30 | 31 | PATH=/sbin:/bin:/usr/sbin:/usr/bin 32 | 33 | PROGNAME=$(basename -- $0) 34 | PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'` 35 | REVISION="1.0.1" 36 | 37 | . $PROGPATH/utils.sh 38 | 39 | # parse command line 40 | usage () { 41 | echo "" 42 | echo "USAGE: " 43 | echo " $PROGNAME -v VOLUME -n BRICKS [-w GB -c GB]" 44 | echo " -n BRICKS: number of bricks" 45 | echo " -w and -c values in GB" 46 | exit $STATE_UNKNOWN 47 | } 48 | 49 | while getopts "v:n:w:c:" opt; do 50 | case $opt in 51 | v) VOLUME=${OPTARG} ;; 52 | n) BRICKS=${OPTARG} ;; 53 | w) WARN=${OPTARG} ;; 54 | c) CRIT=${OPTARG} ;; 55 | *) usage ;; 56 | esac 57 | done 58 | 59 | if [ -z "${VOLUME}" -o -z "${BRICKS}" ]; then 60 | usage 61 | fi 62 | 63 | Exit () { 64 | echo "$1: ${2:0}" 65 | status=STATE_$1 66 | exit ${!status} 67 | } 68 | 69 | # check for commands 70 | for cmd in basename bc awk sudo pidof gluster; do 71 | if ! type -p "$cmd" >/dev/null; then 72 | Exit UNKNOWN "$cmd not found" 73 | fi 74 | done 75 | 76 | # check for glusterd (management daemon) 77 | if ! pidof glusterd &>/dev/null; then 78 | Exit CRITICAL "glusterd management daemon not running" 79 | fi 80 | 81 | # check for glusterfsd (brick daemon) 82 | if ! pidof glusterfsd &>/dev/null; then 83 | Exit CRITICAL "glusterfsd brick daemon not running" 84 | fi 85 | 86 | # get volume heal status 87 | heal=0 88 | for entries in $(sudo gluster volume heal ${VOLUME} info | awk '/^Number of entries: /{print $4}'); do 89 | if [ "$entries" -gt 0 ]; then 90 | let $((heal+=entries)) 91 | fi 92 | done 93 | if [ "$heal" -gt 0 ]; then 94 | errors=("${errors[@]}" "$heal unsynched entries") 95 | fi 96 | 97 | # get volume status 98 | bricksfound=0 99 | freegb=9999999 100 | shopt -s nullglob 101 | while read -r line; do 102 | field=($(echo $line)) 103 | case ${field[0]} in 104 | Brick) 105 | brick=${field[@]:2} 106 | ;; 107 | Disk) 108 | key=${field[@]:0:3} 109 | if [ "${key}" = "Disk Space Free" ]; then 110 | freeunit=${field[@]:4} 111 | free=${freeunit:0:-2} 112 | freeconvgb=`echo "($free*1024)" | bc` 113 | unit=${freeunit#$free} 114 | if [ "$unit" = "TB" ]; then 115 | free=$freeconvgb 116 | unit="GB" 117 | fi 118 | if [ "$unit" != "GB" ]; then 119 | Exit UNKNOWN "unknown disk space size $freeunit" 120 | fi 121 | free=$(echo "${free} / 1" | bc -q) 122 | if [ $free -lt $freegb ]; then 123 | freegb=$free 124 | fi 125 | fi 126 | ;; 127 | Online) 128 | online=${field[@]:2} 129 | if [ "${online}" = "Y" ]; then 130 | let $((bricksfound++)) 131 | else 132 | errors=("${errors[@]}" "$brick offline") 133 | fi 134 | ;; 135 | esac 136 | done < <(sudo gluster volume status ${VOLUME} detail) 137 | 138 | if [ $bricksfound -eq 0 ]; then 139 | Exit CRITICAL "no bricks found" 140 | elif [ $bricksfound -lt $BRICKS ]; then 141 | errors=("${errors[@]}" "found $bricksfound bricks, expected $BRICKS ") 142 | ex_stat="WARNING_stat" 143 | fi 144 | 145 | if [ -n "$CRIT" -a -n "$WARN" ]; then 146 | if [ $CRIT -ge $WARN ]; then 147 | Exit UNKNOWN "critical threshold below warning" 148 | elif [ $freegb -lt $CRIT ]; then 149 | errors=("${errors[@]}" "free space ${freegb}GB") 150 | ex_stat="CRITICAL_stat" 151 | elif [ $freegb -lt $WARN ]; then 152 | errors=("${errors[@]}" "free space ${freegb}GB") 153 | ex_stat="WARNING_stat" 154 | fi 155 | fi 156 | 157 | # exit with warning if errors 158 | if [ -n "$errors" ]; then 159 | sep='; ' 160 | msg=$(printf "${sep}%s" "${errors[@]}") 161 | msg=${msg:${#sep}} 162 | if [ ${ex_stat} == "CRITICAL_stat" ]; then 163 | Exit CRITICAL "${msg}" 164 | else 165 | Exit WARNING "${msg}" 166 | fi 167 | fi 168 | 169 | # exit with no errors 170 | Exit OK "${bricksfound} bricks; free space ${freegb}GB" 171 | --------------------------------------------------------------------------------