mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Added WebUI support for Clickatell transport
This commit is contained in:
@@ -30,10 +30,11 @@ $config_extra = mres($_POST['config_extra']);
|
||||
$config_room_id = mres($_POST['config_room_id']);
|
||||
$config_from = mres($_POST['config_from']);
|
||||
$config_userkey = mres($_POST['config_userkey']);
|
||||
$config_to = mres($_POST['config_to']);
|
||||
$status = 'error';
|
||||
$message = 'Error with config';
|
||||
|
||||
if ($action == 'remove' || $action == 'remove-slack' || $action == 'remove-hipchat' || $action == 'remove-pushover' || $action == 'remove-boxcar') {
|
||||
if ($action == 'remove' || $action == 'remove-slack' || $action == 'remove-hipchat' || $action == 'remove-pushover' || $action == 'remove-boxcar' || $action == 'remove-clickatell') {
|
||||
$config_id = mres($_POST['config_id']);
|
||||
if (empty($config_id)) {
|
||||
$message = 'No config id passed';
|
||||
@@ -52,6 +53,9 @@ if ($action == 'remove' || $action == 'remove-slack' || $action == 'remove-hipch
|
||||
elseif ($action == 'remove-boxcar') {
|
||||
dbDelete('config', "`config_name` LIKE 'alert.transports.boxcar.$config_id.%'");
|
||||
}
|
||||
elseif ($action == 'remove-clickatell') {
|
||||
dbDelete('config', "`config_name` LIKE 'alert.transports.clickatell.$config_id.%'");
|
||||
}
|
||||
|
||||
$status = 'ok';
|
||||
$message = 'Config item removed';
|
||||
@@ -156,6 +160,31 @@ else if ($action == 'add-boxcar') {
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ($action == 'add-clickatell') {
|
||||
if (empty($config_value)) {
|
||||
$message = 'No Clickatell token provided';
|
||||
}
|
||||
elseif (empty($config_to)) {
|
||||
$message = 'No mobile numbers provided';
|
||||
}
|
||||
else {
|
||||
$config_id = dbInsert(array('config_name' => 'alert.transports.clickatell.', 'config_value' => $config_value, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $config_value, 'config_descr' => 'Clickatell Transport'), 'config');
|
||||
if ($config_id > 0) {
|
||||
dbUpdate(array('config_name' => 'alert.transports.clickatell.'.$config_id.'.token'), 'config', 'config_id=?', array($config_id));
|
||||
$status = 'ok';
|
||||
$message = 'Config item created';
|
||||
$mobiles = explode('\n', $config_to);
|
||||
foreach ($mobiles as $mobile) {
|
||||
if (!empty($mobile)) {
|
||||
dbInsert(array('config_name' => 'alert.transports.clickatell.'.$config_id.'.to', 'config_value' => $mobile, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $v, 'config_descr' => 'Clickatell mobile'), 'config');
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$message = 'Could not create config item';
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (empty($config_group) || empty($config_sub_group) || empty($config_name) || empty($config_value)) {
|
||||
$message = 'Missing config name or value';
|
||||
|
||||
@@ -173,6 +173,34 @@ $no_refresh = true;
|
||||
</div>
|
||||
<!-- End Boxcar Modal -->
|
||||
|
||||
<!-- Clickatell Modal -->
|
||||
<div class="modal fade" id="new-config-clickatell" role="dialog" aria-hidden="true" title="Create new config item">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-body">
|
||||
<form role="form" class="new_config_form">
|
||||
<div class="form-group">
|
||||
<span class="message"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="clickatell_value">Clickatell Token</label>
|
||||
<input type="text" class="form-control" name="clickatell_value" id="clickatell_value" placeholder="Enter the Clickatell Token">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="clickatell_to">Clickatell Mobile numbers (specify one per line)</label>
|
||||
<textarea class="form-control" name="clickatell_to" id="clickatell_to" placeholder="Enter the mobile numbers"></textarea>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button class="btn btn-success" id="submit-clickatell">Add config</button>
|
||||
<a href="#" class="btn" data-dismiss="modal">Cancel</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- End Clickatell Modal -->
|
||||
|
||||
<?php
|
||||
if (isset($_GET['error'])) {
|
||||
print_error('We had issues connecting to your Pager Duty account, please try again');
|
||||
@@ -720,6 +748,71 @@ echo '<div id="boxcar_appkey_template" class="hide">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h4 class="panel-title">
|
||||
<a data-toggle="collapse" data-parent="#accordion" href="#clickatell_transport_expand">Clickatell transport</a> <button name="test-alert" id="test-alert" type="button" data-transport="clickatell" class="btn btn-primary btn-xs pull-right">Test transport</button>
|
||||
</h4>
|
||||
</div>
|
||||
<div id="clickatell_transport_expand" class="panel-collapse collapse">
|
||||
<div class="panel-body">
|
||||
<div class="form-group">
|
||||
<div class="col-sm-8">
|
||||
<button class="btn btn-success btn-xs" type="button" name="new_config" id="new_config_item" data-toggle="modal" data-target="#new-config-clickatell">Add Clickatell config</button>
|
||||
</div>
|
||||
</div>';
|
||||
$clickatells = get_config_like_name('alert.transports.clickatell.%.token');
|
||||
foreach ($clickatells as $clickatell) {
|
||||
$to = get_config_like_name('alert.transports.clickatell.'.$clickatell['config_id'].'.to');
|
||||
$new_extra = array();
|
||||
unset($upd_extra);
|
||||
foreach ($to as $number) {
|
||||
$split_extra = explode('.', $number['config_name']);
|
||||
if ($split_extra[4] != 'token') {
|
||||
$new_extra[] = $number['config_value'];
|
||||
}
|
||||
}
|
||||
$upd_extra = implode(PHP_EOL, $new_extra);
|
||||
echo '<div id="'.$clickatell['config_id'].'">
|
||||
<div class="form-group has-feedback">
|
||||
<label for="clickatell_token" class="col-sm-4 control-label">Clickatell Token </label>
|
||||
<div class="col-sm-4">
|
||||
<input id="clickatell_token" class="form-control" type="text" name="global-config-input" value="'.$clickatell['config_value'].'" data-config_id="'.$clickatell['config_id'].'">
|
||||
<span class="glyphicon form-control-feedback" aria-hidden="true"></span>
|
||||
</div>
|
||||
<div class="col-sm-2">
|
||||
<button type="button" class="btn btn-danger del-clickatell-config" name="del-clickatell-call" data-config_id="'.$clickatell['config_id'].'"><i class="fa fa-minus"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group has-feedback">
|
||||
<div class="col-sm-offset-4 col-sm-4">
|
||||
<textarea class="form-control" name="global-config-textarea" id="clickatell_to" placeholder="Enter the config options" data-config_id="'.$clickatell['config_id'].'" data-type="clickatell">'.$upd_extra.'</textarea>
|
||||
<span class="glyphicon form-control-feedback" aria-hidden="true"></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>';
|
||||
}//end foreach
|
||||
|
||||
echo '<div id="clickatell_token_template" class="hide">
|
||||
<div class="form-group has-feedback">
|
||||
<label for="clickatell_token" class="col-sm-4 control-label api-method">Clickatell Token </label>
|
||||
<div class="col-sm-4">
|
||||
<input id="clickatell_token" class="form-control" type="text" name="global-config-input" value="" data-config_id="">
|
||||
<span class="glyphicon form-control-feedback" aria-hidden="true"></span>
|
||||
</div>
|
||||
<div class="col-sm-2">
|
||||
<button type="button" class="btn btn-danger del-clickatell-config" id="del-clickatell-call" name="del-clickatell-call" data-config_id=""><i class="fa fa-minus"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group has-feedback">
|
||||
<div class="col-sm-offset-4 col-sm-4">
|
||||
<textarea class="form-control" name="global-config-textarea" id="clickatell_to" placeholder="Enter the config options" data-config_id="" data-type="clickatell"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
';
|
||||
@@ -955,6 +1048,42 @@ echo '<div id="boxcar_appkey_template" class="hide">
|
||||
});
|
||||
});// End Add Boxcar config
|
||||
|
||||
// Add Clickatell config
|
||||
itemIndex = 0;
|
||||
$("button#submit-clickatell").click(function(){
|
||||
var config_value = $('#clickatell_value').val();
|
||||
var config_to = $('#clickatell_to').val();
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "ajax_form.php",
|
||||
data: {type: "config-item", action: 'add-clickatell', config_group: "alerting", config_sub_group: "transports", config_to: config_to, config_value: config_value},
|
||||
dataType: "json",
|
||||
success: function(data){
|
||||
if (data.status == 'ok') {
|
||||
itemIndex++;
|
||||
var $template = $('#clickatell_token_template'),
|
||||
$clone = $template
|
||||
.clone()
|
||||
.removeClass('hide')
|
||||
.attr('id',data.config_id)
|
||||
.attr('boxcar-appkey-index', itemIndex)
|
||||
.insertBefore($template);
|
||||
$clone.find('[id="clickatell_token"]').attr('data-config_id',data.config_id);
|
||||
$clone.find('[id="del-clickatell-call"]').attr('data-config_id',data.config_id);
|
||||
$clone.find('[name="global-config-input"]').attr('value', config_value);
|
||||
$clone.find('[id="clickatell_to"]').val(config_to);
|
||||
$clone.find('[id="clickatell_to"]').attr('data-config_id',data.config_id);
|
||||
$("#new-config-clickatell").modal('hide');
|
||||
} else {
|
||||
$("#message").html('<div class="alert alert-info">' + data.message + '</div>');
|
||||
}
|
||||
},
|
||||
error: function(){
|
||||
$("#message").html('<div class="alert alert-info">Error creating config item</div>');
|
||||
}
|
||||
});
|
||||
});// End Add Clickatell config
|
||||
|
||||
// Delete api config
|
||||
$(document).on('click', 'button[name="del-api-call"]', function(event) {
|
||||
var config_id = $(this).data('config_id');
|
||||
@@ -1060,6 +1189,27 @@ echo '<div id="boxcar_appkey_template" class="hide">
|
||||
});
|
||||
});// End delete Boxcar config
|
||||
|
||||
// Delete Clickatell config
|
||||
$(document).on('click', 'button[name="del-clickatell-call"]', function(event) {
|
||||
var config_id = $(this).data('config_id');
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: 'ajax_form.php',
|
||||
data: {type: "config-item", action: 'remove-clickatell', config_id: config_id},
|
||||
dataType: "json",
|
||||
success: function (data) {
|
||||
if (data.status == 'ok') {
|
||||
$("#"+config_id).remove();
|
||||
} else {
|
||||
$("#message").html('<div class="alert alert-info">' + data.message + '</div>');
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
$("#message").html('<div class="alert alert-info">An error occurred.</div>');
|
||||
}
|
||||
});
|
||||
});// End delete Clickatell config
|
||||
|
||||
$( 'select[name="global-config-select"]').change(function(event) {
|
||||
event.preventDefault();
|
||||
var $this = $(this);
|
||||
|
||||
Reference in New Issue
Block a user