secce 发表于 2013-1-11 09:05:51

Nagios自定义shell脚本检测MySql的AB复制

1. 建立一个Shell脚本,用于检测MySql的AB复制

vim /usr/local/nagios/libexec/check_mysqlab

[*]#!/bin/bash
[*]#=========================================
[*]#File:      checkmysqlab
[*]#Description:
[*]#Author:    smileliuyb
[*]#Modify:    smileliuyb
[*]#Creation Date: 20130110
[*]#Last Modified: 20130110
[*]#=========================================
[*]
[*]ipadd=$1
[*]mysql -h $ipadd -u username -ppasswd -e 'stop slave;' &> /dev/null
[*]#mysql -h $ipadd -u username -ppasswd -e 'show slave status \G' &> dev/null
[*]if [ $? -eq 0 ];then
[*]    mysql -h $ipadd -u username -ppasswd -e 'start slave;' &> /dev/null
[*]    num=`mysql -h $ipadd -u amoebauser -pabc -e 'show slave status \G' | grep -c Yes`
[*]    if [ $num -eq 2 ];then
[*]      echo "OK";
[*]      exit 0;
[*]    else
[*]      echo "Error";
[*]      exit 2;
[*]    fi
[*]else
[*]    echo "Error";
[*]    exit 2;
[*]fi
chown nagios.nagios /usr/local/nagios/libexec/check_mysqlab
chmod a+x /usr/local/nagios/libexec/check_mysqlab
2.配置Nagios,在Nagios中加入新命令调用该脚本
vim /usr/local/nagios/etc/objects/commands.cfg

[*]define command{
[*]      command_name    check_mysql_ab
[*]      command_line    $USER1$/check_mysqlab $HOSTADDRESS$
[*]      }
3.配置Nagios,建立新的被监控对象和被监控服务
vim /usr/local/nagios/etc/objects/localhost.cfg


[*]define host {
[*]      host_name       192.168.50.62
[*]      alias         50.62
[*]      address         192.168.50.62
[*]      check_command   check-host-alive
[*]      notification_options    d,u,r
[*]      check_interval1
[*]      max_check_attempts      2
[*]      contact_groupsadmins
[*]      notification_interval   10
[*]      notification_period   24x7
[*]}


[*]define service{
[*]      host_name 192.168.50.62
[*]      service_description   mysqlab
[*]      check_period    24x7
[*]      normal_check_interval   2
[*]      retry_check_interval    1
[*]      max_check_attempts      3
[*]      notification_period   24x7
[*]      notification_options    w,u,c,r
[*]      check_command   check_mysql_ab
[*]}

花蜻宽 发表于 2013-3-14 07:30:24

我是来刷分的,嘿嘿

ct38 发表于 2013-5-16 02:35:15

路边的野花不要,踩。

yanfangsheng123 发表于 2013-5-17 08:51:00

脱了衣服我是禽兽,穿上衣服我是衣冠禽兽!

a2005147 发表于 2013-5-18 11:38:33

有道理。。。

luoson1 发表于 2013-5-19 14:45:06

鸳鸳相抱何时了,鸯在一边看热闹。

civilvar 发表于 2013-5-20 17:02:33

路过,学习下
页: [1]
查看完整版本: Nagios自定义shell脚本检测MySql的AB复制