소스 검색

/alert ~ отсылать в ночное время нотификации без звука

Yuriy Zhilovets 5 년 전
부모
커밋
9413730678
1개의 변경된 파일7개의 추가작업 그리고 4개의 파일을 삭제
  1. 7 4
      telegram.pl

+ 7 - 4
telegram.pl

@@ -129,7 +129,12 @@ post "/alert" => sub
     my $message .= "$icon ` [" . ($alert->{labels}->{server}||"") . "] " . $alert->{labels}->{alertname} . " " .$alert->{labels}->{instance} 
                 . " " . $alert->{labels}->{job} . "`\n";
     $message .= $alert->{annotations}->{summary} . "\n" . "_" . $alert->{annotations}->{description} . "_";  
-    notify($channel, $message, {});
+    
+    my $rest = {};
+    
+    my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
+    $rest->{silent} = 1 if $hour < 9 || $hour > 23;
+    notify($channel, $message, $rest);
   }
                         
   $c->render(text=>"ok");
@@ -234,9 +239,6 @@ sub command::start
   notify($chatid, "$config->{title}.\nДля получения списка команд наберите */help*");
 }
 
-#sub command::credit
-#sub command::balance
-
 
 ############################
 
@@ -322,6 +324,7 @@ sub notify
   
   $params->{parse_mode} = "Markdown" unless $rest->{parse_mode} && $rest->{parse_mode} eq "none";
   $params->{reply_to_message_id} = $rest->{msgid} if $rest->{msgid};
+  $params->{disable_notification} = 1 if $rest->{silent};
   
   return request("sendMessage", $params)->catch(sub
   {