We wrote a couple of tools to assist with this scenario. I'm attaching them.

They leverage an external tool which we wrote to parse the Nagios configuration and identify/verify hosts, but that dependency can be removed easily.

We run them from cron.  Examples:

55 03 * * * /etc/nagios/tools/toggle-host-notifications --off server1
05 04 * * * /etc/nagios/tools/toggle-host-notifications --on server1

00 02 * * * /etc/nagios/tools/toggle-service-notifications --off -- service "HTTP redirect" server3.domain.com 40 02 * * * /etc/nagios/tools/toggle-service-notifications --on -- service "HTTP redirect" server3.domain.com


-John

#!/usr/bin/perl -w

# Write commands to Nagios indicating that the host is entering or
# leaving some sort of downtime.

# Author: John R. Daily ([EMAIL PROTECTED])

use strict;
use warnings;

use Getopt::Long;

# Arguments: {--on|--off} <hostname> ...

# Host name search tool
my $NH = '/usr/local/bin/nh';

my $CMD_FILE = '/var/log/nagios/rw/nagios.cmd';

my $turn_on = 0;
my $turn_off = 0;
my $help = 0;

sub usage {
    return <<END;
Usage: toggle-host-notifications {--on|--off} <hostname> ...
END
}

my $result = GetOptions (
                         "help" => \$help,
                         "on" => \$turn_on,
                         "off" => \$turn_off
                         );

die usage() unless $result;

if ($help) {
    print usage();
    exit;
}

unless ($turn_on xor $turn_off) {
    die "Must use ONE of --on or --off.\n";
}

unless (@ARGV >= 1) {
    die "Need Nagios hostname (run $NH to find hostname)\n";
}

foreach my $host (@ARGV) {
    die "Unknown Nagios hostname: $host\n"
      unless system("$NH --verify $host") == 0;

    die "Cannot send Nagios the message\n"
      unless write_command($CMD_FILE, $host, $turn_on, $turn_off);
}

sub write_command {
    my ($outfile, $host, $on, $off) = @_;
    my $timestamp = time();

    my $prefix = "DISABLE";
    if ($on) {
        $prefix = "ENABLE";
    }

    return 0 unless open(OUT, ">>$outfile");
    print OUT sprintf("[%d] %s_HOST_SVC_NOTIFICATIONS;%s\n",
                      $timestamp, $prefix, $host);
    print OUT sprintf("[%d] %s_HOST_NOTIFICATIONS;%s\n",
                      $timestamp, $prefix, $host);
    return 1;
}
#!/usr/bin/perl -w

# Write commands to Nagios indicating that the service is entering or
# leaving some sort of downtime.

# Author: John R. Daily ([EMAIL PROTECTED])

use strict;
use warnings;

use Getopt::Long;

# Arguments: {--on|--off} <hostname> ...

# Host name search tool
my $NH = '/usr/local/bin/nh';

my $CMD_FILE = '/var/log/nagios/rw/nagios.cmd';

my $turn_on = 0;
my $turn_off = 0;
my $help = 0;
my $service = 0;

sub usage {
    return <<END;
Usage: toggle-service-notifications {--on|--off} --service <service> <hostname> ...

Any number of hosts may be provided, but only one service.
END
}

my $result = GetOptions (
                         "help" => \$help,
                         "on" => \$turn_on,
                         "off" => \$turn_off,
                         "service=s" => \$service
                         );

die usage() unless $result;

if ($help || !$service) {
    print usage();
    exit;
}

unless ($turn_on xor $turn_off) {
    die "Must use ONE of --on or --off.\n";
}

unless (@ARGV >= 1) {
    die "Need Nagios hostname (run $NH to find hostname)\n";
}

foreach my $host (@ARGV) {
    die "Unknown Nagios hostname: $host\n"
      unless system("$NH --verify $host") == 0;

    die "Cannot send Nagios the message\n"
      unless write_command($CMD_FILE, $host, $service, $turn_on, $turn_off);
}

sub write_command {
    my ($outfile, $host, $service, $on, $off) = @_;
    my $timestamp = time();

    my $prefix = "DISABLE";
    if ($on) {
        $prefix = "ENABLE";
    }

    return 0 unless open(OUT, ">>$outfile");
    print OUT sprintf("[%d] %s_SVC_NOTIFICATIONS;%s;%s\n",
                      $timestamp, $prefix, $host, $service);
    return 1;
}
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Nagios-users mailing list
Nagios-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting 
any issue. 
::: Messages without supporting info will risk being sent to /dev/null

Reply via email to