ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
SlackbotHandler.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the Monolog package.
5  *
6  * (c) Jordi Boggiano <j.boggiano@seld.be>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
12 namespace Monolog\Handler;
13 
14 use Monolog\Logger;
15 
23 {
28  private $slackTeam;
29 
34  private $token;
35 
40  private $channel;
41 
50  {
51  parent::__construct($level, $bubble);
52 
53  $this->slackTeam = $slackTeam;
54  $this->token = $token;
55  $this->channel = $channel;
56  }
57 
63  protected function write(array $record)
64  {
65  $slackbotUrl = sprintf(
66  'https://%s.slack.com/services/hooks/slackbot?token=%s&channel=%s',
67  $this->slackTeam,
68  $this->token,
69  $this->channel
70  );
71 
72  $ch = curl_init();
73  curl_setopt($ch, CURLOPT_URL, $slackbotUrl);
74  curl_setopt($ch, CURLOPT_POST, true);
75  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
76  curl_setopt($ch, CURLOPT_POSTFIELDS, $record['message']);
77 
78  Curl\Util::execute($ch);
79  }
80 }
__construct($slackTeam, $token, $channel, $level=Logger::CRITICAL, $bubble=true)
Base Handler class providing the Handler structure.
static execute($ch, $retries=5, $closeAfterDone=true)
Executes a CURL request with optional retries and exception on failure.
Definition: Util.php:32
Sends notifications through Slack&#39;s Slackbot.
const CRITICAL
Critical conditions.
Definition: Logger.php:65