nagios服务器上添加监控的主机及服务:

Nagios配置文件:

[root@a etc]# cd objects/

[root@a objects]# ls

commands.cfg(定义监控命令)  localhost.cfg(定义监控什么)  switch.cfg(定义交换机) timeperiods.cfg(模板文件)

contacts.cfg(定义联系人的)  printer.cfg(定义打印机模板的)    templates.cfg(模板定制文件)  windows.cfg(监控windows及其模板)

[root@a objects]# pwd

/usr/local/nagios/etc/objects

添加一台主机:[root@a objects]# vim localhost.cfg

nagios添加主机和写mysql插件_本地插件

检查配置文件是否有误:

nagios添加主机和写mysql插件_添加新主机_02

重启服务并查看(点击host):

nagios添加主机和写mysql插件_本地插件_03

nagios添加主机和写mysql插件_添加新主机_04

监控服务(ssh):[root@a objects]# vim localhost.cfg

nagios添加主机和写mysql插件_本地插件_05

[root@a objects]# /etc/init.d/nagios reload

Running configuration check...

Reloading nagios configuration...

Done

nagios添加主机和写mysql插件_nagios_06

 

写插件:

0           正常

1           警告

2           严重警告

一:写一个监控本机mysql的插件:

[root@a libexec]# vim check_mysql

#!/bin/bash

mysql -e "show databases" &>/dev/null

 if [ $? -eq 0 ]

      then

           echo "mysql runing....."

           exit 0

  else

           echo "mysql stop"

           exit 2

  fi

测试插件;

[root@a libexec]# chmod 755 check_mysql

nagios添加主机和写mysql插件_添加新主机_07

二:写一个调用插件的命令

nagios添加主机和写mysql插件_添加新主机_08

测试插件:

[root@a objects]# /usr/local/nagios/libexec/check_mysql -H localhost

mysql stop

[root@a objects]# /etc/init.d/mysqld start

启动 MySQL                                               [确定]

[root@a objects]# /usr/local/nagios/libexec/check_mysql -H localhost

mysql runing.....

localhost.cfg文件;

[root@a objects]# vim localhost.cfg

nagios添加主机和写mysql插件_添加新主机_09

测试配置文件是否有错:

[root@a objects]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

[root@a objects]# /etc/init.d/nagios reload

Running configuration check...

Reloading nagios configuration...

Done

nagios添加主机和写mysql插件_添加新主机_10