feature: Added Rocket.Chat transport #5427

* Implement Rocket.Chat transport

* copyright stuff as I didn't have anything to hack anything on transport.rocket.php

* Update config-item.inc.php

Use space instead of tabs

* Update config-item.inc.php

kill a blank line

* Update AUTHORS.md

I agree to the conditions of the Contributor Agreement contained in doc/General/Contributing.md.
This commit is contained in:
ToeiRei
2017-02-01 00:05:35 +01:00
committed by Neil Lathwood
parent a33ae25d0b
commit 6bc7b1991e
5 changed files with 247 additions and 2 deletions

View File

@@ -37,7 +37,7 @@ $config_token = mres($_POST['config_token']);
$status = 'error';
$message = 'Error with config';
if ($action == 'remove' || $action == 'remove-slack' || $action == 'remove-hipchat' || $action == 'remove-pushover' || $action == 'remove-boxcar' || $action == 'remove-clickatell' || $action == 'remove-playsms') {
if ($action == 'remove' || $action == 'remove-slack' || $action == 'remove-rocket' || $action == 'remove-hipchat' || $action == 'remove-pushover' || $action == 'remove-boxcar' || $action == 'remove-clickatell' || $action == 'remove-playsms') {
$config_id = mres($_POST['config_id']);
if (empty($config_id)) {
$message = 'No config id passed';
@@ -45,6 +45,8 @@ if ($action == 'remove' || $action == 'remove-slack' || $action == 'remove-hipch
if (dbDelete('config', '`config_id`=?', array($config_id))) {
if ($action == 'remove-slack') {
dbDelete('config', "`config_name` LIKE 'alert.transports.slack.$config_id.%'");
} elseif ($action == 'remove-rocket') {
dbDelete('config', "`config_name` LIKE 'alert.transports.rocket.$config_id.%'");
} elseif ($action == 'remove-hipchat') {
dbDelete('config', "`config_name` LIKE 'alert.transports.hipchat.$config_id.%'");
} elseif ($action == 'remove-pushover') {
@@ -56,7 +58,6 @@ if ($action == 'remove' || $action == 'remove-slack' || $action == 'remove-hipch
} elseif ($action == 'remove-playsms') {
dbDelete('config', "`config_name` LIKE 'alert.transports.playsms.$config_id.%'");
}
$status = 'ok';
$message = 'Config item removed';
} else {
@@ -83,6 +84,26 @@ if ($action == 'remove' || $action == 'remove-slack' || $action == 'remove-hipch
$message = 'Could not create config item';
}
}
} elseif ($action == 'add-rocket') {
if (empty($config_value)) {
$message = 'No Rocket.Chat url provided';
} else {
$config_id = dbInsert(array('config_name' => 'alert.transports.rocket.', 'config_value' => $config_value, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $config_value, 'config_descr' => 'Rocket.Chat Transport'), 'config');
if ($config_id > 0) {
dbUpdate(array('config_name' => 'alert.transports.rocket.'.$config_id.'.url'), 'config', 'config_id=?', array($config_id));
$status = 'ok';
$message = 'Config item created';
$extras = explode('\n', $config_extra);
foreach ($extras as $option) {
list($k,$v) = explode('=', $option, 2);
if (!empty($k) || !empty($v)) {
dbInsert(array('config_name' => 'alert.transports.rocket.'.$config_id.'.'.$k, 'config_value' => $v, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $v, 'config_descr' => 'Rocket.Chat Transport'), 'config');
}
}
} else {
$message = 'Could not create config item';
}
}
} elseif ($action == 'add-hipchat') {
if (empty($config_value) || empty($config_room_id) || empty($config_from)) {
$message = 'No hipchat url, room id or from provided';

View File

@@ -33,6 +33,8 @@ if (!is_numeric($config_id)) {
if (!empty($k) || !empty($v)) {
if ($config_type == 'slack') {
$db_id[] = dbInsert(array('config_name' => 'alert.transports.slack.'.$config_id.'.'.$k, 'config_value' => $v, 'config_group' => 'alerting', 'config_sub_group' => 'transports', 'config_default' => $v, 'config_descr' => 'Slack Transport'), 'config');
} elseif ($config_type == 'rocket') {
$db_id[] = dbInsert(array('config_name' => 'alert.transports.rocket.'.$config_id.'.'.$k, 'config_value' => $v, 'config_group' => 'alerting', 'config_sub_group' => 'transports', 'config_default' => $v, 'config_descr' => 'Rocket.Chat Transport'), 'config');
} elseif ($config_type == 'hipchat') {
$db_id[] = dbInsert(array('config_name' => 'alert.transports.hipchat.'.$config_id.'.'.$k, 'config_value' => $v, 'config_group' => 'alerting', 'config_sub_group' => 'transports', 'config_default' => $v, 'config_descr' => 'Hipchat Transport'), 'config');
} elseif ($config_type == 'pushover') {
@@ -57,6 +59,8 @@ if (!is_numeric($config_id)) {
if ($config_type == 'slack') {
dbDelete('config', "(`config_name` LIKE 'alert.transports.slack.$config_id.%' AND `config_name` != 'alert.transports.slack.$config_id.url' AND `config_id` NOT IN ($db_inserts))");
} elseif ($config_type == 'rocket') {
dbDelete('config', "(`config_name` LIKE 'alert.transports.rocket.$config_id.%' AND `config_name` != 'alert.transports.rocket.$config_id.url' AND `config_id` NOT IN ($db_inserts))");
} elseif ($config_type == 'hipchat') {
dbDelete('config', "(`config_name` LIKE 'alert.transports.hipchat.$config_id.%' AND (`config_name` != 'alert.transports.hipchat.$config_id.url' AND `config_name` != 'alert.transports.hipchat.$config_id.room_id' AND `config_name` != 'alert.transports.hipchat.$config_id.from') AND `config_id` NOT IN ($db_inserts))");
} elseif ($config_type == 'pushover') {