initial commit

This commit is contained in:
chenjinsong
2018-09-27 16:21:05 +08:00
commit dc91c4c987
2011 changed files with 408920 additions and 0 deletions

BIN
snmp/ZDJZ-mib库说明.doc Normal file

Binary file not shown.

Binary file not shown.

471
snmp/附件/ZDJZ-MIB.txt Normal file
View File

@@ -0,0 +1,471 @@
ZDJZ-MIB DEFINITIONS ::= BEGIN
IMPORTS
MODULE-IDENTITY, OBJECT-TYPE, TimeTicks FROM SNMPv2-SMI
DisplayString, FROM SNMPv2-TC
enterprises
FROM RFC1155-SMI;
zdjz OBJECT IDENTIFIER ::= { enterprises 5000001 }
device OBJECT IDENTIFIER ::= { zdjz 1 }
DeviceOverviewEntry::=
SEQUENCE {
deviceIndex INTEGER,
deviceWorkMode INTEGER,
deviceRunTimes DisplayString,
deviceCpuUtilization DisplayString,
deviceMemUtilization DisplayString
}
deviceOverviewTable OBJECT-TYPE
SYNTAX SEQUENCE OF DeviceOverviewEntry
MAX-ACCESS not-accessible
STATUS current
DESCRIPTION " Device Overview "
::= { device 1 }
deviceOverviewEntry OBJECT-TYPE
SYNTAX CpuEntry
MAX-ACCESS not-accessible
STATUS current
DESCRIPTION " CPU status description table entry "
INDEX { deviceIndex }
::= { deviceOverviewTable 1 }
deviceIndex OBJECT-TYPE
SYNTAX INTEGER
MAX-ACCESS read-only
STATUS current
DESCRIPTION " Device Index "
::= { deviceOverviewEntry 1 }
deviceWorkMode OBJECT-TYPE
SYNTAX INTEGER
MAX-ACCESS read-only
STATUS current
DESCRIPTION " Device Work Mode(1:normal 0:abnormal) "
::= { deviceOverviewEntry 2 }
deviceRunTimes OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION " Device Run Times "
::= { deviceOverviewEntry 3 }
deviceCpuUtilization OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION " Device Cpu Utilization "
::= { deviceOverviewEntry 4 }
deviceMemUtilization OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION " Device Memory Utilization "
::= { deviceOverviewEntry 5 }
CpuEntry::=
SEQUENCE {
deviceIndex INTEGER,
userPerc DisplayString,
sysPerc DisplayString,
waitPerc DisplayString,
nicePerc DisplayString,
idlePerc DisplayString,
totalPerc DisplayString,
freq DisplayString
}
cpuTable OBJECT-TYPE
SYNTAX SEQUENCE OF CpuEntry
MAX-ACCESS not-accessible
STATUS current
DESCRIPTION " CPU INFO "
::= { device 2 }
cpuEntry OBJECT-TYPE
SYNTAX CpuEntry
MAX-ACCESS not-accessible
STATUS current
DESCRIPTION " CPU status description table entry "
INDEX { deviceIndex }
::= { cpuTable 1}
deviceIndex OBJECT-TYPE
SYNTAX INTEGER
MAX-ACCESS read-only
STATUS current
DESCRIPTION " Device ID "
::= { cpuEntry 1 }
userPerc OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION " User Cpu Percent "
::= { cpuEntry 2 }
sysPerc OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION " System Cpu Percent "
::= { cpuEntry 3 }
waitPerc OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION " Wait Cpu Percent "
::= { cpuEntry 4 }
nicePerc OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION " Nice Cpu Percent "
::= { cpuEntry 5 }
idlePerc OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION " Idle Cpu Percent "
::= { cpuEntry 6 }
totalPerc OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION " Total Cpu Used Percent "
::= { cpuEntry 7 }
freq OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION " Frequency Of Cpu(MHz) "
::= { cpuEntry 8 }
MemEntry::=
SEQUENCE {
deviceIndex INTEGER,
swapTotal DisplayString,
swapFree DisplayString,
memTotal DisplayString,
memUsed DisplayString,
memFree DisplayString,
memUsedPerc DisplayString
}
memTable OBJECT-TYPE
SYNTAX SEQUENCE OF MemEntry
MAX-ACCESS not-accessible
STATUS current
DESCRIPTION " MEMORY INFO "
::= { device 3 }
memEntry OBJECT-TYPE
SYNTAX memEntry
MAX-ACCESS not-accessible
STATUS current
DESCRIPTION " Memory status description table entry "
INDEX { deviceIndex }
::= { memTable 1}
deviceIndex OBJECT-TYPE
SYNTAX INTEGER
MAX-ACCESS read-only
STATUS current
DESCRIPTION " Device ID "
::= { memEntry 1 }
swapTotal OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION " Swap total(G) "
::= { memEntry 2 }
swapFree OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION " Swap free(G) "
::= { memEntry 3 }
memTotal OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION " Mem total(G) "
::= { memEntry 4 }
memUsed OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION " Mem used(G) "
::= { memEntry 5 }
memFree OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION " Mem free(G) "
::= { memEntry 6 }
memUsedPerc OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION " Mem used percent(%) "
::= { memEntry 7 }
DiskEntry::=
SEQUENCE {
deviceIndex INTEGER,
dirName DisplayString,
total DisplayString,
free DisplayString,
usedPerc DisplayString,
isWrited INTEGER
}
diskTable OBJECT-TYPE
SYNTAX SEQUENCE OF DiskEntry
MAX-ACCESS not-accessible
STATUS current
DESCRIPTION " DISK INFO "
::= { device 4 }
diskEntry OBJECT-TYPE
SYNTAX diskEntry
MAX-ACCESS not-accessible
STATUS current
DESCRIPTION " Disk status description table entry "
INDEX { deviceIndex }
::= { diskTable 1}
deviceIndex OBJECT-TYPE
SYNTAX INTEGER
MAX-ACCESS read-only
STATUS current
DESCRIPTION " Device ID "
::= { diskEntry 1 }
dirName OBJECT-TYPE
SYNTAX INTEGER
MAX-ACCESS read-only
STATUS current
DESCRIPTION " Disk Dir Name "
::= { diskEntry 2 }
total OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION " Total Size "
::= { diskEntry 3 }
free OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION " Free Size "
::= { diskEntry 4 }
usedPerc OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION " Disk Used Percent "
::= { diskEntry 5 }
isWrited OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION " 0:is; 1:isn't "
::= { diskEntry 6 }
NetEntry::=
SEQUENCE {
deviceIndex INTEGER,
name DisplayString,
rxPackets DisplayString,
txPackets DisplayString,
rxBytes DisplayString,
txBytes DisplayString,
rxErrors DisplayString,
txErrors DisplayString,
rxDropped DisplayString,
txDropped DisplayString,
speed DisplayString,
rxBps DisplayString,
txBps DisplayString,
rxPps DisplayString,
txPps DisplayString,
rxErrorPerc DisplayString,
txErrorPerc DisplayString,
rxDroppedPerc DisplayString,
txDroppedPerc DisplayString
}
netTable OBJECT-TYPE
SYNTAX SEQUENCE OF NetEntry
MAX-ACCESS not-accessible
STATUS current
DESCRIPTION " NET INFO "
::= { device 5 }
netEntry OBJECT-TYPE
SYNTAX netEntry
MAX-ACCESS not-accessible
STATUS current
DESCRIPTION " Net status description table entry "
INDEX { deviceIndex }
::= { netTable 1}
deviceIndex OBJECT-TYPE
SYNTAX INTEGER
MAX-ACCESS read-only
STATUS current
DESCRIPTION " Device ID "
::= { netEntry 1 }
name OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION " Network Name "
::= { netEntry 2 }
rxPackets OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION " rxPackets "
::= { netEntry 3 }
txPackets OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION " txPackets "
::= { netEntry 4 }
rxBytes OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION " rxBytes "
::= { netEntry 5 }
txBytes OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION " txBytes "
::= { netEntry 6 }
rxErrors OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION " rxErrors "
::= { netEntry 7 }
txErrors OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION " txErrors "
::= { netEntry 8 }
rxDropped OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION " rxDropped "
::= { netEntry 9 }
txDropped OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION " txDropped "
::= { netEntry 10 }
speed OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION " speed "
::= { netEntry 11 }
rxBps OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION " rxBps "
::= { netEntry 12 }
txBps OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION " txBps "
::= { netEntry 13 }
rxPps OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION " rxPps "
::= { netEntry 14 }
txPps OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION " txPps "
::= { netEntry 15 }
rxErrorPerc OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION " rxErrorPerc "
::= { netEntry 16 }
txErrorPerc OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION " txErrorPerc "
::= { netEntry 17 }
rxDroppedPerc OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION " rxDroppedPerc "
::= { netEntry 18 }
txDroppedPerc OBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION " txDroppedPerc "
::= { netEntry 19 }
END

Binary file not shown.

4
snmp/附件/shell/config Normal file
View File

@@ -0,0 +1,4 @@
configPath=/home/snmp/configs
ip1=10.0.6.247
ip2=10.0.6.247
snmp_result_dir=/home/snmp/csv

View File

@@ -0,0 +1,9 @@
pubInfo=100003,1,cpu,cpu
checkState=1
checkGap=5
checkOutTime=0
checkMaxTimes=3
planCheckTime=0
uploadGap=0
dataFileDir=/home/snmp/csv
police=

View File

@@ -0,0 +1,9 @@
pubInfo=100003,3,disk,disk
checkState=1
checkGap=5
checkOutTime=0
checkMaxTimes=3
planCheckTime=0
uploadGap=0
dataFileDir=/home/snmp/csv
police=

View File

@@ -0,0 +1,9 @@
pubInfo=100003,2,memory,memory
checkState=1
checkGap=5
checkOutTime=0
checkMaxTimes=3
planCheckTime=0
uploadGap=0
dataFileDir=/home/snmp/csv
police=

View File

@@ -0,0 +1,9 @@
pubInfo=100003,4,net,net
checkState=1
checkGap=5
checkOutTime=0
checkMaxTimes=3
planCheckTime=0
uploadGap=0
dataFileDir=/home/snmp/csv
police=

View File

@@ -0,0 +1,9 @@
pubInfo=100003,0,systeminfo,servicessysinfo
checkState=1
checkGap=15
checkOutTime=0
checkMaxTimes=3
planCheckTime=0
uploadGap=0
dataFileDir=/home/snmp/csv
police=

130
snmp/附件/shell/cpu.sh Normal file
View File

@@ -0,0 +1,130 @@
#!/bin/bash
PLACE=".1.3.6.1.4.1.5000001.1.2.1" # ZDJZ-MIB::cpuEntry的根OID
#
# 脚本会接收到两个参数
# $1 --请求类型
# -s --snmpset
# -g --snmpget
# -n --snmpgetnext/snmpwalk 注snmpwalk的本质是循环执行snmpgetnext以当次snmpgetnext的最终执行OID作为下次snmpgetnext的请求OID
# $2 --请求的OID
#
REQ="$2" # 请求的OID
RET="" # 最终执行的OID
#
# 提取cpu监测结果文件的内容
#
basePath=$(cd `dirname $0`; pwd) # 脚本所在目录
while read line;do # 读取配置文件
eval "$line"
done < ${basePath}/config
declare -A devices_arr # 所有设备所有cpu数据存放的数组最后从这里取数据格式devices_arr[“项”“设备序号”“核心序号”]
# 例如取第2台设备的cpu的第3个核心的用户使用率devices_arr[223]
declare -A device_core # 设备对应的cpu核心数格式device_core[1]=81号设备cpu8核
device_index=1 # 设备序号
core_index=1 # cpu核心序号
item_num=8 # 项目数量,根据业务而定
details=`awk 'NR>2{print}' ${snmp_result_dir}/"cpu.csv"` # 取得details内容
details_rownum=`echo "$details"|awk '{print NR}'|tail -n1` # details行数
for((i=0;i<$details_rownum;i++));do
for_i_flag=1
rownum_t=$((i+1))
detail_row=`echo "$details"|awk 'NR=="'$rownum_t'"{print}'` # details某行的整行数据
OLD_IFS="$IFS"
IFS=","
detail_row_arr=($detail_row) # 将整行数据用逗号隔开转为数组
IFS=$OLD_IFS
for((j=4;j<${#detail_row_arr[@]};j++));do
if [[ ${detail_row_arr[3]} =~ "-" ]];then
devices_arr+=([$((j-2))${device_index}${core_index}]=${detail_row_arr[$j]})
else
device_core+=([$device_index]=$((core_index-1)))
device_index=$((device_index+1)) # 设备序号加1
core_index=1 # 重置cpu核心序号
for_i_flag=0
break
fi
done
if [ $for_i_flag == "1" ];then
core_index=$((core_index+1))
fi
done
#
# 处理snmpgetnext请求获取REQ的递增后的下个OID递增规则需要自定义
#
if [ "$1" = "-n" ]; then
caseFlag=1
# 机器编号 -------------------开始
case $REQ in
$PLACE| \
$PLACE.0| \
$PLACE.0.*| \
$PLACE.1) RET=$PLACE.1.1; caseFlag=0 ;;
esac
for((i=1;i<=$((device_index-1))&&$caseFlag==1;i++));do
case $REQ in
$PLACE.1.$((i-1))| \
$PLACE.1.$((i-1)).*) RET=$PLACE.1.$i; caseFlag=0 ;;
esac
done
# 机器编号 -------------------结束
# cpu信息 --------------------开始
for((i=2;i<=$item_num&&$caseFlag==1;i++));do
case $REQ in
$PLACE.$((i-1)).*| \
$PLACE.$i| \
$PLACE.$i.0) RET=$PLACE.$i.1.1; caseFlag=0 ;;
esac
for((j=1;j<=$((device_index-1))&&$caseFlag==1;j++));do
case $REQ in
$PLACE.$i.$((j-1)).*| \
$PLACE.$i.$j) RET=$PLACE.$i.$j.1; caseFlag=0 ;;
esac
for((k=1;k<=${device_core[$j]}&&$caseFlag==1;k++));do
case $REQ in
$PLACE.$i.$j.$((k-1))| \
$PLACE.$i.$j.$((k-1)).*) RET=$PLACE.$i.$j.$k; caseFlag=0 ;;
esac
done
done
done
# cpu信息 --------------------结束
fi
#
# 根据RET输出查询结果
#
echo "$RET"
for((i=1;i<=$((device_index-1));i++));do
case "$RET" in
$PLACE.1.$i) echo "integer"; echo $i; exit 0 ;;
esac
done
for((i=2;i<=$item_num;i++));do
for((j=1;j<=$((device_index-1));j++));do
for((k=1;k<=${device_core[$j]};k++));do
case "$RET" in
$PLACE.$i.$j.$k) echo "string"; echo ${devices_arr[$i$j$k]}; exit 0 ;;
esac
done
done
done
echo "string"; echo "error OID"; exit 0

148
snmp/附件/shell/disk.sh Normal file
View File

@@ -0,0 +1,148 @@
#!/bin/bash
PLACE=".1.3.6.1.4.1.5000001.1.4.1" # DISK-MIB::diskEntry的根OID
#
# 脚本会接收到两个参数
# $1 --请求类型
# -s --snmpset
# -g --snmpget
# -n --snmpgetnext/snmpwalk 注snmpwalk的本质是循环执行snmpgetnext以当次snmpgetnext的最终执行OID作为下次snmpgetnext的请求OID
# $2 --请求的OID
#
REQ="$2" # 请求的OID
RET="" # 最终执行的OID
#
# 提取disk监测结果文件的内容
#
basePath=$(cd `dirname $0`; pwd) # 脚本所在目录
while read line;do # 读取配置文件
eval "$line"
done < ${basePath}/config
declare -A devices_arr # 所有设备所有cpu数据存放的数组最后从这里取数据格式devices_arr[“项”“设备序号”“硬盘序号”]
# 例如取第2台设备的第3个disk的可用容量第4项devices_arr[423]
declare -A device_disk # 设备对应的各disk数量格式device_core[1]=31号设备挂载了3个disk
device_index=1 # 设备序号
disk_index=0 # disk序号
item_num=6 # 项目数量,根据业务而定
details=`awk 'NR>2{print}' ${snmp_result_dir}"/disk.csv"` # 取得details内容
details_rownum=`echo "$details"|awk '{print NR}'|tail -n1` # details行数
for((i=0;i<$details_rownum;i++));do
for_i_flag=1
rownum_t=$((i+1))
detail_row=`echo "$details"|awk 'NR=="'$rownum_t'"{print}'` # details某行的整行数据
OLD_IFS="$IFS"
IFS=","
detail_row_arr=($detail_row) # 将整行数据用逗号隔开转为数组
IFS=$OLD_IFS
forthInfo=${detail_row_arr[3]}
OLD_IFS="$IFS"
IFS=":"
forth_arr=($forthInfo) # 将数组第四个元素的disk-indx和挂载路径拆开
IFS=$OLD_IFS
disk_and_index=${forth_arr[0]}
disk_name=${forth_arr[1]} # disk挂载路径disk名称
OLD_IFS="$IFS"
IFS="-"
disk_and_index_arr=($disk_and_index)
IFS=$OLD_IFS
device_index_t=${disk_and_index_arr[1]} # 当前设备序号
if [[ $device_index_t == $device_index ]];then
disk_index=$((disk_index+1))
devices_arr+=(["2"${device_index}${disk_index}]=$disk_name) # 将第二项disk名称存入
else
device_disk+=([$device_index]=$disk_index)
disk_index=1
device_index=$device_index_t
devices_arr+=(["2"${device_index}${disk_index}]=${disk_name}) # 将第二项disk名称存入
fi
for((j=4;j<${#detail_row_arr[@]};j++));do
devices_arr+=([$((j-1))${device_index}${disk_index}]=${detail_row_arr[$j]})
done
done
device_disk+=([$device_index]=$disk_index)
#
# 处理snmpgetnext请求获取REQ的递增后的下个OID递增规则需要自定义
#
if [ "$1" = "-n" ]; then
caseFlag=1
# 机器编号 -------------------开始
case $REQ in
$PLACE| \
$PLACE.0| \
$PLACE.0.*| \
$PLACE.1) RET=$PLACE.1.1; caseFlag=0 ;;
esac
for((i=1;i<=$device_index&&$caseFlag==1;i++));do
case $REQ in
$PLACE.1.$((i-1))| \
$PLACE.1.$((i-1)).*) RET=$PLACE.1.$i; caseFlag=0 ;;
esac
done
# 机器编号 -------------------结束
# disk信息 --------------------开始
for((i=2;i<=$item_num&&$caseFlag==1;i++));do
case $REQ in
$PLACE.$((i-1)).*| \
$PLACE.$i| \
$PLACE.$i.0) RET=$PLACE.$i.1.1; caseFlag=0 ;;
esac
for((j=1;j<=$device_index&&$caseFlag==1;j++));do
case $REQ in
$PLACE.$i.$((j-1)).*| \
$PLACE.$i.$j) RET=$PLACE.$i.$j.1; caseFlag=0 ;;
esac
for((k=1;k<=${device_disk[$j]}&&$caseFlag==1;k++));do
case $REQ in
$PLACE.$i.$j.$((k-1))| \
$PLACE.$i.$j.$((k-1)).*) RET=$PLACE.$i.$j.$k; caseFlag=0 ;;
esac
done
done
done
# disk信息 --------------------结束
fi
#
# 根据RET输出查询结果
#
echo "$RET"
for((i=1;i<=$device_index;i++));do
case "$RET" in
$PLACE.1.$i) echo "integer"; echo $i; exit 0 ;;
esac
done
for((i=2;i<=$item_num;i++));do
for((j=1;j<=$device_index;j++));do
for((k=1;k<=${device_disk[$j]};k++));do
case "$RET" in
$PLACE.$i.$j.$k) echo "string"; echo "${devices_arr[$i$j$k]}"; exit 0 ;;
esac
done
done
done
echo "string"; echo "error OID"; exit 0

View File

@@ -0,0 +1,590 @@
#!/bin/bash
basePath=$(cd `dirname $0`; pwd)
date=`date +%Y%m%d%H%M%S`
d=`date "+%Y-%m-%d %H:%M:%S"` #temp column
t=`date -d "$d" +%s` #temp column
t2=`date "+%N" | awk '{print int($0)}'`
dateStamp=$((t*1000+t2/1000000)) #current time stamp
sep=\$@\$
cd ${basePath}
while read line;do # 读取config
eval "$line"
done < config
if [ ! -d macInfo ]
then
mkdir macInfo
fi
if [ ! -d result ]
then
mkdir result
fi
if [ ! -f firstTimeDate ]
then
touch firstTimeDate
echo ${dateStamp} > firstTimeDate
firstTimeDate=${dateStamp}
else
firstTimeDate=`cat firstTimeDate`
fi
# 读取任务配置文件
OLD_IFS="$IFS"
IFS=","
cpu_pubInfo=`cat ${configPath}/cpu_cpu.cfg | grep pubInfo | awk -F'=' '{print $2}'`
cpu_checkState=`cat ${configPath}/cpu_cpu.cfg | grep checkState | awk -F'=' '{print $2}'`
cpu_checkGap=`cat ${configPath}/cpu_cpu.cfg | grep checkGap | awk -F'=' '{print $2}'`
cpu_checkOutTime=`cat ${configPath}/cpu_cpu.cfg | grep checkOutTime | awk -F'=' '{print $2}'`
cpu_checkMaxTimes=`cat ${configPath}/cpu_cpu.cfg | grep checkMaxTimes | awk -F'=' '{print $2}'`
cpu_planCheckTime=`cat ${configPath}/cpu_cpu.cfg | grep planCheckTime | awk -F'=' '{print $2}'`
cpu_uploadGap=`cat ${configPath}/cpu_cpu.cfg | grep uploadGap | awk -F'=' '{print $2}'`
cpu_dataFileDir=`cat ${configPath}/cpu_cpu.cfg | grep dataFileDir | awk -F'=' '{print $2}'`
cpu_polices=`cat ${configPath}/cpu_cpu.cfg | grep police | awk -F'=' '{print $2}'`
cpu_polices_arr=($cpu_polices)
cpu_police_flag=0
cpu_nextDateStamp=$((cpu_checkGap*60*1000+dateStamp))
mem_pubInfo=`cat ${configPath}/memory_memory.cfg | grep pubInfo | awk -F'=' '{print $2}'`
mem_checkState=`cat ${configPath}/memory_memory.cfg | grep checkState | awk -F'=' '{print $2}'`
mem_checkGap=`cat ${configPath}/memory_memory.cfg | grep checkGap | awk -F'=' '{print $2}'`
mem_checkOutTime=`cat ${configPath}/memory_memory.cfg | grep checkOutTime | awk -F'=' '{print $2}'`
mem_checkMaxTimes=`cat ${configPath}/memory_memory.cfg | grep checkMaxTimes | awk -F'=' '{print $2}'`
mem_planCheckTime=`cat ${configPath}/memory_memory.cfg | grep planCheckTime | awk -F'=' '{print $2}'`
mem_uploadGap=`cat ${configPath}/memory_memory.cfg | grep uploadGap | awk -F'=' '{print $2}'`
mem_dataFileDir=`cat ${configPath}/memory_memory.cfg | grep dataFileDir | awk -F'=' '{print $2}'`
mem_polices=`cat ${configPath}/memory_memory.cfg | grep police | awk -F'=' '{print $2}'`
mem_polices_arr=($mem_polices)
mem_police_flag=0
mem_nextDateStamp=$((mem_checkGap*60*1000+dateStamp))
disk_pubInfo=`cat ${configPath}/disk_disk.cfg | grep pubInfo | awk -F'=' '{print $2}'`
disk_checkState=`cat ${configPath}/disk_disk.cfg | grep checkState | awk -F'=' '{print $2}'`
disk_checkGap=`cat ${configPath}/disk_disk.cfg | grep checkGap | awk -F'=' '{print $2}'`
disk_checkOutTime=`cat ${configPath}/disk_disk.cfg | grep checkOutTime | awk -F'=' '{print $2}'`
disk_checkMaxTimes=`cat ${configPath}/disk_disk.cfg | grep checkMaxTimes | awk -F'=' '{print $2}'`
disk_planCheckTime=`cat ${configPath}/disk_disk.cfg | grep planCheckTime | awk -F'=' '{print $2}'`
disk_uploadGap=`cat ${configPath}/disk_disk.cfg | grep uploadGap | awk -F'=' '{print $2}'`
disk_dataFileDir=`cat ${configPath}/disk_disk.cfg | grep dataFileDir | awk -F'=' '{print $2}'`
disk_polices=`cat ${configPath}/disk_disk.cfg | grep police | awk -F'=' '{print $2}'`
disk_polices_arr=($disk_polices)
disk_police_flag=0
disk_nextDateStamp=$((disk_checkGap*60*1000+dateStamp))
net_pubInfo=`cat ${configPath}/net_net.cfg | grep pubInfo | awk -F'=' '{print $2}'`
net_checkState=`cat ${configPath}/net_net.cfg | grep checkState | awk -F'=' '{print $2}'`
net_checkGap=`cat ${configPath}/net_net.cfg | grep checkGap | awk -F'=' '{print $2}'`
net_checkOutTime=`cat ${configPath}/net_net.cfg | grep checkOutTime | awk -F'=' '{print $2}'`
net_checkMaxTimes=`cat ${configPath}/net_net.cfg | grep checkMaxTimes | awk -F'=' '{print $2}'`
net_planCheckTime=`cat ${configPath}/net_net.cfg | grep planCheckTime | awk -F'=' '{print $2}'`
net_uploadGap=`cat ${configPath}/net_net.cfg | grep uploadGap | awk -F'=' '{print $2}'`
net_dataFileDir=`cat ${configPath}/net_net.cfg | grep dataFileDir | awk -F'=' '{print $2}'`
net_polices=`cat ${configPath}/net_net.cfg | grep police | awk -F'=' '{print $2}'`
net_polices_arr=($net_polices)
net_police_flag=0
net_nextDateStamp=$((net_checkGap*60*1000+dateStamp))
sys_pubInfo=`cat ${configPath}/systeminfo_servicessysinfo.cfg | grep pubInfo | awk -F'=' '{print $2}'`
sys_checkState=`cat ${configPath}/systeminfo_servicessysinfo.cfg | grep checkState | awk -F'=' '{print $2}'`
sys_checkGap=`cat ${configPath}/systeminfo_servicessysinfo.cfg | grep checkGap | awk -F'=' '{print $2}'`
sys_checkOutTime=`cat ${configPath}/systeminfo_servicessysinfo.cfg | grep checkOutTime | awk -F'=' '{print $2}'`
sys_checkMaxTimes=`cat ${configPath}/systeminfo_servicessysinfo.cfg | grep checkMaxTimes | awk -F'=' '{print $2}'`
sys_planCheckTime=`cat ${configPath}/systeminfo_servicessysinfo.cfg | grep planCheckTime | awk -F'=' '{print $2}'`
sys_uploadGap=`cat ${configPath}/systeminfo_servicessysinfo.cfg | grep uploadGap | awk -F'=' '{print $2}'`
sys_dataFileDir=`cat ${configPath}/systeminfo_servicessysinfo.cfg | grep dataFileDir | awk -F'=' '{print $2}'`
sys_polices=`cat ${configPath}/systeminfo_servicessysinfo.cfg | grep police | awk -F'=' '{print $2}'`
sys_polices_arr=($sys_polices)
sys_police_flag=0
sys_nextDateStamp=$((sys_checkGap*60*1000+dateStamp))
IFS="$OLD_IFS"
sysinfoSrc=`cat ${sysinfoPath}`
## begin content weaving ##
# task info
cpuResult_taskInfo=${cpu_pubInfo}","${firstTimeDate}","${cpu_checkOutTime}","${dateStamp}",1,"${cpu_nextDateStamp}","
memResult_taskInfo=${mem_pubInfo}","${firstTimeDate}","${mem_checkOutTime}","${dateStamp}",1,"${mem_nextDateStamp}","
diskResult_taskInfo=${disk_pubInfo}","${firstTimeDate}","${disk_checkOutTime}","${dateStamp}",1,"${disk_nextDateStamp}","
netResult_taskInfo=${net_pubInfo}","${firstTimeDate}","${net_checkOutTime}","${dateStamp}",1,"${net_nextDateStamp}","
sysResult_taskInfo=${sys_pubInfo}","${firstTimeDate}","${sys_checkOutTime}","${dateStamp}",1,"${sys_nextDateStamp}",1,"
cpuResult_coreNum=0
disk_total_num=0
net_total_num=0
sys_net_total_num=0
diskResult_baseInfo="\""
memResult_baseInfo="\""
netResult_baseInfo="\""
sysResult_baseInfo="\""
# result file
cpuResult=result/cpuResult_${date}
memResult=result/memResult_${date}
diskResult=result/diskResult_${date}
netResult=result/netResult_${date}
sysResult=result/sysResult_${date}
function getDetail {
cpuInfo=macInfo/$1_cpuInfo_${date}
memInfo=macInfo/$1_memInfo_${date}
diskInfo=macInfo/$1_diskInfo_${date}
netInfo=macInfo/$1_netInfo_${date}
sysInfo=macInfo/$1_sysInfo_${date}
ssh -tt $2 "sar -P ALL 1 1" > ${cpuInfo}
ssh -tt $2 "cat /proc/cpuinfo | grep MHz" > ${cpuInfo}2
ssh -tt $2 "free|awk 'NR>1{print}'" > ${memInfo}
ssh -tt $2 "df -l|grep -v tmpfs|awk 'NR>1{print}'" > ${diskInfo}
# 网卡信息
special_net_result_t=`ssh -C $2 "/bin/bash" < remote_net.sh` # 获取特殊网卡信息
special_net_result_base=${special_net_result_t%details,*}
special_net_result_details_t=${special_net_result_t#*details,}
special_net_result_details="\""${special_net_result_details_t#*\"}
special_net_result_details_t_arr=($special_net_result_details_t)
special_net_result_detailsNum=${special_net_result_details_t_arr[0]}
special_net_result=${special_net_result_base}"details,"${special_net_result_detailsNum}$'\n'
for((i=1;i<${#special_net_result_details_t_arr[@]};i++));do
special_net_result=${special_net_result}${special_net_result_details_t_arr[$i]}$'\n'
done
echo "$special_net_result" > ${netInfo}3
getNetInfo
dos2unix ${cpuInfo} > /dev/null 2>&1
dos2unix ${cpuInfo}2 > /dev/null 2>&1
dos2unix ${memInfo} > /dev/null 2>&1
dos2unix ${diskInfo} > /dev/null 2>&1
#dos2unix ${diskInfo} > /dev/null 2>&1
# cpu info
cpu_t=`awk -F "(" '{print $3}' ${cpuInfo}` # temp column
cpu_coreNum=`echo $cpu_t|awk -F " " '{print $1}'`
cpuResult_coreNum=$((cpuResult_coreNum+cpu_coreNum))
cpu_totalMHz=`awk '{total+=$4}END{print total}' ${cpuInfo}2`
cpu_averMHz=`echo "scale=2;$cpu_totalMHz/$cpu_coreNum"|bc|awk '{printf "%.2f",$0}'`
cpu_idle_total=`awk 'NR==4{print $9}' ${cpuInfo}`
cpu_shiyonglv=`bc <<<100-$cpu_idle_total|awk '{printf "%.2f",$0}'`
cpuResult_baseInfo=${cpuResult_baseInfo}${sep}"cpu${index} i18n_client.SystemInfo.mhz_n81i"${cpu_averMHz}"MHzi18n_client.SystemInfo.shiyonglv_n81i "${cpu_shiyonglv}"%; "
getCpuBase2 ${cpuInfo} ${cpuInfo}2
getCpuDetail ${cpuInfo} ${cpuInfo}2
# mem info
swap_total_t=`cat ${memInfo}|grep '^S'|awk '{print $2}'`
swap_total=`echo "scale=2;${swap_total_t}/1024/1024"|bc|awk '{printf "%.2f",$0}'`
swap_free_t=`cat ${memInfo}|grep '^S'|awk '{print $4}'`
swap_free=`echo "scale=2;${swap_free_t}/1024/1024"|bc|awk '{printf "%.2f",$0}'`
mem_total_t=`awk 'NR==1{print $2}' ${memInfo}`
mem_total=`echo "scale=2;${mem_total_t}/1024/1024"|bc|awk '{printf "%.2f",$0}'`
mem_used_t=`awk 'NR==1{print $3}' ${memInfo}`
mem_used=`echo "scale=2;${mem_used_t}/1024/1024"|bc|awk '{printf "%.2f",$0}'`
mem_free=`echo "${mem_total}-${mem_used}"|bc|awk '{printf "%.2f",$0}'`
mem_shiyonglv=`echo "scale=2;${mem_used}/${mem_total}*100.00"|bc|awk '{printf "%.2f",$0}'`
memResult_baseInfo="${memResult_baseInfo}"${sep}"i18n_client.SystemInfo.memerySize_n81i: "${mem_total}"G, i18n_client.SystemInfo.currentUsed_n81i"${mem_used}"G, i18n_client.SystemInfo.spaceRemain_n81i"${mem_free}"G, i18n_client.SystemInfo.shiyonglv_n81i"${mem_shiyonglv}"% "
mem_detail_nopolice=${swap_total}","${swap_free}","${mem_total}","${mem_used}","${mem_free}","${mem_shiyonglv}","$'\n'
OLD_IFS="$IFS"
IFS=","
mem_detail_nopolice_arr=(${mem_detail_nopolice})
IFS=$OLD_IFS
# police
if [ ! -z $mem_polices ]
then
mem_police_most_level=0
mem_police_flag_t=0 #临时变量
mem_baseInfo_police=""
for((j=0;j<${#mem_polices_arr[@]};j++));do
mem_detail_police_t=""
OLD_IFS="$IFS"
IFS="|"
mem_police_arr=(${mem_polices_arr[$j]})
IFS=$OLD_IFS
if (($(echo "${mem_detail_nopolice_arr[((${mem_police_arr[0]}-1))]} ${mem_police_arr[1]} ${mem_police_arr[2]}"|bc) == 1))
then #触发告警
mem_detail_police_t=${mem_police_arr[0]}","${mem_police_arr[3]}","${mem_police_arr[2]}","
mem_police_flag=1
mem_police_flag_t=1
if ((${mem_police_arr[3]} > ${mem_police_most_level}))
then
mem_police_most_level=${mem_police_arr[3]}
mem_detail_police=$mem_detail_police_t
mem_baseInfo_police="${mem_detail_nopolice_arr[0]}"${mem_police_arr[4]}${mem_detail_nopolice_arr[((${mem_police_arr[0]}-1))]}"% i18n_client.GetInfoRun.abnormal_n81i</br>"
fi
elif [ $mem_police_flag_t -eq 0 ]&&[ -z "${mem_baseInfo_police}" ];then
mem_detail_police="\"\",,,"
mem_baseInfo_police="${mem_detail_nopolice_arr[0]}"${mem_police_arr[4]}${mem_detail_nopolice_arr[((${mem_police_arr[0]}-1))]}" i18n_client.GetInfoRun.normal_n81i</br>"
fi
done
memResult_baseInfo_police=${memResult_baseInfo_police}${mem_baseInfo_police}
else
mem_detail_police="\"\",,,"
fi
memResult_detail=${memResult_detail}${mem_detail_police}${mem_detail_nopolice}
#memResult_detail="${memResult_detail}""\"\",,,"${swap_total}","${swap_free}","${mem_total}","${mem_used}","${mem_free}","${mem_shiyonglv}","$'\n'
# disk info
disk_total_size=`awk '{total+=$2}END{print total}' ${diskInfo}` # Kb
disk_total_used_size=`awk '{total+=$3}END{print total}' ${diskInfo}`
disk_total_shiyonglv=`echo "scale=2;(${disk_total_used_size}*100)/${disk_total_size}"|bc|awk '{printf "%.2f",$0}'`
diskResult_baseInfo=${diskResult_baseInfo}${sep}"disk-"${index}"i18n_client.SystemInfo.diskSize_n81i"`echo "scale=2;${disk_total_size}/1024/1024"|bc|awk '{printf "%.2f",$0}'`"Gi18n_client.SystemInfo.used2_n81i "${disk_total_shiyonglv}"% ;"
getDiskBase ${diskInfo}
getDiskDetail
# net info
#net_avai_if_arr=($(awk 'NR==1{print $0}' ${netInfo}))
#net_all_if_arr=($(awk 'NR>1{print}' ${netInfo} | awk -F ':' '{print $1 NR}'))
#getNetInfo
}
function getCpuBase2 {
arr1=($(awk '/^[0-2]/{print $9}' $1|awk 'NR>2{print $0}'))
arr2=($(awk '{print $4}' $2))
for((i=0;i<${#arr1[@]};i++));do
cpu_t2=`bc <<<100-${arr1[$i]} |awk '{printf "%.2f",$0}'`
cpuResult_baseInfo=${cpuResult_baseInfo}${sep}"cpu"${index}"-$i i18n_client.SystemInfo.mhz_n81i"${arr2[$i]}"MHzi18n_client.SystemInfo.shiyonglv_n81i "${cpu_t2}"%; "
done
}
function getCpuDetail {
cpu_t3=`awk '/^[0-2]/{print $0}' $1|awk 'NR>1{print $0}'`
for((i=2;i<=`echo "${cpu_t3}"|awk 'END{print NR}'`;i++));do
cpu_row=`echo "${cpu_t3}"|awk 'NR=="'$i'"{print $0}'`
cpu_idle=`echo "${cpu_row}"|awk '{print $9}'`
cpu_shiyonglv_t=`bc <<<100-${cpu_idle} |awk '{printf "%.2f",$0}'`
cpu_detail_nopolice="cpu${index}-$((i-2)),"`echo "${cpu_row}"|awk '{print $4}'`","`echo "${cpu_row}"|awk '{print $6}'`","`echo "${cpu_row}"|awk '{print $7}'`","`echo "${cpu_row}"|awk '{print $5}'`","`echo "${cpu_row}"|awk '{print $9}'`","${cpu_shiyonglv_t}","`awk 'NR=="'$((i-1))'"{print $4}' $2`$'\n'
# police
if [ ! -z $cpu_polices ]
then
OLD_IFS="$IFS"
IFS=","
cpu_detail_nopolice_arr=(${cpu_detail_nopolice})
IFS=$OLD_IFS
cpu_police_most_level=0
cpu_police_flag_t=0 #临时变量
cpu_baseInfo_police=""
for((j=0;j<${#cpu_polices_arr[@]};j++));do
cpu_detail_police_t=""
OLD_IFS="$IFS"
IFS="|"
cpu_police_arr=(${cpu_polices_arr[$j]})
IFS=$OLD_IFS
if (($(echo "${cpu_detail_nopolice_arr[((${cpu_police_arr[0]}-1))]} ${cpu_police_arr[1]} ${cpu_police_arr[2]}"|bc) == 1))
then #触发告警
cpu_detail_police_t=${cpu_police_arr[0]}","${cpu_police_arr[3]}","${cpu_police_arr[2]}","
cpu_police_flag=1
cpu_police_flag_t=1
if ((${cpu_police_arr[3]} > ${cpu_police_most_level}))
then
cpu_police_most_level=${cpu_police_arr[3]}
cpu_detail_police=$cpu_detail_police_t
cpu_baseInfo_police="【cpu${index}-$((i-2))"${cpu_police_arr[4]}${cpu_detail_nopolice_arr[((${cpu_police_arr[0]}-1))]}"% i18n_client.GetInfoRun.abnormal_n81i</br>"
fi
elif [ $cpu_police_flag_t -eq 0 ]&&[ -z "${cpu_baseInfo_police}" ];then
cpu_detail_police="\"\",,,"
cpu_baseInfo_police="【cpu${index}-$((i-2))"${cpu_police_arr[4]}${cpu_detail_nopolice_arr[((${cpu_police_arr[0]}-1))]}"% i18n_client.GetInfoRun.normal_n81i</br>"
fi
done
cpuResult_baseInfo_police=${cpuResult_baseInfo_police}${cpu_baseInfo_police}
else
cpu_detail_police="\"\",,,"
fi
cpuResult_detail=${cpuResult_detail}${cpu_detail_police}${cpu_detail_nopolice}
done
cpuResult_detail=${cpuResult_detail}"\"\",,,cpu${index},"`awk 'NR==4{print $4}' $1`","`awk 'NR==4{print $6}' $1`","`awk 'NR==4{print $7}' $1`","`awk 'NR==4{print $5}' $1`","`awk 'NR==4{print $9}' $1`","${cpu_shiyonglv}","${cpu_averMHz}$'\n'
}
function getDiskBase {
disk_size_arr=($(awk '{print $2}' $1))
disk_used_arr=($(awk '{print $3}' $1))
disk_avai_arr=($(awk '{print $4}' $1)) # available
disk_usep_arr=($(awk '{print $5}' $1))
disk_moun_arr=($(awk '{print $6}' $1)) # mount on
for((i=0;i<${#disk_size_arr[@]};i++));do
disk_size=`echo "scale=2;${disk_size_arr[$i]}/1024/1024"|bc|awk '{printf "%.2f",$0}'` # Gb
disk_used=`echo "scale=2;${disk_used_arr[$i]}/1024/1024"|bc|awk '{printf "%.2f",$0}'`
disk_avai=`echo "scale=2;${disk_avai_arr[$i]}/1024/1024"|bc|awk '{printf "%.2f",$0}'`
disk_usep=${disk_usep_arr[$i]}
disk_moun=${disk_moun_arr[$i]}
diskResult_baseInfo=${diskResult_baseInfo}${sep}"【disk-$index:"${disk_moun}"】i18n_client.SystemInfo.size_n81i "${disk_size}"G, i18n_client.SystemInfo.used1_n81i "${disk_used}"G, i18n_client.SystemInfo.spaceRemain_n81i "${disk_avai}"G, i18n_client.SystemInfo.shiyonglv_n81i "${disk_usep}" ; "
done
}
function getDiskDetail {
disk_total_num=`echo "${disk_total_num}+${#disk_size_arr[@]}"|bc`
for((i=0;i<${#disk_size_arr[@]};i++));do
disk_size=`echo "scale=2;${disk_size_arr[$i]}/1024/1024"|bc|awk '{printf "%.2f",$0}'` # Gb
disk_avai=`echo "scale=2;${disk_avai_arr[$i]}/1024/1024"|bc|awk '{printf "%.2f",$0}'`
disk_detail_nopolice="disk-$index:"${disk_moun_arr[$i]}","${disk_size}","${disk_avai}","${disk_usep_arr[$i]%\%*}",0,"$'\n'
OLD_IFS=$IFS
IFS=","
disk_detail_nopolice_arr=(${disk_detail_nopolice})
IFS=$OLD_IFS
# police
if [ ! -z $disk_polices ]
then
disk_police_most_level=0
disk_police_flag_t=0 #临时变量
disk_baseInfo_police=""
for((j=0;j<${#disk_polices_arr[@]};j++));do
disk_detail_police_t=""
OLD_IFS="$IFS"
IFS="|"
disk_police_arr=(${disk_polices_arr[$j]})
IFS=$OLD_IFS
if (($(echo "${disk_detail_nopolice_arr[((${disk_police_arr[0]}-1))]} ${disk_police_arr[1]} ${disk_police_arr[2]}"|bc) == 1))
then #触发告警
disk_detail_police_t=${disk_police_arr[0]}","${disk_police_arr[3]}","${disk_police_arr[2]}","
disk_police_flag=1
disk_police_flag_t=1
if ((${disk_police_arr[3]} > ${disk_police_most_level}))
then
disk_police_most_level=${disk_police_arr[3]}
disk_detail_police=$disk_detail_police_t
disk_baseInfo_police="${disk_detail_nopolice_arr[0]}"${disk_police_arr[4]}${disk_detail_nopolice_arr[((${disk_police_arr[0]}-1))]}"% i18n_client.GetInfoRun.abnormal_n81i</br>"
fi
elif [ $disk_police_flag_t -eq 0 ]&&[ -z "${disk_baseInfo_police}" ];then
disk_detail_police="\"\",,,"
disk_baseInfo_police="${disk_detail_nopolice_arr[0]}"${disk_police_arr[4]}${disk_detail_nopolice_arr[((${disk_police_arr[0]}-1))]}" i18n_client.GetInfoRun.normal_n81i</br>"
fi
done
diskResult_baseInfo_police=${diskResult_baseInfo_police}${disk_baseInfo_police}
else
disk_detail_police="\"\",,,"
fi
diskResult_detail=${diskResult_detail}${disk_detail_police}${disk_detail_nopolice}
done
}
function getNetInfo {
# 处理特殊网卡信息的内容
special_base_row=`awk 'NR==1{print $0}' ${netInfo}3` # 第一行
special_base_11=`echo ${special_base_row} | awk -F '"' '{print $2}'` # 11列
special_base_11=${sep}${special_base_11#*$sep}
special_base_12=`echo $special_base_row | awk -F '"' '{print $4}'` # 12列
special_base_12=${sep}${special_base_12#*$sep}
special_base_t=${special_base_11}${special_base_12}
special_base_t=${special_base_t//$sep/\!}
OLDIFS=$IFS
IFS="\!"
special_base_t_arr=(${special_base_t})
IFS=$OLD_IFS
special_base=""
for((i=1;i<${#special_base_t_arr[@]};i++));do
special_base=${special_base}"${sep}if${index}-"${special_base_t_arr[$i]}
done
special_detail_rows=`awk 'NR>2{print}' ${netInfo}3` # details行下方所有行
special_detail_rows_arr=($special_detail_rows) # details下方所有行的数组每个元素为一行内容
#special_if_t=`echo ${special_detail_rows}|awk -F ',' '{print $4}'` # 取每行第三、四个逗号之间的网卡名
special_if_arr=() # 网卡名称数组
special_if_baseInfo="" # 初始化特殊网卡基础信息
for ((i=0;i<${#special_detail_rows_arr[@]};i++));do
special_detail_row=`echo ${special_detail_rows_arr[$i]} | awk -F ',' '{print gensub($4,"if"'$index'"-"$4,1)}'` # detail行网卡名替换为ifx-开头的名字
netResult_detail=${netResult_detail}${special_detail_row}$'\n'
special_if_baseInfo=${special_if_baseInfo}${special_base_12}${special_base_11}
special_if_arr[$i]=`echo ${special_detail_rows_arr[$i]}| awk -F ',' '{print $4}'`
done
sys_net_total_num=`echo "${sys_net_total_num}+${#net_all_if_arr[@]}"|bc`
net_total_num=`echo "${net_total_num}+${#net_avai_if_arr[@]}"|bc`
net_avai_baseInfo=""
net_disa_baseInfo=""
for((i=0;i<${#net_all_if_arr[@]};i++));do
ifName_t=${net_all_if_arr[$i]}
ifName=${ifName_t%?}
echo ${special_if_arr[0]}"--"${special_if_arr[1]}"--"${special_if_arr[2]}"--"${ifName}
if echo "${special_if_arr[@]}"|grep -w "${ifName}" &>/dev/null;then
let "net_total_num--"
let "sys_net_total_num--"
continue
fi
net_rowNum=$((${net_all_if_arr[$i]: -1}+1))
net_if_name_t=`awk 'NR=="'${net_rowNum}'"{print $1}' ${netInfo}`
net_if_name=${net_if_name_t%?}
is_avai=`echo "${net_avai_if_arr[@]}" | grep -wq "${net_all_if_arr[$i]%?}" && echo "1" || echo "0"`
if [ "1" -eq "$is_avai" ]
then
echo "#!/bin/bash"$'\n'"ethtool ${net_if_name}" > ethtool.sh
net_if_ethtoolResult=`ssh -C $value "/bin/bash" < ethtool.sh`
net_if_speed_t=`echo "${net_if_ethtoolResult}"|grep "Speed:"|awk '{print $2}'`
if [ ${#net_if_speed_t} -lt 1 ]
then
net_if_speed=0
else
net_if_speed=${net_if_speed_t:0:${#net_if_speed_t}-4}
fi
net_if_rxByte1=`awk 'NR=="'${net_rowNum}'"{print $2}' ${netInfo}`
net_if_rxByte2=`awk 'NR=="'${net_rowNum}'"{print $2}' ${netInfo}2`
net_if_rxBps=`echo "scale=2;($net_if_rxByte2-$net_if_rxByte1)*8/5"|bc|awk '{printf "%.2f",$0}'`
net_if_rxPackets1=`awk 'NR=="'${net_rowNum}'"{print $3}' ${netInfo}`
net_if_rxPackets2=`awk 'NR=="'${net_rowNum}'"{print $3}' ${netInfo}2`
net_if_rxPps_t=`echo "($net_if_rxPackets2-$net_if_rxPackets1)"|bc`
net_if_rxPps=`echo "scale=2;($net_if_rxPackets2-$net_if_rxPackets1)*8/5"|bc|awk '{printf "%.2f",$0}'`
net_if_txByte1=`awk 'NR=="'${net_rowNum}'"{print $10}' ${netInfo}`
net_if_txByte2=`awk 'NR=="'${net_rowNum}'"{print $10}' ${netInfo}`
net_if_txBps=`echo "scale=2;($net_if_txByte2-$net_if_txByte1)*8/5"|bc|awk '{printf "%.2f",$0}'`
net_if_txPackets1=`awk 'NR=="'${net_rowNum}'"{print $11}' ${netInfo}`
net_if_txPackets2=`awk 'NR=="'${net_rowNum}'"{print $11}' ${netInfo}2`
net_if_txPps_t=`echo "($net_if_rxPackets2-$net_if_rxPackets1)"|bc`
net_if_txPps=`echo "scale=2;($net_if_rxPackets2-$net_if_rxPackets1)*8/5"|bc|awk '{printf "%.2f",$0}'`
net_if_rxError1=`awk 'NR=="'${net_rowNum}'"{print $4}' ${netInfo}`
net_if_rxError2=`awk 'NR=="'${net_rowNum}'"{print $4}' ${netInfo}2`
net_if_txError1=`awk 'NR=="'${net_rowNum}'"{print $12}' ${netInfo}`
net_if_txError2=`awk 'NR=="'${net_rowNum}'"{print $12}' ${netInfo}2`
net_if_rxDrop1=`awk 'NR=="'${net_rowNum}'"{print $5}' ${netInfo}`
net_if_rxDrop2=`awk 'NR=="'${net_rowNum}'"{print $5}' ${netInfo}2`
net_if_txDrop1=`awk 'NR=="'${net_rowNum}'"{print $13}' ${netInfo}`
net_if_txDrop2=`awk 'NR=="'${net_rowNum}'"{print $13}' ${netInfo}2`
if [ $net_if_rxPps_t -gt 0 ]
then
net_if_rxErrorPerc=`echo "scale=2;($net_if_rxError2-$net_if_rxError1)*100/($net_if_rxPackets2-$net_if_rxPackets1)"|bc|awk '{printf "%.2f",$0}'`
net_if_rxDropPerc=`echo "scale=2;($net_if_rxDrop2-$net_if_rxDrop1)*100/($net_if_rxPackets2-$net_if_rxPackets1)"|bc|awk '{printf "%.2f",$0}'`
else
net_if_rxErrorPerc=0.00
net_if_rxDropPerc=0.00
fi
if [ $net_if_txPps_t -gt 0 ]
then
net_if_txErrorPerc=`echo "scale=2;($net_if_txError2-$net_if_txError1)*100/($net_if_txPackets2-$net_if_txPackets1)"|bc|awk '{printf "%.2f",$0}'`
net_if_txDropPerc=`echo "scale=2;($net_if_txDrop2-$net_if_txDrop1)*100/($net_if_txPackets2-$net_if_txPackets1)"|bc|awk '{printf "%.2f",$0}'`
else
net_if_txErrorPerc=0.00
net_if_txDropPerc=0.00
fi
net_avai_baseInfo=${net_avai_baseInfo}${sep}"if"${index}"-"${net_if_name}" i18n_client.SystemInfo.netSpeed_n81i"${net_if_speed}"Mbps, i18n_client.SystemInfo.input_n81i"${net_if_rxBps}"bps、"${net_if_rxPps}"pps, Output"${net_if_txBps}"bps、"${net_if_txPps}"pps; "
net_detail_nopolice="if${index}-"${net_if_name}","${net_if_rxPackets2}","${net_if_txPackets2}","${net_if_rxByte2}","${net_if_txByte2}","${net_if_rxError2}","${net_if_txError2}","${net_if_rxDrop2}","${net_if_txDrop2}","${net_if_speed}","${net_if_rxBps}","${net_if_txBps}","${net_if_rxPps}","${net_if_txPps}","${net_if_rxErrorPerc}","${net_if_txErrorPerc}","${net_if_rxDropPerc}","${net_if_txDropPerc}$'\n'
#netResult_detail=${netResult_detail}"\"\",,,if${index}-"${net_if_name}","${net_if_rxPackets2}","${net_if_txPackets2}","${net_if_rxByte2}","${net_if_txByte2}","${net_if_rxError2}","${net_if_txError2}","${net_if_rxDrop2}","${net_if_txDrop2}","${net_if_speed}","${net_if_rxBps}","${net_if_txBps}","${net_if_rxPps}","${net_if_txPps}","${net_if_rxErrorPerc}","${net_if_txErrorPerc}","${net_if_rxDropPerc}","${net_if_txDropPerc}$'\n'
# police
if [ ! -z $net_polices ]
then
OLD_IFS="$IFS"
IFS=","
net_detail_nopolice_arr=(${net_detail_nopolice})
IFS=$OLD_IFS
net_police_most_level=0
net_police_flag_t=0 #临时变量
net_baseInfo_police=""
for((j=0;j<${#net_polices_arr[@]};j++));do
net_detail_police_t=""
OLD_IFS="$IFS"
IFS="|"
net_police_arr=(${net_polices_arr[$j]})
IFS=$OLD_IFS
if (($(echo "${net_detail_nopolice_arr[((${net_police_arr[0]}-1))]} ${net_police_arr[1]} ${net_police_arr[2]}"|bc) == 1))
then #触发告警
net_detail_police_t=${net_police_arr[0]}","${net_police_arr[3]}","${net_police_arr[2]}","
net_police_flag=1
net_police_flag_t=1
if ((${net_police_arr[3]} > ${net_police_most_level}))
then
net_police_most_level=${net_police_arr[3]}
net_detail_police=$net_detail_police_t
net_baseInfo_police="${net_detail_nopolice_arr[0]}"${net_police_arr[4]}${net_detail_nopolice_arr[((${net_police_arr[0]}-1))]}"% i18n_client.GetInfoRun.abnormal_n81i</br>"
fi
elif [ $net_police_flag_t -eq 0 ]&&[ -z "${net_baseInfo_police}" ];then
net_detail_police="\"\",,,"
net_baseInfo_police="${net_detail_nopolice_arr[0]}"${net_police_arr[4]}${net_detail_nopolice_arr[((${net_police_arr[0]}-1))]}"% i18n_client.GetInfoRun.normal_n81i</br>"
fi
done
netResult_baseInfo_police=${netResult_baseInfo_police}${net_baseInfo_police}
else
net_detail_police="\"\",,,"
fi
netResult_detail=${netResult_detail}${net_detail_police}${net_detail_nopolice}
else
net_disa_baseInfo=${net_disa_baseInfo}${sep}"if"${index}"-"${net_if_name}"i18n_client.SystemInfo.disable_n81i; "
fi
done
sys_net_total_num=`echo "${sys_net_total_num}+${#special_detail_rows_arr[@]}"|bc`
net_total_num=`echo "$net_total_num+${#special_detail_rows_arr[@]}"|bc`
netResult_baseInfo=${netResult_baseInfo}"${sep}if"${index}"-"${#special_detail_rows_arr[@]}"i18n_client.SystemInfo.insert_n81i: "${special_base}${net_avai_baseInfo}${net_disa_baseInfo}$'\n'
}
# main
index=1
flag=1
while [ $flag -eq 1 ]; do
key='ip'${index}
value=`eval echo '$'${key}`
if [ -z ${value} ]
then
flag=0
else
getDetail ${key} ${value}
let "index++"
fi
done
## result
# cpu
cpuResult_baseInfo=${cpuResult_baseInfo}"\""
if ((${cpu_police_flag} == 0 ))
then
cpuResult_baseInfo_police="\""${cpuResult_baseInfo}
cpu_police_flag=1
else
cpuResult_baseInfo_police="\""${cpuResult_baseInfo_police}"\""
cpu_police_flag=0
fi
echo "${cpuResult_taskInfo}""${cpu_police_flag},""\"${cpuResult_coreNum}""i18n_client.SystemInfo.core_n81i: ""${cpuResult_baseInfo}"",""${cpuResult_baseInfo_police}"$'\n'"details,""$((cpuResult_coreNum+index-1))"$'\n'"${cpuResult_detail}" > ${cpu_dataFileDir}/${date}".csv" #${cpuResult}
# mem
memResult_baseInfo=${memResult_baseInfo}"\""
if ((${mem_police_flag} == 0 ))
then
memResult_baseInfo_police=${memResult_baseInfo}
mem_police_flag=1
else
memResult_baseInfo_police="\""${memResult_baseInfo_police}"\""
mem_police_flag=0
fi
echo "${memResult_taskInfo}"${mem_police_flag}",${memResult_baseInfo}"",""${memResult_baseInfo_police}"$'\n'"details,""$((index-1))"$'\n'"${memResult_detail}" > ${mem_dataFileDir}/${date}".csv" #${memResult}
# disk
diskResult_baseInfo=${diskResult_baseInfo}"\""
if ((${disk_police_flag} == 0 ))
then
diskResult_baseInfo_police=${diskResult_baseInfo}
disk_police_flag=1
else
diskResult_baseInfo_police="\""${diskResult_baseInfo_police}"\""
disk_police_flag=0
fi
echo "${diskResult_taskInfo}"${disk_police_flag}",${diskResult_baseInfo}"",""${diskResult_baseInfo_police}"$'\n'"details,$disk_total_num"$'\n'"${diskResult_detail}" > ${disk_dataFileDir}/${date}".csv" #${diskResult}
# net
netResult_baseInfo=${netResult_baseInfo}"\""
if ((${net_police_flag} == 0 ))
then
netResult_baseInfo_police=${netResult_baseInfo}
net_police_flag=1
else
netResult_baseInfo_police="\""${netResult_baseInfo_police}"\""
net_police_flag=0
fi
echo "${netResult_taskInfo}"${net_police_flag}",${netResult_baseInfo}"",""${netResult_baseInfo_police}"$'\n'"details,$net_total_num"$'\n'"${netResult_detail}" > ${net_dataFileDir}/${date}".csv" #${netResult}
# sys
sysinfo=`cat ${sysinfoPath}`
echo "${sysResult_taskInfo}""${sysinfo}" > ${sys_dataFileDir}/${date}".csv" #${sysResult}

View File

@@ -0,0 +1,623 @@
#!/bin/bash
basePath=$(cd `dirname $0`; pwd)
date=`date +%Y%m%d%H%M%S`
d=`date "+%Y-%m-%d %H:%M:%S"` #temp column
t=`date -d "$d" +%s` #temp column
t2=`date "+%N" | awk '{print int($0)}'`
dateStamp=$((t*1000+t2/1000000)) #current time stamp
sep=\$@\$
cd ${basePath}
while read line;do
eval "$line"
done < config
if [ ! -d macInfo ]
then
mkdir macInfo
fi
if [ ! -d result ]
then
mkdir result
fi
if [ ! -f firstTimeDate ]
then
touch firstTimeDate
echo ${dateStamp} > firstTimeDate
firstTimeDate=${dateStamp}
else
firstTimeDate=`cat firstTimeDate`
fi
# config info from config file
OLD_IFS="$IFS"
IFS=","
cpu_pubInfo=`cat ${configPath}/cpu_cpu.cfg | grep pubInfo | awk -F'=' '{print $2}'`
cpu_checkState=`cat ${configPath}/cpu_cpu.cfg | grep checkState | awk -F'=' '{print $2}'`
cpu_checkGap=`cat ${configPath}/cpu_cpu.cfg | grep checkGap | awk -F'=' '{print $2}'`
cpu_checkOutTime=`cat ${configPath}/cpu_cpu.cfg | grep checkOutTime | awk -F'=' '{print $2}'`
cpu_checkMaxTimes=`cat ${configPath}/cpu_cpu.cfg | grep checkMaxTimes | awk -F'=' '{print $2}'`
cpu_planCheckTime=`cat ${configPath}/cpu_cpu.cfg | grep planCheckTime | awk -F'=' '{print $2}'`
cpu_uploadGap=`cat ${configPath}/cpu_cpu.cfg | grep uploadGap | awk -F'=' '{print $2}'`
cpu_dataFileDir=`cat ${configPath}/cpu_cpu.cfg | grep dataFileDir | awk -F'=' '{print $2}'`
cpu_polices=`cat ${configPath}/cpu_cpu.cfg | grep police | awk -F'=' '{print $2}'`
cpu_polices_arr=($cpu_polices)
cpu_police_flag=0
cpu_nextDateStamp=$((cpu_checkGap*60*1000+dateStamp))
mem_pubInfo=`cat ${configPath}/memory_memory.cfg | grep pubInfo | awk -F'=' '{print $2}'`
mem_checkState=`cat ${configPath}/memory_memory.cfg | grep checkState | awk -F'=' '{print $2}'`
mem_checkGap=`cat ${configPath}/memory_memory.cfg | grep checkGap | awk -F'=' '{print $2}'`
mem_checkOutTime=`cat ${configPath}/memory_memory.cfg | grep checkOutTime | awk -F'=' '{print $2}'`
mem_checkMaxTimes=`cat ${configPath}/memory_memory.cfg | grep checkMaxTimes | awk -F'=' '{print $2}'`
mem_planCheckTime=`cat ${configPath}/memory_memory.cfg | grep planCheckTime | awk -F'=' '{print $2}'`
mem_uploadGap=`cat ${configPath}/memory_memory.cfg | grep uploadGap | awk -F'=' '{print $2}'`
mem_dataFileDir=`cat ${configPath}/memory_memory.cfg | grep dataFileDir | awk -F'=' '{print $2}'`
mem_polices=`cat ${configPath}/memory_memory.cfg | grep police | awk -F'=' '{print $2}'`
mem_polices_arr=($mem_polices)
mem_police_flag=0
mem_nextDateStamp=$((mem_checkGap*60*1000+dateStamp))
disk_pubInfo=`cat ${configPath}/disk_disk.cfg | grep pubInfo | awk -F'=' '{print $2}'`
disk_checkState=`cat ${configPath}/disk_disk.cfg | grep checkState | awk -F'=' '{print $2}'`
disk_checkGap=`cat ${configPath}/disk_disk.cfg | grep checkGap | awk -F'=' '{print $2}'`
disk_checkOutTime=`cat ${configPath}/disk_disk.cfg | grep checkOutTime | awk -F'=' '{print $2}'`
disk_checkMaxTimes=`cat ${configPath}/disk_disk.cfg | grep checkMaxTimes | awk -F'=' '{print $2}'`
disk_planCheckTime=`cat ${configPath}/disk_disk.cfg | grep planCheckTime | awk -F'=' '{print $2}'`
disk_uploadGap=`cat ${configPath}/disk_disk.cfg | grep uploadGap | awk -F'=' '{print $2}'`
disk_dataFileDir=`cat ${configPath}/disk_disk.cfg | grep dataFileDir | awk -F'=' '{print $2}'`
disk_polices=`cat ${configPath}/disk_disk.cfg | grep police | awk -F'=' '{print $2}'`
disk_polices_arr=($disk_polices)
disk_police_flag=0
disk_nextDateStamp=$((disk_checkGap*60*1000+dateStamp))
net_pubInfo=`cat ${configPath}/net_net.cfg | grep pubInfo | awk -F'=' '{print $2}'`
net_checkState=`cat ${configPath}/net_net.cfg | grep checkState | awk -F'=' '{print $2}'`
net_checkGap=`cat ${configPath}/net_net.cfg | grep checkGap | awk -F'=' '{print $2}'`
net_checkOutTime=`cat ${configPath}/net_net.cfg | grep checkOutTime | awk -F'=' '{print $2}'`
net_checkMaxTimes=`cat ${configPath}/net_net.cfg | grep checkMaxTimes | awk -F'=' '{print $2}'`
net_planCheckTime=`cat ${configPath}/net_net.cfg | grep planCheckTime | awk -F'=' '{print $2}'`
net_uploadGap=`cat ${configPath}/net_net.cfg | grep uploadGap | awk -F'=' '{print $2}'`
net_dataFileDir=`cat ${configPath}/net_net.cfg | grep dataFileDir | awk -F'=' '{print $2}'`
net_polices=`cat ${configPath}/net_net.cfg | grep police | awk -F'=' '{print $2}'`
net_polices_arr=($net_polices)
net_police_flag=0
net_nextDateStamp=$((net_checkGap*60*1000+dateStamp))
sys_pubInfo=`cat ${configPath}/systeminfo_servicessysinfo.cfg | grep pubInfo | awk -F'=' '{print $2}'`
sys_checkState=`cat ${configPath}/systeminfo_servicessysinfo.cfg | grep checkState | awk -F'=' '{print $2}'`
sys_checkGap=`cat ${configPath}/systeminfo_servicessysinfo.cfg | grep checkGap | awk -F'=' '{print $2}'`
sys_checkOutTime=`cat ${configPath}/systeminfo_servicessysinfo.cfg | grep checkOutTime | awk -F'=' '{print $2}'`
sys_checkMaxTimes=`cat ${configPath}/systeminfo_servicessysinfo.cfg | grep checkMaxTimes | awk -F'=' '{print $2}'`
sys_planCheckTime=`cat ${configPath}/systeminfo_servicessysinfo.cfg | grep planCheckTime | awk -F'=' '{print $2}'`
sys_uploadGap=`cat ${configPath}/systeminfo_servicessysinfo.cfg | grep uploadGap | awk -F'=' '{print $2}'`
sys_dataFileDir=`cat ${configPath}/systeminfo_servicessysinfo.cfg | grep dataFileDir | awk -F'=' '{print $2}'`
sys_polices=`cat ${configPath}/systeminfo_servicessysinfo.cfg | grep police | awk -F'=' '{print $2}'`
sys_polices_arr=($sys_polices)
sys_police_flag=0
sys_nextDateStamp=$((sys_checkGap*60*1000+dateStamp))
IFS="$OLD_IFS"
## begin content weaving ##
# task info
cpuResult_taskInfo=${cpu_pubInfo}","${firstTimeDate}","${cpu_checkOutTime}","${dateStamp}",1,"${cpu_nextDateStamp}","
memResult_taskInfo=${mem_pubInfo}","${firstTimeDate}","${mem_checkOutTime}","${dateStamp}",1,"${mem_nextDateStamp}","
diskResult_taskInfo=${disk_pubInfo}","${firstTimeDate}","${disk_checkOutTime}","${dateStamp}",1,"${disk_nextDateStamp}","
netResult_taskInfo=${net_pubInfo}","${firstTimeDate}","${net_checkOutTime}","${dateStamp}",1,"${net_nextDateStamp}","
sysResult_taskInfo=${sys_pubInfo}","${firstTimeDate}","${sys_checkOutTime}","${dateStamp}",1,"${sys_nextDateStamp}",1,"
cpuResult_coreNum=0
disk_total_num=0
net_total_num=0
sys_net_total_num=0
diskResult_baseInfo="\""
memResult_baseInfo="\""
netResult_baseInfo="\""
sysResult_baseInfo="\""
# result file
cpuResult=result/cpuResult_${date}
memResult=result/memResult_${date}
diskResult=result/diskResult_${date}
netResult=result/netResult_${date}
sysResult=result/sysResult_${date}
function getDetail {
cpuInfo=macInfo/$1"_cpuInfo_"${date}
memInfo=macInfo/$1"_memInfo_"${date}
diskInfo=macInfo/$1"_diskInfo_"${date}
netInfo=macInfo/$1"_netInfo_"${date}
sysInfo=macInfo/$1"_sysInfo_"${date}
runtimes=macInfo/$1"_runtimes_"${date}
ssh -tt $2 "sar -P ALL 1 1" > ${cpuInfo}
ssh -tt $2 "cat /proc/cpuinfo | grep MHz" > ${cpuInfo}2
ssh -tt $2 "free|awk 'NR>1{print}'" > ${memInfo}
ssh -tt $2 "df -l|grep -v tmpfs|awk 'NR>1{print}'" > ${diskInfo}
ssh -tt $2 "/etc/init.d/network status|awk 'NR==4{print}'|sed 's/lo//g' && cat /proc/net/dev|awk 'NR>2{print}'|awk '!/^( lo)/'" > ${netInfo}
sleep 5s
ssh -tt $2 "/etc/init.d/network status|awk 'NR==4{print}'|sed 's/lo//g' && cat /proc/net/dev|awk 'NR>2{print}'|awk '!/^( lo)/'" > ${netInfo}2
ssh -tt $2 "cat /proc/uptime | awk '{print \$"1"}'" > ${runtimes}
dos2unix ${cpuInfo} > /dev/null 2>&1
dos2unix ${cpuInfo}2 > /dev/null 2>&1
dos2unix ${memInfo} > /dev/null 2>&1
dos2unix ${diskInfo} > /dev/null 2>&1
dos2unix ${diskInfo} > /dev/null 2>&1
dos2unix ${runtimes} > /dev/null 2>&1
# cpu info
cpu_t=`awk -F "(" '{print $3}' ${cpuInfo}` # temp column
cpu_coreNum=${cpu_t:0:1}
cpuResult_coreNum=$((cpuResult_coreNum+cpu_coreNum))
cpu_totalMHz=`awk '{total+=$4}END{print total}' ${cpuInfo}2`
cpu_averMHz=`echo "scale=2;$cpu_totalMHz/$cpu_coreNum"|bc|awk '{printf "%.2f",$0}'`
cpu_idle_total=`awk 'NR==4{print $9}' ${cpuInfo}`
cpu_shiyonglv=`bc <<<100-$cpu_idle_total|awk '{printf "%.2f",$0}'`
cpuResult_baseInfo=${cpuResult_baseInfo}${sep}"cpu${index} i18n_client.SystemInfo.mhz_n81i"${cpu_averMHz}"MHzi18n_client.SystemInfo.shiyonglv_n81i "${cpu_shiyonglv}"%; "
getCpuBase2 ${cpuInfo} ${cpuInfo}2
getCpuDetail ${cpuInfo} ${cpuInfo}2
# mem info
swap_total_t=`cat ${memInfo}|grep '^S'|awk '{print $2}'`
swap_total=`echo "scale=2;${swap_total_t}/1024/1024"|bc|awk '{printf "%.2f",$0}'`
swap_free_t=`cat ${memInfo}|grep '^S'|awk '{print $4}'`
swap_free=`echo "scale=2;${swap_free_t}/1024/1024"|bc|awk '{printf "%.2f",$0}'`
mem_total_t=`awk 'NR==1{print $2}' ${memInfo}`
mem_total=`echo "scale=2;${mem_total_t}/1024/1024"|bc|awk '{printf "%.2f",$0}'`
mem_used_t=`awk 'NR==1{print $3}' ${memInfo}`
mem_used=`echo "scale=2;${mem_used_t}/1024/1024"|bc|awk '{printf "%.2f",$0}'`
mem_free=`echo "${mem_total}-${mem_used}"|bc|awk '{printf "%.2f",$0}'`
mem_shiyonglv=`echo "scale=2;${mem_used}/${mem_total}*100.00"|bc|awk '{printf "%.2f",$0}'`
if [[ "${memResult_baseInfo}" != "\"" ]];then
memResult_baseInfo="${memResult_baseInfo}"${sep}
fi
memResult_baseInfo="${memResult_baseInfo}""i18n_client.SystemInfo.memerySize_n81i: "${mem_total}"G, i18n_client.SystemInfo.currentUsed_n81i"${mem_used}"G, i18n_client.SystemInfo.spaceRemain_n81i"${mem_free}"G, i18n_client.SystemInfo.shiyonglv_n81i"${mem_shiyonglv}"% "
mem_detail_nopolice=${swap_total}","${swap_free}","${mem_total}","${mem_used}","${mem_free}","${mem_shiyonglv}","$'\n'
OLD_IFS="$IFS"
IFS=","
mem_detail_nopolice_arr=(${mem_detail_nopolice})
IFS=$OLD_IFS
# police
if [ ! -z $mem_polices ]
then
mem_police_most_level=0
mem_police_flag_t=0 #临时变量
mem_baseInfo_police=""
for((j=0;j<${#mem_polices_arr[@]};j++));do
mem_detail_police_t=""
OLD_IFS="$IFS"
IFS="|"
mem_police_arr=(${mem_polices_arr[$j]})
IFS=$OLD_IFS
if (($(echo "${mem_detail_nopolice_arr[((${mem_police_arr[0]}-1))]} ${mem_police_arr[1]} ${mem_police_arr[2]}"|bc) == 1))
then #触发告警
mem_detail_police_t=${mem_police_arr[0]}","${mem_police_arr[3]}","${mem_police_arr[2]}","
mem_police_flag=1
mem_police_flag_t=1
if ((${mem_police_arr[3]} > ${mem_police_most_level}))
then
mem_police_most_level=${mem_police_arr[3]}
mem_detail_police=$mem_detail_police_t
mem_baseInfo_police="${mem_detail_nopolice_arr[0]}"${mem_police_arr[4]}${mem_detail_nopolice_arr[((${mem_police_arr[0]}-1))]}"% i18n_client.GetInfoRun.abnormal_n81i</br>"
fi
elif [ $mem_police_flag_t -eq 0 ]&&[ -z "${mem_baseInfo_police}" ];then
mem_detail_police="\"\",,,"
mem_baseInfo_police="${mem_detail_nopolice_arr[0]}"${mem_police_arr[4]}${mem_detail_nopolice_arr[((${mem_police_arr[0]}-1))]}" i18n_client.GetInfoRun.normal_n81i</br>"
fi
done
memResult_baseInfo_police=${memResult_baseInfo_police}${mem_baseInfo_police}
else
mem_detail_police="\"\",,,"
fi
memResult_detail=${memResult_detail}${mem_detail_police}${mem_detail_nopolice}
#memResult_detail="${memResult_detail}""\"\",,,"${swap_total}","${swap_free}","${mem_total}","${mem_used}","${mem_free}","${mem_shiyonglv}","$'\n'
# disk info
disk_total_size=`awk '{total+=$2}END{print total}' ${diskInfo}` # Kb
disk_total_used_size=`awk '{total+=$3}END{print total}' ${diskInfo}`
disk_total_shiyonglv=`echo "scale=2;(${disk_total_used_size}*100)/${disk_total_size}"|bc|awk '{printf "%.2f",$0}'`
if [[ "${diskResult_baseInfo}" != "\"" ]];then
diskResult_baseInfo="${diskResult_baseInfo}"${sep}
fi
diskResult_baseInfo=${diskResult_baseInfo}"disk-"${index}"i18n_client.SystemInfo.diskSize_n81i"`echo "scale=2;${disk_total_size}/1024/1024"|bc|awk '{printf "%.2f",$0}'`"Gi18n_client.SystemInfo.used2_n81i "${disk_total_shiyonglv}"% ;"
getDiskBase ${diskInfo}
getDiskDetail
# net info
net_avai_if_arr=($(awk 'NR==1{print $0}' ${netInfo}))
net_all_if_arr=($(awk 'NR>1{print}' ${netInfo} | awk -F ':' '{print $1 NR}'))
if_total_num=0
if_total_num=$((if_total_num+${#net_avai_if_arr[@]}))
getNetInfo
# sys info
sys_host_t=`awk 'NR==1{print $3}' ${cpuInfo}`
sys_host=${sys_host_t:1:${#sys_host_t}-1}
sys_version=`awk 'NR==1{print $2}' ${cpuInfo}`
if [[ "${sysResult_baseInfo}" != "\"" ]];then
sysResult_baseInfo="${sysResult_baseInfo}"${sep}
fi
sysResult_baseInfo=${sysResult_baseInfo}${index}"-"${sys_host}": "${sys_version}", "$cpu_coreNum"i18n_client.SystemInfo.message.core_n81i CPU, "${cpu_averMHz}"MHz, "${mem_total}"i18n_client.SystemInfo.message.memery_n81i, "`echo "scale=2;${disk_total_size}/1024/1024"|bc|awk '{printf "%.2f",$0}'`"i18n_client.SystemInfo.message.disk_n81i, "${#net_all_if_arr[@]}"i18n_client.SystemInfo.message.netcard_n81i"
getSysDetail
getSysDisk
getSysNet
# run times
runtimes_t=`cat ${runtimes}`
runtimesResult=${runtimesResult}${runtimes_t}" "
}
function getSysDetail {
sysResult_detail=${sysResult_detail}"\"\",,,"${index}"-"${sys_host}",\""${sys_version}"\","${cpu_coreNum}","${cpu_averMHz}","${mem_total}","${swap_total}","${disk_total_size}","${#net_all_if_arr[@]}","$'\n'
}
function getSysDisk {
for((i=0;i<${#disk_size_arr[@]};i++));do
sys_disk_size_t=`echo "scale=2;${disk_size_arr[$i]}/1024/1024"|bc|awk '{printf "%.2f",$0}'`
sysResult_disk=${sysResult_disk}"$index:"${disk_moun_arr[$i]}","${sys_disk_size_t}","$'\n'
done
}
function getSysNet {
sys_net_gateway=`ssh -tt $value "ip route show"`
for((i=0;i<${#net_all_if_arr[@]};i++));do
sys_net_rowNum=$((${net_all_if_arr[$i]: -1}+1))
sys_net_if_name_t=`awk 'NR=="'${sys_net_rowNum}'"{print $1}' ${netInfo}`
sys_net_if_name=${sys_net_if_name_t%?}
sys_net_is_avai=`echo "${net_avai_if_arr[@]}" | grep -wq "${net_all_if_arr[$i]%?}" && echo "1" || echo "0"`
if [ "1" -eq "$sys_net_is_avai" ]
then
echo "#!/bin/bash"$'\n'"ethtool ${sys_net_if_name}" > netExec.sh
sys_net_if_ethtoolResult=`ssh -C $value "/bin/bash" < netExec.sh`
echo "#!/bin/bash"$'\n'"ifconfig ${sys_net_if_name}" > netExec.sh
sys_net_if_ifconfigResult=`ssh -C $value "/bin/bash" < netExec.sh`
echo "#!/bin/bash"$'\n'"ip route show" > netExec.sh
sys_net_if_speed_t=`echo "${sys_net_if_ethtoolResult}"|grep "Speed:"|awk '{print $2}'`
if [ ${#sys_net_if_speed_t} -lt 1 ]
then
sys_net_if_speed=0
else
sys_net_if_speed=${sys_net_if_speed_t:0:${#sys_net_if_speed_t}-4}
fi
sys_net_if_ip=`echo "${sys_net_if_ifconfigResult}"|grep "inet "|awk '{print $2}'`
sys_net_if_mask=`echo "${sys_net_if_ifconfigResult}"|grep "inet "|awk '{print $4}'`
sys_net_if_gateway=`echo $sys_net_gateway|awk '{print $3}'`
sys_net_if_mac=`echo "${sys_net_if_ifconfigResult}"|grep "ether "|awk '{print $2}'`
sysResult_net=${sysResult_net}${index}"-"${sys_net_if_name}",Available,"${sys_net_if_speed}","${sys_net_if_ip}","${sys_net_if_mask}","${sys_net_if_gateway}","${sys_net_if_mac}","$'\n'
else
echo "#!/bin/bash"$'\n'"ethtool ${sys_net_if_name}" > netExec.sh
sys_net_if_ethtoolResult=`ssh -C $value "/bin/bash" < netExec.sh`
echo "#!/bin/bash"$'\n'"ifconfig ${sys_net_if_name}" > netExec.sh
sys_net_if_ifconfigResult=`ssh -C $value "/bin/bash" < netExec.sh`
sys_net_if_speed_t=`echo "${sys_net_if_ethtoolResult}"|grep "Speed:"|awk '{print $2}'`
if [ ${#sys_net_if_speed_t} -lt 1 ]
then
sys_net_if_speed=0
else
sys_net_if_speed=${sys_net_if_speed_t:0:${#sys_net_if_speed_t}-4}
fi
sys_net_if_mac=`echo "${sys_net_if_ifconfigResult}"|grep "ether "|awk '{print $2}'`
sysResult_net=${sysResult_net}${index}"-"${sys_net_if_name}",Unavailable,"${sys_net_if_speed}",0.0.0.0,0.0.0.0,0,0,0,0,"${sys_net_if_mac}","$'\n'
fi
done
}
function getCpuBase2 {
arr1=($(awk '/^[0-2]/{print $9}' $1|awk 'NR>2{print $0}'))
arr2=($(awk '{print $4}' $2))
for((i=0;i<${#arr1[@]};i++));do
cpu_t2=`bc <<<100-${arr1[$i]} |awk '{printf "%.2f",$0}'`
cpuResult_baseInfo=${cpuResult_baseInfo}${sep}"cpu"${index}"-$i i18n_client.SystemInfo.mhz_n81i"${arr2[$i]}"MHzi18n_client.SystemInfo.shiyonglv_n81i "${cpu_t2}"%; "
done
}
function getCpuDetail {
cpu_t3=`awk '/^[0-2]/{print $0}' $1|awk 'NR>1{print $0}'`
for((i=2;i<=`echo "${cpu_t3}"|awk 'END{print NR}'`;i++));do
cpu_row=`echo "${cpu_t3}"|awk 'NR=="'$i'"{print $0}'`
cpu_idle=`echo "${cpu_row}"|awk '{print $9}'`
cpu_shiyonglv_t=`bc <<<100-${cpu_idle} |awk '{printf "%.2f",$0}'`
cpu_detail_nopolice="cpu${index}-$((i-2)),"`echo "${cpu_row}"|awk '{print $4}'`","`echo "${cpu_row}"|awk '{print $6}'`","`echo "${cpu_row}"|awk '{print $7}'`","`echo "${cpu_row}"|awk '{print $5}'`","`echo "${cpu_row}"|awk '{print $9}'`","${cpu_shiyonglv_t}","`awk 'NR=="'$((i-1))'"{print $4}' $2`$'\n'
# police
if [ ! -z $cpu_polices ]
then
OLD_IFS="$IFS"
IFS=","
cpu_detail_nopolice_arr=(${cpu_detail_nopolice})
IFS=$OLD_IFS
cpu_police_most_level=0
cpu_police_flag_t=0 #临时变量
cpu_baseInfo_police=""
for((j=0;j<${#cpu_polices_arr[@]};j++));do
cpu_detail_police_t=""
OLD_IFS="$IFS"
IFS="|"
cpu_police_arr=(${cpu_polices_arr[$j]})
IFS=$OLD_IFS
if (($(echo "${cpu_detail_nopolice_arr[((${cpu_police_arr[0]}-1))]} ${cpu_police_arr[1]} ${cpu_police_arr[2]}"|bc) == 1))
then #触发告警
cpu_detail_police_t=${cpu_police_arr[0]}","${cpu_police_arr[3]}","${cpu_police_arr[2]}","
cpu_police_flag=1
cpu_police_flag_t=1
if ((${cpu_police_arr[3]} > ${cpu_police_most_level}))
then
cpu_police_most_level=${cpu_police_arr[3]}
cpu_detail_police=$cpu_detail_police_t
cpu_baseInfo_police="【cpu${index}-$((i-2))"${cpu_police_arr[4]}${cpu_detail_nopolice_arr[((${cpu_police_arr[0]}-1))]}"% i18n_client.GetInfoRun.abnormal_n81i</br>"
fi
elif [ $cpu_police_flag_t -eq 0 ]&&[ -z "${cpu_baseInfo_police}" ];then
cpu_detail_police="\"\",,,"
cpu_baseInfo_police="【cpu${index}-$((i-2))"${cpu_police_arr[4]}${cpu_detail_nopolice_arr[((${cpu_police_arr[0]}-1))]}"% i18n_client.GetInfoRun.normal_n81i</br>"
fi
done
cpuResult_baseInfo_police=${cpuResult_baseInfo_police}${cpu_baseInfo_police}
else
cpu_detail_police="\"\",,,"
fi
cpuResult_detail=${cpuResult_detail}${cpu_detail_police}${cpu_detail_nopolice}
done
cpuResult_detail=${cpuResult_detail}"\"\",,,cpu${index},"`awk 'NR==4{print $4}' $1`","`awk 'NR==4{print $6}' $1`","`awk 'NR==4{print $7}' $1`","`awk 'NR==4{print $5}' $1`","`awk 'NR==4{print $9}' $1`","${cpu_shiyonglv}","${cpu_averMHz}$'\n'
}
function getDiskBase {
disk_size_arr=($(awk '{print $2}' $1))
disk_used_arr=($(awk '{print $3}' $1))
disk_avai_arr=($(awk '{print $4}' $1)) # available
disk_usep_arr=($(awk '{print $5}' $1))
disk_moun_arr=($(awk '{print $6}' $1)) # mount on
for((i=0;i<${#disk_size_arr[@]};i++));do
disk_size=`echo "scale=2;${disk_size_arr[$i]}/1024/1024"|bc|awk '{printf "%.2f",$0}'` # Gb
disk_used=`echo "scale=2;${disk_used_arr[$i]}/1024/1024"|bc|awk '{printf "%.2f",$0}'`
disk_avai=`echo "scale=2;${disk_avai_arr[$i]}/1024/1024"|bc|awk '{printf "%.2f",$0}'`
disk_usep=${disk_usep_arr[$i]}
disk_moun=${disk_moun_arr[$i]}
diskResult_baseInfo=${diskResult_baseInfo}${sep}"【disk-$index:"${disk_moun}"】i18n_client.SystemInfo.size_n81i "${disk_size}"G, i18n_client.SystemInfo.used1_n81i "${disk_used}"G, i18n_client.SystemInfo.spaceRemain_n81i "${disk_avai}"G, i18n_client.SystemInfo.shiyonglv_n81i "${disk_usep}" ; "
done
}
function getDiskDetail {
disk_total_num=`echo "${disk_total_num}+${#disk_size_arr[@]}"|bc`
for((i=0;i<${#disk_size_arr[@]};i++));do
disk_size=`echo "scale=2;${disk_size_arr[$i]}/1024/1024"|bc|awk '{printf "%.2f",$0}'` # Gb
disk_avai=`echo "scale=2;${disk_avai_arr[$i]}/1024/1024"|bc|awk '{printf "%.2f",$0}'`
disk_detail_nopolice="disk-$index:"${disk_moun_arr[$i]}","${disk_size}","${disk_avai}","${disk_usep_arr[$i]%\%*}",0,"$'\n'
OLD_IFS=$IFS
IFS=","
disk_detail_nopolice_arr=(${disk_detail_nopolice})
IFS=$OLD_IFS
# police
if [ ! -z $disk_polices ]
then
disk_police_most_level=0
disk_police_flag_t=0 #临时变量
disk_baseInfo_police=""
for((j=0;j<${#disk_polices_arr[@]};j++));do
disk_detail_police_t=""
OLD_IFS="$IFS"
IFS="|"
disk_police_arr=(${disk_polices_arr[$j]})
IFS=$OLD_IFS
if (($(echo "${disk_detail_nopolice_arr[((${disk_police_arr[0]}-1))]} ${disk_police_arr[1]} ${disk_police_arr[2]}"|bc) == 1))
then #触发告警
disk_detail_police_t=${disk_police_arr[0]}","${disk_police_arr[3]}","${disk_police_arr[2]}","
disk_police_flag=1
disk_police_flag_t=1
if ((${disk_police_arr[3]} > ${disk_police_most_level}))
then
disk_police_most_level=${disk_police_arr[3]}
disk_detail_police=$disk_detail_police_t
disk_baseInfo_police="${disk_detail_nopolice_arr[0]}"${disk_police_arr[4]}${disk_detail_nopolice_arr[((${disk_police_arr[0]}-1))]}"% i18n_client.GetInfoRun.abnormal_n81i</br>"
fi
elif [ $disk_police_flag_t -eq 0 ]&&[ -z "${disk_baseInfo_police}" ];then
disk_detail_police="\"\",,,"
disk_baseInfo_police="${disk_detail_nopolice_arr[0]}"${disk_police_arr[4]}${disk_detail_nopolice_arr[((${disk_police_arr[0]}-1))]}" i18n_client.GetInfoRun.normal_n81i</br>"
fi
done
diskResult_baseInfo_police=${diskResult_baseInfo_police}${disk_baseInfo_police}
else
disk_detail_police="\"\",,,"
fi
diskResult_detail=${diskResult_detail}${disk_detail_police}${disk_detail_nopolice}
done
}
function getNetInfo {
sys_net_total_num=`echo "${sys_net_total_num}+${#net_all_if_arr[@]}"|bc`
net_total_num=`echo "${net_total_num}+${#net_avai_if_arr[@]}"|bc`
net_avai_baseInfo=""
net_disa_baseInfo=""
for((i=0;i<${#net_all_if_arr[@]};i++));do
net_rowNum=$((${net_all_if_arr[$i]: -1}+1))
net_if_name_t=`awk 'NR=="'${net_rowNum}'"{print $1}' ${netInfo}`
net_if_name=${net_if_name_t%?}
is_avai=`echo "${net_avai_if_arr[@]}" | grep -wq "${net_all_if_arr[$i]%?}" && echo "1" || echo "0"`
if [ "1" -eq "$is_avai" ]
then
echo "#!/bin/bash"$'\n'"ethtool ${net_if_name}" > ethtool.sh
net_if_ethtoolResult=`ssh -C 10.0.6.247 "/bin/bash" < ethtool.sh`
net_if_speed_t=`echo "${net_if_ethtoolResult}"|grep "Speed:"|awk '{print $2}'`
if [ ${#net_if_speed_t} -lt 1 ]
then
net_if_speed=0
else
net_if_speed=${net_if_speed_t:0:${#net_if_speed_t}-4}
fi
net_if_rxByte1=`awk 'NR=="'${net_rowNum}'"{print $2}' ${netInfo}`
net_if_rxByte2=`awk 'NR=="'${net_rowNum}'"{print $2}' ${netInfo}2`
net_if_rxBps=`echo "scale=2;($net_if_rxByte2-$net_if_rxByte1)*8/5"|bc|awk '{printf "%.2f",$0}'`
net_if_rxPackets1=`awk 'NR=="'${net_rowNum}'"{print $3}' ${netInfo}`
net_if_rxPackets2=`awk 'NR=="'${net_rowNum}'"{print $3}' ${netInfo}2`
net_if_rxPps_t=`echo "($net_if_rxPackets2-$net_if_rxPackets1)"|bc`
net_if_rxPps=`echo "scale=2;($net_if_rxPackets2-$net_if_rxPackets1)*8/5"|bc|awk '{printf "%.2f",$0}'`
net_if_txByte1=`awk 'NR=="'${net_rowNum}'"{print $10}' ${netInfo}`
net_if_txByte2=`awk 'NR=="'${net_rowNum}'"{print $10}' ${netInfo}`
net_if_txBps=`echo "scale=2;($net_if_txByte2-$net_if_txByte1)*8/5"|bc|awk '{printf "%.2f",$0}'`
net_if_txPackets1=`awk 'NR=="'${net_rowNum}'"{print $11}' ${netInfo}`
net_if_txPackets2=`awk 'NR=="'${net_rowNum}'"{print $11}' ${netInfo}2`
net_if_txPps_t=`echo "($net_if_rxPackets2-$net_if_rxPackets1)"|bc`
net_if_txPps=`echo "scale=2;($net_if_rxPackets2-$net_if_rxPackets1)*8/5"|bc|awk '{printf "%.2f",$0}'`
net_if_rxError1=`awk 'NR=="'${net_rowNum}'"{print $4}' ${netInfo}`
net_if_rxError2=`awk 'NR=="'${net_rowNum}'"{print $4}' ${netInfo}2`
net_if_txError1=`awk 'NR=="'${net_rowNum}'"{print $12}' ${netInfo}`
net_if_txError2=`awk 'NR=="'${net_rowNum}'"{print $12}' ${netInfo}2`
net_if_rxDrop1=`awk 'NR=="'${net_rowNum}'"{print $5}' ${netInfo}`
net_if_rxDrop2=`awk 'NR=="'${net_rowNum}'"{print $5}' ${netInfo}2`
net_if_txDrop1=`awk 'NR=="'${net_rowNum}'"{print $13}' ${netInfo}`
net_if_txDrop2=`awk 'NR=="'${net_rowNum}'"{print $13}' ${netInfo}2`
if [ $net_if_rxPps_t -gt 0 ]
then
net_if_rxErrorPerc=`echo "scale=2;($net_if_rxError2-$net_if_rxError1)*100/($net_if_rxPackets2-$net_if_rxPackets1)"|bc|awk '{printf "%.2f",$0}'`
net_if_rxDropPerc=`echo "scale=2;($net_if_rxDrop2-$net_if_rxDrop1)*100/($net_if_rxPackets2-$net_if_rxPackets1)"|bc|awk '{printf "%.2f",$0}'`
else
net_if_rxErrorPerc=0.00
net_if_rxDropPerc=0.00
fi
if [ $net_if_txPps_t -gt 0 ]
then
net_if_txErrorPerc=`echo "scale=2;($net_if_txError2-$net_if_txError1)*100/($net_if_txPackets2-$net_if_txPackets1)"|bc|awk '{printf "%.2f",$0}'`
net_if_txDropPerc=`echo "scale=2;($net_if_txDrop2-$net_if_txDrop1)*100/($net_if_txPackets2-$net_if_txPackets1)"|bc|awk '{printf "%.2f",$0}'`
else
net_if_txErrorPerc=0.00
net_if_txDropPerc=0.00
fi
net_avai_baseInfo=${net_avai_baseInfo}${sep}"if"${index}"-"${net_if_name}" i18n_client.SystemInfo.netSpeed_n81i"${net_if_speed}"Mbps, i18n_client.SystemInfo.input_n81i"${net_if_rxBps}"bps、"${net_if_rxPps}"pps, Output"${net_if_txBps}"bps、"${net_if_txPps}"pps; "
net_detail_nopolice="if${index}-"${net_if_name}","${net_if_rxPackets2}","${net_if_txPackets2}","${net_if_rxByte2}","${net_if_txByte2}","${net_if_rxError2}","${net_if_txError2}","${net_if_rxDrop2}","${net_if_txDrop2}","${net_if_speed}","${net_if_rxBps}","${net_if_txBps}","${net_if_rxPps}","${net_if_txPps}","${net_if_rxErrorPerc}","${net_if_txErrorPerc}","${net_if_rxDropPerc}","${net_if_txDropPerc}$'\n'
#netResult_detail=${netResult_detail}"\"\",,,if${index}-"${net_if_name}","${net_if_rxPackets2}","${net_if_txPackets2}","${net_if_rxByte2}","${net_if_txByte2}","${net_if_rxError2}","${net_if_txError2}","${net_if_rxDrop2}","${net_if_txDrop2}","${net_if_speed}","${net_if_rxBps}","${net_if_txBps}","${net_if_rxPps}","${net_if_txPps}","${net_if_rxErrorPerc}","${net_if_txErrorPerc}","${net_if_rxDropPerc}","${net_if_txDropPerc}$'\n'
# police
if [ ! -z $net_polices ]
then
OLD_IFS="$IFS"
IFS=","
net_detail_nopolice_arr=(${net_detail_nopolice})
IFS=$OLD_IFS
net_police_most_level=0
net_police_flag_t=0 #临时变量
net_baseInfo_police=""
for((j=0;j<${#net_polices_arr[@]};j++));do
net_detail_police_t=""
OLD_IFS="$IFS"
IFS="|"
net_police_arr=(${net_polices_arr[$j]})
IFS=$OLD_IFS
if (($(echo "${net_detail_nopolice_arr[((${net_police_arr[0]}-1))]} ${net_police_arr[1]} ${net_police_arr[2]}"|bc) == 1))
then #触发告警
net_detail_police_t=${net_police_arr[0]}","${net_police_arr[3]}","${net_police_arr[2]}","
net_police_flag=1
net_police_flag_t=1
if ((${net_police_arr[3]} > ${net_police_most_level}))
then
net_police_most_level=${net_police_arr[3]}
net_detail_police=$net_detail_police_t
net_baseInfo_police="${net_detail_nopolice_arr[0]}"${net_police_arr[4]}${net_detail_nopolice_arr[((${net_police_arr[0]}-1))]}"% i18n_client.GetInfoRun.abnormal_n81i</br>"
fi
elif [ $net_police_flag_t -eq 0 ]&&[ -z "${net_baseInfo_police}" ];then
net_detail_police="\"\",,,"
net_baseInfo_police="${net_detail_nopolice_arr[0]}"${net_police_arr[4]}${net_detail_nopolice_arr[((${net_police_arr[0]}-1))]}"% i18n_client.GetInfoRun.normal_n81i</br>"
fi
done
netResult_baseInfo_police=${netResult_baseInfo_police}${net_baseInfo_police}
else
net_detail_police="\"\",,,"
fi
netResult_detail=${netResult_detail}${net_detail_police}${net_detail_nopolice}
else
net_disa_baseInfo=${net_disa_baseInfo}${sep}"if"${index}"-"${net_if_name}"i18n_client.SystemInfo.disable_n81i; "
fi
done
if [[ "${netResult_baseInfo}" != "\"" ]];then
netResult_baseInfo="${netResult_baseInfo}"${sep}
fi
netResult_baseInfo=${netResult_baseInfo}"if"${index}"-"${#net_all_if_arr[@]}"i18n_client.SystemInfo.insert_n81i: "${net_avai_baseInfo}${net_disa_baseInfo}
}
# main
index=1
flag=1
while [ $flag -eq 1 ]; do
key='ip'${index}
value=`eval echo '$'${key}`
if [ -z ${value} ]
then
flag=0
else
getDetail ${key} ${value}
let "index++"
fi
done
## result
# cpu
cpuResult_baseInfo=${cpuResult_baseInfo}"\""
if ((${cpu_police_flag} == 0 ))
then
cpuResult_baseInfo_police="\""${cpuResult_baseInfo}
cpu_police_flag=1
else
cpuResult_baseInfo_police="\""${cpuResult_baseInfo_police}"\""
cpu_police_flag=0
fi
echo "${cpuResult_taskInfo}""${cpu_police_flag},""\"${cpuResult_coreNum}""i18n_client.SystemInfo.core_n81i: ""${cpuResult_baseInfo}"",""${cpuResult_baseInfo_police}"$'\n'"details,""$((cpuResult_coreNum+index-1))"$'\n'"${cpuResult_detail}" > ${snmp_result_dir}/"cpu.csv"
# mem
memResult_baseInfo=${memResult_baseInfo}"\""
if ((${mem_police_flag} == 0 ))
then
memResult_baseInfo_police=${memResult_baseInfo}
mem_police_flag=1
else
memResult_baseInfo_police="\""${memResult_baseInfo_police}"\""
mem_police_flag=0
fi
echo "${memResult_taskInfo}"${mem_police_flag}",${memResult_baseInfo}"",""${memResult_baseInfo_police}"$'\n'"details,""$((index-1))"$'\n'"${memResult_detail}" > ${snmp_result_dir}/"mem.csv"
# disk
diskResult_baseInfo=${diskResult_baseInfo}"\""
if ((${disk_police_flag} == 0 ))
then
diskResult_baseInfo_police=${diskResult_baseInfo}
disk_police_flag=1
else
diskResult_baseInfo_police="\""${diskResult_baseInfo_police}"\""
disk_police_flag=0
fi
echo "${diskResult_taskInfo}"${disk_police_flag}",${diskResult_baseInfo}"",""${diskResult_baseInfo_police}"$'\n'"details,$disk_total_num"$'\n'"${diskResult_detail}" > ${snmp_result_dir}/"disk.csv"
# net
netResult_baseInfo=${netResult_baseInfo}"\""
if ((${net_police_flag} == 0 ))
then
netResult_baseInfo_police=${netResult_baseInfo}
net_police_flag=1
else
netResult_baseInfo_police="\""${netResult_baseInfo_police}"\""
net_police_flag=0
fi
echo "${netResult_taskInfo}"${net_police_flag}",${netResult_baseInfo}"",""${netResult_baseInfo_police}"$'\n'"details,$net_total_num"$'\n'"${netResult_detail}" > ${snmp_result_dir}/"net.csv"
# sys
sysResult_baseInfo=${sysResult_baseInfo}"\""
echo "${sysResult_taskInfo}""${sysResult_baseInfo}"",""${sysResult_baseInfo}"$'\n'"details,$((index-1))"$'\n'"${sysResult_detail}""disk,${disk_total_num}"$'\n'"${sysResult_disk}""net,${sys_net_total_num}"$'\n'"${sysResult_net}" > ${snmp_result_dir}/"sys.csv"
# runtimes
echo "${runtimesResult}" > ${snmp_result_dir}/"runtimes.csv"

107
snmp/附件/shell/mem.sh Normal file
View File

@@ -0,0 +1,107 @@
#!/bin/bash
PLACE=".1.3.6.1.4.1.5000001.1.3.1" # MEM-MIB::memEntry的根OID
#
# 脚本会接收到两个参数
# $1 --请求类型
# -s --snmpset
# -g --snmpget
# -n --snmpgetnext/snmpwalk 注snmpwalk的本质是循环执行snmpgetnext以当次snmpgetnext的最终执行OID作为下次snmpgetnext的请求OID
# $2 --请求的OID
#
REQ="$2" # 请求的OID
RET="" # 最终执行的OID
#
# 提取mem监测结果文件的内容
#
basePath=$(cd `dirname $0`; pwd) # 脚本所在目录
while read line;do # 读取配置文件
eval "$line"
done < ${basePath}/config
declare -A devices_arr # 所有设备所有mem数据存放的数组最后从这里取数据格式devices_arr[“项”“设备序号"]
# 例如取第2台设备的总内存大小devices_arr[42]
item_num=7 # 项目数量,根据业务而定
details=`awk 'NR>2{print}' ${snmp_result_dir}"/mem.csv"` # 取得details内容
details_rownum=`echo "$details"|awk '{print NR}'|tail -n1` # details行数
for((i=0;i<$details_rownum;i++));do
device_index=$((i+1))
detail_row=`echo "$details"|awk 'NR=="'$device_index'"{print}'` # details某行的整行数据
OLD_IFS="$IFS"
IFS=","
detail_row_arr=($detail_row) # 将整行数据用逗号隔开转为数组
IFS=$OLD_IFS
for((j=3;j<${#detail_row_arr[@]};j++));do
devices_arr+=([$((j-1))${device_index}]=${detail_row_arr[$((j))]})
done
done
#
# 处理snmpgetnext请求获取REQ的递增后的下个OID递增规则需要自定义
#
if [ "$1" = "-n" ]; then
caseFlag=1
# 机器编号 -------------------开始
case $REQ in
$PLACE| \
$PLACE.0| \
$PLACE.0.*| \
$PLACE.1) RET=$PLACE.1.1; caseFlag=0 ;;
esac
for((i=1;i<=$device_index&&$caseFlag==1;i++));do
case $REQ in
$PLACE.1.$((i-1))| \
$PLACE.1.$((i-1)).*) RET=$PLACE.1.$i; caseFlag=0 ;;
esac
done
# 机器编号 -------------------结束
# mem信息 --------------------开始
for((i=2;i<=$item_num&&$caseFlag==1;i++));do
case $REQ in
$PLACE.$((i-1)).*| \
$PLACE.$i) RET=$PLACE.$i.1; caseFlag=0 ;;
esac
for((j=1;j<=$device_index&&$caseFlag==1;j++));do
case $REQ in
$PLACE.$i.$((j-1))| \
$PLACE.$i.$((j-1)).*) RET=$PLACE.$i.$j; caseFlag=0 ;;
#$PLACE.$i.$((j-1)).*| \
#$PLACE.$i.$j) RET=$PLACE.$i.$j; caseFlag=0 ;;
esac
done
done
# cpu信息 --------------------结束
fi
#
# 根据RET输出查询结果
#
echo "$RET"
for((i=1;i<=$device_index;i++));do
case "$RET" in
$PLACE.1.$i) echo "integer"; echo $i; exit 0 ;;
esac
done
for((i=2;i<=$item_num;i++));do
for((j=1;j<=device_index;j++));do
case "$RET" in
$PLACE.$i.$j) echo "string"; echo ${devices_arr[$i$j]}; exit 0 ;;
esac
done
done
echo "string"; echo "error OID"; exit 0

145
snmp/附件/shell/net.sh Normal file
View File

@@ -0,0 +1,145 @@
#!/bin/bash
PLACE=".1.3.6.1.4.1.5000001.1.5.1" # NET-MIB::netEntry的根OID
#
# 脚本会接收到两个参数
# $1 --请求类型
# -s --snmpset
# -g --snmpget
# -n --snmpgetnext/snmpwalk 注snmpwalk的本质是循环执行snmpgetnext以当次snmpgetnext的最终执行OID作为下次snmpgetnext的请求OID
# $2 --请求的OID
#
REQ="$2" # 请求的OID
RET="" # 最终执行的OID
#
# 提取net监测结果文件的内容
#
basePath=$(cd `dirname $0`; pwd) # 脚本所在目录
while read line;do # 读取配置文件
eval "$line"
done < ${basePath}/config
declare -A devices_arr # 所有设备所有cpu数据存放的数组最后从这里取数据格式devices_arr[“项”“设备序号”“网卡序号”]。个位数的项目号前面加0
# 例如取第2台设备的第3个网卡的速度第11项devices_arr[1123]第3台设备的第1个网卡的rxErrors第6项devices_arr[0631]
declare -A device_net # 设备对应的网卡数量格式device_core[1]=31号设备有3个网卡
device_index=1 # 设备序号
net_index=0 # 网卡序号
item_num=19 # 项目数量,根据业务而定
details=`awk 'NR>2{print}' ${snmp_result_dir}"/net.csv"` # 取得details内容
details_rownum=`echo "$details"|awk '{print NR}'|tail -n1` # details行数
for((i=0;i<$details_rownum;i++));do
for_i_flag=1
rownum_t=$((i+1))
detail_row=`echo "$details"|awk 'NR=="'$rownum_t'"{print}'` # details某行的整行数据
OLD_IFS="$IFS"
IFS=","
detail_row_arr=($detail_row) # 将整行数据用逗号隔开转为数组
IFS=$OLD_IFS
forthInfo=${detail_row_arr[3]}
OLD_IFS="$IFS"
IFS="-"
name_and_index_arr=($forthInfo)
IFS=$OLD_IFS
net_name=${name_and_index_arr[1]} # 网卡名称
device_index_t=${name_and_index_arr[0]#*if} # 当前设备序号
if [[ $device_index_t == $device_index ]];then
net_index=$((net_index+1))
devices_arr+=(["2"${device_index}${net_index}]=$net_name) # 将第二项net名称存入
else
device_net+=([$device_index]=$net_index)
net_index=1
device_index=$device_index_t
devices_arr+=(["2"${device_index}${net_index}]=${net_name}) # 将第二项net名称存入
fi
for((j=4;j<${#detail_row_arr[@]};j++));do
item_index=$((j-1))
if [[ j < 11 ]];then
item_index="0"${item_index}
fi
devices_arr+=([${item_index}${device_index}${net_index}]=${detail_row_arr[$j]})
done
done
device_net+=([$device_index]=$net_index)
#
# 处理snmpgetnext请求获取REQ的递增后的下个OID递增规则需要自定义
#
if [ "$1" = "-n" ]; then
caseFlag=1
# 机器编号 -------------------开始
case $REQ in
$PLACE| \
$PLACE.0| \
$PLACE.0.*| \
$PLACE.1) RET=$PLACE.1.1; caseFlag=0 ;;
esac
for((i=1;i<=$device_index&&$caseFlag==1;i++));do
case $REQ in
$PLACE.1.$((i-1))| \
$PLACE.1.$((i-1)).*) RET=$PLACE.1.$i; caseFlag=0 ;;
esac
done
# 机器编号 -------------------结束
# net信息 --------------------开始
for((i=2;i<=$item_num&&$caseFlag==1;i++));do
case $REQ in
$PLACE.$((i-1)).*| \
$PLACE.$i| \
$PLACE.$i.0) RET=$PLACE.$i.1.1; caseFlag=0 ;;
esac
for((j=1;j<=$device_index&&$caseFlag==1;j++));do
case $REQ in
$PLACE.$i.$((j-1)).*| \
$PLACE.$i.$j) RET=$PLACE.$i.$j.1; caseFlag=0 ;;
esac
for((k=1;k<=${device_net[$j]}&&$caseFlag==1;k++));do
case $REQ in
$PLACE.$i.$j.$((k-1))| \
$PLACE.$i.$j.$((k-1)).*) RET=$PLACE.$i.$j.$k; caseFlag=0 ;;
esac
done
done
done
# net信息 --------------------结束
fi
#
# 根据RET输出查询结果
#
echo "$RET"
for((i=1;i<=$device_index;i++));do
case "$RET" in
$PLACE.1.$i) echo "integer"; echo $i; exit 0 ;;
esac
done
for((i=2;i<=$item_num;i++));do
for((j=1;j<=$device_index;j++));do
for((k=1;k<=${device_net[$j]};k++));do
case "$RET" in
$PLACE.$i.$j.$k) echo "string"; echo "${devices_arr[$i$j$k]}"; exit 0 ;;
esac
done
done
done
echo "string"; echo "error OID"; exit 0

View File

@@ -0,0 +1,2 @@
#!/bin/bash
ip route show

View File

@@ -0,0 +1,145 @@
#!/bin/bash
PLACE=".1.3.6.1.4.1.5000001.1.1.1" # ZDJZ-MIB::deviceOverviewEntry的根OID
#
# 脚本会接收到两个参数
# $1 --请求类型
# -s --snmpset
# -g --snmpget
# -n --snmpgetnext/snmpwalk 注snmpwalk的本质是循环执行snmpgetnext以当次snmpgetnext的最终执行OID作为下次snmpgetnext的请求OID
# $2 --请求的OID
#
REQ="$2" # 请求的OID
RET="" # 最终执行的OID
#
# 获取系统运行时间并提取cpu、内存结果文件内容组织成结果
#
basePath=$(cd `dirname $0`; pwd) # 脚本所在目录
while read line;do # 读取配置文件
eval "$line"
done < ${basePath}/config
declare -A devices_arr # 所有设备数据存放的数组最后从这里取数据格式devices_arr["项""设备序号"]
# 例如取第2台设备的运行时间devices_arr[32]
device_index=1 # 设备序号
item_num=5 # 项目数量,根据业务而定
# 获取cpu使用率 -----------------------开始
cpu_details=`awk 'NR>2{print}' ${snmp_result_dir}/"cpu.csv"` # 取得details内容
cpu_details_rownum=`echo "$cpu_details"|awk '{print NR}'|tail -n1` # details行数
for((i=0;i<$cpu_details_rownum;i++));do
rownum_t=$((i+1))
cpu_detail_row=`echo "$cpu_details"|awk 'NR=="'$rownum_t'"{print}'` # details某行的整行数据
OLD_IFS="$IFS"
IFS=","
cpu_detail_row_arr=($cpu_detail_row) # 将整行数据用逗号隔开转为数组
IFS=$OLD_IFS
if [[ ${cpu_detail_row_arr[3]} =~ "-" ]];then
continue
else
devices_arr+=([4${device_index}]=${cpu_detail_row_arr[9]})
device_index=$((device_index+1)) # 设备序号加1
fi
done
device_index=1 # 重置设备序号,准备处理内存信息
# 获取cpu使用率 -----------------------结束
# 获取内存使用率 ----------------------开始
mem_details=`awk 'NR>2{print}' ${snmp_result_dir}"/mem.csv"` # 取得details内容
mem_details_rownum=`echo "$mem_details"|awk '{print NR}'|tail -n1` # details行数
for((i=0;i<$mem_details_rownum;i++));do
rownum_t=$((i+1))
mem_detail_row=`echo "$mem_details"|awk 'NR=="'$rownum_t'"{print}'` # details某行的整行数据
OLD_IFS="$IFS"
IFS=","
mem_detail_row_arr=($mem_detail_row) # 将整行数据用逗号隔开转为数组
IFS=$OLD_IFS
devices_arr+=([5${device_index}]=${mem_detail_row_arr[8]})
device_index=$((device_index+1))
done
device_index=1
# 获取内存使用率 ----------------------结束
# 获取运行时间 ------------------------开始
runtimes=`cat ${snmp_result_dir}"/runtimes.csv"`
runtimes_arr=($runtimes)
for((i=0;i<${#runtimes_arr[@]};i++));do
devices_arr+=([3${device_index}]=${runtimes_arr[i]})
device_index=$((device_index+1))
done
device_index=$((device_index-1))
# 获取运行时间 ------------------------结束
# 设置状态 ----------------------------开始
for((i=1;i<=$device_index;i++));do
devices_arr+=([2$i]=1)
done
# 设置状态 ----------------------------结束
#
# 处理snmpgetnext请求获取REQ的递增后的下个OID递增规则需要自定义
#
if [ "$1" = "-n" ]; then
caseFlag=1
# 机器编号 -------------------开始
case $REQ in
$PLACE| \
$PLACE.0| \
$PLACE.0.*| \
$PLACE.1) RET=$PLACE.1.1; caseFlag=0 ;;
esac
for((i=1;i<=$device_index&&$caseFlag==1;i++));do
case $REQ in
$PLACE.1.$((i-1))| \
$PLACE.1.$((i-1)).*) RET=$PLACE.1.$i; caseFlag=0 ;;
esac
done
# 机器编号 -------------------结束
# 详细信息 --------------------开始
for((i=2;i<=$item_num&&$caseFlag==1;i++));do
case $REQ in
$PLACE.$((i-1)).*| \
$PLACE.$i) RET=$PLACE.$i.1; caseFlag=0 ;;
esac
for((j=1;j<=$device_index&&$caseFlag==1;j++));do
case $REQ in
$PLACE.$i.$((j-1))| \
$PLACE.$i.$((j-1)).*) RET=$PLACE.$i.$j; caseFlag=0 ;;
esac
done
done
# 详细信息 --------------------结束
fi
#
# 根据RET输出查询结果
#
echo "$RET"
for((i=1;i<=$device_index;i++));do
case "$RET" in
$PLACE.1.$i) echo "integer"; echo $i; exit 0 ;;
esac
done
for((i=2;i<=$item_num;i++));do
for((j=1;j<=device_index;j++));do
case "$RET" in
$PLACE.$i.$j) echo "string"; echo ${devices_arr[$i$j]}; exit 0 ;;
esac
done
done
echo "string"; echo "error OID"; exit 0