├── t
├── 001_load.t
└── 002_slack_mocks.t
├── MANIFEST
├── .travis.yml
├── .gitignore
├── Makefile.PL
├── lib
├── ZabbixNotify.pm
├── PagerDutyBot.pm
├── HipChatBot.pm
└── SlackBot.pm
├── bin
└── zbx-notify
├── README.md
└── LICENSE
/t/001_load.t:
--------------------------------------------------------------------------------
1 | # -*- perl -*-
2 |
3 | # t/001_load.t - check module loading and create testing directory
4 |
5 | use Test::More tests => 1;
6 |
7 | BEGIN { use_ok( 'SlackBot' ); }
8 |
9 |
10 |
--------------------------------------------------------------------------------
/MANIFEST:
--------------------------------------------------------------------------------
1 | MANIFEST
2 | LICENSE
3 | Makefile.PL
4 | lib/SlackBot.pm
5 | lib/HipChatBot.pm
6 | lib/PagerDutyBot.pm
7 | lib/ZabbixNotify.pm
8 | bin/zbx-notify
9 | t/001_load.t
10 | t/002_slack_mocks.t
11 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: perl
2 | perl:
3 | - "5.22"
4 | - "5.20"
5 | - "5.18"
6 | - "5.14"
7 | before_install:
8 | - cpanm --install JSON::XS
9 | - cpanm --install LWP
10 | - cpanm --install Test::Exception
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /blib/
2 | /.build/
3 | _build/
4 | cover_db/
5 | inc/
6 | Build
7 | !Build/
8 | Build.bat
9 | .last_cover_stats
10 | /Makefile
11 | /Makefile.old
12 | /MANIFEST.bak
13 | /META.yml
14 | /META.json
15 | /MYMETA.*
16 | nytprof.out
17 | /pm_to_blib
18 | *.o
19 | *.bs
20 | /_eumm/
21 |
--------------------------------------------------------------------------------
/Makefile.PL:
--------------------------------------------------------------------------------
1 |
2 |
3 | use ExtUtils::MakeMaker;
4 | # See lib/ExtUtils/MakeMaker.pm for details of how to influence
5 | # the contents of the Makefile that is written.
6 | WriteMakefile(
7 | NAME => 'ZabbixNotify',
8 | VERSION_FROM => 'lib/ZabbixNotify.pm', # finds \$VERSION
9 | AUTHOR => 'vzhuravlev ()',
10 | ABSTRACT => 'Send messages from Zabbix to Slack, HipChat or PagerDuty',
11 | PREREQ_PM => {
12 | 'Test::Simple' => 0.44,
13 | },
14 | EXE_FILES => ['bin/zbx-notify'],
15 | );
16 |
--------------------------------------------------------------------------------
/lib/ZabbixNotify.pm:
--------------------------------------------------------------------------------
1 | package ZabbixNotify;
2 | use strict;
3 | use warnings;
4 | our $VERSION = '0.8';
5 |
6 | use Carp;
7 | use Data::Dumper;
8 | use vars qw ($AUTOLOAD);
9 | use constant { ## no critic(ProhibitConstantPragma)
10 | HTTP_TOO_MANY_REQUESTS => 429,
11 | RETRY_DEFAULT => 2,
12 | RETRY_WAIT_SECS => 5,
13 | };
14 |
15 | sub AUTOLOAD {
16 | my $self = shift;
17 | my $type = ref($self) || croak "$self is not an object";
18 | my $field = $AUTOLOAD;
19 | $field =~ s/.*://;
20 | unless ( exists $self->{$field} ) {
21 | croak "$field does not exist in object/class $type";
22 | }
23 | if (@_) {
24 | return $self->{$field} = shift;
25 | }
26 | else {
27 | return $self->{$field};
28 | }
29 | }
30 |
31 |
32 | =zbx_macro_to_json
33 | transform everything(zabbix macros) in double squares [[ ]] to json STRING
34 | note that unicode chars already encoded to \u1234 currently in message when called.
35 | =cut
36 | sub zbx_macro_to_json {
37 | my $self = shift;
38 | my $message = shift;
39 | my $orig ;
40 | my $result ;
41 |
42 | while ( $message =~ /( \[ \[) (.*?) (\] \] ) /gxs) {
43 |
44 | $orig = $1.$2.$3;
45 | $result = $2;
46 | print $orig."\n";
47 | #order matters
48 | utf8::encode( $result);
49 | $result =~ s/ \\ /\\\\/xg; #\
50 | $result =~ s/ \/ /\\\//xg; #/
51 | $result =~ s/ " /\\"/xg; #"
52 | $result =~ s/ \n /\\n/xg; #\n
53 | $result =~ s/ \r /\\r/xg; #\r
54 | $result =~ s/ \x{8} //xg; #backspace
55 | $result =~ s/ \x{C} //xg; #formfeed
56 | $result =~ s/ \x{9} / /xg; #horizontal tab
57 | utf8::decode( $result);
58 |
59 | $orig = quotemeta($orig);
60 |
61 | $message =~ s/$orig/$result/;
62 | }
63 | print $message."\n";
64 | return $message;
65 |
66 | }
67 |
68 |
69 | sub DESTROY { }
70 |
71 | 1;
72 |
--------------------------------------------------------------------------------
/t/002_slack_mocks.t:
--------------------------------------------------------------------------------
1 | # -*- perl -*-
2 | # t/002_slack_mocks.t - check module loading and create testing directory
3 | use strict;
4 | use warnings;
5 | use Test::More;
6 |
7 | BEGIN {
8 | eval "use Test::Exception";
9 | plan skip_all => "Test::Exception needed" if $@;
10 | }
11 |
12 | # ... tests that need Test::Exception ...
13 | BEGIN { use_ok( 'SlackBot' ); }
14 | use SlackBot;
15 | my $random_key = 'xoxb-30461853043-mQE7IGah4bGeC15T5gua4IzD';
16 | my $slack_bot = SlackBot->new( { api_token => $random_key , debug => 1} );
17 | ok( defined($slack_bot) && ref $slack_bot eq 'SlackBot', 'new() works' );
18 |
19 |
20 |
21 | my $mock_url="http://www.mocky.io/v2/5703a3f1270000e71f06afa1";
22 | =mock for chat.postMessage
23 | OK response parse
24 | like this:
25 | {
26 | "ok": true,
27 | "channel": "D0FJXP7L0",
28 | "ts": "1459856086.000002",
29 | "message": {
30 | "text": "Hello world",
31 | "username": "bot",
32 | "type": "message",
33 | "subtype": "bot_message",
34 | "ts": "1459856086.000002"
35 | }
36 | }
37 | =cut
38 | $slack_bot->mock_url($mock_url);
39 | my $response = $slack_bot->chat_postMessage( {channel=> 'channel', attachments=> {} });
40 | ok($response->{ts} eq '1459856086.000002', 'Check ts in response');
41 | ok($response->{ok} , 'Check ok in response');
42 | ok($response->{channel} eq 'D0FJXP7L0', 'Check channel in response');
43 |
44 |
45 | =mock for channel not found
46 | HTTP 200 OK
47 | {
48 | "ok": false,
49 | "error": "channel_not_found"
50 | }
51 | =cut
52 | $mock_url = 'http://www.mocky.io/v2/5703b37a270000582106afc0';
53 | $slack_bot->mock_url($mock_url);
54 | throws_ok { $slack_bot->chat_postMessage( {channel=> 'channel', attachments=> {} }) } '/Error channel_not_found/', 'check wrong channel';
55 |
56 |
57 |
58 | =mock for message_not_found (in update or delete)
59 | http://www.mocky.io/v2/5703b6d52700009b2106afc4
60 | HTTP 200 OK
61 | {
62 | "ok": false,
63 | "error": "message_not_found"
64 | }
65 | =cut
66 | $mock_url = 'http://www.mocky.io/v2/5703b6d52700009b2106afc4';
67 | $slack_bot->mock_url($mock_url);
68 | lives_ok { $slack_bot->chat_postMessage( {channel=> 'channel',attachments=> {} }) } 'check message_not_found';
69 |
70 |
71 |
72 |
73 |
74 | =mock 429
75 | Mock that simulates HTTP 429 response with Header Retry-After:10
76 | see https://api.slack.com/docs/rate-limits
77 | =cut
78 | my $mock_429 = 'http://www.mocky.io/v2/57037d9d270000811b06af54';
79 | $slack_bot->mock_url($mock_429);
80 | throws_ok { $slack_bot->get_with_retries($mock_429) } '/429 Too Many Requests/', 'get_with_retries(429 LINK)';
81 |
82 |
83 |
84 | =mock 429 no header
85 | Mock that simulates HTTP 429 response without Header Retry-After
86 | see https://api.slack.com/docs/rate-limits
87 | =cut
88 | $slack_bot->mock_url($mock_429);
89 | $mock_429 = 'http://www.mocky.io/v2/57038de22700003a1d06af7a';
90 | throws_ok { $slack_bot->get_with_retries($mock_429) } '/429 Too Many Requests/', 'get_with_retries(429 LINK)';
91 |
92 |
93 |
94 | done_testing();
--------------------------------------------------------------------------------
/bin/zbx-notify:
--------------------------------------------------------------------------------
1 | #!/usr/bin/perl
2 | use warnings;
3 | use strict;
4 | use 5.010;
5 | no if $] >= 5.018, warnings => "experimental::smartmatch";
6 | use Data::Dumper;
7 | use Getopt::Long;
8 | use SlackBot;
9 | use HipChatBot;
10 | use PagerDutyBot;
11 |
12 | my %contents;
13 | my $debug = 0;
14 | my $fork = 1;
15 | my $ssl_verify_hostname = undef; # whether or not user wants to explicitly set the value for: #$ENV{'PERL_LWP_SSL_VERIFY_HOSTNAME'};
16 | my $api_token;
17 | #slack only
18 | my $slack;
19 | $contents{slack}->{mode} = "event"; #default mode in slack
20 |
21 | #hipchat only
22 | my $hipchat;
23 | my $hipchat_api_url;
24 | $contents{hipchat}->{message_format} = 'text';
25 | $contents{hipchat}->{notify} = 'true';
26 | #pd only
27 | my $pagerduty;
28 |
29 |
30 |
31 | GetOptions(
32 | "api_token=s" => \$api_token,
33 | "debug!" => \$debug,
34 | "fork!" => \$fork,
35 | "ssl_verify_hostname!" => \$ssl_verify_hostname,
36 |
37 | "hipchat" => \$hipchat,
38 | "hipchat_api_url=s" => \$hipchat_api_url,
39 | "hipchat_message_format=s" => \$contents{hipchat}->{message_format},
40 | "hipchat_notify=s" => \$contents{hipchat}->{notify},
41 | "hipchat_from=s" => \$contents{hipchat}->{from},
42 |
43 | "pagerduty" => \$pagerduty,
44 | "pagerduty_client=s" => \$contents{pagerduty}->{client},
45 | "pagerduty_client_url=s" => \$contents{pagerduty}->{client_url},
46 |
47 | "slack" => \$slack,
48 | "slack_mode=s" => \$contents{slack}->{mode},
49 | ) or die("Error in command line arguments\n");
50 | die "Please provide --slack --hipchat --pagerduty but only one\n"
51 | unless defined($hipchat) xor defined($slack) xor defined($pagerduty);
52 | die "You must provide 'api_token'\n" unless $api_token;
53 |
54 |
55 |
56 | #get params (from,subject,message from zabbix notification)
57 | binmode STDOUT, ":encoding(UTF-8)";
58 | my $send_to = shift @ARGV or die "Invalid number of arguments\n";
59 |
60 | $contents{subject} = shift @ARGV;
61 | utf8::decode( $contents{subject} );
62 | die "Subject provided is wrong\n"
63 | unless $contents{subject} =~ m/^[[:print:]]+$/; #subject
64 |
65 | $contents{message} = shift @ARGV;
66 | utf8::decode( $contents{message} );
67 | die "Message provided is wrong\n"
68 | unless $contents{message} =~ m/^( [[:print:]] | \t | \n | \r )+$/x; #message
69 |
70 | #parse contents to find something interesting (OK|PROBLEM, SEVERITY LEVEL...)
71 | %contents = ( %contents, parse_message( $contents{subject}.' '.$contents{message} ) );
72 | my $bot;
73 | if ($slack) {
74 | die "Invalid slack_mode is provided. Please use 'alarm', 'event' or 'alarm-no-delete'\n"
75 | unless $contents{slack}->{mode} =~ /^(alarm|event|alarm-no-delete)$/;
76 | $bot = SlackBot->new( { api_token => $api_token } );
77 | $bot->channel($send_to);
78 |
79 | }
80 | elsif ($hipchat) {
81 | $bot = HipChatBot->new({
82 | api_token => $api_token
83 | });
84 | $bot->web_api_url($hipchat_api_url) if $hipchat_api_url;
85 |
86 | $bot->room($send_to);
87 | if ( defined($contents{hipchat}->{from}) ) {
88 | utf8::decode( $contents{hipchat}->{from} );
89 | die "'from' provided is wrong\n"
90 | unless $contents{hipchat}->{from} =~ m/^[[:print:]]+$/; #from
91 | }
92 | }
93 | elsif ($pagerduty) {
94 |
95 | $bot = PagerDutyBot->new({api_token => $api_token});
96 |
97 | }
98 |
99 | $bot->debug($debug) if $debug;
100 | print Dumper $bot if $debug;
101 |
102 |
103 | print Dumper \%contents if $debug;
104 | binmode STDOUT, ":raw";
105 |
106 |
107 | set_ssl_verify_hostname();
108 |
109 |
110 |
111 | if (not $fork) { $bot->post_message( \%contents ); }
112 | else {
113 | my $pid = fork();
114 | if ( $pid == 0 ) {
115 |
116 | #child
117 | die "CANNOT FORK!!\n" unless defined $pid;
118 | open( STDOUT, '>' , "/dev/null" ); # suppressing output
119 | open( STDERR, '>' , "/dev/null" ); # suppressing output
120 | print "This is child process\n";
121 | $bot->post_message( \%contents );
122 | exit 0;
123 | }
124 | #print "Forked child ID is $pid\n";
125 | exit 0;
126 | }
127 |
128 | #######EXTRA SUBS################
129 | sub parse_message {
130 | my $message = shift;
131 | my %result;
132 | $result{'status'} = 'PROBLEM';
133 | given ($message) {
134 | when (/eventid: *(\d+)/i) { $result{'eventid'} = $1; continue }
135 | when (/\bPROBLEM\b/) { $result{'status'} = 'PROBLEM'; continue }
136 | when (/\bOK\b/) {
137 | $result{'status'} = 'OK';
138 | }
139 | when (/\bNot classified\b/) { $result{'severity'} = 'Not classified' }
140 | when (/\bInformation\b/) { $result{'severity'} = 'Information' }
141 | when (/\bWarning\b/) { $result{'severity'} = 'Warning' }
142 | when (/\bAverage\b/) { $result{'severity'} = 'Average' }
143 | when (/\bHigh\b/) { $result{'severity'} = 'High' }
144 | when (/\bDisaster\b/) { $result{'severity'} = 'Disaster' }
145 | default { $result{'severity'} = 'Not classified' }
146 | }
147 | return %result;
148 | }
149 |
150 |
151 | sub set_ssl_verify_hostname{
152 | if (defined($ssl_verify_hostname )){
153 | if($ssl_verify_hostname == 0) {
154 | $ENV{'PERL_LWP_SSL_VERIFY_HOSTNAME'} = 0;
155 | print "setting PERL_LWP_SSL_VERIFY_HOSTNAME to $ssl_verify_hostname\n" if $debug;
156 | }
157 | elsif ($ssl_verify_hostname == 1){
158 | $ENV{'PERL_LWP_SSL_VERIFY_HOSTNAME'} = 1;
159 | print "setting PERL_LWP_SSL_VERIFY_HOSTNAME to $ssl_verify_hostname\n" if $debug;
160 | }
161 |
162 | }
163 | }
164 |
165 |
166 |
--------------------------------------------------------------------------------
/lib/PagerDutyBot.pm:
--------------------------------------------------------------------------------
1 | package PagerDutyBot;
2 | use strict;
3 | use warnings;
4 | our $VERSION = '0.8';
5 | use parent 'ZabbixNotify';
6 | use LWP;
7 | use URI;
8 | use Carp;
9 | use JSON::XS;
10 | use Data::Dumper;
11 | use English '-no_match_vars';
12 |
13 | use constant { ## no critic(ProhibitConstantPragma)
14 | HTTP_TOO_MANY_REQUESTS => 429,
15 | RETRY_DEFAULT => 2,
16 | RETRY_WAIT_SECS => 5,
17 | };
18 |
19 | sub new {
20 | my $class = shift;
21 | my $args = shift;
22 |
23 | my $debug = $args->{debug} || 0;
24 | my $api_token = $args->{api_token}
25 | || croak " Failed to create PagerDuty bot - No Service key provided\n";
26 | die "Service key provided is wrong. Should be 32 characters\n"
27 | unless $args->{api_token} =~ m/^[A-Za-z0-9_]{32}$/;
28 |
29 | my $self = bless {
30 | api_token => $api_token,
31 | debug => $debug,
32 | last_err => '',
33 | mock_url => undef
34 | }, $class;
35 |
36 | return $self;
37 | }
38 |
39 |
40 |
41 | sub post_message {
42 | my $self = shift;
43 | my $contents = shift
44 | || die "No contents provided to post into PagerDuty!\n";
45 |
46 |
47 | my $json_content = $self->create_json_if_plain($contents);
48 |
49 | print Dumper $json_content if $self->debug;
50 | $self->create_event($json_content);
51 |
52 | }
53 |
54 |
55 | sub create_event {
56 | my $self = shift;
57 | my $json = shift || die "Failed to send notification: room is required\n";;
58 |
59 |
60 | my $url = 'https://events.pagerduty.com/generic/2010-04-15/create_event.json';
61 |
62 |
63 | $self->post_with_retries($url,$json);
64 |
65 |
66 | }
67 |
68 |
69 |
70 | =create_json_if_plain
71 | $contents must be already utf8 decoded if non ASCII is present
72 | like utf8::decode( $contents );
73 | =cut
74 |
75 | sub create_json_if_plain {
76 | my $self =shift;
77 | my $contents = shift;
78 | my $json_hash;
79 | my $json_attach;
80 | eval { #check if already JSON:
81 |
82 | my $message = $self->zbx_macro_to_json($contents->{message});
83 | $json_hash = JSON::XS->new->decode( $message );
84 |
85 | };
86 | if ($@) {
87 | print "message is not JSON, going to proceed as with regular text\n";
88 | $json_attach = $self->create_json($contents);
89 | return $json_attach;
90 | }
91 | else {
92 | print "message is JSON, going to proceed as with JSON attachment\n";
93 | if ( not defined( $json_hash->{service_key} )
94 | and exists( $self->{api_token} ) )
95 | {
96 |
97 | print "Adding service_key to the JSON payload...\n";
98 | $json_hash->{service_key} = $self->{api_token};
99 |
100 | }
101 | $json_attach = JSON::XS->new->utf8->encode( $json_hash );
102 | return $json_attach;
103 | }
104 | }
105 |
106 | sub create_json {
107 | my $self = shift;
108 | my $contents_ref = shift;
109 |
110 | my $json_text = {
111 | service_key => $self->{api_token},
112 | incident_key => $contents_ref->{eventid},
113 | };
114 |
115 | if ($contents_ref->{status} eq 'PROBLEM') {
116 | $json_text->{event_type} = 'trigger';
117 |
118 | #foreach ( keys %{ $contents_ref->{details} } ) {
119 | # $json_text->{details}->{$_} = $contents_ref->{details}->{$_};
120 | #}
121 |
122 | $json_text->{description} = $contents_ref->{subject};
123 | $json_text->{details} = $contents_ref->{message};
124 |
125 | }
126 | elsif ($contents_ref->{status} eq 'OK') {
127 | $json_text->{event_type} = 'resolve';
128 | }
129 | else {
130 | die "Unable to detect event_type\n";
131 | }
132 |
133 |
134 | if ( defined $contents_ref->{pagerduty}->{client_url}
135 | and defined $contents_ref->{pagerduty}->{client} )
136 | {
137 | $json_text->{client_url} = $contents_ref->{pagerduty}->{client_url};
138 | $json_text->{client} = $contents_ref->{pagerduty}->{client};
139 | }
140 |
141 | return JSON::XS->new->utf8->encode($json_text);
142 | }
143 |
144 |
145 |
146 |
147 | sub post_with_retries {
148 | my $self = shift;
149 | my $url = shift;
150 | my $json_text = shift;
151 | my $retry_counter = RETRY_DEFAULT;
152 | my $retry_after = RETRY_WAIT_SECS;
153 | my $response;
154 | my $ua = LWP::UserAgent->new();
155 |
156 | if ( defined( $self->mock_url ) ) { $url = $self->mock_url; } #mock replace:
157 | $ua->env_proxy;
158 | $ua->show_progress(1) if $self->debug;
159 |
160 | ATTEMPT: {
161 |
162 | $response = $ua->post(
163 | $url,
164 | 'Content-Type' => 'application/json',
165 | Content => $json_text
166 | );
167 |
168 | if ( $response->is_success ) {
169 |
170 | #Check the status of the notification submission.
171 |
172 | #$self->check_slack_response($response);
173 | print "PagerDuty notification posted successfully.\n";
174 | return $response;
175 |
176 | }
177 | else {
178 | if ( $response->code == HTTP_TOO_MANY_REQUESTS ) {
179 | if ( defined( $response->header('Retry-After') )
180 | and $response->header('Retry-After') > 0 )
181 | {
182 | $retry_after = $response->header('Retry-After');
183 | }
184 |
185 | print $response->status_line . q{ }
186 | . "Will try again in $retry_after seconds\n";
187 |
188 | sleep $retry_after;
189 |
190 | if ( $retry_counter < 1 ) {
191 | decode_and_print_pd_bad_response( $response->content );
192 | die
193 | "Too many retries, unable to send message: ${ \$response->status_line } \n";
194 | }
195 |
196 | $retry_counter--;
197 | redo ATTEMPT;
198 | }
199 | else {
200 | decode_and_print_pd_bad_response( $response->content );
201 | die "PagerDuty connection failed! ${ \$response->status_line } \n";
202 | }
203 | }
204 | }
205 |
206 | }
207 |
208 | #helpers
209 | sub validate_pd_url {
210 | my $pd_url = shift;
211 | if ( $pd_url =~ /https: \/ \/ /x ) {
212 | return 1;
213 | }
214 | else {
215 | return 0;
216 | }
217 | }
218 |
219 |
220 |
221 | sub decode_and_print_pd_bad_response {
222 |
223 | # example of what might be returned
224 | #{"status":"invalid event",
225 | #"message":"Event object is invalid",
226 | #"errors":["incident_key is required for resolve events"]}
227 | my $json_response;
228 | eval { $json_response = JSON::XS->new->decode(shift) };
229 | if ( !$EVAL_ERROR ) {
230 | print $json_response->{status} . "\n" if exists $json_response->{status};
231 | print $json_response->{message} . "\n" if exists $json_response->{message};
232 | if ( exists $json_response->{errors} ) {
233 | foreach ( @{ $json_response->{errors} } ) { print "$_\n"; }
234 | }
235 | }
236 | return;
237 | }
238 |
239 |
240 | sub DESTROY { }
241 |
242 | 1;
243 |
--------------------------------------------------------------------------------
/lib/HipChatBot.pm:
--------------------------------------------------------------------------------
1 | package HipChatBot;
2 | use strict;
3 | use warnings;
4 | our $VERSION = '0.8';
5 | use parent 'ZabbixNotify';
6 | use LWP;
7 | use URI;
8 | use Carp;
9 | use JSON::XS;
10 | use Data::Dumper;
11 | use English '-no_match_vars';
12 |
13 | use constant { ## no critic(ProhibitConstantPragma)
14 | MAX_HIPCHAT_ROOM_ID_LENGTH => 100,
15 | MAX_HIPCHAT_MESSAGE_LENGTH => 10000,
16 | MAX_HIPCHAT_FROM_LENGTH => 64,
17 | HTTP_TOO_MANY_REQUESTS => 429,
18 | RETRY_DEFAULT => 2,
19 | RETRY_WAIT_SECS => 5,
20 | };
21 |
22 |
23 |
24 | sub new {
25 | my $class = shift;
26 | my $args = shift;
27 |
28 | my $debug = $args->{debug} || 0;
29 | my $api_token = $args->{api_token}
30 | || croak " Failed to create HipChat bot - No token provided\n";
31 | my $web_api_url = 'https://api.hipchat.com';
32 |
33 | my $self = bless {
34 | api_token => $api_token,
35 | web_api_url => $web_api_url,
36 | debug => $debug,
37 | room => undef,
38 | last_err => '',
39 | mock_url => undef
40 | }, $class;
41 |
42 | if (defined $args->{web_api_url}) {
43 | $self->web_api_url($args->{web_api_url});
44 | }
45 | if (defined $args->{room}) {
46 | $self->room($args->{room});
47 | }
48 |
49 | return $self;
50 | }
51 |
52 |
53 | sub room {
54 | my $self = shift;
55 | if (@_) {
56 | my $room = shift;
57 | if ( not validate_hipchat_room_length($room) ) {
58 | die "Room $room is wrong. Exiting...\n";
59 | }
60 | return $self->{room} = $room;
61 | }
62 | else {
63 | return $self->{room};
64 | }
65 | }
66 |
67 |
68 | sub web_api_url {
69 | my $self = shift;
70 | if (@_) {
71 | my $web_api_url = shift;
72 | if ( not validate_hipchat_url($web_api_url) ) {
73 | die "HipChat URL $web_api_url is not valid.\n";
74 | }
75 | return $self->{web_api_url} = $web_api_url;
76 | }
77 | else {
78 | return $self->{web_api_url};
79 | }
80 | }
81 |
82 |
83 | sub post_message {
84 | my $self = shift;
85 | my $contents = shift
86 | || die "No contents provided to post into Hipchat!\n";
87 |
88 | $contents->{color} = choose_color($contents);
89 |
90 | my $json_content = $self->create_json_if_plain($contents);
91 |
92 | print Dumper $json_content if $self->debug;
93 | $self->room_notification($json_content);
94 |
95 | }
96 |
97 |
98 | sub room_notification {
99 | my $self = shift;
100 | my $json = shift || die "Failed to send notification: json is required\n";;
101 |
102 | my $room = $self->room
103 | || die "Failed to send notification: room is required\n";
104 |
105 | my $url =
106 | $self->web_api_url."\/v2\/room/".$room."/notification?auth_token=".$self->api_token;
107 |
108 |
109 |
110 | $self->post_with_retries($url,$json);
111 |
112 |
113 | }
114 |
115 |
116 |
117 | =create_json_if_plain
118 | $contents must be already utf8 decoded if non ASCII is present
119 | like utf8::decode( $contents );
120 | =cut
121 |
122 | sub create_json_if_plain {
123 | my $self =shift;
124 | my $contents = shift;
125 | my $json_hash;
126 | my $json_attach;
127 | eval { #check if already JSON:
128 |
129 | my $message = $self->zbx_macro_to_json($contents->{message});
130 | $json_hash = JSON::XS->new->decode( $message );
131 |
132 | };
133 | if ($@) {
134 | print "message is not JSON, going to proceed as with regular text\n";
135 | $json_attach = create_json($contents);
136 | return $json_attach;
137 | }
138 | else {
139 | print "message is JSON, going to proceed as with JSON attachment\n";
140 | if ( not defined( $json_hash->{color} )
141 | and exists( $contents->{color} ) )
142 | {
143 |
144 | print "Adding color to the attachment...\n";
145 | $json_hash->{color} = $contents->{color};
146 |
147 | }
148 | $json_attach = JSON::XS->new->utf8->encode( $json_hash );
149 | return $json_attach;
150 | }
151 | }
152 |
153 | sub create_json {
154 | my $contents = shift;
155 |
156 | $contents->{message} = $contents->{subject} . "\n" . $contents->{message};
157 |
158 | if ( not validate_hipchat_message_length( $contents->{message} ) ) {
159 | warn "Message is too long. Have to cut it down\n";
160 | $contents->{message} = substr $contents->{message}, 0, MAX_HIPCHAT_MESSAGE_LENGTH;
161 | }
162 |
163 |
164 | my $json_hash = {
165 | color => $contents->{color},
166 | message => $contents->{message},
167 | message_format => $contents->{hipchat}->{message_format},
168 | notify => $contents->{hipchat}->{notify},
169 | };
170 | if (defined($contents->{hipchat}->{from})) {
171 | if ( not validate_hipchat_from_length( $contents->{hipchat}->{from} ) ) {
172 | warn "'from' is too long. Have to cut it down\n";
173 | $contents->{hipchat}->{from} = substr $contents->{hipchat}->{from}, 0, MAX_HIPCHAT_FROM_LENGTH;
174 | }
175 | $json_hash->{from}=$contents->{hipchat}->{from};
176 | }
177 |
178 |
179 | return JSON::XS->new->utf8->encode($json_hash);
180 |
181 | }
182 |
183 | sub choose_color {
184 |
185 | my $contents = shift;
186 | my $color;
187 | if ($contents->{status} eq 'OK') { return 'green'; }
188 | elsif ($contents->{severity} eq 'Not classified') {return 'gray';}
189 | elsif ($contents->{severity} eq 'Information') {return 'green';}
190 | elsif ($contents->{severity} eq 'Warning') {return 'yellow';}
191 | elsif ($contents->{severity} eq 'Average') {return 'yellow';}
192 | elsif ($contents->{severity} eq 'High') {return 'red';}
193 | elsif ($contents->{severity} eq 'Disaster') {return 'red';}
194 | else {return 'gray';}
195 |
196 | }
197 |
198 |
199 |
200 |
201 | sub post_with_retries {
202 | my $self = shift;
203 | my $url = shift;
204 | my $json_text = shift;
205 | my $retry_counter = RETRY_DEFAULT;
206 | my $retry_after = RETRY_WAIT_SECS;
207 | my $response;
208 | my $ua = LWP::UserAgent->new();
209 |
210 | if ( defined( $self->mock_url ) ) { $url = $self->mock_url; } #mock replace:
211 | $ua->env_proxy;
212 | $ua->show_progress(1) if $self->debug;
213 |
214 | ATTEMPT: {
215 |
216 | $response = $ua->post(
217 | $url,
218 | 'Content-Type' => 'application/json',
219 | Content => $json_text
220 | );
221 |
222 | if ( $response->is_success ) {
223 |
224 | #Check the status of the notification submission.
225 |
226 | #$self->check_slack_response($response);
227 | print "HipChat response OK.\n";
228 | return $response;
229 |
230 | }
231 | else {
232 | if ( $response->code == HTTP_TOO_MANY_REQUESTS ) {
233 | if ( defined( $response->header('Retry-After') )
234 | and $response->header('Retry-After') > 0 )
235 | {
236 | $retry_after = $response->header('Retry-After');
237 | }
238 |
239 | print $response->status_line . q{ }
240 | . "Will try again in $retry_after seconds\n";
241 |
242 | sleep $retry_after;
243 |
244 | if ( $retry_counter < 1 ) {
245 | decode_and_print_hipchat_bad_response( $response->content );
246 | die
247 | "Too many retries, unable to send message: ${ \$response->status_line } \n";
248 | }
249 |
250 | $retry_counter--;
251 | redo ATTEMPT;
252 | }
253 | else {
254 | decode_and_print_hipchat_bad_response( $response->content );
255 | die "HipChat connection failed! ${ \$response->status_line } \n";
256 | }
257 | }
258 | }
259 |
260 | }
261 |
262 | #helpers
263 | sub validate_hipchat_room_length {
264 | my $hipchat_room = shift;
265 | if ( length $hipchat_room <= MAX_HIPCHAT_ROOM_ID_LENGTH ) {
266 | return 1;
267 | }
268 | else {
269 | return 0;
270 | }
271 | }
272 |
273 | sub validate_hipchat_url {
274 | my $hipchat_url = shift;
275 | if ( $hipchat_url =~ /https: \/ \/ /x ) {
276 | return 1;
277 | }
278 | else {
279 | return 0;
280 | }
281 | }
282 |
283 | sub validate_hipchat_message_length {
284 | my $hipchat_message = shift;
285 | if ( length $hipchat_message <= MAX_HIPCHAT_MESSAGE_LENGTH ) {
286 | return 1;
287 | }
288 | else {
289 | return 0;
290 | }
291 | }
292 |
293 | sub validate_hipchat_from_length {
294 | my $hipchat_from = shift;
295 | if ( length $hipchat_from <= MAX_HIPCHAT_FROM_LENGTH ) {
296 | return 1;
297 | }
298 | else {
299 | return 0;
300 | }
301 | }
302 |
303 | sub decode_and_print_hipchat_bad_response {
304 |
305 | # example of what might be returned
306 | #{
307 | # "error": {
308 | # "code": 404,
309 | # "message": "Room not found",
310 | # "type": "Not Found"
311 | # }
312 | # }
313 |
314 | my $json_response;
315 | eval { $json_response = JSON::XS->new->decode(shift) };
316 | if ( !$EVAL_ERROR ) {
317 | print $json_response->{error}->{message} . "\n" if exists $json_response->{error}->{message};
318 | }
319 | return;
320 | }
321 |
322 |
323 |
324 |
325 |
326 | sub DESTROY { }
327 |
328 | 1;
329 |
--------------------------------------------------------------------------------
/lib/SlackBot.pm:
--------------------------------------------------------------------------------
1 | package SlackBot;
2 | use strict;
3 | use warnings;
4 | our $VERSION = '0.8';
5 | use parent qw(ZabbixNotify);
6 | use LWP;
7 | use URI;
8 | use Carp;
9 | use JSON::XS;
10 | use Data::Dumper;
11 | use Storable qw(lock_store lock_retrieve);
12 |
13 | use constant { ## no critic(ProhibitConstantPragma)
14 | CLEAR_ALARM_AFTER_SECS => 30,
15 | STORAGEFILE => '/var/tmp/zbx-slack-temp-storage',
16 | HTTP_TOO_MANY_REQUESTS => 429,
17 | RETRY_DEFAULT => 2,
18 | RETRY_WAIT_SECS => 5,
19 | };
20 |
21 | sub new {
22 | my $class = shift;
23 | my $args = shift;
24 |
25 | my $web_api_url = $args->{web_api_url} || 'https://slack.com/api/';
26 | my $api_token = $args->{api_token}
27 | || croak " Failed to create Slack bot - No token provided";
28 | my $debug = $args->{debug} || 0;
29 | my $channel = $args->{channel};
30 |
31 | my $self = bless {
32 | api_token => $api_token,
33 | web_api_url => $web_api_url,
34 | debug => $debug,
35 | channel => $channel,
36 | last_err => '',
37 | mock_url => undef
38 | }, $class;
39 |
40 | return $self;
41 | }
42 |
43 | sub channel {
44 | my $self = shift;
45 | if (@_) {
46 | my $channel = shift;
47 | validate_slack_channel($channel);
48 | return $self->{channel} = $channel;
49 | }
50 | else {
51 | return $self->{channel};
52 | }
53 | }
54 |
55 | sub test {
56 | my $self = shift;
57 |
58 | my $url = URI->new( $self->web_api_url . 'api.test' );
59 | $url->query_form( 'token' => $self->api_token );
60 | $self->get_with_retries($url);
61 | my $response = $self->get_with_retries($url);
62 | my $json_contents = JSON::XS->new->utf8->decode( $response->content );
63 |
64 | return $json_contents;
65 | }
66 |
67 | sub post_message {
68 | my $self = shift;
69 | my $contents = shift || die "No contents provided to post into Slack!\n";
70 |
71 | #prepare color:
72 | $contents->{color} = choose_color($contents);
73 |
74 | my $json_attach = $self->create_json_if_plain($contents);
75 |
76 | #Slack possible modes:
77 | # event - Notifications from Zabbix are posted in Slack in without any 'magic'
78 | # alarm - When problem is resolved in Zabbix - notification is updated in Slack and then deleted.
79 | # Acknowledgements are attached as replies to thread
80 | # alarm-no-delete - When problem is resolved in Zabbix - notification is updated in Slack but not deleted.
81 | # Acknowledgements are attached as replies to thread
82 |
83 |
84 | if (($contents->{slack}->{mode} eq 'alarm' or $contents->{slack}->{mode} eq 'alarm-no-delete')
85 | and defined( $contents->{eventid} ) )
86 | {
87 | #alarm recovery
88 | if ($contents->{status} eq 'OK'){
89 |
90 | print "Alarm recovery message!\n";
91 | $self->post_recoveryMessage($contents,$json_attach);
92 |
93 | }
94 | else {
95 | print "Alarm message or plain event message or acknowledgement!\n";
96 | my $message;
97 | #here goes Slack threading
98 | $self->post_replyMessage($contents,$json_attach);
99 |
100 | }
101 |
102 | }
103 | else { #event mode
104 | my $message = $self->chat_postMessage( { attachments => $json_attach} );
105 | }
106 |
107 |
108 |
109 | }
110 |
111 | sub post_recoveryMessage {
112 |
113 | my $self = shift;
114 | my $contents = shift;
115 | my $json_attach = shift;
116 | my $mes_to_replace;
117 |
118 | if ( $mes_to_replace = retrieve_from_store( $contents->{eventid}, 1 ) ) {
119 | print Dumper $mes_to_replace if $self->debug;
120 | #always update first [0] message (thread start)
121 | $self->chat_updateMessage(
122 | {
123 | attachments => $json_attach,
124 | ts => $mes_to_replace->[0]->{'ts'},
125 | channel => $mes_to_replace->[0]->{'channel'},
126 | text => $mes_to_replace->[0]->{'text'}
127 | }
128 | );
129 | }
130 |
131 | if ( not $mes_to_replace or $self->last_err eq 'message_not_found' ) {
132 |
133 | #post the recovery then
134 | print "No messages found to be deleted\n";
135 |
136 | my $message = $self->chat_postMessage( { attachments => $json_attach } );
137 | $mes_to_replace = [{
138 | ts => $message->{'ts'},
139 | channel => $message->{'channel'}
140 | }];
141 | }
142 |
143 | #delete only if not 'alarm-no-delete' mode
144 | if ($contents->{slack}->{mode} ne 'alarm-no-delete'){
145 | sleep CLEAR_ALARM_AFTER_SECS;
146 |
147 | #delete thread starter and all replies
148 | foreach my $message_to_delete (@{$mes_to_replace}) {
149 | $self->chat_deleteMessage(
150 | {
151 | ts => $message_to_delete->{'ts'},
152 | channel => $message_to_delete->{'channel'}
153 | }
154 | );
155 | }
156 | }
157 |
158 | }
159 |
160 | sub post_replyMessage {
161 | my $self = shift;
162 | my $contents = shift;
163 | my $json_attach = shift;
164 |
165 | if ( defined( $contents->{eventid} ) ) {
166 | #Probably a Reply(Acknowledgement)! Let's attach it to the Slack thread...
167 | my $mes_to_reply;
168 | #false(0) = means do not delete from store.
169 | if ( $mes_to_reply = retrieve_from_store( $contents->{eventid}, 0 ) ) {
170 | print "Found message to reply in Slack\n";
171 | print Dumper $mes_to_reply if $self->debug;
172 | #always use first [0] message found in store (thread start)
173 | my $message =
174 | $self->chat_postMessage( { attachments => $json_attach,
175 | thread_ts => $mes_to_reply->[0]->{ts} } );
176 | print "Storing event id...\n" if $self->{debug};
177 | store_message( $contents->{eventid}, $message );
178 | }
179 | else
180 | {
181 | print "Posting message\n";
182 | my $message = $self->chat_postMessage( { attachments => $json_attach} );
183 |
184 | print "Storing event id...\n" if $self->{debug};
185 | store_message( $contents->{eventid}, $message );
186 |
187 | }
188 | }
189 |
190 | }
191 |
192 | sub chat_postMessage {
193 | my $self = shift;
194 | my $args = shift;
195 |
196 | my $channel =
197 | $args->{channel}
198 | || $self->channel
199 | || die "Failed to postMessage: channel is required\n";
200 |
201 | #required for replies in Slack
202 | my $thread_ts =
203 | $args->{thread_ts};
204 |
205 | my $json_attach = $args->{attachments}
206 | || die "Failed to postMessage: no attachment is provided\n";
207 |
208 | my $url = URI->new( $self->web_api_url . 'chat.postMessage' );
209 |
210 | my %params = (
211 | 'token' => $self->api_token,
212 | 'channel' => $channel,
213 | 'attachments' => $json_attach,
214 | 'as_user' => 'true'
215 | );
216 | if ($thread_ts) {
217 | $params{thread_ts}=$thread_ts;
218 | }
219 | $url->query_form(%params);
220 |
221 | my $response = $self->get_with_retries($url);
222 | my $json_contents = JSON::XS->new->utf8->decode( $response->content );
223 |
224 | return $json_contents;
225 |
226 | }
227 |
228 | sub chat_updateMessage {
229 | my $self = shift;
230 | my $args = shift;
231 |
232 | my $ts = $args->{ts} || die "Failed to updateMessage: ts is required\n";
233 | my $channel = $args->{channel}
234 | || die "Failed to updateMessage: channel is required\n";
235 | my $text = $args->{text};
236 | my $json_attach = $args->{attachments}
237 | || die "Failed to updateMessage: no attachment is provided\n";
238 |
239 | my $url = URI->new( $self->web_api_url . 'chat.update' );
240 | $url->query_form(
241 | 'token' => $self->api_token,
242 | 'ts' => $ts,
243 | 'channel' => $channel,
244 | 'text' => $text,
245 | 'attachments' => $json_attach
246 |
247 | );
248 |
249 | my $response = $self->get_with_retries($url);
250 | my $json_contents = JSON::XS->new->utf8->decode( $response->content );
251 |
252 | return $json_contents;
253 |
254 | }
255 |
256 | sub chat_deleteMessage {
257 | my $self = shift;
258 | my $args = shift;
259 |
260 | my $ts = $args->{ts} || die "Failed to deleteMessage: ts is required\n";
261 | my $channel = $args->{channel}
262 | || die "Failed to deleteMessage: channel is required\n";
263 |
264 | my $url = URI->new( $self->web_api_url . 'chat.delete' );
265 | $url->query_form(
266 | 'token' => $self->api_token,
267 | 'ts' => $ts,
268 | 'channel' => $channel
269 | );
270 |
271 | my $response = $self->get_with_retries($url);
272 | my $json_contents = JSON::XS->new->utf8->decode( $response->content );
273 |
274 | return $json_contents;
275 |
276 | }
277 |
278 |
279 | sub check_slack_response {
280 | my $self = shift;
281 | my $response = shift;
282 |
283 | $self->last_err('') if $self->last_err ne ''; #delete prev error
284 |
285 | if ( !$response->is_success ) {
286 | die "Error: ", $response->status_line . "\n";
287 | }
288 |
289 | my $json_resp = JSON::XS->new->utf8->decode( $response->content );
290 | print "Slack response is:\n".$response->content."\n" if $self->debug;
291 | if ( !$json_resp->{ok} ) {
292 | if ( $json_resp->{error} eq 'message_not_found' ) {
293 | $self->last_err('message_not_found');
294 | return 1;
295 | }
296 |
297 | die "Error " . $json_resp->{error} . "\n";
298 | }
299 | else {
300 | carp "Warning " . $json_resp->{warning} if $json_resp->{warning};
301 | return 1;
302 | }
303 |
304 | }
305 |
306 | #helpers
307 | sub store_message {
308 | my $eventid = shift;
309 | my $message = shift;
310 | my $storage_file = STORAGEFILE;
311 | my ( $stored, $to_store );
312 |
313 | $to_store = {
314 | ts => $message->{ts},
315 | channel => $message->{channel}
316 | };
317 |
318 |
319 | if ( -f $storage_file ) {
320 | $stored = lock_retrieve $storage_file;
321 |
322 | push @{$stored->{$eventid}},$to_store;
323 | lock_store $stored, $storage_file;
324 | }
325 | else {
326 |
327 | #first time file creation, apply proper file permissions and store only single event
328 | lock_store {$eventid=>[
329 | $to_store
330 | ]}, $storage_file;
331 | chmod 0666, $storage_file;
332 | }
333 |
334 | }
335 |
336 | sub retrieve_from_store {
337 | my $eventid = shift;
338 | my $delete = shift || 0;
339 | my $storage_file = STORAGEFILE;
340 | my $stored;
341 | my $message_to_delete;
342 |
343 |
344 | if ( -f $storage_file ) {
345 |
346 | $stored = lock_retrieve $storage_file;
347 |
348 | if ( $message_to_delete = $stored->{$eventid} ) {
349 | delete $stored->{$eventid} if $delete;
350 | lock_store $stored, $storage_file;
351 | }
352 | }
353 |
354 | return $message_to_delete;
355 |
356 | }
357 |
358 | sub validate_slack_channel {
359 | my $slack_channel = shift;
360 | if ( $slack_channel =~ /^[#@].+/ ) {
361 | return $slack_channel;
362 | }
363 | else {
364 | die "Slack channel $slack_channel is neither channel or username.\n";
365 | }
366 | }
367 |
368 | =create_json_if_plain
369 | $contents must be already utf8 decoded if non ASCII is present
370 | like utf8::decode( $contents );
371 | =cut
372 |
373 | sub create_json_if_plain {
374 | my $self = shift;
375 | my $contents = shift;
376 | my $json_hash;
377 | my $json_attach;
378 | eval { #check if already JSON:
379 |
380 | my $message = $self->zbx_macro_to_json($contents->{message});
381 | $json_hash = JSON::XS->new->decode( $message );
382 |
383 | };
384 | if ($@) {
385 | print "message is not JSON, going to proceed as with regular text\n" if $self->{debug};
386 | $json_attach = create_json_attach_only($contents);
387 | return $json_attach;
388 | }
389 | else {
390 | print "message is JSON, going to proceed as with JSON attachment\n" if $self->{debug};
391 | if ( not defined( $json_hash->{color} )
392 | and exists( $contents->{color} ) )
393 | {
394 |
395 | print "Adding color to the attachment...\n";
396 | $json_hash->{color} = $contents->{color};
397 |
398 | }
399 | $json_attach = JSON::XS->new->utf8->encode( [$json_hash] );
400 | return $json_attach;
401 | }
402 | }
403 |
404 | sub create_json_attach_only {
405 | my $contents_ref = shift;
406 | return JSON::XS->new->utf8->encode(
407 | [
408 | {
409 | title => $contents_ref->{subject},
410 | fallback => $contents_ref->{subject},
411 | text => $contents_ref->{message},
412 | color => $contents_ref->{color}
413 | }
414 | ]
415 | );
416 | }
417 |
418 |
419 | sub choose_color {
420 |
421 | my $contents = shift;
422 | my $color;
423 | if ($contents->{status} eq 'OK') { return '#CCFFCC'; }
424 | elsif ($contents->{severity} eq 'Not classified') {return '#DBDBDB';}
425 | elsif ($contents->{severity} eq 'Information') {return '#33CCFF';}
426 | elsif ($contents->{severity} eq 'Warning') {return '#FFFFCC';}
427 | elsif ($contents->{severity} eq 'Average') {return '#FFCCCC';}
428 | elsif ($contents->{severity} eq 'High') {return '#FF9999';}
429 | elsif ($contents->{severity} eq 'Disaster') {return '#FF6666';}
430 | else {return '#DBDBDB';}
431 |
432 | }
433 |
434 |
435 |
436 | sub get_with_retries {
437 | my $self = shift;
438 | my $url = shift;
439 | my $retry_counter = RETRY_DEFAULT;
440 | my $retry_after = RETRY_WAIT_SECS;
441 | my $response;
442 | my $ua = LWP::UserAgent->new();
443 |
444 | if ( defined( $self->mock_url ) ) { $url = $self->mock_url; } #mock replace:
445 | $ua->env_proxy;
446 | $ua->show_progress(1) if $self->debug;
447 |
448 | ATTEMPT: {
449 |
450 | $response = $ua->get($url);
451 |
452 | if ( $response->is_success ) {
453 |
454 | #Check the status of the notification submission.
455 |
456 | $self->check_slack_response($response);
457 | print "Slack response OK.\n";
458 | return $response;
459 |
460 | }
461 | else {
462 | if ( $response->code == HTTP_TOO_MANY_REQUESTS ) {
463 | if ( defined( $response->header('Retry-After') )
464 | and $response->header('Retry-After') > 0 )
465 | {
466 | $retry_after = $response->header('Retry-After');
467 | }
468 |
469 | print $response->status_line . q{ }
470 | . "Will try again in $retry_after seconds\n";
471 |
472 | sleep $retry_after;
473 |
474 | if ( $retry_counter < 1 ) {
475 | die "Too many retries, unable to send message: ${ \$response->status_line } \n";
476 | }
477 |
478 | $retry_counter--;
479 | redo ATTEMPT;
480 | }
481 | else {
482 | die "Slack connection failed! ${ \$response->status_line } \n";
483 | }
484 | }
485 | }
486 |
487 | }
488 |
489 |
490 |
491 |
492 | sub DESTROY { }
493 |
494 | 1;
495 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | DEPRECATED! For Zabbix 4.4 or newer please use the official integration with Slack/PagerDuty based on webhooks.
2 |
3 | https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/media/slack
4 | https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/media/pagerduty
5 |
6 |
7 | # zabbix-notify
8 | [](https://travis-ci.org/v-zhuravlev/zabbix-notify)
9 | Notify alarms from Zabbix 3.x to Slack, HipChat and PagerDuty
10 |
11 | # About
12 | This guide provides step-by-step guide how to install and use scripts to send notifications from Zabbix to popular collaborations platforms: **HipChat** (Deprecated), **Slack** and Incident Management system **PagerDuty**.
13 | Here is the idea in brief:
14 |
15 | - Install scripts on Zabbix Server
16 | - In HipChat, Slack or PagerDuty generate access key for Zabbix
17 | - In Zabbix setup new Media Type, Actions and assign new media type to new impersonal user
18 | - Catch messages in Slack channel:
19 |
20 | 
21 | - HipChat room:
22 |
23 | 
24 | - or PagerDuty Console:
25 |
26 | 
27 |
28 |
29 |
30 | ## Features Include:
31 | **All:**
32 |
33 | - All configuration is done in Zabbix web-interface (no config files anywhere)
34 | - UTF8 supported
35 | - HTTPS/HTTP proxy supported (see how at the end)
36 |
37 | **Slack:**
38 |
39 | - Color coding events depending on Trigger Status and Severity
40 | - Recovery and acknowledgements from Zabbix will be posted as new messages (`--slack_mode=event`)
41 | - Acknowledgements (Zabbix 3.4+) will be attached as replies to [Slack message thread](https://slackhq.com/threaded-messaging-comes-to-slack). Recovery message from Zabbix will update and then delete initial problem message as well as all acknowledgements. (`--slack_mode=alarm`) 
42 | - Acknowledgements will be attached as replies to Slack message thread. Recovery message from Zabbix will update initial message. (`--slack_mode=alarm-no-delete`)
43 | - JSON can be used to compose Slack messages. See Slack [message attachments](https://api.slack.com/docs/attachments)
44 |
45 | **HipChat:**
46 |
47 | - Color coding events depending on Trigger Status and Severity
48 | - HTML or plain text can be used to format HipChat messages.
49 | - JSON can be used to compose messages. See HipChat [API](https://www.hipchat.com/docs/apiv2/method/send_room_notification)
50 |
51 | **PagerDuty:**
52 |
53 | - Recovery message from Zabbix will resolve already created incident in PagerDuty
54 | - Acknowledgements will be added already created incidents
55 | - JSON can be used to compose messages. See PagerDuty API [here](https://developer.pagerduty.com/documentation/integration/events/trigger) and [here](https://developer.pagerduty.com/documentation/integration/events/resolve)
56 |
57 |
58 | **There are limitations to note as well:**
59 |
60 | - Slack and HipChat can reject you messages if you are sending them too often (more then 1 per second). It can accept short bursts but If you continue to spam - you will be blocked for one minute or so. So use Acton Conditions wisely to avoid event storms.
61 |
62 | ## Zabbix Server preparations
63 | Start with installing the script to Zabbix Server.
64 | The script is written in Perl and you will need common modules in order to run it:
65 | ```
66 | LWP
67 | JSON::XS
68 | ```
69 | There are numerous ways to install them:
70 |
71 | | in Debian | In Centos | using CPAN | using cpanm|
72 | |------------|-----------|------------|------------|
73 | | `apt-get install libwww-perl libjson-xs-perl` | `yum install perl-JSON-XS perl-libwww-perl perl-LWP-Protocol-https perl-parent` | `PERL_MM_USE_DEFAULT=1 perl -MCPAN -e 'install Bundle::LWP'` and `PERL_MM_USE_DEFAULT=1 perl -MCPAN -e 'install JSON::XS'` | `cpanm install LWP` and `cpanm install JSON::XS`|
74 |
75 | You may also might requireadditional modules to do `make test` and installation:
76 |
77 | | in Debian | In Centos | using CPAN | using cpanm|
78 | |------------|-----------|------------|------------|
79 | | `apt-get install libtest-simple-perl libtest-most-perl` | `yum install perl-ExtUtils-MakeMaker perl-Test-Simple perl-Test-Exception` | `cpan install ExtUtils::MakeMaker` and `PERL_MM_USE_DEFAULT=1 perl -MCPAN -e 'install Test::Simple'` and `PERL_MM_USE_DEFAULT=1 perl -MCPAN -e 'install Test::Exception'` | `cpanm install ExtUtils::MakeMaker` and `cpanm install Test::Simple` and `cpanm install Test::Exception`|
80 |
81 | Once this is done, download tar and install it into the system:
82 | ```
83 | perl Makefile.PL INSTALLSITESCRIPT=/usr/local/share/zabbix/alertscripts
84 | make test
85 | make install
86 | ```
87 | where INSTALLSITESCRIPT is your Zabbix's alert script folder as defined in zabbix_server.conf.
88 |
89 | Please note that currently `make test` requires Internet connection to test with mocks :) So skip if you don't have one.
90 |
91 | # Slack Setup
92 | 1. You have to have the [Bots app](https://slack.com/apps/A0F7YS25R-bots) installed.
93 | 1. Create a bot
94 | 
95 | 1. Fill in the card:
96 | 
97 | 1. Upload this icon for the bot, or choose another:
98 | 
99 | 1. If you want the bot to broadcast to a channel, invite it to the channel, where you want it to post.
100 | to do this in Slack channel type:
101 | ```
102 | /invite @zabbix_bot
103 | ```
104 |
105 | ## Test with Slack
106 | Once you have done the basic setup, go back to the terminal and test the script by running it under the zabbix user:
107 |
108 | ```
109 | root#: sudo -u zabbix /bin/sh
110 | cd /usr/local/share/zabbix/alertscripts
111 | ```
112 |
113 |
114 | To ADD ALARM:
115 |
116 | ```
117 | ./zbx-notify @your_name_in_slack_here 'PROBLEM:myHOSTNAME Temperature Failure on DAE5S Bus 1 Enclosure 1' 'Host: myHOSTNAME \
118 | Trigger: PROBLEM: myHOSTNAME Temperature Failure on DAE5S Bus 1 Enclosure 1: High \
119 | Timestamp: 2016.03.14 11:57:10 YEKT eventid: 100502' --api_token=your_token_here --slack
120 | ```
121 |
122 | To CLEAR ALARM RUN:
123 |
124 | ```
125 | ./zbx-notify @your_name_in_slack_here 'OK:myHOSTNAME Temperature Failure on DAE5S Bus 1 Enclosure 1' 'Host: myHOSTNAME \
126 | Trigger: OK: myHOSTNAME Temperature Failure on DAE5S Bus 1 Enclosure 1: High \
127 | Timestamp: 2016.03.14 11:57:10 YEKT eventid: 100502' --api_token=your_token_here --slack
128 | ```
129 |
130 |
131 | ## Zabbix Configuration (Slack)
132 | Now all is left is to setup new Action and Media Type.
133 |
134 | ### Media type
135 | First go to **Administration -> Media Types**, press **Create media type**
136 | 
137 | Choose Type: *Script*
138 | Name: *Slack*
139 | Script name: *zbx-notify*
140 | Fill **Script parameters** in the following order
141 | 1: `{ALERT.SENDTO}`
142 | 2: `{ALERT.SUBJECT}`
143 | 3: `{ALERT.MESSAGE}`
144 | 4: `--api_token=you_token_here`
145 | 5: `--slack`
146 | 6: `--no-fork` (for Zabbix 3.4+ only)
147 | Note that there should be no ticks or quotes after `--api-token=` only the key itself.
148 | You may provide additional params as well, by pressing **Add** and filling them in the form:
149 | `--param=value`
150 |
151 | Here is what you can setup for Slack:
152 |
153 | | Parameter | Description | Default value | Example value | JSON mode(see below) |
154 | | ---------------- |:---------------------:|:--------------:|-----------------------------------------|----|
155 | | `api_token` | you bot api token (Mandatory) | none |`--api_token=xoxb-30461853043-mQE7IGah4bGeC15T5gua4IzK`| Yes |
156 | | `slack_mode` | operation mode (`event`, `alarm`, `alarm-no-delete`) | event |`--slack_mode=event`| Yes |
157 | | `debug` | For providing debug output, useful when running from command line | none |`--debug`| Yes |
158 | | `no-fork` | To prevent script from forking on posting to Slack. | none |`--no-fork`| Yes |
159 | | `no-ssl_verify_hostname` | To ignore SSL certificate validation failures. | none |`--no-ssl_verify_hostname`| Yes |
160 |
161 | Press *Add* to finish media type creation.
162 |
163 | ### User changes (for direct to user notifications)
164 | If you want your users to be able to get direct notifications from the bot...
165 |
166 | #### Setting up zabbix slack media for multiple users
167 | 1. Go to **Administration->Users**
168 | 1. Select a user
169 | 1. Select the **Media** tab
170 | 1. Click **Add**
171 | 1. Select **Type**: Slack
172 | 1. Fill in **Send to**: `@slackusername` (with the user's corresponding slack address)
173 | 1. Click Add
174 | 1. Click Update
175 | 1. Repeat for as many users as you want to preconfigure
176 |
177 | #### Setting up zabbix slack media as a user
178 | If your users want to make changes:
179 |
180 | 1. Click the profile icon (near the top right of a zabbix page)
181 | 1. Select the **Media** tab
182 | 1. If there's no Slack type already set up:
183 | 1. Click **Add**
184 | 1. Select **Type**: Slack
185 | 1. Fill in **Send to**: `@slackusername` (with the user's corresponding slack address)
186 | 1. Click Add
187 | 1. If there's already a Slack type, click the corresponding **Edit** action
188 | 1. Update the **Send to** field with the appropriate `@slackusername` (with the user's corresponding slack address)
189 | 1. Update **When active** as appropriate (see zabbix documentation)
190 | 1. Update **Use if severity** as desired
191 | 1. Click Update
192 | 1. Click Update
193 |
194 | ### User creation (For channel notifications)
195 | As you finish with defining new Media Type for Slack proceed to next step and create impersonal user:
196 |
197 | 1. Go to **Administration->Users**
198 | 1. Click **Create user**:
199 | 1. In **User** tab:
200 | 1. **Alias**: Notification Agent
201 | 1. **Groups**: Make sure you add him proper Group Membership so this user has the rights to see new Events (and so notify on them).
202 | 1. **Password**: anything complex you like, you will never use it
203 | 
204 |
205 | 1. **In Media tab:**
206 | 1. Create New media:
207 | 1. **Type:** Slack
208 | 1. **Send to:** Place your Slack #channel name here for example #zabbix.
209 | 
210 |
211 | ### Action creation:
212 |
213 | To Create a new action:
214 |
215 | 1. Go to **Configuration -> Action**
216 | 1. Choose **Event source: Triggers**
217 | 1. press **Create action**
218 | 1. that is to be sent to Slack.
219 |
220 | Here is the example:
221 | In **Operations** tab:
222 | 
223 |
224 | Default subject: anything you like, but I recommend:
225 |
226 | ```
227 | {TRIGGER.STATUS}:{HOSTNAME}:{TRIGGER.NAME}.
228 | ```
229 |
230 | Default message: anything you like.
231 |
232 | ```
233 | Host: {HOSTNAME}
234 | Trigger: {STATUS}: {TRIGGER.NAME}: {TRIGGER.SEVERITY}
235 | Timestamp: {EVENT.DATE} {EVENT.TIME}
236 | {TRIGGER.COMMENT}
237 | {TRIGGER.URL}
238 | http://zabbix.local
239 | Eventid: {EVENT.ID}
240 | ```
241 |
242 | In **Recovery operations** tab:
243 | Default subject: anything you like, but I recommend
244 |
245 | ```
246 | {TRIGGER.STATUS}:{HOSTNAME}:{TRIGGER.NAME}.
247 | ```
248 |
249 | Default message:
250 |
251 | ```
252 | Host: {HOSTNAME}
253 | Trigger: {STATUS}: {TRIGGER.NAME}: {TRIGGER.SEVERITY}
254 | Timestamp: {EVENT.RECOVERY.DATE} {EVENT.RECOVERY.TIME}
255 | {TRIGGER.COMMENT}
256 | {TRIGGER.URL}
257 | http://zabbix.local
258 | Eventid: {EVENT.ID}
259 | ```
260 |
261 | In **Acknowledgement operations** (Zabbix 3.4+) tab:
262 |
263 | ```
264 | {USER.FULLNAME} acknowledged problem at {ACK.DATE} {ACK.TIME} with the following message:
265 | {ACK.MESSAGE}
266 | Current problem status is {EVENT.STATUS}, Eventid: {EVENT.ID}
267 | ```
268 |
269 | Note: if you place Macros **{TRIGGER.SEVERITY}** and **{STATUS}** then your messages in Slack will be color coded.
270 | Note: place line `Eventid: {EVENT.ID}` if you want to use Alarm mode in all messages, including Acknowledgements.
271 |
272 | As an alternative you can place JSON object here that would represent Slack [attachment:](https://api.slack.com/docs/attachments)
273 | 
274 | Note though, that it is required to place all Zabbix MACROS in double brackets [[ ]], so they are properly transformed into JSON String.
275 | For TRIGGER transitioning to PROBLEM you might use:
276 |
277 | ```
278 | {
279 | "fallback": "[[{HOST.NAME}:{TRIGGER.NAME}:{STATUS}]]",
280 | "pretext": "New Alarm",
281 | "author_name": "[[{HOST.NAME}]]",
282 | "title": "[[{TRIGGER.NAME}]]",
283 | "title_link": "http://zabbix/tr_events.php?triggerid={TRIGGER.ID}&eventid={EVENT.ID}",
284 | "text": "[[{TRIGGER.DESCRIPTION}]]",
285 | "fields": [
286 | {
287 | "title": "Status",
288 | "value": "{STATUS}",
289 | "short": true
290 | },
291 | {
292 | "title": "Severity",
293 | "value": "{TRIGGER.SEVERITY}",
294 | "short": true
295 | },
296 | {
297 | "title": "Time",
298 | "value": "{EVENT.DATE} {EVENT.TIME}",
299 | "short": true
300 | },
301 | {
302 | "title": "EventID",
303 | "value": "eventid: {EVENT.ID}",
304 | "short": true
305 | }
306 |
307 |
308 | ]
309 | }
310 | ```
311 |
312 | And for Recovery:
313 |
314 | ```
315 | {
316 | "fallback": "[[{HOST.NAME}:{TRIGGER.NAME}:{STATUS}]]",
317 | "pretext": "Cleared",
318 | "author_name": "[[{HOST.NAME}]]",
319 | "title": "[[{TRIGGER.NAME}]]",
320 | "title_link": "http://zabbix/tr_events.php?triggerid={TRIGGER.ID}&eventid={EVENT.RECOVERY.ID}",
321 | "text": "[[{TRIGGER.DESCRIPTION}]]",
322 | "fields": [
323 | {
324 | "title": "Status",
325 | "value": "{STATUS}",
326 | "short": true
327 | },
328 | {
329 | "title": "Severity",
330 | "value": "{TRIGGER.SEVERITY}",
331 | "short": true
332 | },
333 | {
334 | "title": "Time",
335 | "value": "{EVENT.RECOVERY.DATE} {EVENT.RECOVERY.TIME}",
336 | "short": true
337 | },
338 | {
339 | "title": "EventID",
340 | "value": "eventid: {EVENT.ID}",
341 | "short": true
342 | },
343 | {
344 | "title": "Event Acknowledgement history",
345 | "value": "[[{EVENT.ACK.HISTORY}]]",
346 | "short": false
347 | },
348 | {
349 | "title": "Escalation history",
350 | "value": "[[{ESC.HISTORY}]]",
351 | "short": false
352 | }
353 |
354 |
355 |
356 | ]
357 | }
358 | ```
359 |
360 | In **Condition** tab do not forget to include **Trigger value = Problem condition** (This option is removed in Zabbix 3.4). The rest depends on your needs.
361 | 
362 |
363 | In **Operations** tab select Notification Agent as recipient of the message sent via Slack.
364 | 
365 |
366 | More on Action configuration in Zabbix can be found [here:](https://www.zabbix.com/documentation/3.0/manual/config/notifications/action)
367 |
368 | That it is it
369 |
370 | # Hipchat Setup
371 | Moved here to [wiki:](https://github.com/v-zhuravlev/zabbix-notify/wiki/Hipchat-Setup)
372 |
373 | # PagerDuty Setup
374 | And *finally* PagerDuty. If your team doesn't have the account you can get it [here](https://signup.pagerduty.com/accounts/new)
375 |
376 | Once inside PagerDuty you will need to setup **Services** that will provide you with data. To do this go to **Configuration->Services**:
377 | 
378 |
379 | On the next page choose Zabbix from the list of services and choose a name for your Zabbix installation:
380 | 
381 | You will see Service key on the next page: save it somewhere as you will need this in Zabbix.
382 |
383 | ## Test with PagerDuty
384 | Once you have done the previous step, go back to console and test the script by running it under user Zabbix:
385 |
386 | ```
387 | root#:su - zabbix
388 | cd /usr/local/share/zabbix/alertscripts
389 | ```
390 |
391 | To ADD ALARM:
392 |
393 | ```
394 | ./zbx-notify pagerduty 'PROBLEM:myHOSTNAME Temperature Failure on DAE5S Bus 1 Enclosure 1' \
395 | 'Host: myHOSTNAME \
396 | Trigger: PROBLEM: myHOSTNAME Температуа Failure on DAE5S Bus 1 Enclosure 1: High \
397 | Timestamp: 2016.03.14 11:57:10 eventid: 100502' \
398 | --api_token=1baff6f955c040d795387e7ab9d62090 \
399 | --pagerduty --no-fork
400 | ```
401 |
402 | To RESOLVE IT:
403 |
404 | ```
405 | ./zbx-notify pagerduty 'OK:myHOSTNAME Temperature Failure on DAE5S Bus 1 Enclosure 1' \
406 | 'Host: myHOSTNAME \
407 | Trigger: OK: myHOSTNAME Температуа Failure on DAE5S Bus 1 Enclosure 1: High \
408 | Timestamp: 2016.03.14 11:57:10 eventid: 100502' \
409 | --api_token=1baff6f955c040d795387e7ab9d62090 \
410 | --pagerduty --no-fork
411 | ```
412 |
413 |
414 | ## Zabbix Configuration (PagerDuty)
415 | Now all is left is to setup new Action and Media Type.
416 | ### Media type
417 | First go to **Administration -> Media Types**, press **Create media type**
418 | 
419 | Choose Type: *Script*
420 | Name: *PagerDuty*
421 | Script name: *zbx-notify*
422 | Fill **Script parameters** in the following order
423 | 1: `{ALERT.SENDTO}`
424 | 2: `{ALERT.SUBJECT}`
425 | 3: `{ALERT.MESSAGE}`
426 | 4: `--api_token=you_token_here`
427 | 5: `--pagerduty`
428 | 6: `--no-fork` (for Zabbix 3.4+ only)
429 | Note that there should be no ticks or quotes after `--api-token=` only the key itself.
430 | You may provide additional params as well, by pressing **Add** and filling them in the form:
431 | `--param=value`
432 |
433 | Here is what you can setup for PagerDuty:
434 |
435 | | Parameter | Description | Default value | Example value | JSON mode(see below) |
436 | | ---------------- |:---------------------:|:--------------:|-----------------------------------------|---|
437 | | api_token | your Service key(Mandatory) | none |--api_token=1baff6f955c040d795387e7ab9d62090| Yes |
438 | | pagerduty_client | Zabbix instance name(only works if both client and client_url are provided) | none |--pagerduty_client=Myzabbix | Ignored |
439 | | pagerduty_client_url | Zabbix instance name link | none | --pagerduty_client_url=http://zabbix.local | Ignored |
440 | | debug | For providing debug output, useful when running from command line | none |--debug| Yes |
441 | | no-fork | To prevent script from forking on posting to Slack | none |--no-fork| Yes |
442 | | no-ssl_verify_hostname | To ignore SSL certificate validation failures. | none |--no-ssl_verify_hostname| Yes |
443 |
444 | Click *Add* to finish media type creation.
445 |
446 | ### User creation
447 | As you finish with defining new Media Type for PagerDuty proceed to next step and create impersonal user:
448 | Go to **Administration->Users** Click **Create user**:
449 |
450 | **In User tab:**
451 | **Alias**: Notification Agent
452 | **Groups**: Make sure you add him proper Group Membership so this user has the rights to see new Events (and so notify on them).
453 | **Password**: anything complex you like, you will never use it
454 | 
455 |
456 | **In Media tab:**
457 | Create New media:
458 | **Type:** PagerDuty
459 | **Send to:** PagerDuty
460 | 
461 |
462 |
463 | ### Action creation:
464 | Create new action (go to **Configuration -> Action** ,choose **Event source: Triggers** Click **Create action**) that is to be send to PagerDuty.
465 | Here is the example:
466 | In **Action** tab:
467 | Default/recovery subject: anything you like, but I recommend
468 |
469 | ```
470 | {STATUS} : {HOSTNAME} : {TRIGGER.NAME}
471 | ```
472 |
473 | Default message:
474 | anything you like, for example:
475 |
476 | ```
477 | {TRIGGER.DESCRIPTION}
478 | Status: {STATUS}
479 | Severity: {TRIGGER.SEVERITY}
480 | Timestamp: {EVENT.DATE} {EVENT.TIME}
481 | eventid: {EVENT.ID}
482 | ```
483 |
484 | Recovery message:
485 |
486 | ```
487 | {TRIGGER.DESCRIPTION}
488 | Status: {STATUS}
489 | Severity: {TRIGGER.SEVERITY}
490 | Timestamp: {EVENT.DATE} {EVENT.TIME}
491 | eventid: {EVENT.ID}
492 | Event Acknowledgement history: {EVENT.ACK.HISTORY}
493 | Escalation history: {ESC.HISTORY}
494 | ```
495 |
496 | As an alternative you can place JSON object here that would represent PagerDuty
497 | See PagerDuty API [here](https://developer.pagerduty.com/documentation/integration/events/trigger) and [here](https://developer.pagerduty.com/documentation/integration/events/resolve).
498 | Note though, that it is required to place all Zabbix MACROS in double brackets `[[` `]]`, so they are properly transformed into JSON String.
499 | For TRIGGER transitioning to PROBLEM you might use (Default Message):
500 |
501 | ```
502 | {
503 |
504 | "incident_key": "{EVENT.ID}",
505 | "event_type": "trigger",
506 | "description": "[[{TRIGGER.NAME}]]",
507 | "client": "Zabbix Monitoring system",
508 | "client_url": "http://zabbix",
509 | "details": {
510 | "Status": "[[{STATUS}]]",
511 | "Timestamp": "[[{EVENT.DATE} {EVENT.TIME}]]",
512 | "Hostname": "[[{HOST.NAME}]]",
513 | "Severity": "[[{TRIGGER.SEVERITY}]]",
514 | "Description": "[[{TRIGGER.DESCRIPTION}]]",
515 | "IP": "[[{HOST.IP}]]"
516 | },
517 | "contexts":[
518 | {
519 | "type": "link",
520 | "href": "http://zabbix/tr_events.php?triggerid={TRIGGER.ID}&eventid={EVENT.ID}",
521 | "text": "View Event details in Zabbix"
522 | }
523 | ]
524 | }
525 | ```
526 |
527 | And for Recovery:
528 |
529 | ```
530 | {
531 | "incident_key": "{EVENT.ID}",
532 | "event_type": "resolve",
533 | "description": "[[{TRIGGER.NAME}]]",
534 | "details": {
535 | "Status": "[[{STATUS}]]",
536 | "Timestamp": "[[{EVENT.RECOVERY.DATE} {EVENT.RECOVERY.TIME}]]",
537 | "Event Acknowledgement history: ": "[[{EVENT.ACK.HISTORY}]]",
538 | "Escalation history:": "[[{ESC.HISTORY}]]"
539 | }
540 | }
541 | ```
542 |
543 | **Note**: do not insert `"service_key": "key"` in JSON, it is appended automatically.
544 |
545 | 
546 |
547 |
548 | In **Condition** tab do not forget to include **Trigger value = Problem condition** (This option is removed in Zabbix 3.4). The rest depends on your needs.
549 | 
550 |
551 | In **Operations** tab select Notification Agent as recipient of the message sent via PagerDuty.
552 | 
553 |
554 | More on Action configuration in Zabbix can be found [here:](https://www.zabbix.com/documentation/3.0/manual/config/notifications/action)
555 |
556 | # About using --no-fork
557 |
558 | If you have Zabbix 3.4 or newer, it recommended to use --no-fork option from Zabbix. This will give you an ability to see [errors](https://www.zabbix.com/documentation/3.4/manual/introduction/whatsnew340#return_code_check_for_scripts_and_commands) in Zabbix if something goes wrong:
559 | 
560 |
561 | Just make sure you enabled [concurrent sessions](https://www.zabbix.com/documentation/3.4/manual/introduction/whatsnew340#parallel_processing_of_alerts) in Zabbix.
562 | Use --no-fork with care if you use Slack with --slack_mode=alarm, since script then sleeps for 30s before removing messages from Slack.
563 |
564 |
565 |
566 | # Troubleshooting
567 | In order to troubleshoot problems, try to send test message from the command line under user `zabbix`.
568 | Try using `--no-fork` and `--debug` command line switches
569 |
570 | You may also want to increase the logging of alerter process to DEBUG for a while.
571 | (optional) If appropriate, decrease the level of logging of all zabbix processes to reduce the noise in the log file:
572 |
573 | ```
574 | zabbix_server --runtime-control log_level_decrease
575 | zabbix_server --runtime-control log_level_decrease
576 | zabbix_server --runtime-control log_level_decrease
577 | zabbix_server --runtime-control log_level_decrease
578 | ```
579 |
580 | Then increase the logging of alerter process to DEBUG for a while:
581 |
582 | To do it run it as many times as required to reach DEBUG from your current level (4 times if your current log level is 0)
583 |
584 | ```
585 | zabbix_server --runtime-control log_level_increase=alerter
586 | zabbix_server --runtime-control log_level_increase=alerter
587 | zabbix_server --runtime-control log_level_increase=alerter
588 | zabbix_server --runtime-control log_level_increase=alerter
589 | ```
590 |
591 | now tail you log to see what the problem might be:
592 | `tail -f /var/log/zabbix-server/zabbix_server.log`
593 |
594 | ## HTTP(S) Proxy
595 | If you need to use proxy to connect to services, make sure that environment variables
596 | `http_proxy` and `https_proxy` are set under user `zabbix`, for example:
597 |
598 | ```
599 | export http_proxy=http://proxy_ip:3128/
600 | export https_proxy=$http_proxy
601 | ```
602 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 | {one line to give the program's name and a brief idea of what it does.}
635 | Copyright (C) {year} {name of author}
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | {project} Copyright (C) {year} {fullname}
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------