Tuesday 8 March 2016

Nagios Plugin to check used space

Here is very simple Nagios plugin in shells script which can be be used to check the used disc space in server and accordingly can be get alert mail.

  • If used space less than 70%, then output status remains "OK"
  • if used space >=70% and < 90%, then output status will be "WARNING"
  • If used space >=90%, then output status will be "CRITICAL"
  • If none of the above, then output status will be "Unknown" 

Following is the script for the above requirements :
#!/bin/bash

# Script Name : usedSpace.sh
# Description : This script will check total used space in % of current disc .


used_space=`df -h / | grep -v Filesystem | awk '{print $5}' | sed 's/%//g'`

case "$used_space" in
        [1-9]|1[0-9]|2[0-9]|3[0-9]|4[0-9]|5[0-9]|6[0-9])
                echo "OK - $used_space% of disk space used."
                exit 0
                ;;
        7[0-9]|8[0-9])
                echo "WARNING - $used_space% of disk space used."
                exit 1
                ;;
        9[0-9]|100)
                echo "CRITICAL - $used_space% of disk space used."
                exit 2
                ;;
        *)
                echo "UNKNOWN - $used_space% of disk space used."
                exit 3
                ;;
esac


You can change script as per your used space percentage and can set the email alerting if it is in "WARNING", "CRITICAL" or "UNKNOWN" state.


No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...