重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
背景:由于线上服务器硬盘故障,导致服务,数据失效;
为郊区等地区用户提供了全套网页设计制作服务,及郊区网站建设行业解决方案。主营业务为成都做网站、网站建设、郊区网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!目的:保证第一时间发现硬盘信息是否正常;
方案:使用Nagios 自定义脚本来监控硬盘状态;
注意:下面脚本只提供已经安装hpacucli megacli 软件使用;
#!/bin/bash #Marc.wang 2014/06/17 export PATH=$PATH:/usr/sbin/:/sbin/:/usr/bin/ Get_localhost_Hostname=`hostname -I |awk '{print $1}'` Nagios="nagios.org" SERVER_TYPE=$(/usr/sbin/dmidecode | grep "Vendor" | awk -F\: 'NR==1{print $2}'|awk '{print $1}') #The nagios command run nsca Send_nsca_ssl_message (){ /usr/local/nagios/bin/send_nsca -H ${Nagios} -d ";" -c /usr/local/nagios/etc/send_nsca.cfg } #hp command run HP_DISK_STATUS_COMMAND() { rpm -qa |grep hpacucli >> /dev/null 2>&1 echo $? } # dell command run DELL_IBM_DISK_STATUS_COMMAND() { rpm -qa |grep MegaCli >> /dev/null 2>&1 echo $? } bug_test=$(ps ax |grep hpacucli |grep -v grep |wc -l) if [ "${bug_test}" != "0" ] then echo "$Get_localhost_Hostname;check_raid;2; hpacucli command run not data." | Send_nsca_ssl_message exit 2 fi CHECK_RAID_STATUS_HP () { /usr/sbin/hpacucli ctrl all show config detail |grep physicaldrive -A 4 |sed 's/ //g'|grep "Status:" |grep -v "Status:OK" | wc -l } case $SERVER_TYPE in HP|hp|Hp|Hewlett-Packard) TEST_HP_COMMAND () { hpacucli ctrl all show config detail >> /dev/null 2>&1 echo $? } HP_RPM=$(HP_DISK_STATUS_COMMAND) sleep 3 if [ ${HP_RPM} != "0" ] then echo "$Get_localhost_Hostname;check_raid;2; $SERVER_TYPE command hpacucli Not Found" | Send_nsca_ssl_message exit 2 elif [[ ${HP_RPM} == "0" ]]; then HP_RAID_STATUS_NUMBER=$(CHECK_RAID_STATUS_HP) sleep 3 TEST_HP=$(TEST_HP_COMMAND) if [ "$HP_RAID_STATUS_NUMBER" == "0" ] && [ "$TEST_HP" == "0" ]; then echo "$Get_localhost_Hostname;check_raid;0;Check_Raid_status:OK" | Send_nsca_ssl_message exit 0 elif [ "${TEST_HP}" != "0" ] then echo "$Get_localhost_Hostname;check_raid;2;Check_Raid_status: run command hpacucli Error" | Send_nsca_ssl_message exit 2 elif [ "$HP_RAID_STATUS_NUMBER" != "0" ] && [ "$TEST_HP" == "0" ] then echo "$Get_localhost_Hostname;check_raid;2;Check_Raid_status:Critical" | Send_nsca_ssl_message exit 2 fi fi ;; DELL|Dell|DEll|DeLL|dell|IBM|ibm|Ibm|IBm) if [ -f "/opt/MegaRAID/MegaCli/MegaCli64" ]; then CHECK_RAID_STATUS_IBM_DELL () { /opt/MegaRAID/MegaCli/MegaCli64 -LdPdInfo -a0 | grep -E "(Media Error Count:|Other Error Count:)" |awk -F: '{sum1 += $2} END {print sum1}' } TEST_DELL_COMMAND (){ /opt/MegaRAID/MegaCli/MegaCli64 -LdPdInfo -a0 >> /dev/null echo $? } else CHECK_RAID_STATUS_IBM_DELL () { MegaCli -LdPdInfo -a0 | grep -E "(Media Error Count:|Other Error Count:)" |awk -F: '{sum1 += $2} END {print sum1}' } TEST_DELL_COMMAND (){ MegaCli -LdPdInfo -a0 >> /dev/null echo $? } fi IBM_DELL_RPM=$(DELL_IBM_DISK_STATUS_COMMAND) if [[ ${IBM_DELL_RPM} == "0" ]] then TEST_OTHER_COMMAND=$(TEST_DELL_COMMAND) DELL_IBM_STATUS_NUMBER=$(CHECK_RAID_STATUS_IBM_DELL) if [[ -z "$DELL_IBM_STATUS_NUMBER" ]] then echo "$Get_localhost_Hostname;check_raid;2;Check_Raid_status:MegaCli Command Not Found!" | Send_nsca_ssl_message exit 2 elif [[ "$DELL_IBM_STATUS_NUMBER" -gt "2000" ]] ; then echo "$Get_localhost_Hostname;check_raid;2;Check_Raid_status:Critical" | Send_nsca_ssl_message exit 2 elif [[ "$DELL_IBM_STATUS_NUMBER" -lt "2000" ]] && [[ "$TEST_OTHER_COMMAND" == "0" ]] then echo "$Get_localhost_Hostname;check_raid;0;Check_Raid_status:OK" | Send_nsca_ssl_message exit 0 fi fi ;; *) echo "$Get_localhost_Hostname;check_raid;2;This machine is not IBM DELL or HP!" | Send_nsca_ssl_message ;; esac
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。