mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Removed legacy code from transports (#10081)
This commit is contained in:
committed by
Tony Murray
parent
c76115bf46
commit
d31a551464
@@ -30,24 +30,11 @@ class Api extends Transport
|
||||
{
|
||||
public function deliverAlert($obj, $opts)
|
||||
{
|
||||
if (empty($this->config)) {
|
||||
return $this->deliverAlertOld($obj, $opts);
|
||||
}
|
||||
$url = $this->config['api-url'];
|
||||
$method = $this->config['api-method'];
|
||||
return $this->contactAPI($obj, $url, $method);
|
||||
}
|
||||
|
||||
private function deliverAlertOld($obj, $opts)
|
||||
{
|
||||
foreach ($opts as $method => $apis) {
|
||||
foreach ($apis as $api) {
|
||||
$this->contactAPI($obj, $api, $method);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private function contactAPI($obj, $api, $method)
|
||||
{
|
||||
$method = strtolower($method);
|
||||
|
||||
@@ -45,23 +45,12 @@ class Boxcar extends Transport
|
||||
{
|
||||
public function deliverAlert($obj, $opts)
|
||||
{
|
||||
if (empty($this->config)) {
|
||||
return $this->deliverAlertOld($obj, $opts);
|
||||
}
|
||||
$boxcar_opts = $this->parseUserOptions($this->config['options']);
|
||||
$boxcar_opts['access_token'] = $this->config['boxcar-token'];
|
||||
|
||||
return $this->contactBoxcar($obj, $boxcar_opts);
|
||||
}
|
||||
|
||||
public function deliverAlertOld($obj, $opts)
|
||||
{
|
||||
foreach ($opts as $api) {
|
||||
$this->contactBoxcar($obj, $api);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function contactBoxcar($obj, $api)
|
||||
{
|
||||
$data = [];
|
||||
|
||||
@@ -29,19 +29,11 @@ class Clickatell extends Transport
|
||||
{
|
||||
public function deliverAlert($obj, $opts)
|
||||
{
|
||||
if (empty($this->config)) {
|
||||
return $this->deliverAlertOld($obj, $opts);
|
||||
}
|
||||
$clickatell_opts['token'] = $this->config['clickatell-token'];
|
||||
$clickatell_opts['to'] = preg_split('/([,\r\n]+)/', $this->config['clickatell-numbers']);
|
||||
return $this->contactClickatell($obj, $clickatell_opts);
|
||||
}
|
||||
|
||||
public function deliverAlertOld($obj, $opts)
|
||||
{
|
||||
return $this->contactClickatell($obj, $opts);
|
||||
}
|
||||
|
||||
public static function contactClickatell($obj, $opts)
|
||||
{
|
||||
$url = 'https://platform.clickatell.com/messages/http/send?apiKey=' . $opts['token'] . '&to=' . implode(',', $opts['to']) . '&content=' . urlencode($obj['title']);
|
||||
|
||||
@@ -34,10 +34,6 @@ class Discord extends Transport
|
||||
{
|
||||
public function deliverAlert($obj, $opts)
|
||||
{
|
||||
if (empty($this->config)) {
|
||||
return $this->deliverAlertOld($obj, $opts);
|
||||
}
|
||||
|
||||
$discord_opts = [
|
||||
'url' => $this->config['url'],
|
||||
'options' => $this->parseUserOptions($this->config['options']),
|
||||
@@ -46,14 +42,6 @@ class Discord extends Transport
|
||||
return $this->contactDiscord($obj, $discord_opts);
|
||||
}
|
||||
|
||||
public function deliverAlertOld($obj, $opts)
|
||||
{
|
||||
foreach ($opts as $discord_opts) {
|
||||
$this->contactDiscord($obj, $discord_opts);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function contactDiscord($obj, $discord_opts)
|
||||
{
|
||||
$host = $discord_opts['url'];
|
||||
|
||||
@@ -29,9 +29,6 @@ class Hipchat extends Transport
|
||||
{
|
||||
public function deliverAlert($obj, $opts)
|
||||
{
|
||||
if (empty($this->config)) {
|
||||
return $this->deliverAlertOld($obj, $opts);
|
||||
}
|
||||
$hipchat_opts = $this->parseUserOptions($this->config['hipchat-options']);
|
||||
$hipchat_opts['url'] = $this->config['hipchat-url'];
|
||||
$hipchat_opts['room_id'] = $this->config['hipchat-room-id'];
|
||||
@@ -40,15 +37,6 @@ class Hipchat extends Transport
|
||||
return $this->contactHipchat($obj, $hipchat_opts);
|
||||
}
|
||||
|
||||
public function deliverAlertOld($obj, $opts)
|
||||
{
|
||||
// loop through each room
|
||||
foreach ($opts as $option) {
|
||||
$this->contactHipchat($obj, $option);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function contactHipchat($obj, $option)
|
||||
{
|
||||
$version = 1;
|
||||
|
||||
@@ -29,10 +29,6 @@ class Mattermost extends Transport
|
||||
{
|
||||
public function deliverAlert($obj, $opts)
|
||||
{
|
||||
if (empty($this->config)) {
|
||||
return $this->deliverAlertOld($obj, $opts);
|
||||
}
|
||||
|
||||
$mattermost_opts = [
|
||||
'url' => $this->config['mattermost-url'],
|
||||
'username' => $this->config['mattermost-username'],
|
||||
@@ -44,14 +40,6 @@ class Mattermost extends Transport
|
||||
return $this->contactMattermost($obj, $mattermost_opts);
|
||||
}
|
||||
|
||||
public function deliverAlertOld($obj, $opts)
|
||||
{
|
||||
foreach ($opts as $tmp_api) {
|
||||
$this->contactMattermost($obj, $tmp_api);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function contactMattermost($obj, $api)
|
||||
{
|
||||
$host = $api['url'];
|
||||
|
||||
@@ -29,18 +29,10 @@ class Nagios extends Transport
|
||||
{
|
||||
public function deliverAlert($obj, $opts)
|
||||
{
|
||||
if (empty($this->config)) {
|
||||
return $this->deliverAlertOld($obj, $opts);
|
||||
}
|
||||
$opts = $this->config['nagios-fifo'];
|
||||
return $this->contactNagios($obj, $opts);
|
||||
}
|
||||
|
||||
public function deliverAlertOld($obj, $opts)
|
||||
{
|
||||
return $this->contactNagios($obj, $opts);
|
||||
}
|
||||
|
||||
public static function contactNagios($obj, $opts)
|
||||
{
|
||||
/*
|
||||
|
||||
@@ -44,41 +44,9 @@ class Pagerduty extends Transport
|
||||
} else {
|
||||
$obj['event_type'] = 'trigger';
|
||||
}
|
||||
|
||||
if (empty($this->config)) {
|
||||
return $this->deliverAlertEvent($obj, $opts);
|
||||
}
|
||||
return $this->contactPagerduty($obj, $this->config);
|
||||
}
|
||||
|
||||
public function deliverAlertEvent($obj, $opts)
|
||||
{
|
||||
// This code uses events for PD
|
||||
$protocol = array(
|
||||
'service_key' => $opts,
|
||||
'incident_key' => $obj['alert_id'],
|
||||
'description' => ($obj['name'] ? $obj['name'] . ' on ' . $obj['hostname'] : $obj['title']),
|
||||
'client' => 'LibreNMS',
|
||||
);
|
||||
|
||||
foreach ($obj['faults'] as $fault => $data) {
|
||||
$protocol['details'][] = $data['string'];
|
||||
}
|
||||
$curl = curl_init();
|
||||
set_curl_proxy($curl);
|
||||
curl_setopt($curl, CURLOPT_URL, 'https://events.pagerduty.com/generic/2010-04-15/create_event.json');
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type' => 'application/json'));
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($protocol));
|
||||
$ret = curl_exec($curl);
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
if ($code != 200) {
|
||||
var_dump("PagerDuty returned Error, retry later"); //FIXME: propper debuging
|
||||
return 'HTTP Status code ' . $code;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $obj
|
||||
* @param $config
|
||||
|
||||
@@ -29,9 +29,6 @@ class Playsms extends Transport
|
||||
{
|
||||
public function deliverAlert($obj, $opts)
|
||||
{
|
||||
if (empty($this->config)) {
|
||||
return $this->deliverAlertOld($obj, $opts);
|
||||
}
|
||||
$playsms_opts['url'] = $this->config['playsms-url'];
|
||||
$playsms_opts['user'] = $this->config['playsms-user'];
|
||||
$playsms_opts['token'] = $this->config['playsms-token'];
|
||||
@@ -40,11 +37,6 @@ class Playsms extends Transport
|
||||
return $this->contactPlaysms($obj, $playsms_opts);
|
||||
}
|
||||
|
||||
public function deliverAlertOld($obj, $opts)
|
||||
{
|
||||
return $this->contactPlaysms($obj, $opts);
|
||||
}
|
||||
|
||||
public static function contactPlaysms($obj, $opts)
|
||||
{
|
||||
$data = array("u" => $opts['user'], "h" => $opts['token'], "to" => implode(',', $opts['to']), "msg" => $obj['title']);
|
||||
|
||||
@@ -43,26 +43,12 @@ class Pushover extends Transport
|
||||
{
|
||||
public function deliverAlert($obj, $opts)
|
||||
{
|
||||
if (empty($this->config)) {
|
||||
return $this->deliverAlertOld($obj, $opts);
|
||||
}
|
||||
$pushover_opts = $this->config;
|
||||
$pushover_opts['options'] = $this->parseUserOptions($this->config['options']);
|
||||
|
||||
return $this->contactPushover($obj, $pushover_opts);
|
||||
}
|
||||
|
||||
public function deliverAlertOld($obj, $opts)
|
||||
{
|
||||
foreach ($opts as $api) {
|
||||
$response = $this->contactPushover($obj, $api);
|
||||
if ($response !== true) {
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function contactPushover($obj, $api)
|
||||
{
|
||||
$data = array();
|
||||
|
||||
@@ -29,23 +29,12 @@ class Rocket extends Transport
|
||||
{
|
||||
public function deliverAlert($obj, $opts)
|
||||
{
|
||||
if (empty($this->config)) {
|
||||
return $this->deliverAlertOld($obj, $opts);
|
||||
}
|
||||
$rocket_opts = $this->parseUserOptions($this->config['rocket-options']);
|
||||
$rocket_opts['url'] = $this->config['rocket-url'];
|
||||
|
||||
return $this->contactRocket($obj, $rocket_opts);
|
||||
}
|
||||
|
||||
public function deliverAlertOld($obj, $opts)
|
||||
{
|
||||
foreach ($opts as $tmp_api) {
|
||||
$this->contactRocket($obj, $tmp_api);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function contactRocket($obj, $api)
|
||||
{
|
||||
$host = $api['url'];
|
||||
|
||||
@@ -29,23 +29,12 @@ class Slack extends Transport
|
||||
{
|
||||
public function deliverAlert($obj, $opts)
|
||||
{
|
||||
if (empty($this->config)) {
|
||||
return $this->deliverAlertOld($obj, $opts);
|
||||
}
|
||||
$slack_opts = $this->parseUserOptions($this->config['slack-options']);
|
||||
$slack_opts['url'] = $this->config['slack-url'];
|
||||
|
||||
return $this->contactSlack($obj, $slack_opts);
|
||||
}
|
||||
|
||||
public function deliverAlertOld($obj, $opts)
|
||||
{
|
||||
foreach ($opts as $tmp_api) {
|
||||
$this->contactSlack($obj, $tmp_api);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function contactSlack($obj, $api)
|
||||
{
|
||||
$host = $api['url'];
|
||||
|
||||
@@ -29,9 +29,6 @@ class Smseagle extends Transport
|
||||
{
|
||||
public function deliverAlert($obj, $opts)
|
||||
{
|
||||
if (empty($this->config)) {
|
||||
return $this->deliverAlertOld($obj, $opts);
|
||||
}
|
||||
$smseagle_opts['url'] = $this->config['smseagle-url'];
|
||||
$smseagle_opts['user'] = $this->config['smseagle-user'];
|
||||
$smseagle_opts['token'] = $this->config['smseagle-pass'];
|
||||
@@ -39,11 +36,6 @@ class Smseagle extends Transport
|
||||
return $this->contactSmseagle($obj, $smseagle_opts);
|
||||
}
|
||||
|
||||
public function deliverAlertOld($obj, $opts)
|
||||
{
|
||||
return $this->contactSmseagle($obj, $opts);
|
||||
}
|
||||
|
||||
public static function contactSmseagle($obj, $opts)
|
||||
{
|
||||
$params = [
|
||||
|
||||
@@ -29,9 +29,6 @@ class Smsfeedback extends Transport
|
||||
{
|
||||
public function deliverAlert($obj, $opts)
|
||||
{
|
||||
if (empty($this->config)) {
|
||||
return $this->deliverAlertOld($obj, $opts);
|
||||
}
|
||||
$smsfeedback_opts['user'] = $this->config['smsfeedback-user'];
|
||||
$smsfeedback_opts['token'] = $this->config['smsfeedback-pass'];
|
||||
$smsfeedback_opts['sender'] = $this->config['smsfeedback-sender'];
|
||||
@@ -39,11 +36,6 @@ class Smsfeedback extends Transport
|
||||
return $this->contactsmsfeedback($obj, $smsfeedback_opts);
|
||||
}
|
||||
|
||||
public function deliverAlertOld($obj, $opts)
|
||||
{
|
||||
return $this->contactsmsfeedback($obj, $opts);
|
||||
}
|
||||
|
||||
public static function contactsmsfeedback($obj, $opts)
|
||||
{
|
||||
$params = [
|
||||
|
||||
@@ -30,23 +30,12 @@ class Telegram extends Transport
|
||||
{
|
||||
public function deliverAlert($obj, $opts)
|
||||
{
|
||||
if (empty($this->config)) {
|
||||
return $this->deliverAlertOld($obj, $opts);
|
||||
}
|
||||
$telegram_opts['chat_id'] = $this->config['telegram-chat-id'];
|
||||
$telegram_opts['token'] = $this->config['telegram-token'];
|
||||
$telegram_opts['format'] = $this->config['telegram-format'];
|
||||
return $this->contactTelegram($obj, $telegram_opts);
|
||||
}
|
||||
|
||||
public function deliverAlertOld($obj, $opts)
|
||||
{
|
||||
foreach ($opts as $chat_id => $data) {
|
||||
$this->contactTelegram($obj, $data);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function contactTelegram($obj, $data)
|
||||
{
|
||||
$curl = curl_init();
|
||||
|
||||
Reference in New Issue
Block a user