Stream logs to Slack in Perl

I want to stream my logs on my home RPi3b to a Slack channel for my vacation side project. With some searches I found an article including a simple shell script to implement this function: "Stream Any Log File to Slack Using curl".

However it's a little tricky as the script replaces " to ' as escaping mechanism. I would prefer to use more formal way to implement this, also, I haven't written Perl for a while, so I have decided to implement this function in Perl:

In this script there are some notes:

  • Choosing tail -F instead of File::Tail is because File::Tail is quite old and no inotify implementation. On the other side, tail performs well in this section.
  • Choosing JSON::PP (pure perl version) is because it's built-in in Perl 5.14+, and that's also why I have added use v5.14 requirement in the beginning.
  • Choosing WWW::Mechanize for API calling is because there is no built-in module able to handle HTTPS connections, therefore I have decided to install a familiar one (for me).

btw, // operator has been introduced in Perl 5.10, and I didn't think it last there for such a long time...

The weird part of AWS bandwidth cost

I just got curious during handling the invoice of AWS. My gut feeling is that all inbound traffic are free (mostly), for example, you can see this in "Amazon EC2 On-Demand Pricing":

Data Transfer IN To Amazon EC2 From Internet
All data transfer in $0.00 per GB

But if you're dealing with inbound traffic across AZ in the same region:

Data transferred "in" to and "out" from Amazon EC2, Amazon RDS, Amazon Redshift, Amazon DynamoDB Accelerator (DAX), and Amazon ElastiCache instances, Elastic Network Interfaces or VPC Peering connections across Availability Zones in the same AWS Region is charged at $0.01/GB in each direction.

Yeah, inbound traffic across AZ is more expensive than the one from internet (which is free).

Also, inbound traffic to public IPv4 addresses and/or Elastic IP are not free:

IPv4: Data transferred “in” to and “out” from public or Elastic IPv4 address is charged at $0.01/GB in each direction.
IPv6: Data transferred “in” to and “out” from an IPv6 address in a different VPC is charged at $0.01/GB in each direction.

Anyway, this reminds me that I need to count US$0.02/GB instead of US$0.01/GB for such sort of traffic.

Golang software packaging for offline environment

Open build services like Launchpad PPA usually forbid internet connections during building, therefore it's impossible to download dependencies during building, and we need to include all dependencies into the source package.

Two things need to be done for building Golang softwares on no-internet building services:

  • Download all dependencies into vendor/ via go mod vendor command. This is usually done on the local machine with internet connections.
  • Ask Golang compiler to use vendor/ via go build -mod vendor command. Usually inside debian/rules file or Makefile.

If you're also working on Launchpad PPA like me, it's also suggested that add Simon Eisenmann's Golang Backports to the building dependency settings. This repository includes new Golang softwares so that you won't be hit by something like "syntax error".