#!/bin/bash ############################################################################## # Bash script written by Vahid Hedayati April 2013 ############################################################################## # 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 . ############################################################################## # This script takes: # snmpwalk="/usr/bin/snmpwalk" snmpget="/usr/bin/snmpget" function usage() { echo "$0 localhost public 100" echo "where localhost is server" echo "public is snmp pass" echo "100 is when swap reaches below a 100Mb" echo "-----------------------------------" } server=$1; pass=$2; limit=$3; if [ $# -lt 3 ]; then usage; exit 1; fi run=$(snmpget -v2c -c $pass $server .1.3.6.1.4.1.2021.4.4.0) if [[ $run =~ "INTEGER" ]]; then free=$(echo $run|awk -F"INTEGER: " '{smb=( $2 / 1024); print smb}') if [[ $free > $limit ]]; then graph="swap="$free"MB;;;0" echo "SWAP OK: Free $free MB.|$graph" exit 0; else graph="swap="$free"MB;;;0" echo "SWAP CRITICAL: Free $free MB.|$graph" exit 2; fi else graph="swap=0MB;;;0" echo "SWAP CRITICAL: does not exist|$graph"; exit 2; fi