Created
December 12, 2016 13:27
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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