使用NDOUtils将Nagios监控信息存入mysql

参考
http://nagios.sourceforge.net/docs/ndoutils/NDOUtils.pdf

1.NDOUtils安装需求

nagios
mysql
cpan DBI #非必需
cpan DBD::mysql #非必需

2.关联mysql头文件和库
不做关联可能在config或make时出错

  1. echo '/usr/lib' >> /etc/ld.so.conf

  2. ldconfig -v

3.安装ndoutils

http://sourceforge.net/project/showfiles.php?group_id=26589

  1. --with-mysql-inc=/opt/mysql/include --with-mysql-lib=/opt/mysql/lib

  2. #config成功

  3. #make出错

*config时使用以下mysql参数

  1. <del datetime="2009-05-27T06:58:24+00:00">LDFLAGS=-L/opt/mysql/lib </del>

  2. #ndo2db不能导入到数据库

相关错误

  1. make

  2. ll ./src

看看是否有以下文件
ndo2db-2x
ndo2db-3x
ndomod-2x.o
ndomod-3x.o

4.拷贝文件
# 我的Nagios是3.0.6,所以拷贝的是ndomod-3x.o、ndo2db-3x,如果你的是2.X.x请拷贝ndomod-2x.o、ndo2db-2x

  1. cp ./config/ndo* /usr/local/nagios/etc/

  2. chown nagios:nagios /usr/local/nagios/etc/*

6.创建ndo的mysql 数据库及用户

  1. cd ./db/

  2. ./installdb -u root -p 123456 -h localhost -d nagios

用命令导入(其实和用脚本是一回事,也可以用phpmyadmin来导入)

  1. db_user=nagiosndo

  2. db_pass=password123

vi /usr/local/nagios/etc/nagios.cfg

  1. /usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg


  2. echo 'rm -f /usr/local/nagios/var/ndo.sock' >> /etc/rc.local

  3. echo '/usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg' >> /etc/rc.local

  4. #开机启动

  1. /usr/local/nagios/bin/ndo2db-3x: error while loading shared libraries: libmysqlclient.so.16: cannot open shared object file: No such file or directory

出现以上错误请执行第2步

10.重启动nagios

  1. tail -20 /usr/local/nagios/var/nagios.log

[1242971625] ndomod: Successfully flushed 80 queued items to data sink.
[1242971625] ndomod: Error writing to data sink! Some output may get lost…

貌似有点问题
参考:

http://www.nagios.net.cn/blog/blog.php?do-showone-itemid-62-type-blog.html

先改成输出成文件
#vi ndomod.cfg

  1. service nagios restart

看看有没有/usr/local/nagios/var/ndo.dat文件,ok,发现文件,说明第一步可以生成文件
查看文件内容

  1. ../bin/file2sock -s /usr/local/nagios/var/ndo.dat -d /usr/local/nagios/var/ndo.sock -t unix -p 5668

Error while writing to destination socket: Connection reset by peer

尝试tcp方式
vi ndo2db.cfg

  1. ps aux|grep ndo2db

  2. kill $pid

  3. /usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg


  4. ../bin/file2sock -s ndo.dat -d localhost -t tcp -p 5668

Error while writing to destination socket: Connection reset by peer

依然不行,重新编译ndoutils并加上 LDFLAGS=-L/opt/mysql/lib
参考

http://www.itnms.net/discuz/viewthread.php?tid=1357&extra=pageD1&page=1

  1. Dec  7 14:09:13 localhost nagios: ndomod: Still unable to connect to data sink.  10547 items lost, 5000 queued items to flush.

  2. Dec  7 14:09:29 localhost nagios: ndomod: Still unable to connect to data sink.  10746 items lost, 5000 queued items to flush.

连接不到mysql,重启一下

/usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg

  1. Dec  7 14:09:45 localhost nagios: ndomod: Successfully connected to data sink.  10861 items lost, 5000 queued items to flush.

  2. Dec  7 14:09:45 localhost nagios: ndomod: Successfully flushed 5000 queued items to data sink.

  3. Dec  7 14:09:45 localhost ndo2db-3x: Successfully connected to MySQL database

你可能感兴趣的:(ndoutils)