Adding Slack Notifications to phpipam

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:

screenshot-2016-11-03-22-24-18

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);

[cc lang=”php” escaped=”true”]
// 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);
[/cc]

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.

#vDM30in30 progress:

Leave a Reply