Эх сурвалжийг харах

/alert + настоящая отсылка

Yuriy Zhilovets 5 жил өмнө
parent
commit
c3994cd855
1 өөрчлөгдсөн 12 нэмэгдсэн , 5 устгасан
  1. 12 5
      telegram.pl

+ 12 - 5
telegram.pl

@@ -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");
 };