|
@@ -89,6 +89,9 @@ my %C = (
|
|
|
Z => "\x03",
|
|
|
);
|
|
|
|
|
|
+my @NagStates = qw/UP DOWN WARNING UNKNOWN .. .. .. .. .. ..
|
|
|
+ OK WARNING CRITICAL UNKNOWN/;
|
|
|
+
|
|
|
# Bold: U+0002 ("0x02") — Example: ^Bold Text^ whereas ^ represents the control character.
|
|
|
# Italics: U+001D ("0x1D") — Example: ^Italicized Text^ whereas ^ represents the control character.
|
|
|
# Underline: U+001F ("0x1F") — Example: ^Underlined Text^ whereas ^ represents the control character.
|
|
@@ -145,6 +148,7 @@ sub nagios_ack {
|
|
|
}
|
|
|
|
|
|
sub nagios_check {
|
|
|
+ #1412375470;filer2;DISK_all;2;W=10% C=5%
|
|
|
( $param, $server, $window ) = @_;
|
|
|
@issue = parse_status();
|
|
|
if (!@issue) {
|
|
@@ -152,6 +156,7 @@ sub nagios_check {
|
|
|
}
|
|
|
my $message = " CHECK ".$param . join ' ', reverse @issue;
|
|
|
Irssi::active_server->command('MSG ' . $DEBUG . $message);
|
|
|
+ # validate_alert($$$$$$) { # $d,$type,$host,$state,$output,$service
|
|
|
}
|
|
|
|
|
|
sub nagios_status {
|
|
@@ -183,9 +188,9 @@ sub mark($$$) {
|
|
|
my $M=sprintf('%02d', scalar @ACKS % 100);
|
|
|
my $N=sprintf('%02d', $I % 100);
|
|
|
if ($I < scalar @ACKS) {
|
|
|
- return "[".$C{W}.$Flag.$C{Z}." /$M] ";
|
|
|
+ return "[".$C{W}.$Flag.$C{Z}." ]/$M ";
|
|
|
} else {
|
|
|
- return "[".$C{W}.$Flag.$state_to_color->{$state}.$N.$C{Z}."/$M] ";
|
|
|
+ return "[".$C{W}.$Flag.$state_to_color->{$state}.$N.$C{Z}."]/$M ";
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -322,12 +327,25 @@ sub create_fifo($) { # [2004-08-14]
|
|
|
} #
|
|
|
|
|
|
# Query nagios ###########################################################
|
|
|
-sub query_nagios_status(){
|
|
|
+sub query_nagios_status($){
|
|
|
+ # 1412478149;hyppocampe;apt;2;CRITICAL : unknown: qemu-utils, qemu-kvm, qemu-keymaps
|
|
|
+ my ($server)=@_;
|
|
|
my @unixcat;
|
|
|
my $unixline;
|
|
|
foreach $unixline ( `echo "GET services
|
|
|
Columns: last_state_change host_name display_name state plugin_output
|
|
|
Filter: state > 1" | unixcat $nagioscmd` ) {
|
|
|
+ ($d,$host,$service,$state,$output)=split /;/,$unixline;
|
|
|
+ validate_alert($d,'SERVICE',$host,$NagStates[$state+10],$output,$service);
|
|
|
+ Irssi::print("%B>>%n $unixline", MSGLEVEL_CLIENTCRAP);
|
|
|
+ }
|
|
|
+
|
|
|
+ return;
|
|
|
+ foreach $unixline ( `echo "GET hosts
|
|
|
+Columns: last_state_change host_name state plugin_output
|
|
|
+Filter: state > 1" | unixcat $nagioscmd` ) {
|
|
|
+ ($d,$host,$state,$output)=split /;/,$unixline;
|
|
|
+ validate_alert($d,'HOST',$host,$NagStates[$state],$output,"");
|
|
|
Irssi::print("%B>>%n $unixline", MSGLEVEL_CLIENTCRAP);
|
|
|
}
|
|
|
|
|
@@ -336,8 +354,8 @@ Filter: state > 1" | unixcat $nagioscmd` ) {
|
|
|
# Columns: last_state_change host_name display_name state plugin_output
|
|
|
# Filter: state > 1
|
|
|
# EOF
|
|
|
-
|
|
|
}
|
|
|
+
|
|
|
# Parse alert to find vars ###############################################
|
|
|
sub parse_naglog(){
|
|
|
$d=0; $status_line=""; $host="";$output="";$service="";
|
|
@@ -373,7 +391,8 @@ sub parse_naglog(){
|
|
|
next
|
|
|
}
|
|
|
}
|
|
|
-sub validate_alert($$$$$$) {
|
|
|
+
|
|
|
+sub validate_alert($$$$$$) { # $d,$type,$host,$state,$output,$service
|
|
|
($d,$type,$host,$state,$output,$service)=@_;
|
|
|
next if exists $renot{"$host:$service"} && $renot{"$host:$service"} >= time() - 5;
|
|
|
$renot{"$host:$service"} = time();
|
|
@@ -381,26 +400,15 @@ sub validate_alert($$$$$$) {
|
|
|
#################
|
|
|
# HOST
|
|
|
$id = ackable($host,$service,$state,$output,$d);
|
|
|
- $msg = $state_to_color->{$state} . "$id$host is $state".$C{Z}." : $output";
|
|
|
+ $msg = "$id".$state_to_color->{$state} . "$host:$service".$C{Z}." is $state : $output";
|
|
|
#Irssi::print( "%B>>%n $IRSSI{name} $msg", MSGLEVEL_CLIENTCRAP);
|
|
|
|
|
|
- $last_alert="NAGIOS - $host is $state";
|
|
|
+ $last_alert="NAGIOS - $service/$host is $state";
|
|
|
$d=time2date($d);
|
|
|
$message = " $d - $last_alert - $msg";
|
|
|
Irssi::active_server->command('MSG ' . Irssi::settings_get_str("nagios_ack_channel") .
|
|
|
" ".$message);
|
|
|
- #################
|
|
|
- # SERVICE
|
|
|
- $id = ackable($host,$service,$state,$output,$d);
|
|
|
- if ( $id !~ /\[!/ ) {
|
|
|
- $msg = "$id".$state_to_color->{$state} . "$host:$service".$C{Z}." is $state : $output";
|
|
|
-
|
|
|
-# Irssi::print( "%B>>%n $IRSSI{name} $msg", MSGLEVEL_CLIENTCRAP);
|
|
|
- $last_alert="NAGIOS - $service on $host is $state";
|
|
|
- $d=time2date($d);
|
|
|
- $message = " $d - $last_alert - $msg";
|
|
|
- Irssi::active_server->command('MSG ' . Irssi::settings_get_str("nagios_ack_channel")
|
|
|
- ." ".$message);
|
|
|
+ # Irssi::print( "%B>>%n $IRSSI{name} $msg", MSGLEVEL_CLIENTCRAP);
|
|
|
}
|
|
|
|
|
|
sub event_privmsg {
|
|
@@ -419,7 +427,7 @@ sub event_privmsg {
|
|
|
|
|
|
# !nagios list [*] :
|
|
|
if ($1 =~ /^refresh/i) {
|
|
|
- query_nagios_status();
|
|
|
+ query_nagios_status($server);
|
|
|
}
|
|
|
if ($1 =~ /^list/i) {
|
|
|
foreach $K (@ACKS) {
|
|
@@ -427,7 +435,7 @@ sub event_privmsg {
|
|
|
" ". mark(' ',$i++,$K->[2]) ." ".$K->[0]." / $K->[1] / $K->[2] / $K->[3] / ".time2date $K->[4]);
|
|
|
}
|
|
|
}
|
|
|
- elsif ($1 =~ /^!help/i) {
|
|
|
+ elsif ($1 =~ /^help/i) {
|
|
|
$server->command ( "msg ".Irssi::settings_get_str("nagios_ack_channel").
|
|
|
" !nagios list : liste des alertes nagios reçuesici");
|
|
|
$server->command ( "msg ".Irssi::settings_get_str("nagios_ack_channel").
|
|
@@ -438,10 +446,10 @@ sub event_privmsg {
|
|
|
" !check : liste des alertes auprès de nagios");
|
|
|
}
|
|
|
return 1;
|
|
|
- } elsif ( $text =~ /^!check ?(.*)/i ){
|
|
|
- nagios_check($1,undef,undef);
|
|
|
- } elsif ( $text =~ /^!ack ?(.*)/i ){
|
|
|
- nagios_ack($1,undef,undef);
|
|
|
+ } elsif ( $text =~ /^check ?(.*)/i ){
|
|
|
+ nagios_check($1,$server,undef);
|
|
|
+ } elsif ( $text =~ /^ack ?(.*)/i ){
|
|
|
+ nagios_ack($1,$server,undef);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -471,4 +479,5 @@ Irssi::signal_add("message public", "event_privmsg");
|
|
|
Irssi::signal_add('setup changed', \&setup); # re-read setup when it changes
|
|
|
print CLIENTCRAP "%B>>%n $IRSSI{name} $VERSION (by $IRSSI{authors}) loaded";
|
|
|
|
|
|
+
|
|
|
1;
|