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.
Related Posts
- Evaluating 2016 — Published
- In The Bag #5 - Week 48 — Published
- In The Bag #4 - Week 47 — Published
- macOS: Spectacle — Published
- Facelift — Published