feature: Add Smseagle transport support (#5989)

* added alert transport for SMSEagle hardware gateway (smseagle.eu)

* added newline

* schema file update + small code refactor

* added docs
This commit is contained in:
barryodonovan
2017-02-24 11:55:53 +00:00
committed by Neil Lathwood
parent 20ae9e2ecd
commit 0f663b3a82
6 changed files with 154 additions and 1 deletions

View File

@@ -29,6 +29,7 @@ Table of Content:
- [osTicket](#transports-osticket)
- [Microsoft Teams](#transports-msteams)
- [Cisco Spark](#transports-ciscospark)
- [SMSEagle](#transports-smseagle)
- [Entities](#entities)
- [Devices](#entity-devices)
- [BGP Peers](#entity-bgppeers)
@@ -598,6 +599,24 @@ $config['alert']['transports']['ciscospark']['roomid'] = '1234567890QWERTYUIOP';
```
~
## <a name="transports-smseagle">SMSEagle</a>
[Using a proxy?](../Support/Configuration.md#proxy-support)
SMSEagle is a hardware SMS Gateway that can be used via their HTTP-API using a Username and password
Please consult their documentation at [www.smseagle.eu](http://www.smseagle.eu)
Destination numbers are one per line, with no spaces. They can be in either local or international dialling format.
~~
```php
$config['alert']['transports']['smseagle']['url'] = 'ip.add.re.ss';
$config['alert']['transports']['smseagle']['user'] = 'smseagle_user';
$config['alert']['transports']['smseagle']['token'] = 'smseagle_user_password';
$config['alert']['transports']['smseagle']['to'][] = '+3534567890';
$config['alert']['transports']['smseagle']['to'][] = '0834567891';
```
~~
# <a name="entities">Entities
Entities as described earlier are based on the table and column names within the database, if you are unsure of what the entity is you want then have a browse around inside MySQL using `show tables` and `desc <tablename>`.

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') {
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') {
$config_id = mres($_POST['config_id']);
if (empty($config_id)) {
$message = 'No config id passed';
@@ -57,6 +57,8 @@ if ($action == 'remove' || $action == 'remove-slack' || $action == 'remove-rocke
dbDelete('config', "`config_name` LIKE 'alert.transports.clickatell.$config_id.%'");
} elseif ($action == 'remove-playsms') {
dbDelete('config', "`config_name` LIKE 'alert.transports.playsms.$config_id.%'");
} elseif ($action == 'remove-smseagle') {
dbDelete('config', "`config_name` LIKE 'alert.transports.smseagle.$config_id.%'");
}
$status = 'ok';
$message = 'Config item removed';
@@ -218,6 +220,33 @@ if ($action == 'remove' || $action == 'remove-slack' || $action == 'remove-rocke
$message = 'Could not create config item';
}
}
} elseif ($action == 'add-smseagle') {
if (empty($config_value)) {
$message = 'No SMSEagle URL provided';
} elseif (empty($config_user)) {
$message = 'No SMSEagle User provided';
} elseif (empty($config_to)) {
$message = 'No mobile numbers provided';
} else {
$config_id = dbInsert(array('config_name' => 'alert.transports.smseagle.', 'config_value' => $config_value, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $config_value, 'config_descr' => 'SMSEagle Transport'), 'config');
if ($config_id > 0) {
dbUpdate(array('config_name' => 'alert.transports.smseagle.'.$config_id.'.url'), 'config', 'config_id=?', array($config_id));
$additional_id['user'] = dbInsert(array('config_name' => 'alert.transports.smseagle.'.$config_id.'.user', 'config_value' => $config_user, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $config_user, 'config_descr' => 'SMSEagle User'), 'config');
$additional_id['token'] = dbInsert(array('config_name' => 'alert.transports.smseagle.'.$config_id.'.token', 'config_value' => $config_token, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $config_token, 'config_descr' => 'SMSEagle Token'), 'config');
$status = 'ok';
$message = 'Config item created';
$mobiles = explode('\n', $config_to);
$x=0;
foreach ($mobiles as $mobile) {
if (!empty($mobile)) {
dbInsert(array('config_name' => 'alert.transports.smseagle.'.$config_id.'.to.'.$x, 'config_value' => $mobile, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $v, 'config_descr' => 'SMSEagle mobile'), 'config');
$x++;
}
}
} 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';

View File

@@ -47,6 +47,9 @@ if (!is_numeric($config_id)) {
} elseif ($config_type == 'playsms') {
$db_id[] = dbInsert(array('config_name' => 'alert.transports.playsms.to.'.$x, 'config_value' => $k, 'config_group' => 'alerting', 'config_sub_group' => 'transports', 'config_default' => $v, 'config_descr' => 'PlaySMS Transport'), 'config');
$x++;
} elseif ($config_type == 'smseagle') {
$db_id[] = dbInsert(array('config_name' => 'alert.transports.smseagle.to.'.$x, 'config_value' => $k, 'config_group' => 'alerting', 'config_sub_group' => 'transports', 'config_default' => $v, 'config_descr' => 'SMSEagle Transport'), 'config');
$x++;
}
}
}
@@ -71,6 +74,8 @@ if (!is_numeric($config_id)) {
dbDelete('config', "(`config_name` LIKE 'alert.transports.clickatell.to.%' AND `config_id` NOT IN ($db_inserts))");
} elseif ($config_type == 'playsms') {
dbDelete('config', "(`config_name` LIKE 'alert.transports.playsms.to.%' AND `config_id` NOT IN ($db_inserts))");
} elseif ($config_type == 'smseagle') {
dbDelete('config', "(`config_name` LIKE 'alert.transports.smseagle.to.%' AND `config_id` NOT IN ($db_inserts))");
}
}

View File

@@ -1154,6 +1154,63 @@ echo '
<input id="ciscospark_roomid" class="form-control" type="text" name="global-config-input" value="'.$ciscospark_roomid['config_value'].'" data-config_id="'.$ciscospark_roomid['config_id'].'">
<span class="form-control-feedback">
<i class="fa" aria-hidden="true"></i>
</span>
</div>
</div>
</div>
</div>
</div>';
$smseagle_url = get_config_by_name('alert.transports.smseagle.url');
$smseagle_user = get_config_by_name('alert.transports.smseagle.user');
$smseagle_token = get_config_by_name('alert.transports.smseagle.token');
$mobiles = get_config_like_name('alert.transports.smseagle.to.%');
$new_mobiles = array();
foreach ($mobiles as $mobile) {
$new_mobiles[] = $mobile['config_value'];
}
$upd_mobiles = implode(PHP_EOL, $new_mobiles);
echo '
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#smseagle_transport_expand"><i class="fa fa-caret-down"></i> SMSEagle transport</a> <button name="test-alert" id="test-alert" type="button" data-transport="smseagle" class="btn btn-primary btn-xs pull-right">Test transport</button>
</h4>
</div>
<div id="smseagle_transport_expand" class="panel-collapse collapse">
<div class="panel-body">
<div class="form-group has-feedback">
<label for="smseagle_url" class="col-sm-4 control-label">SMSEagle URL </label>
<div class="col-sm-4">
<input id="smseagle_url" class="form-control" type="text" name="global-config-input" value="'.$smseagle_url['config_value'].'" data-config_id="'.$smseagle_url['config_id'].'">
<span class="form-control-feedback">
<i class="fa" aria-hidden="true"></i>
</span>
</div>
</div>
<div class="form-group has-feedback">
<label for="smseagle_user" class="col-sm-4 control-label">User</label>
<div class="col-sm-4">
<input id="smseagle_user" class="form-control" type="text" name="global-config-input" value="'.$smseagle_user['config_value'].'" data-config_id="'.$smseagle_user['config_id'].'">
<span class="form-control-feedback">
<i class="fa" aria-hidden="true"></i>
</span>
</div>
</div>
<div class="form-group has-feedback">
<label for="smseagle_token" class="col-sm-4 control-label">Password</label>
<div class="col-sm-4">
<input id="smseagle_token" class="form-control" type="text" name="global-config-input" value="'.$smseagle_token['config_value'].'" data-config_id="'.$smseagle_token['config_id'].'">
<span class="form-control-feedback">
<i class="fa" aria-hidden="true"></i>
</span>
</div>
</div>
<div class="form-group has-feedback">
<label for="smseagle_to" class="col-sm-4 control-label">Mobiles</label>
<div class="col-sm-4">
<textarea class="form-control" name="global-config-textarea" id="smseagle_to" placeholder="Enter mobile phone numbers, one per line" data-config_id="'.$smseagle_url['config_id'].'" data-type="smseagle">'.$upd_mobiles.'</textarea>
<span class="form-control-feedback">
<i class="fa" aria-hidden="true"></i>
</span>
</div>
</div>

View File

@@ -0,0 +1,42 @@
/* Copyright (C) 2015 Daniel Preussker <f0o@librenms.org>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/**
* SMSEagle API Transport
* @author Barry O'Donovan <barry@lightnet.ie>
* @copyright 2017 Barry O'Donovan, LibreNMS
* @license GPL
* @package LibreNMS
* @subpackage Alerts
*/
$params = array(
'login' => $opts['user'],
'pass' => $opts['token'],
'to' => implode(',',$opts['to']),
'message' => $obj['title'],
);
$url = 'http://'.$opts['url'].'/index.php/http_api/send_sms?'.http_build_query($params);
$curl = curl_init($url);
set_curl_proxy($curl);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$ret = curl_exec($curl);
if (substr($ret,0,2) == "OK") {
return true;
} else {
return false;
}

1
sql-schema/168.sql Normal file
View File

@@ -0,0 +1 @@
INSERT INTO config (config_name,config_value,config_default,config_descr,config_group,config_group_order,config_sub_group,config_sub_group_order,config_hidden,config_disabled) values ('alert.transports.smseagle.url','','','SMSEagle API URL','alerting',0,'transports',0,'0','0'),('alert.transports.smseagle.user','','','SMSEagle User','alerting',0,'transports',0,'0','0'),('alert.transports.smseagle.token','','','SMSEagle Token','alerting',0,'transports',0,'0','0')