Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
janvonde committed Jan 29, 2017
0 parents commit 415a5b9
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 0 deletions.
73 changes: 73 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# check_sftpspace

This is a monitoring plugin for [icinga](https://www.icinga.com) to check the free space on a sftp share.

It was initially developed by [intranda GmbH](http://www.intranda.com).


### Requirements
This script requires a working key authentication without password to the sftp host. You can set it up like this:

```
ssh-keygen -t rsa
ssh-keygen -e -f ~/.ssh/id_rsa.pub | grep -v "Comment:" > ~/.ssh/id_rsa_rfc.pub
cat ~/.ssh/id_rsa_rfc.pub >> backup_authorized_keys
echo mkdir .ssh | sftp USER@HOST
scp backup_authorized_keys USER@HOST:.ssh/authorized_keys
```
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]
```

Replace the variables:
* __host__: sftp host to connect to
* __user__: username at the sftp server
* __warn__: percentage of needed minimum free space before warning
* __crit__: percentage of needed minimum free space before critical



You can define the icinga2 check command as follows:
```
/* Define check command for check_piwik */
object CheckCommand "sftpspace" {
import "plugin-check-command"
command = [ PluginDir + "/check_sftpspace.sh" ]
arguments = {
"-h" = {
"required" = true
"value" = "$ss_host$"
}
"-u" = {
"required" = true
"value" = "$ss_user$"
}
"-w" = {
"required" = true
"value" = "$ss_warn$"
}
"-c" = {
"required" = true
"value" = "$ss_crit$"
}
}
vars.ss_warn = 30
vars.ss_crit = 10
}
```
### License
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, or (at your option) any later version.

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 General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

68 changes: 68 additions & 0 deletions check_sftpspace.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/bin/bash

#####
#
# Monitoring plugin to check free space on SFTP share
#
# Copyright (c) 2015 intranda GmbH
# Copyright (c) 2017 Jan Vonde <[email protected]>
#
#
# Usage: ./check_sftpsace.sh -h [host] -u [user] -w [warn] -c [crit]
#
#
# Changelog:
# 2015-12-07: initial Version
# 2017-01-01: remove unused comments, fix WARN and CRIT, add perfdata
#
# For more information visit https://github.com/janvonde/check_sftpspace
#####


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

if [ $# == 8 ]; then
while getopts "h:u:w:c:" OPCOES; do
case $OPCOES in
h ) SFTPHOST=$OPTARG;;
u ) SFTPUSER=$OPTARG;;
w ) WARN=$OPTARG;;
c ) CRIT=$OPTARG;;
? ) echo $USAGE
exit 1;;
* ) echo $USAGE
exit 1;;
esac
done
else echo $USAGE; exit 3
fi



## error handling
type -P sftp &>/dev/null || { echo "ERROR: sftp is required but seems not to be installed. Aborting." >&2; exit 1; }



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



## check and return info
if [ ${PERCENT} -lt ${CRIT} ]; then
echo "CRITICAL: ${PERCENT}% free disk space: ${AVAILABLE} from ${TOTAL} |sftp_disk_usage=${USED};${WARN};${CRIT};0;${TOTAL}"
exit 2
fi

if [ ${PERCENT} -lt ${WARN} ]; then
echo "WARNING: ${PERCENT}% free disk space: ${AVAILABLE} from ${TOTAL} |sftp_disk_usage=${USED};${WARN};${CRIT};0;${TOTAL}"
exit 1
fi


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

18 changes: 18 additions & 0 deletions icingaexchange.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: check_sftpspace
description: "file:///README.md"
url: "https://github.com/janvonde/check_sftpspace"
tags: sftp,ssh,remote,space,df
vendor: Linux
target: Operating System
type: Plugin
license: gplv3
releases:
-
name: 1.0
description: "1.0 Release"
files:
-
name: check_sftpspace.sh
url: "file:///check_sftpspace.sh"
description: "initial release"
checksum: d0241fd279edb6f4f715f10f7f466f30

0 comments on commit 415a5b9

Please sign in to comment.