Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Do you know if is there any easy way to send output of every check run by nagios to syslog?

share|improve this question
up vote 0 down vote accepted

I wrote a small script which can be used as a notification and / or event handler. This was beneficial at the time since I did not want to log soft error states and the build I was working with could not separate the two. It also provides some formatting options.

This is easy to use by adding a user syslog with the notify-by-syslog options defined. Simply add this user as a contact whereever you want a specific service to log to syslog.

The Nagios command in the config file:

define command{
        command_name    notify-service-by-syslog
        command_line    /usr/bin/perl $USER1$/ \
                 --state $SERVICESTATE$ --host $HOSTADDRESS$ \
define command{
        command_name    notify-host-by-syslog
        command_line    /usr/bin/perl $USER1$/ \
                --hard $HOSTSTATETYPE$ --state $HOSTSTATE$ --host $HOSTADDRESS$ \

The script

#!/usr/bin/perl -w

use Sys::Syslog qw(:standard :macros);
use strict;
use Getopt::Long;

my $help;
my $hard;
my $state;
my $host;
my $msg;


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";

    syslog($alert,"$host     $msg");

sub get_options
        ("help|h"        => \$help,
         "hard:s"        => \$hard,
         "state:s"       => \$state,
         "host:s"        => \$host,
         "msg:s"         => \$msg
    if( defined($help) )
        print "--help called\n\n";
sub print_usage
    print "--help | -H: Print this screen\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;
share|improve this answer
Thanks! this was what I finally did too, although my scripts is in bash to reduce overhead (we have LOTS of services monitored). – Matt Dec 20 '11 at 11:45

Did you set up the use_syslog option in Nagios configuration?

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.