package rule;

print "reloading rules\n";

# don't flood us with multiple warnings for the same thing
%neighbour = (
    "asterix", "rbb21",
    "mollix", "rbb21",
    "phoenix", "rbb21",
    "docix", "rbb21",
    "bernix", "rber",
    "luzix", "rluz",
    "basix", "rbas",
    "dubix", "rdub",
    "beatnix", "rbb70",

    "rber", "rbb70",
    "rluz", "rbb70",
    "rbas", "rbb70",
    "rdub", "rbb70",
    "rbb21", "rbb70"
);

sub create_events {
    my( $i );
    my( $host, $service, $name, @went_down );

    @went_down = keys %BigSister::common::went_down;
    for( $i=$#went_down; $i>=0; $i-- ) {
	($host,$service) = split( /\./, $name = $went_down[$i] );
	next if( $BigSister::common::is_up{$name} );
	if( $service eq "disk" ) {
	    next;
	}
	elsif( $service eq "cpu" ) {
	    next;
	}
	elsif( $service eq "conn" ) {
	    next if( $neighbour{$host} && $BigSister::common::is_down{$neighbour{$host}.".$service"} );
	    &BigSister::common::event_raise( $name, $host, $service, $service, 70,
		sub { $BigSister::common::is_up{$name} } );
	}
	else {
	    next if( $BigSister::common::is_down{ $host.".conn" } );
	    &BigSister::common::event_raise( $name, $host, $service, $service, 60,
		sub { $BigSister::common::is_up{$name} } );
	}
    }
    return 0;
}


1;
