#!/bin/sh # 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. # #logfile="/tmp/$1.txt" comstr="public" indx_oid="1.3.6.1.2.1.47.1.1.1.1.7" baseoid="1.3.6.1.2.1.47.1.1.1.1.2" initialoid="iso.3.6.1.4.1.9.9.91.1.1.1.1.4" snmp_index_qry="0" VERSION="1.0" ########### #FUNCTIONS# ########### print_version() { echo "$SCRIPTNAME" version "$VERSION" echo "This nagios plugins comes with ABSOLUTELY NO WARRANTY." echo "Author: Zahid Hussain" echo "Islamabad, 2016" } print_help() { print_version echo "" print_usage echo "**** Check the RSP of Cisco ASR9K Temperature Status ****" echo "" echo -e "Usage: check_cpu -H [host] -R [RSP0/RSP1] -t [Inlet/Outlet] -w [warn] -c [crit] \n -H Hostname to query \n -R RSP Num (e.g. RSP0)\n -t SensorType ( Inlet or Outlet ) \n -h Print Help \n -V Print version" } # Arguments while getopts H:R:t:W:C:hV OPT do case "$OPT" in H) host="$OPTARG" ;; R) RSPNum="$OPTARG" ;; t) Sensortype="$OPTARG";; W) warn="$OPTARG";; C) crit="$OPTARG";; h) print_help exit 0 ;; V) print_version exit 0 ;; esac done # i=0 for indices in $(snmpwalk -v2c -c $comstr $host $indx_oid | grep $RSPNum | grep -vE "Mgm|mod|vol|com|cpu|slot" | sed 's/^.*\.//g' | cut -d= -f1 | sed 's/[ \t]*$//') do arr[i]=$indices snmpwalk -v2c -c $comstr $host $baseoid.${arr[$i]} | grep $Sensortype | sed 's/^.*\.//g' | cut -d= -f1 |sed 's/ //' > /dev/null if [ "${PIPESTATUS[1]}" -eq "0" ];then modindex=${arr[$i]};i=$((i+1));fi done temp_oid="$initialoid.$modindex" temp_figure=$(snmpwalk -v2c -c $comstr $host $temp_oid | cut -d: -f4 | sed 's/ //' | cut -c -2 ) Perf_Data=" "$temp_figure" | $RSPNum"_Temp"="$temp_figure";"$warn";"$crit" " if [[ $temp_figure -lt $warn || $temp_figure -eq $warn ]] ; then echo "OK - $Perf_Data" exit 0 elif [[ $temp_figure -gt $warn && $temp_figure -lt $crit ]] ; then echo "Warning - $Perf_Data" exit 1 elif [[ $temp_figure -gt $crit || $temp_figure -eq $crit ]]; then echo "Critical - $Perf_Data" exit 2 else echo "$temp_figure;$warn;$crit;Unknown" exit 3 fi