DELL服务器OMSA监控硬件脚本并生成html报告

Z先森 2019-01-02 AM 1814℃ 0条

脚本 hardware_status.sh,获取硬件指标:

#!/bin/bash
#by maxbon 2018/12/27 硬件检测脚本
source /etc/profile

#获取设备IP
function GetDeviceIp()
{
     IPs=`ifconfig | grep "inet addr:" |egrep -v "127.0.0.1|172.18|172.17" |awk '{print $2}' |awk -F: '{print$2"<br>"}'`
     echo "$IPs"
}

#获取OMSA信息存放至临时文件
function GetOmsaInfo()
{
    /opt/dell/srvadmin/sbin/omreport chassis >/tmp/GetOmsaMain
    /opt/dell/srvadmin/sbin/omreport chassis temps >/tmp/GetTemps
    /opt/dell/srvadmin/bin/omreport storage adisk controller=0 >/tmp/GetDisk
    /opt/dell/srvadmin/bin/omreport storage controller >/tmp/GetRaid
    /opt/dell/srvadmin/bin/omreport chassis memory >/tmp/GetMemory
}

#获取所有组件状态
function GetMain()
{
    Fans=$(cat /tmp/GetOmsaMain | grep "Fans" | awk '{print $1}')
    Intrusion=$(cat /tmp/GetOmsaMain | grep "Intrusion" | awk '{print $1}')
    Memory=$(cat /tmp/GetOmsaMain | grep "Memory" | awk '{print $1}')
    Power_Supplies=$(cat /tmp/GetOmsaMain | grep "Power Supplies" | awk '{print $1}')
    Power_Management=$(cat /tmp/GetOmsaMain | grep "Power Management" | awk '{print $1}')
    Processors=$(cat /tmp/GetOmsaMain | grep "Processors" | awk '{print $1}')
    Temperatures=$(cat /tmp/GetOmsaMain | grep "Temperatures" | awk '{print $1}')
    Voltages=$(cat /tmp/GetOmsaMain | grep "Voltages" | awk '{print $1}')
    echo "风扇状态: $Fans"
    echo "<br>机箱盖状态: $Intrusion"
    echo "<br>内存状态: $Memory"
    echo "<br>电源供给状态: $Power_Supplies"
    echo "<br>电源管理状态: $Power_Management"
    echo "<br>处理器状态: $Processors"
    echo "<br>温度状态: $Temperatures"
    echo "<br>电压状态: $Voltages"
}

#获取温度
function GetTemps()
{
        TEMP=$(cat /tmp/GetTemps | grep -A1 "$1" | tail -n1 | awk -F: '{print $2}')
    TEMP_STATUS=$(cat /tmp/GetTemps | grep -B1 "$1" | head -n1 | awk -F: '{print $2}')
        echo "${2}温度:${TEMP} 状态:${TEMP_STATUS}<br>"
}

#获取内存状态
function GetMemory()
{
    cat /tmp/GetMemory | grep "Connector Name" | awk -F: '{print $2}' | while read line
    do
        Memory_Type=$(cat /tmp/GetMemory | grep -A1 "\<$line\>" | tail -n1 |awk -F: '{print $2}')
        if [[ "$Memory_Type" =~ "Not" ]];then
            continue
        else
            Memory_Status=$(cat /tmp/GetMemory | grep -B1 "\<$line\>" | head -n1)
            Memory_DDR=$(cat /tmp/GetMemory | grep -A1 "\<$line\>" | tail -n1 | awk -F- '{print $1}')
            Memory_Size=$(cat /tmp/GetMemory | grep -A2 "\<$line\>" | tail -n1)
            echo "内存位置: $line"
            echo "<br>内存状态: $Memory_Status"
            echo "<br>内存大小: $Memory_Size"
            echo "<br><br>"
        fi
    done
}

#获取硬盘状态
function GetDisk()
{
    cat /tmp/GetDisk | grep ": Physical Disk" | awk '{$1="";$2="";print}' | while read line
    do
        Disk_Name=$(cat /tmp/GetDisk | grep -B2 -A32 "$line" | grep "Name" | grep -v "Device Name" | grep -v "Power Status" | awk '{$1="";$2="";print}')
        Disk_Status=$(cat /tmp/GetDisk | grep -B2 -A32 "$line" | grep "Status" | grep -v "Device Name" | grep -v "Power Status" | awk '{$1="";$2="";print}')
        Disk_State=$(cat /tmp/GetDisk | grep -B2 -A32 "$line" | grep "State" | grep -v "Device Name" | grep -v "Power Status" | awk '{$1="";$2="";print}')
        Disk_Pid=$(cat /tmp/GetDisk | grep -B2 -A32 "$line" | grep "Product ID" | grep -v "Device Name" | grep -v "Power Status" | awk '{$1="";$2="";print}')
        echo "硬盘位置: $Disk_Name"
        echo "<br>硬盘状态: $Disk_Status"
        echo "<br>是否在线: $Disk_State"
        echo "<br>硬盘ID: $Disk_Pid"
        echo "<br><br>"
    done
}

#获取RAID卡状态
function GetRaid()
{
    Raid_Name=$(cat /tmp/GetRaid | grep "Name" | awk -F: '{print $2}')
    Raid_Status=$(cat /tmp/GetRaid | grep "Status" | awk -F: '{print $2}')
    echo "Raid卡: $Raid_Name"
    echo "<br>状态: $Raid_Status"
}

GetOmsaInfo #获取OMSA信息
echo "<!doctype html>"
echo "`date`"
GetDeviceIp #获取设备IP
echo "<table width=\"100%\">"
echo "<td valign=\"top\"><h4>-----------所有组件-------------</h4>"
GetMain #获取所有组件状态
echo "</td><td valign=\"top\"><h4>-----------设备温度-------------</h4>"
GetTemps "Board Inlet" "主板进气口" #获取设备温度
GetTemps "Board Exhaust" "主板排气口"
GetTemps "CPU1" "CPU1"
GetTemps "CPU2" "CPU2"
echo "</td><td valign=\"top\"><h4>------------内存----------------</h4>"
GetMemory #获取内存状态
echo "</td><td valign=\"top\"><h4>------------硬盘----------------</h4>"
GetDisk #获取硬盘状态
echo "</td><td valign=\"top\"><h4>-----------RAID卡---------------</h4>"
GetRaid #获取RAID卡状态
echo "</td></table>"

脚本report_hardware.sh,生成html报告

#!/bin/bash
#by maxbon 2018/12/27 自动检测服务器硬件状态并生成html
source /etc/profile
DATE=`date +%Y%m%d`
SERVER=`ifconfig | grep "inet addr:" |egrep -v "127.0.0.1|172.18|172.17" |awk '{print $2}' |awk -F: '{print$2}'|head -1`
sh /shell/hardware_status.sh >/tmp/${SERVER} 2>>/shell/hardware_run.out
echo "[`date`][$?]" >>/shell/hardware_run.out
rm -f /tmp/${SERVER}
rm -f /tmp/Get*

编辑任务计划:

crontab -e
00 17 * * * sh /shell/report_hardware.sh
标签: 脚本, srvadmin, shell, crontab, awk

如无特殊说明,本博所有文章均为博主原创。

评论啦~