Zabbix Enterprise Application extract CentOS 6.2 system online days from database

Source: Internet
Author: User
Tags mysql host

History causes the company has a lot of CentOS 6.2 system, from one day 6.2 system suddenly automatic restart, troubleshooting Half-day discovery is 6.2 kernel bug (more than 208 days may automatically restart, You can refer to https:// access.redhat.com/site/solutions/68466), so in order not to affect the business, After discovering that 6.2 systems have been online for more than 180 days to schedule a restart, here's how to use Zabbix to get a 6.2 system server's online days from the database, then notify the business to restart and avoid an unexpected restart that will cause the business to be affected.

1. Script Content

#!/bin/bash#script name check_6.2_uptime.sh . /etc/profilelogdir= '/tmp/zabbix_log ' Mysql_ host= ' localhost ' mysql_user= ' Zabbix ' mysql_passwd= ' Zabbix ' mysql_database= ' Zabbix ' year= ' date +%y ' month= ' date  +%m-%d ' next_month= ' date +%m-%d -d  "1 days" ' if [ ! -d  $logdir  ];then    mkdir  $logdirfi # #zabbix  get centos 6.2 uptime# select os system versionmysql -h  $mysql _host  -u  $mysql _user -p$ mysql_passwd  $mysql _database > $logdir/mysql_zabbix_os_system.txt<<eofset names  Utf8;select from_unixtime (Hi.clock)  as Date,g.name as Group_Name,h.host as  host, hi.value as system_version  from hosts_groups hg join  Groups g on g.groupid = hg.groupid join items i on hg.hostid  = i.hostid join hosts h on h.hostid=i.hostid join history_str hi on   i.itemid = hi.itemid  where  i.key_= ' system.sw.os[name] '  and hi.value  like  '%6.2% '  and g.name <>  ' all MySQL host group '  and  hi.clock  >= unix_timestamp (' ${year}-${month} 00:00:00 ')  and  hi.clock <=  unix_timestamp (' ${year}-${next_month} 00:00:00 ')  group by h.host; eof#select uptimemysql -h  $mysql _host  -u  $mysql _user -p$mysql_passwd  $mysql _database > $logdir/mysql_zabbix_os_uptime.txt<<eofset names utf8;select  From_unixtime (Hi.clock)  as date,g.name as group_name,h.host as host, round ( Max (Hi.value_max)/86400,0)  as system_uptime  from hosts_groups hg join  groups g on g.groupid =&Nbsp;hg.groupid join items i on hg.hostid = i.hostid join hosts  h on h.hostid=i.hostid join trends_uint hi on  i.itemid =  hi.itemid  where  i.key_= ' System.uptime '  and  hi.clock >=  unix_timestamp (' ${year}-${month} 00:00:00 ')  and  hi.clock <= unix_ TIMESTAMP (' ${year}-${next_month} 00:00:00 ')  group by h.host; eofsed -i  '/date*/d '   $logdir/mysql_zabbix_os_system.txtsed -i  '/date*/d '   $logdir /mysql_zabbix_os_uptime.txtawk  ' {print $1 ' \ T "$ $" \ T "$4" \t6.2 "} '   $logdir/mysql_zabbix_os_ system.txt >  $logdir/mysql_zabbix_os_system_version.txtawk  ' {print $1 "\ t" $ "\ T" $4 "\ T" $ } '   $logdir/mysql_zabbix_os_uptime.txt >  $logdir/mysql_zabbix_os_uptime_new.txtawk  ' NR== FNR{A[$1,$2,$3]=$4;NEXT}{PRINT&NBSP;$0,A[$1,$2,$3]} '   $logdir/mysql_zabbix_os_uptime_new.txt  $logdir/mysql_zabbix_os_system_version.txt|awk  ' {if ($5 >  {print $0}} ' |sort -k2nr >  $logdir/zabbix_os_uptime_result.txtsed -i   ' 1i  query date \ t belongs to group \ T host ip\t system version \ t online days '   $logdir/zabbix_os_uptime_result.txt

Default results in /tmp/zabbix_log/zabbix_os_uptime_result.txt, modify the database information for your scripts according to your environment.

1. function

Use the following command directly

/bin/bash check_6.2_uptime.sh

3, the result content (partial display, the main group information shielding)

[email protected] zabbix_log]# cat Zabbix_os_uptime_result.txt Query Date Group host IP system version online days 2014-07-23xxx room-Self-research project--xx10.10.10.466.2 2182014-07-23xxx Room-Self-research project--xxx10.10.10.476.2 2182014-07-23xxx Room--Self-research project--xxx192.168.10.1536.2 2022014-07-23xxx Room--Self-research project--xxx192.168.10.1546.2 202

4. txt into Excel format

please see "http://jingyan.baidu.com/article/359911f5108f3757fe0306fb.html", I will not introduce, very simple.

If you want to use my script, you can download from the attachment, that this article is good for you, please give a praise and praise, thank you.

This article is from the "Yin-Technical Exchange" blog, please be sure to keep this source http://dl528888.blog.51cto.com/2382721/1529157

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.