Created
April 4, 2023 14:09
-
-
Save gslin/c5cee10151a4142aff60ff8613ac630f to your computer and use it in GitHub Desktop.
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/perl | |
use v5.14; | |
use strict; | |
use warnings; | |
use IO::File; | |
use JSON::PP; | |
use WWW::Mechanize; | |
sub main() { | |
my $webhook_url = $ARGV[0] or die 'no webhook_url'; | |
my $filename = $ARGV[1] or die 'no filename'; | |
my $filter = $ARGV[2] // ''; | |
my $fh = IO::File->new("tail -F -n0 ${filename} |"); | |
my $ua = WWW::Mechanize->new; | |
while (my $line = <$fh>) { | |
next unless $line =~ $filter; | |
my $payload = {text => $line, type => 'plain_text'}; | |
$ua->post( | |
$webhook_url, | |
'Content-Type' => 'application/json', | |
Content => encode_json($payload), | |
); | |
} | |
$fh->close; | |
} | |
&main; | |
__END__ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment