f5 负载均衡巡检脚本

f5 负载均衡巡检脚本

1.适用软件版本

f5 bigip ltm 9.1.1 --10.2.4

2.巡检内容

主机名,SN号,管理IP,配置同步状态,主备状态,cpu、内存使用,snmp trap和access配置,当前连接数,新建连接数,电源状态和数量,系统的温度,系统的启动时间,ntp的状态,HA 特性,网络的failover状态;

3.适用设备型号

bigip 1500,bigip3400,bigip6400 ,bigip6900,bigip1600,bigip3600;

4.脚本内容

 

#!/bin/bash
#DATE 20170227
#AUTHOR Huang
#DESCRIPTION:Script only for bigip ltm checking
function Tmm_cpu() 
{
    #cpu usage calcuation
    #"((<DeltaTmTotalCycles> - (<DeltaTmIdleCycles> + <DeltaTmSleepCycles>)) / <DeltaTmTotalCycles>) *100"
    h="localhost"
    cmd="snmpwalk -cpublic -v2c"
    sysStatTmTotalCycles=".1.3.6.1.4.1.3375.2.1.1.2.1.41"
    sysStatTmIdleCycles=".1.3.6.1.4.1.3375.2.1.1.2.1.42"
    sysStatTmSleepCycles=".1.3.6.1.4.1.3375.2.1.1.2.1.43"
    tag=$(snmpwalk -cpublic -v2c $h ".1.3.6.1.4.1.3375.2.1.1.2.1.45")
    if [ $? -eq 0 ];then
        total_init=$($cmd $h $sysStatTmTotalCycles|awk '{print $NF}')
        idle_init=$($cmd $h $sysStatTmIdleCycles|awk '{print $NF}')
        slp_init=$($cmd $h sysStatTmSleepCycles|awk '{print $NF}')
        sleep 30s
        total_ter=$($cmd $h $sysStatTmTotalCycles|awk '{print $NF}')
        idle_ter=$($cmd $h $sysStatTmIdleCycles|awk '{print $NF}')
        slp_ter=$($cmd $h sysStatTmSleepCycles|awk '{print $NF}')
    else
        echo -e "\033[31m Something is wrong,$(snmpwalk -cpublic -v2c $h ".1.3.6.1.4.1.3375.2.1.1.2.1") \33[5m"
        break
    fi
    declare -i ds
    declare -i dtt
    declare -i dti
    delta_tm_total=$(($total_ter-$total_init))
    dtt=${delta_tm_total#-}
    delta_tm_idle=$(($idle_ter-$idle_init))
    dti=${delta_tm_idle#-}
    delta_sleep=$(($slp_ter-$slp_init))
    ds=${delta_sleep#-}
    cpu_consum=$(($dtt-$dti-$ds))
    #echo "$dtt"
    cpu_usage=$(echo "$cpu_consum $dtt"|awk '{printf "%.2f",$1/$2*100}')
    echo $cpu_usage
}
function Module_type()
{

    ifcount=`b interface list |grep -v mgmt |grep interface|wc -l`
    cpucount=`cat /proc/cpuinfo |grep  processor|wc -l`
    #echo $ifcount,$cpucount
    if [ $cpucount -eq 2 -a $ifcount -eq 6 ];then
        #echo "device type:BIGIP 1600"
        tp='1600'

    fi

    if  [ $cpucount -eq 1 -a $ifcount -eq 6 ];then
            #echo "device type:BIGIP 1500"
            tp='1500'
    fi
    if [ $cpucount -eq 1 -a $ifcount -eq 10 ];then
            #echo "device type:BIGIP 3400"
            tp='3400'
    fi
    if [ $cpucount -eq 2 -a $ifcount -eq 10 ];then
            #echo "device type:BIGIP 3600"
            tp='3600'
    fi
    if [ $cpucount -eq 2 -a $ifcount -eq 20 ];then
            #echo "device type:BIGIP 6400"
            tp='6400'
    fi
    if [ $cpucount -eq 4 -a $ifcount -eq 20 ];then
            #echo "device type:BIGIP 6900"
            tp='6900'
    fi
    if [ $cpucount -eq 8 -a $ifcount -eq 26 ];then
            #echo "device type:BIGIP 8900"
            tp='8900'
    fi
    echo "Device Type:$tp"
}
function MEMORY_USAGE()
{
    if [ $type =="1600" -o $type=="8900" -o $type=="3600" ];then
    #1600,8900,3600

        mem_usage=$(b memory show |grep TMM|awk 'gsub(/GB|MB/,"",$0) {printf "%.2f\n",$8/1024/$5*100}')
    #1500
    elif [ $tpye =="1500" ];then    
        mem_usage=$(b memory show |grep TMM|awk 'gsub(/MB/,"",$0) {printf "%.2f\n",$8/$5*100}')
    #3400 su di er qi 1g and 2g is different in calculation of memory method
    elif [ $type =="3400" -a `phymem -g` -eq 1 ];then
        mem_usage=$(b memory show |grep Total|awk 'gsub(/MB/,"",$0) {printf "%.2f\n",$6/$3*100}')
    elif [ $type =="3400" -a `phymem -g` -eq 2 ];then    
        mem_usage=$(b memory show |grep Total|awk 'gsub(/GB|MB/,"",$0) {printf "%.2f\n",$6/1024/$3*100}')

    #6400
    elif [ $type=="6400" ];then
        mem_usage=$(b memory show |grep Total|awk 'gsub(/GB|MB/,"",$0) {printf "%.2f\n",$6/1024/$3*100}')

    elif [ $tpye=="6900" ];then
    #6900
    mem_usage=$(b memory show |grep TMM|awk 'gsub(/GB/,"",$0) {printf "%.2f\n",$8/$5*100}')
    fi
    
    echo $mem_usage

}
function Throughput()
{
    h="localhost"
    cmd="snmpwalk -cpublic -v2c"
    sysStatClientBytesIn='.1.3.6.1.4.1.3375.2.1.1.2.1.3'
    sysStatClientBytesOut='.1.3.6.1.4.1.3375.2.1.1.2.1.5'
    sysStatServerBytesIn='.1.3.6.1.4.1.3375.2.1.1.2.1.10'
    sysStatServerBytesOut='.1.3.6.1.4.1.3375.2.1.1.2.1.12'
    tag=$(snmpwalk -cpublic -v2c $h ".1.3.6.1.4.1.3375.2.1.1.2.1.45")
    if [ $? -eq 0 ];then
        cli_byte_in1=$($cmd $h $sysStatClientBytesIn|awk '{print $NF}')
        cli_byte_out1=$($cmd $h $sysStatClientBytesOut|awk '{print $NF}')
        ser_byte_in1=$($cmd $h $sysStatServerBytesIn|awk '{print $NF}')
        ser_bype_out1=$($cmd $h $sysStatServerBytesOut|awk '{print $NF}')
        sleep 10s
        cli_byte_in2=$($cmd $h $sysStatClientBytesIn|awk '{print $NF}')
        cli_byte_out2=$($cmd $h $sysStatClientBytesOut|awk '{print $NF}')
        ser_byte_in2=$($cmd $h $sysStatServerBytesIn|awk '{print $NF}')
        ser_byte_out2=$($cmd $h $sysStatServerBytesOut|awk '{print $NF}')

    else
        echo -e "\033[31m Something about SNMP is wrong,$(snmpwalk -cpublic -v2c $h ".1.3.6.1.4.1.3375.2.1.1.2.1") \33[5m"
        break
    fi
    cli_th_byte=$((($cli_byte_in2-$cli_byte_in1)+($cli_byte_out2-$cli_byte_out1)))
    ser_th_byte=$((($ser_byte_in2-$ser_byte_in1)+($ser_byte_out2-$ser_bype_out1)))
    cli_throughput=$( echo "$cli_th_byte"|awk '{printf "%.2f",$1*0.8/1000}')
    ser_throughput=$( echo "$ser_th_byte"|awk '{printf "%.2f",$1*0.8/1000}')
    echo "client_throughput=$cli_throughput k/s ,server_throughput=$ser_throughput k/s"
}

function POWER_SUPPLY()
{
    SN=$(b platform |grep "Chassis   serial"|awk '{print $4}')
    #Currently,in our network ,there are only four bigip system which has two 
    #psu,they are 8900,6900 and new 3600.These devices have only SN number. 
    #I use the SN's md5  as the value to get  numbers of aciving and installed psu.
    X=$(echo $SN|md5sum|awk '{print $1}')
    #jizhonghesuan_erp and accouting ltm have two psu
    #ems outbound to interface  is a bigip 8900
    #oa system has a bigip 6900
    # 8900    f5-pqus-vmuu
    # 8900    f5-pnqd-fuug
    # 6900    f5-xslk-yvur
    # 6900    f5-mtop-zjpd
    # 6900    f5-kqps-ayze
    # 3600    f5-xznx-qcgn
    # 3600    f5-ithb-lyon
    # 3600    f5-sxxi-gucx
    # 3600    f5-zkzy-bcnc
    SN_array=(
    f5-pqus-vmuu
    f5-pnqd-fuug
    f5-xslk-yvur
    f5-mtop-zjpd
    f5-kqps-ayze
    f5-xznx-qcgn
    f5-ithb-lyon
    f5-sxxi-gucx
    f5-zkzy-bcnc
    )
    a_len=$((${#SN_array[@]}-1))
    for i in `seq 0 $a_len`
    do
        SN_md5[$i]=$(echo $i|md5sum|awk -F " " '{print $1}')
    done
    #echo ${SN_md5[@]}
    #Tow condictions : single core or dual,default is single mathch=0if search the SN_md5 in the array of  the known SN_md5 array
    #match is set to 1
    match=0
    for iterm in ${SN_md5[@]}
    do
        if [ "$X" == "$iterm" ];then
            match=1
        fi
    done
    case $match in 
        
        1)
            psu_installed="TWO"
            psu_active=$(b platform show  all|grep -A1 "POWER SUPPLY"|tail -1|awk -F "" '{for(i=1;i<=NF;++i) if($i=="a") ++psu_count}END{print psu_count}')
            #echo "psu_active is :$psu_active"
            ;;
        0)
            psu_installed="ONE"
            psu_active=$(b platform show  all|grep -A1 "POWER SUPPLY"|tail -1|awk -F "" '{for(i=1;i<=NF;++i) if($i=="a") ++psu_count}END{print psu_count}')
            #echo "psu_active is :$psu_active"
        ;;
    esac    
    echo "$psu_installed,$psu_active"
}
function CHASSIS_TEMPERATURE()
{
    ch_tmp=$(b platform show all |grep -A 1 "CHASSIS TEMPERATURE"|tail -1|awk '{print $4}')
    echo "CHASSIS TEMPERATURE is :$ch_tmp"
}
function UPTIME()
{
    ut=$(uptime|awk '{printf("%s days\n",$3)}')
    echo "UPTIME is:$ut"
}
function SYS_date()
{
    echo $(date +%F" "%H:%M)
}
function log_ltm()
{
    cat /var/log/ltm >>/tmp/checking.txt && zcat /var/log/ltm.* >>/tmp/checking.txt
}
function MGMT()
{
    b mgmt show|awk 'BEGIN{OFS=":"}{print $1,$2}'
}
function SNMP_agent()
{
    #the allowed snmp manager IP address or network
    Client_Allow_List=$(b snmpd allow show |grep -Ev 'SNMPD|127'|sed 's/ //g')
    #community config segment
    COMMUNITY_conf=$(b snmpd community all show|grep -v pub|awk '{print $NF}')
    #get community strings
    COMMUNITY_name=$(b snmpd community "$COMMUNITY_conf" community name show|awk '{print $NF}')
    READ_WRITE_access=$(b snmpd community "$COMMUNITY_conf" access show|awk '{print $NF}')
    ACCESS_oid=$(b snmpd community "$COMMUNITY_conf"  oid show|awk -F "-" '{print $2}')
    SNMP_Manager_ip=$(b snmpd community "$COMMUNITY_conf" source show|awk -F: '{print $NF}')
    
    printf "%s\n" "Acess_IP_list=$Client_Allow_List" "COMMUNITYR_AME=$COMMUNITY_name" \
    "ACCESSR_EVEL=$READ_WRITE_access" "SNMP_MANAGER_IP=$SNMP_Manager_ip" "SNMP_OID=$ACCESS_oid"
}
function SNMP_trap()
{
    #SNMP trap enable or disable information
    SNMP_trap_fun=$(b snmpd agenttrap show|awk '{print $NF}')
    DEV_traps=$(b snmpd bigip traps show|awk '{print $NF}')
    #TRAPs iterms
    TRAP_iterms=$(b snmpd trapsess all show|awk '{print $NF}')
    for i in $TRAP_iterms
    do
        TRAP_ver=$(b snmpd trapsess $i version show |awk '{print $NF}')
        TRAP_comm=$(b snmpd trapsess $i community show |awk '{print $NF}')
        TRAP_host=$(b snmpd trapsess $i host show|awk '{print $NF}')
        TRAP_host_port=$(b snmpd trapsess $i port show|awk '{print $NF}')
        echo -e "TRAP_iterm=$i\nTRAP_version=$TRAP_ver\nTRAP_community=$TRAP_comm\nTRAP_host=$TRAP_host\nTRAP_host_port=$TRAP_host_port\n"
    done
    echo -e "TRAP_functions=$SNMP_trap_fun\nBIGIP_traps_function=$DEV_traps\n"
}
function syslog_setting()
{
    remote_host=$(b syslog list all |grep server|awk '{print $NF}')
    if [ "$remote_host"=="none" ] ;then
        echo "Syslog server is not setting"
    else
        echo "Syslog server is:$remote_host"
    fi    
}
function DEV_Acc_control()
{
    http_ip=$(b httpd list all|grep -w "All"|sed 's/"//g'|awk '{print $NF}')
    if [ "$all_ip"=="All" ];then
        HTTP_all="All ip is allowed to manage by http method."
    else
        HTTP_all="The allowed ip is:$all_ip by http method."
    fi
    
    ssh_ip=$(b sshd list all|grep -wi "All"|sed 's/"//g'|awk '{print $NF}')
    
    if [ "$ssh_ip"=="ALL" ];then
        SSH_all="All ip is allowed to manage by ssh method."
    else
        SSH_all="The allowed ip is:$ssh_ip by ssh method."
    fi
    
    echo -e "$HTTP_all\n$SSH_all"
}
function NET_failover()
{
    net_fail_state=$(b failover network failover show|awk '{print $NF}')
    if [ "$net_fail_state"=="disable" ];then
        echo "NETWORK failover is disabled."
    elif [ "$net_fail_state"=="enable" ];then
        echo "NETWORK failover is enabled."
    else
        echo "NETWORK failover is $net_fail_state"
    fi
}
function HA_feature()
{    b ha table all show|grep -E "VLAN|gateway"
    if [ $? -eq 0 ];then
        b ha table all show|grep -E "VLAN|gateway"|awk '{if ($5=="yes") {print $1,$2,$3,"is enabled"} else {print $1,$2,$3,"is disabled"}}'
    else
        echo "Fail safe feature is disabled."
    fi
}
function ACT_Conn()
{

    h="localhost"
    cmd="snmpwalk -cpublic -v2c"
    sysStatClientCurConns=".1.3.6.1.4.1.3375.2.1.1.2.1.8"
    act_swap=$($cmd $h $sysStatClientCurConns)
    act_conn=${act_swap##F5-BIGIP-SYSTEM-MIB::sysStatClientCurConns.0 = Counter64: }
    echo "Active connestions are:$act_conn"

}
function NEW_conn()
{
    h="localhost"
    cmd="snmpwalk -cpublic -v2c"
    sysTcpStatAccepts=".1.3.6.1.4.1.3375.2.1.1.2.12.6"
    sysStatServerTotConns=".1.3.6.1.4.1.3375.2.1.1.2.1.14"
    
    cli_acc_swap1=$($cmd $h $sysTcpStatAccepts)
    cli_accept1=${cli_acc_swap1##F5-BIGIP-SYSTEM-MIB::sysTcpStatAccepts.0 = Counter64: }
    ser_conn_swap1=$($cmd $h $sysStatServerTotConns)
    ser_conn1=${ser_conn_swap1##F5-BIGIP-SYSTEM-MIB::sysStatServerTotConns.0 = Counter64: }
    sleep 10s
    cli_acc_swap2=$($cmd $h $sysTcpStatAccepts)
    cli_accept2=${cli_acc_swap2##F5-BIGIP-SYSTEM-MIB::sysTcpStatAccepts.0 = Counter64: }
    ser_conn_swap2=$($cmd $h $sysStatServerTotConns)
    ser_conn2=${ser_conn_swap2##F5-BIGIP-SYSTEM-MIB::sysStatServerTotConns.0 = Counter64: }
    
    delta_c_a=$(($cli_accept2-$cli_accept1))
    delta_s_conn=$(($ser_conn2-$ser_conn1))
    echo "$delta_c_a $delta_s_conn" |awk '{printf "ClientSideCon:%.1f\tSerSideCon:%.1f\n",$1/10,$2/10}'
}

# SN judgement
function DEV_sn()
{
    SN=$(b platform |grep "Chassis   serial"|awk '{print $4}')
    echo "Device Serial Number:$SN"
}
#HOSTNAME
function DEV_hn()
{
    HN=$(b system hostname |awk -F: '{print $2}')
    echo "Hostname:$HN"
}
#dev_IP
function DEV_ip()
{
    IP_arr=($(b self list|grep self|grep -v '1.1.1'|awk '{print $2}'))
    len_arr=${#IP_arr[@]}
    rand=$(($RANDOM%$len_arr))
    #get a random ip
    dev_ip=${IP_arr[rand]}
    echo "DEVICE IP:$dev_ip"
}
#bigip software version info
function SOFT_ver()
{
    soft_ver=$(b version show |grep  BIG-IP|awk '{print $3,$4}')
    echo "BIGIP VERSION:$soft_ver"
}

Module_type
DEV_sn
DEV_hn
DEV_ip
SOFT_ver
echo "SUPPORT ENGINEER:Jianpeng Huang"
echo "SUPPORT DATE:$(date +%Y/%m/%d)"
echo "LOCATION of SUPPORT:XiBianMen"
#checking the status of the cluster configsync
code=$(bigpipe config sync show |grep Status |awk '{print $4}')
if [ $code != "Synchronized" ];then
    echo "DEVICE OF CONFIG UNSYNCHRONIZED:$(bigpipe config sync show |grep Status)"
else
    echo "DEVICE OF CONFIG SYNCHRONIZED:$code"
fi

#checking the device master or slave status
stat_code=`b failover show |cut -d " " -f 2`
if [ $stat_code == "active" ];then 
    echo "CURRENT STATE:Active"
elif [ $stat_code=='standby' ];then 
    echo "CURRENT STATE:standby"
else
    echo "$(b failover show)"
fi
CPU_USAGE=`Tmm_cpu`
echo "TMM CPU_USAGE:$CPU_USAGE"
echo $(Throughput)
POWER_SUPPLY
CHASSIS_TEMPERATURE
UPTIME
SYS_date
log_ltm
MGMT
SNMP_agent
SNMP_trap
syslog_setting
DEV_Acc_control
HA_feature
NET_failover
NEW_conn
ACT_Conn

5.脚本的使用

[root@cnpl1600:Standby] config # sh checking.sh 

6.脚本的效果

 

转载于:https://www.cnblogs.com/wonderingpanda/p/6526059.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值