本文假设读者已安装好icinga,此外nsca本身nagios插件,icinga/nagios都适用
一。编译安装nsca
1.编译,拷贝文件
tar -vxzf nsca-2.7.2.tar.gz
./configure
make
cp src/nsca /usr/local/icinga/bin
cp sample-config/nsca.cfg /usr/local/icinga/etc
cp src/send_nsca /usr/local/icinga/bin
cp sample-config/send_nsca.cfg /usr/local/icinga/etc
2.修改nsca.cfg,本案例是icinga,需把文件中的所有nagios替换成icinga
server_address=192.168.100.100
debug=1
#与icinga的命令文件相同(默认就不用改)
command_file=/usr/local/icinga/var/rw/icinga.cmd
二。icinga配置文件
1.配置文件 template.cfg 添加模板
#ADD FOR PASSIVE CHECK
define service{
name passive-service
use generic-service
max_check_attempts 1
active_checks_enabled 0
passive_checks_enabled 1
normal_check_interval 5
retry_check_interval 1
notification_interval 10
notification_options w,u,c,r,f,s
contact_groups admins
register 0
}
2.配置文件 linux.cfg/hpux.cfg 添加主机, 主机组,服务,服务组(分组管理)
#ADD FOR PASSIVE CHECK
define hostgroup{
hostgroup_name nsca_cluster ; The name of the hostgroup
alias nsca_Servers ; Long name of the group
members 192.168.100.100
}
define servicegroup {
servicegroup_name NSCA-MON
alias NSCA-MON
}
define host{
use linux-server ;using linux-server template!!!
host_name 192.168.100.100
alias local-host
icon_image redhat.gif
statusmap_image redhat.gd2
address 192.168.100.100
}
define service{
hostgroup_name nsca_cluster
use passive-service
servicegroups NSCA-MON
service_description CheckDummy
check_command check_dummy!0
notifications_enabled 1
}
3.配置文件 commands.cfg 添加服务
# ADD FOR PASSIVE CHECK
define command{
command_name check_dummy
command_line /usr/local/icinga/libexec/check_dummy $ARG1$
}
三。查看icinga的nsca插件是否成功运行
1.启动服务端nsca
nsca -c ../etc/nsca.cfg --daemon
nestat -an|grep 5667 此时端口是LISTEN的
2.send_nsca发送数据
# vi xxx.txt写入一行并保存,注意其中的tab分隔符
192.168.100.100 CheckDummy 0 this is a test of nsca
# 发送数据到服务端
echo xxx.txt| send_nsca -H 192.168.100.100 -p 5667 -c ../etc/send_nsca.cfg
3.查看系统日志,确认服务端是否收到信息
grep nsca /var/log/messages
结果如下,说明已经成功,如果没有输出[被动服务检查],则说明icinga的命令/服务配置等不正确,没有找到描述为[CheckDummy]的命令
nsca[21562]:
SERVICE CHECK -> Host Name: '192.168.100.100', Service Description:
'CheckDummy', Return Code: '0', Output: 'this is a test of nsca'
nsca[21562]: End of connection...
icinga: 额外命令: PROCESS_SERVICE_CHECK_RESULT;192.168.100.100;CheckDummy;0;this is a test of nsca
icinga: 被动服务检查: 192.168.100.100;CheckDummy;0;this is a test of nsca
4.完成。
可根据需要,写程序调用send_nsca发送给icinga监控结果数据了。
查看icinga控制台,主机192.168.100.100 服务CheckDummy 状态 正常