以前有的用户需要对F5上配置的业务进行监控,会索要每个业务甚至于每个节点的一些信息,因为不同的配置有不同的名称,所以oid并不是固定的,只要配置名字有变化,oid就会出现变化,现贴出获取一些oid的方法,以供备用。不喜勿喷。
#!/bin/bashfunction define(){ user=`whoami` path=/tmp/snmp/ vs_curconn_oid_tmp=${path}vs_curconn_oid.tmp vs_curconn_name_tmp=${path}vs_curconn_name.tmp vs_curconn=${path}vs_curconn.txt vs_totconn_oid_tmp=${path}vs_totconn_oid.tmp vs_totconn_name_tmp=${path}vs_totconn_name.tmp vs_totconn=${path}vs_totconn.txt vs_maxconn_oid_tmp=${path}vs_maxconn_oid.tmp vs_maxconn_name_tmp=${path}vs_maxconn_name.tmp vs_maxconn=${path}vs_maxconn.txt pool_curconn_oid_tmp=${path}pool_curconn_oid.tmp pool_curconn_name_tmp=${path}pool_curconn_name.tmp pool_curconn=${path}pool_curconn.txt pool_totconn_oid_tmp=${path}pool_totconn_oid.tmp pool_totconn_name_tmp=${path}pool_totconn_name.tmp pool_totconn=${path}pool_totconn.txt pool_maxconn_oid_tmp=${path}pool_maxconn_oid.tmp pool_maxconn_name_tmp=${path}pool_maxconn_name.tmp pool_maxconn=${path}pool_maxconn.txt member_curconn_oid_tmp=${path}member_curconn_oid.tmp member_curconn_name_tmp=${path}member_curconn_name.tmp member_curconn=${path}member_curconn.txt member_totconn_oid_tmp=${path}member_totconn_oid.tmp member_totconn_name_tmp=${path}member_totconn_name.tmp member_totconn=${path}member_totconn.txt member_maxconn_oid_tmp=${path}member_maxconn_oid.tmp member_maxconn_name_tmp=${path}member_maxconn_name.tmp member_maxconn=${path}member_maxconn.txt}function check(){ if [ $user != root ] then echo "Please use root user." exit 1 fi if [ ! -d $path ] then mkdir $path fi}function line(){ cols=`tput cols` for l in `seq 1 ${cols}` do echo -n "=" done}function vs_curconn_start(){ snmpwalk -v 2c -c public localhost -On .1.3.6.1.4.1.3375.2.2.10.2.3.1.12 > $vs_curconn_oid_tmp snmpwalk -v 2c -c public localhost .1.3.6.1.4.1.3375.2.2.10.2.3.1.12 > $vs_curconn_name_tmp count=0 while read line do count=$((${count}+1)) eval vs_count_oid${count}=`echo $line | awk '{print $1}'` done < $vs_curconn_oid_tmp count=0 while read line do count=$((${count}+1)) eval vs_count_name${count}=`echo $line | awk -F '\"' '{print $2}'` done < $vs_curconn_name_tmp line >> $vs_curconn echo -e "LTM Virtual Server Client Current Connections" >> $vs_curconn echo "" >> $vs_curconn for i in `seq 1 $count` do eval echo -n "\${vs_count_name${i}}" >> $vs_curconn echo -en "\t\t" >> $vs_curconn eval echo "\${vs_count_oid${i}}" >> $vs_curconn done line >> $vs_curconn}function vs_totconn_start(){ snmpwalk -v 2c -c public localhost -On .1.3.6.1.4.1.3375.2.2.10.2.3.1.11 > $vs_totconn_oid_tmp snmpwalk -v 2c -c public localhost .1.3.6.1.4.1.3375.2.2.10.2.3.1.11 > $vs_totconn_name_tmp count=0 while read line do count=$((${count}+1)) eval vs_count_oid${count}=`echo $line | awk '{print $1}'` done < $vs_totconn_oid_tmp count=0 while read line do count=$((${count}+1)) eval vs_count_name${count}=`echo $line | awk -F '\"' '{print $2}'` done < $vs_totconn_name_tmp line >> $vs_totconn echo -e "LTM Virtual Server Client Total Connections" >> $vs_totconn echo "" >> $vs_totconn for i in `seq 1 $count` do eval echo -n "\${vs_count_name${i}}" >> $vs_totconn echo -en "\t\t" >> $vs_totconn eval echo "\${vs_count_oid${i}}" >> $vs_totconn done line >> $vs_totconn} function vs_maxconn_start(){ snmpwalk -v 2c -c public localhost -On .1.3.6.1.4.1.3375.2.2.10.2.3.1.10 > $vs_maxconn_oid_tmp snmpwalk -v 2c -c public localhost .1.3.6.1.4.1.3375.2.2.10.2.3.1.10 > $vs_maxconn_name_tmp count=0 while read line do count=$((${count}+1)) eval vs_count_oid${count}=`echo $line | awk '{print $1}'` done < $vs_maxconn_oid_tmp count=0 while read line do count=$((${count}+1)) eval vs_count_name${count}=`echo $line | awk -F '\"' '{print $2}'` done < $vs_maxconn_name_tmp line >> $vs_maxconn echo -e "LTM Virtual Server Client Maximum Connections" >> $vs_maxconn echo "" >> $vs_maxconn for i in `seq 1 $count` do eval echo -n "\${vs_count_name${i}}" >> $vs_maxconn echo -en "\t\t" >> $vs_maxconn eval echo "\${vs_count_oid${i}}" >> $vs_maxconn done line >> $vs_maxconn} function pool_curconn_start(){ snmpwalk -v 2c -c public localhost -On .1.3.6.1.4.1.3375.2.2.5.2.3.1.8 > $pool_curconn_oid_tmp snmpwalk -v 2c -c public localhost .1.3.6.1.4.1.3375.2.2.5.2.3.1.8 > $pool_curconn_name_tmp count=0 while read line do count=$((${count}+1)) eval pool_count_oid${count}=`echo $line | awk '{print $1}'` done < $pool_curconn_oid_tmp count=0 while read line do count=$((${count}+1)) eval pool_count_name${count}=`echo $line | awk -F '\"' '{print $2}'` done < $pool_curconn_name_tmp line >> $pool_curconn echo -e "LTM Pool Server Current Connections" >> $pool_curconn echo "" >> $pool_curconn for i in `seq 1 $count` do eval echo -n "\${pool_count_name${i}}" >> $pool_curconn echo -en "\t\t" >> $pool_curconn eval echo "\${pool_count_oid${i}}" >> $pool_curconn done line >> $pool_curconn}function pool_totconn_start(){ snmpwalk -v 2c -c public localhost -On .1.3.6.1.4.1.3375.2.2.5.2.3.1.7 > $pool_totconn_oid_tmp snmpwalk -v 2c -c public localhost .1.3.6.1.4.1.3375.2.2.5.2.3.1.7 > $pool_totconn_name_tmp count=0 while read line do count=$((${count}+1)) eval pool_count_oid${count}=`echo $line | awk '{print $1}'` done < $pool_totconn_oid_tmp count=0 while read line do count=$((${count}+1)) eval pool_count_name${count}=`echo $line | awk -F '\"' '{print $2}'` done < $pool_totconn_name_tmp line >> $pool_totconn echo -e "LTM Pool Server Total Connections" >> $pool_totconn echo "" >> $pool_totconn for i in `seq 1 $count` do eval echo -n "\${pool_count_name${i}}" >> $pool_totconn echo -en "\t\t" >> $pool_totconn eval echo "\${pool_count_oid${i}}" >> $pool_totconn done line >> $pool_totconn} function pool_maxconn_start(){ snmpwalk -v 2c -c public localhost -On .1.3.6.1.4.1.3375.2.2.5.2.3.1.6 > $pool_maxconn_oid_tmp snmpwalk -v 2c -c public localhost .1.3.6.1.4.1.3375.2.2.5.2.3.1.6 > $pool_maxconn_name_tmp count=0 while read line do count=$((${count}+1)) eval pool_count_oid${count}=`echo $line | awk '{print $1}'` done < $pool_maxconn_oid_tmp count=0 while read line do count=$((${count}+1)) eval pool_count_name${count}=`echo $line | awk -F '\"' '{print $2}'` done < $pool_maxconn_name_tmp line >> $pool_maxconn echo -e "LTM Pool Server Maximum Connections" >> $pool_maxconn echo "" >> $pool_maxconn for i in `seq 1 $count` do eval echo -n "\${pool_count_name${i}}" >> $pool_maxconn echo -en "\t\t" >> $pool_maxconn eval echo "\${pool_count_oid${i}}" >> $pool_maxconn done line >> $pool_maxconn} function member_curconn_start(){ snmpwalk -v 2c -c public localhost -On .1.3.6.1.4.1.3375.2.2.5.4.3.1.11 > $member_curconn_oid_tmp snmpwalk -v 2c -c public localhost .1.3.6.1.4.1.3375.2.2.5.4.3.1.11 > $member_curconn_name_tmp count=0 while read line do count=$((${count}+1)) eval member_count_oid${count}=`echo $line | awk '{print $1}'` done < $member_curconn_oid_tmp count=0 while read line do count=$((${count}+1)) eval member_count_name${count}=`echo $line | awk -F '[\"|.| ]+' '{print $2"-"$4"."$5"."$6"."$7":"$8}'` done < $member_curconn_name_tmp line >> $member_curconn echo -e "LTM Pool Member Server Current Connections" >> $member_curconn echo "" >> $member_curconn for i in `seq 1 $count` do eval echo -n "\${member_count_name${i}}" >> $member_curconn echo -en "\t\t" >> $member_curconn eval echo "\${member_count_oid${i}}" >> $member_curconn done line >> $member_curconn}function member_totconn_start(){ snmpwalk -v 2c -c public localhost -On .1.3.6.1.4.1.3375.2.2.5.4.3.1.10 > $member_totconn_oid_tmp snmpwalk -v 2c -c public localhost .1.3.6.1.4.1.3375.2.2.5.4.3.1.10 > $member_totconn_name_tmp count=0 while read line do count=$((${count}+1)) eval member_count_oid${count}=`echo $line | awk '{print $1}'` done < $member_totconn_oid_tmp count=0 while read line do count=$((${count}+1)) eval member_count_name${count}=`echo $line | awk -F '[\"|.| ]+' '{print $2"-"$4"."$5"."$6"."$7":"$8}'` done < $member_totconn_name_tmp line >> $member_totconn echo -e "LTM Pool Member Server Total Connections" >> $member_totconn echo "" >> $member_totconn for i in `seq 1 $count` do eval echo -n "\${member_count_name${i}}" >> $member_totconn echo -en "\t\t" >> $member_totconn eval echo "\${member_count_oid${i}}" >> $member_totconn done line >> $member_totconn}function member_maxconn_start(){ snmpwalk -v 2c -c public localhost -On .1.3.6.1.4.1.3375.2.2.5.4.3.1.9 > $member_maxconn_oid_tmp snmpwalk -v 2c -c public localhost .1.3.6.1.4.1.3375.2.2.5.4.3.1.9 > $member_maxconn_name_tmp count=0 while read line do count=$((${count}+1)) eval member_count_oid${count}=`echo $line | awk '{print $1}'` done < $member_maxconn_oid_tmp count=0 while read line do count=$((${count}+1)) eval member_count_name${count}=`echo $line | awk -F '[\"|.| ]+' '{print $2"-"$4"."$5"."$6"."$7":"$8}'` done < $member_maxconn_name_tmp line >> $member_maxconn echo -e "LTM Pool Member Server Maximum Connections" >> $member_maxconn echo "" >> $member_maxconn for i in `seq 1 $count` do eval echo -n "\${member_count_name${i}}" >> $member_maxconn echo -en "\t\t" >> $member_maxconn eval echo "\${member_count_oid${i}}" >> $member_maxconn done line >> $member_maxconn}function delete_tmp(){ find $path -type f -name "*.tmp" | xargs rm -f {}}function main(){ define check vs_curconn_start vs_totconn_start vs_maxconn_start pool_curconn_start pool_totconn_start pool_maxconn_start member_curconn_start member_totconn_start member_maxconn_start delete_tmp}main