Skip to content

Commit

Permalink
Merge pull request #2 from mmallejac/master
Browse files Browse the repository at this point in the history
Add non-mandatory sftp option
  • Loading branch information
janvonde authored Jul 31, 2020
2 parents 105f821 + 8437445 commit fea721c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ See also: http://wiki.hetzner.de/index.php/Backup_Space_SSH_Keys
### Usage
Try the plugin at the command line like this:
```
./check_sftpsace.sh -h [host] -u [user] -w [warn] -c [crit]
./check_sftpsace.sh -h [host] -u [user] [ -o sftpOpt ] -w [warn] -c [crit]
```

Replace the variables:
* __host__: sftp host to connect to
* __user__: username at the sftp server
* __sftpOpt__: extra sftp option, e.g. `port=23`
* __warn__: percentage of needed minimum free space before warning
* __crit__: percentage of needed minimum free space before critical

Expand All @@ -49,6 +50,10 @@ object CheckCommand "sftpspace" {
"required" = true
"value" = "$ss_user$"
}
"-o" = {
"required" = false
"value" = "$ss_sftpOpt$"
}
"-w" = {
"required" = true
"value" = "$ss_warn$"
Expand Down
16 changes: 10 additions & 6 deletions check_sftpspace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,26 @@
# Copyright (c) 2017 Jan Vonde <[email protected]>
#
#
# Usage: ./check_sftpsace.sh -h [host] -u [user] -w [warn] -c [crit]
# Usage: ./check_sftpsace.sh -h [host] -u [user] [ -o sftpOption ] -w [warn] -c [crit]
#
#
# Changelog:
# 2015-12-07: initial Version
# 2017-01-01: remove unused comments, fix WARN and CRIT, add perfdata
# 2020-07-30: add -o option
#
# For more information visit https://github.com/janvonde/check_sftpspace
#####


USAGE="Usage: check_sftpsace.sh -h [host] -u [user] -w [warn] -c [crit]"
USAGE="Usage: check_sftpsace.sh -h [host] -u [user] [ -o sftpOption] -w [warn] -c [crit]"

if [ $# == 8 ]; then
while getopts "h:u:w:c:" OPCOES; do
if [ $# -ge 8 ]; then
while getopts "h:u:o::w:c:" OPCOES; do
case $OPCOES in
h ) SFTPHOST=$OPTARG;;
u ) SFTPUSER=$OPTARG;;
o ) SFTPOPTN=$OPTARG;;
w ) WARN=$OPTARG;;
c ) CRIT=$OPTARG;;
? ) echo $USAGE
Expand All @@ -42,10 +44,12 @@ fi
## error handling
type -P sftp &>/dev/null || { echo "ERROR: sftp is required but seems not to be installed. Aborting." >&2; exit 1; }

## sftp extra opt
[ -z $SFTPOPTN ] && SFTPOPTN="port=22"


## get info and store
RESULT=$(echo "df -h" | sftp ${SFTPUSER}@${SFTPHOST} 2>&1 | tail -1 | column -t)
RESULT=$(echo "df -h" | sftp -o $SFTPOPTN ${SFTPUSER}@${SFTPHOST} 2>&1 | tail -1 | column -t)
read TOTAL USED AVAILABLE ROOT PERCENT <<< $RESULT
PERCENT=$(expr 100 - ${PERCENT/\%/})

Expand All @@ -63,6 +67,6 @@ if [ ${PERCENT} -lt ${WARN} ]; then
fi


echo "OK - ${AVAILABLE} free space: (${USED} out of ${TOTAL} or ${PERCENT}% used) |sftp_disk_usage=${USED};${WARN};${CRIT};0;${TOTAL}"
echo "OK - ${AVAILABLE} free space: (${USED} out of ${TOTAL} or ${PERCENT}% free) |sftp_disk_usage=${USED};${WARN};${CRIT};0;${TOTAL}"
exit 0

0 comments on commit fea721c

Please sign in to comment.