Slack Notifier

prtg

We use Slack for messaging here at LocalSearch and love it very much. We also use PRTG for system monitoring and notifications – why not integrate them both together so I can receive PRTG notifications in a channel in Slack?

slack_notifier_screenie

While Slack has a large gallery of integrations PRTG unfortunately wasn’t on the list. So I have written a quick windows app to allow notifications from PRTG via its ‘Execute Application’ notifier. While I specifically built it for PRTG it’s a command line app which could potentially use to publish any type of message to Slack.

From the command line basically just send it with the following switches to publish to a particular Slack #channel:

The command line switches are as follows:

--url Required. The slack webhook url to post to.

--channel What slack #channel to publish the message to.

--color What color the message is e.g. good, warning, error or any hex
color #439FE0.

--title (Default: ) The title of the message to publish to the channel.

--text Required. (Default: ) The text to publish to the channel.

--pretext Required. (Default: ) The pretext to publish to the channel.

--fallback (Default: ) Fallback message to publish to the channel.

--username The username the message will look like it came from.

--icon An icon to use with the message e.g. http://images.google.com/new-image.jpg

--help Display this help screen.

Download “Slack Notifier” Slack_Notifier_v1.2.zip – Downloaded 1227 times – 221 kB

Any problems hit me in the comments.
– The Ninja.

Slack Notifier was last modified: May 18th, 2015 by admin
  • Matthew Clark

    Hi Adam,

    We are wanting to use this. What syntax did you put in the parameter field of the notification on PRTG itself?

    When I run the program from the command line, I get an app crash with the error:
    “Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly ‘CommandLine, Version=1.9.71.2, Culture=neutral, PublicKeyToken=de6f01bd326f8c32’ or one of its dependencies. The system cannot find the file specified at Slack_Notifier.Program.Main(String[] args)”

    If possible it would be great if you can give any ideas why this isn’t working or if I need any other software for this to run.

    Thank you!

    • adamcaz

      Whoops sorry Matt I left out a dependency you need for the application. I have added it now and you should be fine to re-download it and give it a go.

      Any problems let me know. :)

      • Matthew Clark

        Hi Adam,

        Thank you. We have actually found another method.

        By using a incoming webhook, PRTG can use the execute HTTP action to push a notification to Slack.

        You just use the https://hooks.slack.com/services/T0464KSYF/B04EVULKV URL for the channel and then in the post data section you put: payload={“text”: “%device n %shortname n *%status* n %message n”, “icon_emoji”: “:rage4:”} as an example.

      • adamcaz

        Yep definitely another way you can do it! Fortunately the slack notifier also work for old legacy phone systems, alarm systems etc where all you have is ‘run application’. Glad you found a solution Matt!

      • Babul A. Mukherjee

        Only downside that I’ve found for this is I can’t encode the URL using the text to Slack. I’d prefer the URL be hidden behind the message to keep things tidy. I’d prefer to do the notification without external dependencies so I have one less thing to troubleshoot 😉

        Example:

        payload={“text”: “[%sitename] %device %name %status %down ()”}

        The “” are invalid characters in the PRTG postdata.

  • Luke Harris

    Hi Adam I just wanted to say a big thankyou for your work with this little app. It is exactly what I was looking for!

  • Jay Singh

    I can’t edit your application. I am trying to create a script that will allow notifications to be sent to slack, but need to add channel information etc. I am not a developer, and therefore I am having trouble setting this up.

    • adamcaz

      Hi Jay, you need to go into Slack and set up what’s called an “Incoming Webhook” first:

      https://api.slack.com/incoming-webhooks

      Once you do this you will have a webhook url which you can specify using –url switch on SlackNotifier from your script. This will allow SlackNotifier to push messaged to your Slack channel.

  • Henrik Goldman