CentOS5配置OneAlert实现服务器监控告警
环境准备与依赖安装
CentOS 5系统默认未包含OneAlert所需的部分依赖包,需通过EPEL仓库补充安装:
wget http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
rpm -Uvh epel-release-5*.rpm
yum install python-simplejson curl
OneAlert客户端配置流程
从官方获取监控脚本并设置执行权限:
wget -O /usr/local/bin/onealert_monitor https://raw.githubusercontent.com/onealert/agent/master/linux/onealert_monitor.py
chmod +x /usr/local/bin/onealert_monitor
API密钥配置
在/etc/onealert.cfg
中写入从控制台获取的认证信息:
echo 'API_KEY="your_32char_api_key"' > /etc/onealert.cfg
Nagios集成方案
修改Nagios配置文件/etc/nagios/objects/commands.cfg
添加告警指令:
define command {
command_name notify-onealert
command_line /usr/local/bin/onealert_monitor -t "$NOTIFICATIONTYPE$" -d "$HOSTNAME$" -s "$SERVICEDESC$" -o "$SERVICESTATE$"
}
服务验证与测试
手动触发测试告警检查配置有效性:
echo "Test alert from CentOS5" | /usr/local/bin/onealert_monitor -p test_alert
执行后登录OneAlert控制台确认告警接收状态。
故障排查要点
- 检查
/var/log/messages
中的脚本执行日志 - 验证API密钥是否包含特殊字符需转义处理
- 确认Python版本为2.4以上且simplejson库安装正常