Skip to content


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

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

1.NDOUtils安装需求

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

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

ln -s /opt/mysql/include/* /usr/include/
ln -s /opt/mysql/lib/* /usr/lib/


echo ‘/usr/lib’ >> /etc/ld.so.conf
ldconfig -v

3.安装ndoutils
http://sourceforge.net/project/showfiles.php?group_id=26589

wget -c http://nchc.dl.sourceforge.net/sourceforge/nagios/ndoutils-1.4b7.tar.gz
tar zxvf ndoutils-1.4b7.tar.gz
cd ndoutils-1.4b7
./configure –prefix=/usr/local/nagios –enable-mysql –disable-pgsql LDFLAGS=-L/opt/mysql/lib –with-mysql-inc=/opt/mysql/include/mysql –with-mysql-lib=/opt/mysql/lib/mysql

*config时使用以下mysql参数

–with-mysql-inc=/opt/mysql/include –with-mysql-lib=/opt/mysql/lib
#config成功
#make出错

*config时使用以下mysql参数

–with-mysql-inc=/opt/mysql/include/mysql –with-mysql-lib=/opt/mysql/lib/mysql
#config出错
#make成功并生成文件
#启动ndo2db会出错

*没有LDFLAGS=-L/opt/mysql/lib

LDFLAGS=-L/opt/mysql/lib
#ndo2db不能导入到数据库

相关错误

In file included from io.c:10:
../include/config.h:261:25: mysql/mysql.h: 没有那个文件或目录
../include/config.h:262:26: mysql/errmsg.h: 没有那个文件或目录
make[1]: *** [io.o] 错误 1
checking for mysql/mysql.h… no

*** MySQL include file could not be located… **********************

You chose to compile NDBXT with MySQL support, but I was unable to
locate on your system. If the include file is
installed, use the –with-mysql-inc argument to specify the location
of the MySQL include file.


make
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

cp ./src/ndomod-3x.o /usr/local/nagios/bin
cp ./src/ndo2db-3x /usr/local/nagios/bin
cp ./src/log2ndo /usr/local/nagios/bin
cp ./src/file2sock /usr/local/nagios/bin
chown nagios:nagios /usr/local/nagios/bin/*

5.拷贝配置文件
cp ./config/ndo* /usr/local/nagios/etc/
chown nagios:nagios /usr/local/nagios/etc/*

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

CREATE DATABASE `nagios` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
GRANT select,insert,update,delete ON nagios.* TO nagiosndo@localhost identified by ‘password123’;
FLUSH PRIVILEGES ;

7.导入数据库结构
使用db/installdb脚本
需要以下支持

cpan DBI
cpan DBD::mysql


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

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

/opt/mysql/bin/mysql -u root -p -D nagios -h localhost < ./db/mysql.sql

输入密码

成功导入59张表

8.修改配置文件
vi /usr/local/nagios/etc/ndo2db.cfg

db_user=nagiosndo
db_pass=password123

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

# 修改下面参数的值为-1(一般默认如此)。
event_broker_options=-1
# 复制下面内容粘贴到#broker_module=…下面。
# 注意broker_module= 和config_file是在一行上
# Uncomment the line below if you’re running Nagios 3.x
broker_module=/usr/local/nagios/bin/ndomod-3x.o config_file=/usr/local/nagios/etc/ndomod.cfg

9.启动ndo2db

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

echo ‘rm -f /usr/local/nagios/var/ndo.sock’ >> /etc/rc.local
echo ‘/usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg’ >> /etc/rc.local
#开机启动


Support for the specified database server is either not yet supported, or was not found on your system.


/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

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
service nagios restart

一般情况下到此已完成安装,可以去数据库里看下记录有无增加

11.检查安装是否正确

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

instance_name=default
#output_type=tcpsocket
#output=127.0.0.1

output_type=file
output=/usr/local/nagios/var/ndo.dat


service nagios restart

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

cd /usr/local/nagios/var/
head -30 ndo.dat

HELLO
PROTOCOL: 2
AGENT: NDOMOD
AGENTVERSION: 1.4b7
STARTTIME: 1243393299
DISPOSITION: REALTIME
CONNECTION: FILE
CONNECTTYPE: INITIAL
INSTANCENAME: default
STARTDATADUMP

202:
1=300
2=0
3=0
4=1243393292.450675
73=1243393292
74=262144
72=ndomod: Error writing to data sink! Some output may get lost…
999

201:
1=205
2=0

使用file2sock尝试socket方式

../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

#socket_type=unix
socket_type=tcp

重新载入ndo2db

ps aux|grep ndo2db
kill $pid
/usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg

../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

./configure –prefix=/usr/local/nagios –enable-mysql –disable-pgsql LDFLAGS=-L/opt/mysql/lib –with-mysql-inc=/opt/mysql/include/mysql –with-mysql-lib=/opt/mysql/lib/mysql
make
#再执行一下安装过程后,通过

=================
200912-07 更新

tail /var/log/messages

Dec 7 14:09:13 localhost nagios: ndomod: Still unable to connect to data sink. 10547 items lost, 5000 queued items to flush.
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

Could not bind socket: Address already in use

ps aux|grep ndo2db
没有

查看套接字文件是否存在,删除之
ll /usr/local/nagios/var/ndo.sock
rm /usr/local/nagios/var/ndo.sock

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

tail /var/log/messages

Dec 7 14:09:45 localhost nagios: ndomod: Successfully connected to data sink. 10861 items lost, 5000 queued items to flush.
Dec 7 14:09:45 localhost nagios: ndomod: Successfully flushed 5000 queued items to data sink.
Dec 7 14:09:45 localhost ndo2db-3x: Successfully connected to MySQL database

解决

Posted in Nagios.

Tagged with , , .


3 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

Continuing the Discussion

  1. NDOutils安装配置 - Centos教程 linked to this post on 2010/12/21

    […] 安装文档参考http://nagios.sourceforge.net/docs/ndoutils/NDOUtils.pdf 报错参考http://blog.c1gstudio.com/archives/635 […]

  2. Nagios XI跨站脚本执行和HTML注入漏洞 | 吃杂烩 linked to this post on 2012/08/09

    […] 使用NDOUtils将Nagios监控信息存入mysql ( 2009-05-27) […]



Some HTML is OK

or, reply to this post via trackback.