你知道是否有任何简单的方法发送每个检查运行的nagios输出到系统日志?
我写了一个可以用作通知和/或事件处理程序的小脚本。 这在当时是有益的,因为我不想logging软错误状态,而且我正在使用的构build不能分离这两个错误状态。 它还提供了一些格式选项。
通过添加用户系统日志以及定义的通过系统日志选项,这很容易使用。 只需将此用户添加为希望特定服务login到系统日志的联系人即可。
configuration文件中的Nagios命令:
define command{ command_name notify-service-by-syslog command_line /usr/bin/perl $USER1$/send_syslog.pl \ --state $SERVICESTATE$ --host $HOSTADDRESS$ \ --msg "$HOSTADDRESS$ $SERVICEDESC$ $SERVICESTATE$ $SERVICEOUTPUT$ $LONGSERVICEOUTPUT$" --hard $SERVICESTATETYPE$ } define command{ command_name notify-host-by-syslog command_line /usr/bin/perl $USER1$/send_syslog.pl \ --hard $HOSTSTATETYPE$ --state $HOSTSTATE$ --host $HOSTADDRESS$ \ --msg "$HOSTADDRESS$: $HOSTSTATE$ $HOSTOUTPUT$ $LONGHOSTOUTPUT$" }
send_syslog.pl脚本
#!/usr/bin/perl -w use Sys::Syslog qw(:standard :macros); use strict; use Getopt::Long; &Getopt::Long::config('bundling'); my $help; my $hard; my $state; my $host; my $msg; get_options(); run_process(); sub run_process { if( $hard eq "SOFT" ) { return 0; } my $alert=LOG_DEBUG; $alert=LOG_EMERG if $state eq "DOWN"; $alert=LOG_INFO if $state eq "UP"; $alert=LOG_CRIT if $state eq "CRITICAL"; $alert=LOG_WARNING if $state eq "WARNING"; $alert=LOG_INFO if $state eq "OK"; openlog('nagios','','daemon'); syslog($alert,"$host $msg"); } sub get_options { GetOptions ("help|h" => \$help, "hard:s" => \$hard, "state:s" => \$state, "host:s" => \$host, "msg:s" => \$msg ); if( defined($help) ) { print "--help called\n\n"; print_usage(); } } sub print_usage { print "--help | -H: Print this screen\n"; print "--hard <HOSTSTATETYPE|SERVICESTATETYPE>\n"; print " with a SOFT or HARD state; only alerts on the HARD states.\n"; print "--state <HOSTSTATE|SERVICESTATE>"; print "--host <HOSTADDRESS>\n"; print "--msg <Message Body>: Defines the message body to render\n"; exit 1; }
您是否在Nagiosconfiguration中设置了use_syslog选项?
http://nagios.sourceforge.net/docs/nagioscore/3/en/configmain.html#use_syslog