Created
May 14, 2020 15:09
-
-
Save mamemomonga/4e646283ea837edf1d799f3ad728099f to your computer and use it in GitHub Desktop.
コンテナの/app/log/production.logに特定文字列がでてきたらSlackCatをつかって通知する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
# ----------------- | |
# コンテナの/app/log/production.logに特定文字列がでてきたらSlackCatをつかって通知する | |
# 実行 nohup ./log-monitor.pl & | |
# ----------------- | |
use feature 'say'; | |
use strict; | |
use warnings; | |
$|=1; | |
my $container='コンテナ名'; | |
my $channel='チャンネル名'; | |
my $username='ユーザ名'; | |
my @targets=( | |
"Completed 404 Not Found", | |
"Completed 500 Internal Server Error", | |
); | |
my $kid=open(my $log,"docker exec $container tail -f /app/log/production.log | ") || die $!; | |
while (my $log=<$log>) { | |
foreach my $search (@targets) { | |
if($log=~m#\Q$search\E#sg) { | |
open(my $ofh, "| slackcat --channel $channel --username $username -s") || die $!; | |
print $ofh "エラー「$search」を検出しました\n"; | |
print $ofh $log; | |
print $log; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment