alerts: Added OpsGenie transport. (#7392)

* Add OpsGenie transport.

* Log response body from OpsGenie only when an error occurs.

* Move OpsGenie SQL config to a new sql file.
This commit is contained in:
celalemre
2017-09-28 23:20:21 +03:00
committed by Neil Lathwood
parent f24c840864
commit 973764e7d3
3 changed files with 65 additions and 0 deletions

View File

@@ -1000,6 +1000,27 @@ echo '<div id="telegram_chat_id_template" class="hide">
</div>
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#opsgenie_transport_expand"><i class="fa fa-caret-down"></i> OpsGenie</a> <button name="test-alert" id="test-alert" type="button" data-transport="opsgenie" class="btn btn-primary btn-xs pull-right">Test transport</button>
</h4>
</div>
<div id="opsgenie_transport_expand" class="panel-collapse collapse">
<div class="panel-body">
<div class="form-group has-feedback">
<label for="opsgenie" class="col-sm-4 control-label">OpsGenie URL </label>
<div data-toggle="tooltip" title="' . $config_groups['alert.transports.opsgenie.url']['config_descr'] . '" class="toolTip fa fa-question-circle"></div>
<div class="col-sm-4">
<input id="opsgenie" class="form-control" type="text" name="global-config-input" value="' . $config_groups['alert.transports.opsgenie.url']['config_value'] . '" data-config_id="' . $config_groups['alert.transports.opsgenie.url']['config_id'] . '">
<span class="form-control-feedback">
<i class="fa" aria-hidden="true"></i>
</span>
</div>
</div>
</div>
</div>
</div>';
$clickatell = get_config_by_name('alert.transports.clickatell.token');

View File

@@ -0,0 +1,43 @@
/* Copyright (C) 2017 Celal Emre CICEK <celal.emre@opsgenie.com>
* 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/>. */
/**
* OpsGenie API Transport
* @author Celal Emre CICEK <celal.emre@opsgenie.com>
* @copyright 2017 Celal Emre CICEK
* @license GPL
* @package LibreNMS
* @subpackage Alerts
*/
$url = $opts['url'];
$curl = curl_init();
set_curl_proxy($curl);
curl_setopt($curl, CURLOPT_URL, $url );
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($obj));
$ret = curl_exec($curl);
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if($code != 200) {
var_dump("Error when sending post request to OpsGenie. Response code: " . $code . " Response body: " . $ret); //FIXME: proper debugging
return false;
}
return true;

1
sql-schema/208.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.opsgenie.url','','','OpsGenie Webhook URL','alerting',0,'transports',0,'0','0');