Send Slack messages from Mikrotik RouterOS

This is a quick RouterOS script hack which I just wanted to get up online; it’s not anywhere near perfect but it might be useful to others. My objective here was to post a message to any Slack channel from Mikrotik RouterOS:

RouterOS to Slack

Slack has a super-simple to use ‘incoming webhook‘ integration but unfortunately, this requires that your app make a HTTP POST request – unfortunately not actually possible with RouterOS. Luckily, you can alternatively send messages using a HTTP GET request to Slack’s chat.postMessage API method. All you’ll need to do this is an API test token, which you can generate here.

Once you have your test token (beginning xoxp-..) you can form a HTTP GET request, including your message and any additional args (username, icon, channel..) as per the script below. Submitting a message is as easy as making a /tool fetch url command in your script.

To actually implement this usefully, the script below will parse the log file (ref.) for topics of interest, URL-encode any unsafe ASCII characters (non-exhaustive…) then post a message to your nominated Slack channel.

Todo: Read multiple log lines and post them as a single message using newlines, make logging topics and keywords better.

Previous Post

Quota-based traffic usage alerts in LibreNMS

Out of the box, LibreNMS does not readily expose traffic transfer measurements - it is geared towards network operators who buy (and sell) transit bandwidth wholesale, and not really for the home-gamer who ... Read more

Next Post

Quick RouterOS script for hurricane electric 6to4 tunnel dynamic updating

If your ISP doesn't offer IPv6 you may have set up an IPv6 6to4 tunnel using Hurricane Electric's free 'tunnelbroker.net' service. To operate the tunnel, tunnelbroker.net requires that you configure an IPv4 ... Read more

Comments

  • Hengst

    Seems POST is possible now.

    you can use the simple webhooks from slack and use :

    /tool fetch http-method=post http-content-type=”application/json” http-data=”{\”text\”:\”$yourinfo\”}” url=”https://hooks.slack.com/services/xxxxxxxxxx/xxxxxxxxxxxx/xxxxxxxxxxx

    have fun !

Leave a Comment