Skip to content

Instantly share code, notes, and snippets.

@strrife
Created December 12, 2016 13:27
Show Gist options
  • Save strrife/efc76b814f568727253783393546a104 to your computer and use it in GitHub Desktop.
Save strrife/efc76b814f568727253783393546a104 to your computer and use it in GitHub Desktop.
After a few crashes because of no free space left here's a script that notifies you in Slack "errors" channel
<?php
define('THRESHOLD', 80);
$res = shell_exec('/bin/df -h | /bin/grep \'/dev/sda2\' | /usr/bin/awk \'{print $5}\'');
$res = floatval(str_replace('%', '', trim($res)));
if($res > THRESHOLD){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://hooks.slack.com/services/T01234567/B11234567/123456712345671234567');
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode([
'channel' => 'errors',
'username' => 'Space Commando',
'icon_emoji' => ':rage3:',
'text' => '<@alex>: LOW SPACE on tb03: *' . $res . '%*'
]));
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$result = curl_exec($ch);
curl_close($ch);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment