Skip to content
Snippets Groups Projects
Select Git revision
  • d300be2d5ac7eb8ed722efee302bbca10b9e8a3a
  • master default protected
  • devel
  • hruska-feature-clients-api
  • malostik-#5066-deduplicate-idea-ids
  • warden-postgresql-port
  • hruska-feature-#6799-filter-keys
  • hruska-feature-5066-duplicateIdeaID
  • warden-client-3.0-beta3
  • warden-server-3.0-beta3
  • warden-client-2.2-final
  • warden-server-2.2-final
  • warden-client-3.0-beta2
  • warden-server-3.0-beta2
  • warden-client-2.2
  • warden-server-2.2-patch3
  • warden-client-3.0-beta1
  • warden-server-3.0-beta1
  • warden-server-2.2-patch1
  • warden-client-3.0-beta0
  • warden-server-3.0-beta0
  • warden-server-2.2
  • warden-server-2.1-patch1
  • warden-client-2.1
  • warden-server-2.1
  • warden-server-2.1-beta6
  • warden-server-2.1-beta5
  • warden-server-2.1-beta4
28 results

check_file_count

Blame
  • Pavel Kácha's avatar
    Pavel Kácha authored
    Shuffle directories and filenames to get rid of historic cruft and to better reflect contrib/production status
    898886a0
    History
    check_file_count 940 B
    #!/bin/bash
    
    script=${0##*/}
    warn=0
    crit=65536
    read -rd '' helps <<EOF
    $script: Icinga plugin to check too high number of files in directory.
    
    Usage: $script -d dir [-w num] [-c num] [-h ]
    
      -d dir    directory to watch
      -w num    warning if number of files exceeds this value (default $warn)
      -c num    critical if number of files exceeds this value (default $crit)
    EOF
    
    function bailout {
    	echo -n "$script" | tr '[:lower:]' '[:upper:]'
    	echo " $2 $3"
    	exit "$1"
    }
    
    while getopts hvVd:w:c: opt; do
    	case "$opt" in
    		h) bailout 3 "UNKNOWN" "$helps";;
    		d) dir="$OPTARG";;
    		w) warn="$OPTARG";;
    		c) crit="$OPTARG";;
    		"?") bailout 3 "UNKNOWN" "Unknown option, use -h for help";;
    	esac
    done
    
    [ -z "$dir" ] && bailout 3 "UNKNOWN" "-d not specified"
    
    count=$(find "$dir" -mindepth 1 -maxdepth 1 | wc -l)
    
    [ "$count" -gt "$crit" ] && bailout 2 "CRIT" "$count"
    
    [ "$count" -gt "$warn" ] && bailout 1 "WARN" "$count"
    
    bailout 0 "OK" "$count"