cacti整合nagios

主要步骤:
1、安装ndoutils,把nagios数据写到mysql。
2、在cacti安装npc插件,查看nagios的数据。

一、安装
1、安装ndoutils的依赖包
(1)安装DBI
wget http://search.cpan.org/CPAN/authors/id/T/TI/TIMB/DBI-1.616.tar.gz
tar -zxvf DBI-1.616.tar.gz
cd DBI-1.616
perl Makefile.PL
make && make install

(2)安装DBD-mysql
wgethttp://search.cpan.org/CPAN/authors/id/C/CA/CAPTTOFU/DBD-mysql-4.018.tar.gz
tar xvf DBD-mysql-4.018.tar.gz -C /usr/local/soft
cd DBD-mysql-4.018
perl Makefile.PL --mysql_config=/usr/local/mysql/bin--with-mysql=/usr/local/mysql --mysql_config=/usr/local/mysql/bin/mysql_config
make && make install

2、安装ndoutils
ndoutils作用,把nagios的数据写到mysql,集成nagios到cacti的关健的一部分。

(1)下载编译
wgethttp://nchc.dl.sourceforge.net/project/nagios/ndoutils-1.x/ndoutils-1.4b9/ndoutils-1.4b9.tar.gz
tar -zxvf ndoutils-1.4b9.tar.gz
cd ndoutils-1.4b9
./configure --prefix=/usr/local/nagios --enable-mysql --disable-pgsqlLDFLAGS=-L/usr/local/mysql/lib  --with-mysql-lib=/usr/local/mysql/lib--with-mysql=/usr/local/mysql 

make提示找不到mysql.h:
cp include/config.h include/config.h.bak
vi include/config.h

#include <mysql.h>
#include <errmsg.h>
改为
#include </usr/local/mysql/include/mysql.h>
#include </usr/local/mysql/include/errmsg.h>
make (注:这里不需要make install)

复制执行及配置文件
cp config/ndomod.cfg-sample /usr/local/nagios/etc/ndomod.cfg
cp config/ndo2db.cfg-sample /usr/local/nagios/etc/ndo2db.cfg

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


(2)配置nagios主文件
vi /usr/local/nagios/etc/nagios.cfg
broker_module=/usr/local/nagios/bin/ndomod-3x.o config_file=/usr/local/nagios/etc/ndomod.cfg
process_performance_data=1 

(3)配置ndocmd.cfg文件
vi /usr/local/nagios/etc/ndomod.cfg

output_type=tcpsocket
output=127.0.0.1

(4)配置ndo2db.cfg文件
vi /usr/local/nagios/etc/ndo2db.cfg

socket_type=tcp
socket_name=/usr/local/nagios/var/ndo.sock

db_name=cacti
db_prefix=npc_

db_user=cacti
db_pass=cacti2011

debug_level=1

(5)启动ndo2db
/usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg

3、安装cacti插件npc
wget http://www.constructaegis.com/downloads/npc-2.0.4.tar.gz
tar -zxvf npc-2.0.4.tar.gz
mv npc /home/htdocs/cacti/plugins

登录cacti后台,在插件管理中心安装并启用NPC。
Plugin Management面板,install npc,enable npc。
Settings-npc选项卡下面:
Nagios Command File Path: /usr/local/nagios/var/rw/nagios.cmd
Nagios URL: http://192.168.1.36/nagios/
保存后完成。
至此,ndoutils会自动把nagios的数据写到mysql里cacti库下的npc_*表。

查看访问
http://192.168.1.36/cacti/

二、问题及排错
1、nagios重启
ps aux | grep nagios
/usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg
/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
2、cacti插件npc提示no hosts
tail -100 /var/log/messages
localhost ndo2db-3x: mysql_error: 'Unknown column 'long_output' in 'fieldlist'' 
添加缺失的对应字段
ALTER TABLE npc_eventhandlers ADD long_output TEXT NOT NULL DEFAULT '' AFTERoutput;
ALTER TABLE npc_hostchecks ADD long_output TEXT NOT NULL DEFAULT '' AFTERoutput;
ALTER TABLE npc_hoststatus ADD long_output TEXT NOT NULL DEFAULT '' AFTERoutput;
ALTER TABLE npc_notifications ADD long_output TEXT NOT NULL DEFAULT '' AFTERoutput;
ALTER TABLE npc_servicechecks ADD long_output TEXT NOT NULL DEFAULT '' AFTERoutput;
ALTER TABLE npc_servicestatus ADD long_output TEXT NOT NULL DEFAULT '' AFTERoutput;
ALTER TABLE npc_statehistory ADD long_output TEXT NOT NULL DEFAULT '' AFTERoutput;
ALTER TABLE npc_systemcommands ADD long_output TEXT NOT NULL DEFAULT '' AFTERoutput;

3. 为什么nagios整合cactiNPC里的nagios总是OFF! 

解决办法是修改一下文件的内容,不过最主要的是这几个:
output_type=tcpsocket 
output=127.0.0.1 
socket_type=tcp 

这3个你可以改一次,重启下服务看看,反正我每次改的都不一样,轮着改,
修改配置文件ndocmd.cfg 和 ndo2db.cfg,这里我的配置文件内容为: 
[root@localhost downloads]# vi /usr/local/nagios/etc/ndomod.cfg
instance_name=default 
output_type=tcpsocket 
output=127.0.0.1 
tcp_port=5668 
output_buffer_items=5000 
buffer_file=/usr/local/nagios/var/ndomod.tmp 
file_rotation_interval=14400 
file_rotation_timeout=60 
reconnect_interval=15 
reconnect_warning_interval=15 
data_processing_options=-1 
config_output_options=2 

[root@localhost downloads]# vi /usr/local/nagios/etc/ndo2db.cfg
ndo2db_user=nagios 
ndo2db_group=nagios 
socket_type=tcp 
socket_name=/usr/local/nagios/var/ndo.sock 
tcp_port=5668 
db_servertype=mysql 
db_host=127.0.0.1 
db_port=3306 
db_name=cacti 
db_prefix=npc_ 
db_user=cacti 
db_pass=cacti2008 
max_timedevents_age=1440 
max_systemcommands_age=10080 
max_servicechecks_age=10080 
max_hostchecks_age=10080 
max_eventhandlers_age=44640 
debug_level=1 
debug_verbosity=1 
debug_file=/usr/local/nagios/var/ndo2db.debug 
max_debug_file_size=1000000



三、参考文章
nagios的安装部署和与cacti的整合(配置主参考)
http://bbs.linuxtone.org/thread-2225-1-1.html
在RHEL5.4安装ndoutils1.4.14(configure加LDFLAGS)
http://zhumeng8337797.blog.163.com/blog/static/10076891420109228431760/


转载请注明文章转自:良玉的博客 [http://blog.uouo123.com]

你可能感兴趣的:(cacti整合nagios)