Mastodon

Adding Slack Notifications to phpipam

by Christian Mohn · Read in about 1 min (213 words)

As mentioned before, I’ve kinda turned my home lab into some sort of Slack-Ops deal, where various services in my home lab notify me of events in a private Slack channel.

The latest rendition of that, is adding Slack notifications from phpipam. Once phpipam detects a new device picking up an IP in my network, it notifies me like this:

In order to get this working, I had to edit the /var/www/phpipam/functions/scripts/discoveryCheck.php file in phpipam. discoveryCheck.php is the script that is run when phpipam does local subnet discovery  check, so this was a natural place to add my custom curl command.

I added the following code on line 254 in that file, just below the  code block that ends with $Addresses->modify_address($values);

// Log to Slack -- Run custom CURL script
$command = "curl -s -X POST -H \"Content-type: application/json\" --data '{\"text\":\"$values[lastSeen] - new host autodiscovered: IP: $ip Hostname: $values[dns_name] \"} https://[WEBHOOK URL]";
system($command);

Replace [WEBHOOK URL] with your actual URL. For more details on how to set up a webhook URL, check Logging SSH logins to Slack.

Pretty easy to do locally, but it would be nice of the phpipam developers could make alerting to third party services a native feature - I’m sure there are other use cases for this as well.

Post last updated on July 19, 2018: Various tweaks

About the author

Christian Mohn Profile Picture

Christian Mohn works as a Chief Technologist SDDC for Proact in Norway.

See his About page for more details, or find him on Twitter.

Sponsors