Add possibility to log to slack
This commit is contained in:
Родитель
ec844e9745
Коммит
6efcbb7a78
|
@ -29,6 +29,7 @@ class Config {
|
|||
$this->mysql_password = $config_array["mysql"]["pass"];
|
||||
$this->mysql_db_name = $config_array["mysql"]["db_name"];
|
||||
$this->data_folder = $config_array["general"]["data_folder"];
|
||||
$this->slack_webhook = $config_array["general"]["slack_webhook"];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,6 +40,33 @@ function init_database()
|
|||
mysql_select_db($config->mysql_db_name) or die("ERROR: " . mysql_error());
|
||||
}
|
||||
|
||||
// (string) $message - message to be passed to Slack
|
||||
// (string) $room - room in which to write the message, too
|
||||
// (string) $icon - You can set up custom emoji icons to use with each message
|
||||
function slack($message, $room = "engineering", $icon = ":longbox:")
|
||||
{
|
||||
global $config;
|
||||
|
||||
$room = ($room) ? $room : "engineering";
|
||||
$data = "payload=" . json_encode(array(
|
||||
#"channel" => "#{$room}",
|
||||
"text" => $message,
|
||||
"icon_emoji" => $icon
|
||||
));
|
||||
|
||||
// You can get your webhook endpoint from your Slack settings
|
||||
$url = $config->slack_webhook;
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$result = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
function username()
|
||||
{
|
||||
if (!isset($_SESSION['persona']))
|
||||
|
|
Загрузка…
Ссылка в новой задаче