Removing POST / GET code as slack only uses POST

This commit is contained in:
laf
2015-02-28 11:45:30 +00:00
parent 54cff79acb
commit c1c520d781
2 changed files with 27 additions and 29 deletions

View File

@@ -176,8 +176,8 @@ $config['alert']['transports']['irc'] = true;
The Slack transport will POST the alert message to your Slack Incoming WebHook, you are able to specify multiple webhooks along with the relevant options to go with it. All options are optional, the only required value is for url, without this then no call to Slack will be made. Below is an example of how to send alerts to two channels with different customised options:
```php
$config['alert']['transports']['slack']['post'][] = array('url' => "https://hooks.slack.com/services/A12B34CDE/F56GH78JK/L901LmNopqrSTUVw2w3XYZAB4C", 'channel' => '#Alerting');
$config['alert']['transports']['slack'][] = array('url' => "https://hooks.slack.com/services/A12B34CDE/F56GH78JK/L901LmNopqrSTUVw2w3XYZAB4C", 'channel' => '#Alerting');
$config['alert']['transports']['slack']['post'][] = array('url' => "https://hooks.slack.com/services/A12B34CDE/F56GH78JK/L901LmNopqrSTUVw2w3XYZAB4C", 'channel' => '@john', 'username' => 'LibreNMS', 'icon_emoji' => ':ghost:');
$config['alert']['transports']['slack'][] = array('url' => "https://hooks.slack.com/services/A12B34CDE/F56GH78JK/L901LmNopqrSTUVw2w3XYZAB4C", 'channel' => '@john', 'username' => 'LibreNMS', 'icon_emoji' => ':ghost:');
```

View File

@@ -21,33 +21,31 @@
* @subpackage Alerts
*/
foreach( $opts as $method=>$apis ) {
foreach( $apis as $tmp_api ) {
list($host, $api) = explode("?",$tmp_api['url'],2);
foreach( $obj as $k=>$v ) {
$api = str_replace("%".$k,$method == "get" ? urlencode($v) : $v, $api);
}
$curl = curl_init();
$data = array(
'text' => $obj['msg'],
'channel' => $tmp_api['channel'],
'username' => $tmp_api['username'],
'icon_url' => $tmp_api['icon_url'],
'icon_emoji' => $tmp_api['icon_emoji'],
);
$alert_message = "payload=" . json_encode($data);
curl_setopt($curl, CURLOPT_URL, ($method == "get" ? $host."?".$api : $host) );
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POST,true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $alert_message );
$ret = curl_exec($curl);
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if( $code != 200 ) {
var_dump("API '$host' returnd Error"); //FIXME: propper debuging
var_dump("Params: ".$api); //FIXME: propper debuging
var_dump("Return: ".$ret); //FIXME: propper debuging
return false;
}
foreach( $opts as $tmp_api ) {
$host = $tmp_api['url'];
foreach( $obj as $k=>$v ) {
$api = str_replace("%".$k,$method == "get" ? urlencode($v) : $v, $api);
}
$curl = curl_init();
$data = array(
'text' => $obj['msg'],
'channel' => $tmp_api['channel'],
'username' => $tmp_api['username'],
'icon_url' => $tmp_api['icon_url'],
'icon_emoji' => $tmp_api['icon_emoji'],
);
$alert_message = "payload=" . json_encode($data);
curl_setopt($curl, CURLOPT_URL, $host);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POST,true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $alert_message );
$ret = curl_exec($curl);
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if( $code != 200 ) {
var_dump("API '$host' returnd Error"); //FIXME: propper debuging
var_dump("Params: ".$alert_message); //FIXME: propper debuging
var_dump("Return: ".$ret); //FIXME: propper debuging
return false;
}
}
return true;