Perl5 Slack Syslog BSD daemon

So I have been working on my little Perl daemon for a week now.
It is a simple syslog daemon that listens on port 514 for incoming messages. It listens on a port so it can process log messages from my consumer Linux router as well as the messages from my server.

Messages that are above alert are sent, as are messages that match the regex of SSH or DHCP (I want to keep track of new connections to my wifi).

The rest of the messages are not sent to slack but appended to a log file.

This is very handy as I can get access to info like failed ssh logins, disk failures, and new devices connecting to the network all on my Android phone when I am not home.
Screenshot_2017-10-13-23-00-26.png

The situation arose today that the internet went down and I thought to myself what would happen to all my important syslog messages when they couldn’t be sent?

Before the script only ran an eval block on the botsend() function. The error was returned, handled, but nothing was done and the unsent message was discarded.

So I added a function that appended unsent messengers to an array that are later sent when the server is not busy sending messages to slack.

Slack has a limit of one message per second.

The new addition works well and means that if the internet fails my server will store these messages in memory and resend them at a rate of one message per second when the internet connectivity returns.

It currently sends the newest ones first but I am not sure if this is a bug or a feature at this point!

It currently works with my Linux based WiFi router and my FreeBSD server.

It is easy to scale as all you need to do is send messages to syslog to get them sent to slack. You could sent CPU temp, logged in users etc.

There is a github page: https://github.com/wilyarti/slackbot

Advertisements

One thought on “Perl5 Slack Syslog BSD daemon

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s