bug 修复 修复bug在脚本中注释

master
newrain 3 years ago
parent 2cdf999e30
commit 074b44d224
  1. 17
      zabbix_agentd.d/script/osMonitor.sh

@ -4,6 +4,7 @@
# build 2021-06-16 # build 2021-06-16
#1、磁盘根分区剩余百分比 #返回数值,并添加触发器报警 #1、磁盘根分区剩余百分比 #返回数值,并添加触发器报警
#bug1: lsblk 收集信息问题
function disk() { function disk() {
local _part _disk local _part _disk
_part=$(lsblk -b | grep "centos-root" | awk '{print $(NF-3)}' | awk -F'G' '{print $1}') _part=$(lsblk -b | grep "centos-root" | awk '{print $(NF-3)}' | awk -F'G' '{print $1}')
@ -25,31 +26,35 @@ function swap() {
} }
#4、cpu 1、5、15分钟负载 #返回数值或其他类型 #4、cpu 1、5、15分钟负载 #返回数值或其他类型
#bug2: 变量冲突 uptime
function cpuLoad() { function cpuLoad() {
case $1 in case $1 in
1) 1)
uptime | awk '{print $(NF-2)}' | awk -F',' '{print $1}' /usr/bin/uptime | awk '{print $(NF-2)}' | awk -F',' '{print $1}'
;; ;;
5) 5)
uptime | awk '{print $(NF-1)}' | awk -F',' '{print $1}' /usr/bin/uptime | awk '{print $(NF-1)}' | awk -F',' '{print $1}'
;; ;;
15) 15)
uptime | awk '{print $(NF)}' | awk -F',' '{print $1}' /usr/bin/uptime | awk '{print $(NF)}' | awk -F',' '{print $1}'
;; ;;
esac esac
} }
#5、/etc/passwd /etc/shadow /etc/sodoers 等文件修改情况 #返回任意类型,并添加触发器报警 #5、/etc/passwd /etc/shadow /etc/sodoers 等文件修改情况 #返回任意类型,并添加触发器报警
#bug3: 没有sudo权限
function fileMD5() { function fileMD5() {
[ ! -f /tmp/md5.hash ] && md5sum /etc/passwd /etc/shadow /etc/sudoers >/tmp/md5sum && echo "数据收集中" [ ! -f /tmp/md5.hash ] && sudo md5sum /etc/passwd /etc/shadow /etc/sudoers >/tmp/md5.hash && echo "数据收集中"
md5sum -c /tmp/md5.hash | grep -E "FAILED|失败" sudo md5sum -c /tmp/md5.hash | grep -E "FAILED|失败"
} }
#6、系统启动时间 #返回任意类型 #6、系统启动时间 #返回任意类型
#bug4: /proc/uptime 时间逻辑错了,cpu空闲率 = 空闲时间/(启动时间xcpu核心数)
function uptime() { function uptime() {
local _uptime _idletime local _uptime _idletime
_uptime=$(cat /proc/uptime | awk '{print ($1/60)}') # 单位为分钟 _uptime=$(cat /proc/uptime | awk '{print ($1/60)}') # 单位为分钟
_idletime=$(cat /proc/uptime | awk '{print ($2/60)}') # 系统空闲时间 _idletime=$(cat /proc/uptime | awk '{print ($2/60)}') # 系统空闲时间
_cpus=$(cat /proc/cpuinfo |grep processor |wc -l) # cpu核心数
case $1 in case $1 in
upTime) upTime)
echo $_uptime echo $_uptime
@ -58,7 +63,7 @@ function uptime() {
echo $_idletime echo $_idletime
;; ;;
idle) idle)
echo "scale=2;a=${_idletime}/${_uptime};if (length(a)==scale(a)) print 0;print a " | bc echo "scale=2;a=${_idletime}/(${_uptime}*${_cpus});if (length(a)==scale(a)) print 0;print a " | bc
;; ;;
esac esac
} }

Loading…
Cancel
Save