|
|
@@ -101,15 +101,22 @@ sub check_ip
|
|
|
$c->render(status => 403, text => "Неизвестный IP-адрес " . $c->tx->remote_address);
|
|
|
}
|
|
|
|
|
|
-post "/alertmanager" => sub
|
|
|
+post "/alert" => sub
|
|
|
{
|
|
|
my $c = shift;
|
|
|
return unless check_ip($c);
|
|
|
-
|
|
|
+
|
|
|
+ my $channel = $c->param("to");
|
|
|
my $params = j($c->req->body);
|
|
|
- open(F,">>/tmp/alertmanager.txt");
|
|
|
- say F Dumper $params;
|
|
|
- close(F);
|
|
|
+
|
|
|
+ for my $alert (@{$params->{alerts}})
|
|
|
+ {
|
|
|
+ my $message = $alert->{status} eq "firing" ? "\x{1F534}" : "\x{1F197}";
|
|
|
+ $message .= " [" . ($alert->{labels}->{server}||"") . "] " . $alert->{labels}->{instance} . " " . $alert->{labels}->{job} . "\n";
|
|
|
+ $message .= $alert->{annotations}->{summary} . "\n" . "<i>" . $alert->{annotations}->{description} . "</i>";
|
|
|
+ notify($channel, $message, {});
|
|
|
+ }
|
|
|
+
|
|
|
$c->render(text=>"ok");
|
|
|
};
|
|
|
|