Slack notification broken after update to Zabbix 5.0 from Zabbix 4.4 (Debian stretch to buster also upgraded)
Logs:
zbx-notify:
Logs:
Code:
http://<some URL> Eventid: 37200730' '--api_token=<some token>' '--slack' '--no-fork' '--no-ssl_verify_hostname' '--slack_mode=event'": Can't locate SlackBot.pm in @INC (you may need to install the SlackBot module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.28.1 /usr/local/share/perl/5.28.1 /usr/lib/x86_64-linux-gnu/perl5/5.28 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.28 /usr/share/perl/5.28 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base) at /etc/zabbix/alert.d//zbx-notify line 8. BEGIN failed--compilation aborted at /etc/zabbix/alert.d//zbx-notify line 8.
Code:
#!/usr/bin/perl
use warnings;
use strict;
use 5.010;
no if $] >= 5.018, warnings => "experimental::smartmatch";
use Data::Dumper;
use Getopt::Long;
use SlackBot;
use HipChatBot;
use PagerDutyBot;
my %contents;
my $debug = 0;
my $fork = 1;
my $ssl_verify_hostname = undef; # whether or not user wants to explicitly set the value for: #$ENV{'PERL_LWP_SSL_VERIFY_HOSTNAME'};
my $api_token;
#slack only
my $slack;
$contents{slack}->{mode} = "event"; #default mode in slack
#hipchat only
my $hipchat;
my $hipchat_api_url;
$contents{hipchat}->{message_format} = 'text';
$contents{hipchat}->{notify} = 'true';
#pd only
my $pagerduty;
GetOptions(
"api_token=s" => \$api_token,
"debug!" => \$debug,
"fork!" => \$fork,
"ssl_verify_hostname!" => \$ssl_verify_hostname,
"hipchat" => \$hipchat,
"hipchat_api_url=s" => \$hipchat_api_url,
"hipchat_message_format=s" => \$contents{hipchat}->{message_format},
"hipchat_notify=s" => \$contents{hipchat}->{notify},
"hipchat_from=s" => \$contents{hipchat}->{from},
"pagerduty" => \$pagerduty,
"pagerduty_client=s" => \$contents{pagerduty}->{client},
"pagerduty_client_url=s" => \$contents{pagerduty}->{client_url},
"slack" => \$slack,
"slack_mode=s" => \$contents{slack}->{mode},
) or die("Error in command line arguments\n");
die "Please provide --slack --hipchat --pagerduty but only one\n"
unless defined($hipchat) xor defined($slack) xor defined($pagerduty);
die "You must provide 'api_token'\n" unless $api_token;
#get params (from,subject,message from zabbix notification)
binmode STDOUT, ":encoding(UTF-8)";
my $send_to = shift @ARGV or die "Invalid number of arguments\n";
$contents{subject} = shift @ARGV;
utf8::decode( $contents{subject} );
die "Subject provided is wrong\n"
unless $contents{subject} =~ m/^[[:print:]]+$/; #subject
$contents{message} = shift @ARGV;
utf8::decode( $contents{message} );
die "Message provided is wrong\n"
unless $contents{message} =~ m/^( [[:print:]] | \t | \n | \r )+$/x; #message
#parse contents to find something interesting (OK|PROBLEM, SEVERITY LEVEL...)
%contents = ( %contents, parse_message( $contents{subject}.' '.$contents{message} ) );
my $bot;
if ($slack) {
die "Invalid slack_mode is provided. Please use 'alarm', 'event' or 'alarm-no-delete'\n"
unless $contents{slack}->{mode} =~ /^(alarm|event|alarm-no-delete)$/;
$bot = SlackBot->new( { api_token => $api_token } );
$bot->channel($send_to);
}
elsif ($hipchat) {
$bot = HipChatBot->new({
api_token => $api_token
});
$bot->web_api_url($hipchat_api_url) if $hipchat_api_url;
$bot->room($send_to);
if ( defined($contents{hipchat}->{from}) ) {
utf8::decode( $contents{hipchat}->{from} );
die "'from' provided is wrong\n"
unless $contents{hipchat}->{from} =~ m/^[[:print:]]+$/; #from
}
}
elsif ($pagerduty) {
$bot = PagerDutyBot->new({api_token => $api_token});
}
$bot->debug($debug) if $debug;
print Dumper $bot if $debug;
print Dumper \%contents if $debug;
binmode STDOUT, ":raw";
set_ssl_verify_hostname();
if (not $fork) { $bot->post_message( \%contents ); }
else {
my $pid = fork();
if ( $pid == 0 ) {
#child
die "CANNOT FORK!!\n" unless defined $pid;
open( STDOUT, '>' , "/dev/null" ); # suppressing output
open( STDERR, '>' , "/dev/null" ); # suppressing output
print "This is child process\n";
$bot->post_message( \%contents );
exit 0;
}
#print "Forked child ID is $pid\n";
exit 0;
}
#######EXTRA SUBS################
sub parse_message {
my $message = shift;
my %result;
$result{'status'} = 'PROBLEM';
given ($message) {
when (/eventid: *(\d+)/i) { $result{'eventid'} = $1; continue }
when (/\bPROBLEM\b/) { $result{'status'} = 'PROBLEM'; continue }
when (/\bOK\b/) {
$result{'status'} = 'OK';
}
when (/\bNot classified\b/) { $result{'severity'} = 'Not classified' }
when (/\bInformation\b/) { $result{'severity'} = 'Information' }
when (/\bWarning\b/) { $result{'severity'} = 'Warning' }
when (/\bAverage\b/) { $result{'severity'} = 'Average' }
when (/\bHigh\b/) { $result{'severity'} = 'High' }
when (/\bDisaster\b/) { $result{'severity'} = 'Disaster' }
default { $result{'severity'} = 'Not classified' }
}
return %result;
}
sub set_ssl_verify_hostname{
if (defined($ssl_verify_hostname )){
if($ssl_verify_hostname == 0) {
$ENV{'PERL_LWP_SSL_VERIFY_HOSTNAME'} = 0;
print "setting PERL_LWP_SSL_VERIFY_HOSTNAME to $ssl_verify_hostname\n" if $debug;
}
elsif ($ssl_verify_hostname == 1){
$ENV{'PERL_LWP_SSL_VERIFY_HOSTNAME'} = 1;
print "setting PERL_LWP_SSL_VERIFY_HOSTNAME to $ssl_verify_hostname\n" if $debug;
}
}
}
Comment