Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function slack($message, $channel)
- {
- $token = $_SERVER['TOKEN'];
- $ch = curl_init("https://slack.com/api/chat.postMessage");
- $data = http_build_query([
- "token" => $token,
- "channel" => $channel, //"#mychannel",
- "text" => $message, //"Hello, Foo-Bar channel message.",
- "username" => "ExternalHealthCheckBot",
- ]);
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- $result = curl_exec($ch);
- curl_close($ch);
- return $result;
- }
- function healthCheck() {
- $url = $_SERVER['CHECK_URL'];
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_HTTPHEADER,
- ['Content-Type: application/json']
- );
- $result = curl_exec($ch);
- if (!curl_errno($ch)) {
- switch ($http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE)) {
- case 200: #OK
- break;
- default:
- $str = json_encode(['code' => $http_code, 'response' => $result]);
- slack($str, 'check');
- }
- } else {
- slack(curl_error($ch), 'check');
- }
- curl_close($ch);
- }
- healthCheck();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement