feature: Added support for sending alerts to Telegram #2114 (#6202)

This commit is contained in:
Neil Lathwood
2017-03-22 09:02:24 +00:00
committed by GitHub
parent 124fee657e
commit f6d8859bb4
4 changed files with 229 additions and 7 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-rocket' || $action == 'remove-hipchat' || $action == 'remove-pushover' || $action == 'remove-boxcar' || $action == 'remove-clickatell' || $action == 'remove-playsms' || $action == 'remove-smseagle') {
if ($action == 'remove' || preg_match('/^remove-.*$/', $action)) {
$config_id = mres($_POST['config_id']);
if (empty($config_id)) {
$message = 'No config id passed';
@@ -53,6 +53,8 @@ if ($action == 'remove' || $action == 'remove-slack' || $action == 'remove-rocke
dbDelete('config', "`config_name` LIKE 'alert.transports.pushover.$config_id.%'");
} elseif ($action == 'remove-boxcar') {
dbDelete('config', "`config_name` LIKE 'alert.transports.boxcar.$config_id.%'");
} elseif ($action == 'remove-telegram') {
dbDelete('config', "`config_name` LIKE 'alert.transports.telegram.$config_id.%'");
} elseif ($action == 'remove-clickatell') {
dbDelete('config', "`config_name` LIKE 'alert.transports.clickatell.$config_id.%'");
} elseif ($action == 'remove-playsms') {
@@ -169,6 +171,20 @@ if ($action == 'remove' || $action == 'remove-slack' || $action == 'remove-rocke
$message = 'Could not create config item';
}
}
} elseif ($action == 'add-telegram') {
if (empty($config_value)) {
$message = 'No Telegram chat id provided';
} else {
$config_id = dbInsert(array('config_name' => 'alert.transports.telegram.', 'config_value' => $config_value, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $config_value, 'config_descr' => 'Telegram Transport'), 'config');
if ($config_id > 0) {
dbUpdate(array('config_name' => 'alert.transports.telegram.'.$config_id.'.chat_id'), 'config', 'config_id=?', array($config_id));
dbInsert(array('config_name' => 'alert.transports.telegram.'.$config_id.'.token', 'config_value' => $config_extra, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $config_extra, 'config_descr' => 'Telegram token'), 'config');
$status = 'ok';
$message = 'Config item created';
} else {
$message = 'Could not create config item';
}
}
} elseif ($action == 'add-clickatell') {
if (empty($config_value)) {
$message = 'No Clickatell token provided';