Skip to content

Instantly share code, notes, and snippets.

@gslin
Created April 4, 2023 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gslin/c5cee10151a4142aff60ff8613ac630f to your computer and use it in GitHub Desktop.
Save gslin/c5cee10151a4142aff60ff8613ac630f to your computer and use it in GitHub Desktop.
#!/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