Nagios NSCA 被动监控服务器搭建
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Nagios NSCA 被动监控服务器搭建相关的知识,希望对你有一定的参考价值。
nagios的快速部署,执行环境初始化配置脚本。主要配置epel的yum源等
yum install httpd nagios nagios-common nagios-devel nagios-plugins-all -y
rm -rf /etc/nagios/passwd
htpasswd -c /etc/nagios/passwd nagiosadmin
chmod 640 /etc/nagios/passwd
chown :apache /etc/nagios/passwd
service nagios checkconfig
service nagios start
chkconfig nagios on
被动监控服务端的配置:
yum install nsca*
vi /etc/nagios/nsca.cfg #配置密码、IP地址等信息
pid_file=/var/run/nsca.pid
server_port=5667
server_address=192.168.10.34
nsca_user=nagios
nsca_group=nagios
debug=1
command_file=/var/spool/nagios/cmd/nagios.cmd
alternate_dump_file=/var/spool/nagios/cmd/nsca.dump
aggregate_writes=1
append_to_file=0
max_packet_age=60
password=123456
decryption_method=1
vi contacts.cfg #修改email报警邮件地址
vi templates.cfg #增加被动监控的模板
define service{
name passive_service
use generic-service
max_check_attempts 3
active_checks_enabled 0
passive_checks_enabled 1
normal_check_interval 2
retry_check_interval 1
notifications_enabled 1
notification_interval 2
notification_period 24x7
contact_groups admins
register 0
}
vi command.cfg #增加被动监控的命令
define command{
command_name check_dummy
command_line /usr/lib64/nagios/plugins/check_dummy $ARG1$
}
vi localhost.cfg #增加远程客户端被动监控项目
define host{
use linux-server
host_name cacti-server
alias cacti-server
address 192.168.10.33
}
define service{
use passive_service
host_name cacti-server
service_description LoadAVG
check_command check_dummy!3
check_freshness 1
freshness_threshold 120
notifications_enabled 0
}
service nagios start
service nsca start
被动监控客户端的配置:
yum install nagios-plugins-all nsca-client -y
vi send_nsca.cfg
password=123456
vi nsca.sh
#!/bin/sh
set -e
host_name=$1
svc_name=$2
nsca_add=$3
if [ "$3" ];then
case "$2" in
check_load)
check_ARG="-w 3 -c 5"
;;
check_users)
check_ARG="-w 2 -c 5"
;;
*)
exit 0
;;
esac
/usr/lib64/nagios/plugins/$2 $check_ARG > /tmp/$2 &
sleep 3
out=`cat /tmp/$2`
output=`echo $out|awk ‘{print $1}‘`
if [ $output == "OK" ];then
status=0
elif [ $output == "WARNING" ];then
status=1
elif [ $output == "CRITICAL" ];then
status=2
else
status=3
fi
echo "$host_name LoadAVG $status $out"|/usr/sbin/send_nsca -H $nsca_add -d " " -c /etc/nagios/send_nsca.cfg
else
echo "please use bash nsca.sh hostname servicename nscaddr. recheck!"
fi
sh nsca.sh cacti-server check_load 192.168.10.34
vi /etc/crontab
* * * * * root sh /etc/nagios/nsca.sh cacti-server check_load 192.168.10.34
以上是关于Nagios NSCA 被动监控服务器搭建的主要内容,如果未能解决你的问题,请参考以下文章