mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
refactor: Refactor alert transports to classes (#7844)
* Refactor alert transports to classes * Fix linting * Make Slack alert transport php 5.3 compatible * Rename call method to deliverAlert for alert transport
This commit is contained in:
60
LibreNMS/Alert/Transport/Api.php
Normal file
60
LibreNMS/Alert/Transport/Api.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/* Copyright (C) 2014 Daniel Preussker <f0o@devilcode.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/>. */
|
||||
|
||||
/**
|
||||
* API Transport
|
||||
* @author f0o <f0o@devilcode.org>
|
||||
* @copyright 2014 f0o, LibreNMS
|
||||
* @license GPL
|
||||
* @package LibreNMS
|
||||
* @subpackage Alerts
|
||||
*/
|
||||
|
||||
namespace LibreNMS\Alert\Transport;
|
||||
|
||||
use LibreNMS\Interfaces\Alert\Transport;
|
||||
|
||||
class Api implements Transport
|
||||
{
|
||||
public function deliverAlert($obj, $opts)
|
||||
{
|
||||
foreach ($opts as $method => $apis) {
|
||||
// var_dump($method); //FIXME: propper debuging
|
||||
foreach ($apis as $api) {
|
||||
// var_dump($api); //FIXME: propper debuging
|
||||
list($host, $api) = explode("?", $api, 2);
|
||||
foreach ($obj as $k => $v) {
|
||||
$api = str_replace("%" . $k, $method == "get" ? urlencode($v) : $v, $api);
|
||||
}
|
||||
// var_dump($api); //FIXME: propper debuging
|
||||
$curl = curl_init();
|
||||
set_curl_proxy($curl);
|
||||
curl_setopt($curl, CURLOPT_URL, ($method == "get" ? $host."?".$api : $host));
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, strtoupper($method));
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $api);
|
||||
$ret = curl_exec($curl);
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
if ($code != 200) {
|
||||
var_dump("API '$host' returned Error"); //FIXME: propper debuging
|
||||
var_dump("Params: ".$api); //FIXME: propper debuging
|
||||
var_dump("Return: ".$ret); //FIXME: propper debuging
|
||||
return 'HTTP Status code '.$code;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
103
LibreNMS/Alert/Transport/Boxcar.php
Normal file
103
LibreNMS/Alert/Transport/Boxcar.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/* Copyright (C) 2015 James Campbell <neokjames@gmail.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/>. */
|
||||
|
||||
/* Copyright (C) 2015 Daniel Preussker <f0o@devilcode.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/>. */
|
||||
|
||||
/**
|
||||
* Boxcar API Transport
|
||||
* @author trick77 <jan@trick77.com>
|
||||
* @copyright 2015 trick77, neokjames, f0o, LibreNMS
|
||||
* @license GPL
|
||||
* @package LibreNMS
|
||||
* @subpackage Alerts
|
||||
*/
|
||||
|
||||
namespace LibreNMS\Alert\Transport;
|
||||
|
||||
use LibreNMS\Interfaces\Alert\Transport;
|
||||
|
||||
class Boxcar implements Transport
|
||||
{
|
||||
public function deliverAlert($obj, $opts)
|
||||
{
|
||||
global $config;
|
||||
foreach ($opts as $api) {
|
||||
$data = array();
|
||||
$data['user_credentials'] = $api['access_token'];
|
||||
$data['notification[source_name]'] = $config['project_id'];
|
||||
switch ($obj['severity']) {
|
||||
case "critical":
|
||||
$severity = "Critical";
|
||||
if (!empty($api['sound_critical'])) {
|
||||
$data['notification[sound]'] = $api['sound_critical'];
|
||||
}
|
||||
break;
|
||||
case "warning":
|
||||
$severity = "Warning";
|
||||
if (!empty($api['sound_warning'])) {
|
||||
$data['notification[sound]'] = $api['sound_warning'];
|
||||
}
|
||||
break;
|
||||
}
|
||||
switch ($obj['state']) {
|
||||
case 0:
|
||||
$title_text = "OK";
|
||||
if (!empty($api['sound_ok'])) {
|
||||
$data['notification[sound]'] = $api['sound_ok'];
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
$title_text = $severity;
|
||||
break;
|
||||
case 2:
|
||||
$title_text = "Acknowledged";
|
||||
break;
|
||||
}
|
||||
$data['notification[title]'] = $title_text . " - " . $obj['hostname'] . " - " . $obj['name'];
|
||||
$message_text = "Timestamp: " . $obj['timestamp'];
|
||||
if (!empty($obj['faults'])) {
|
||||
$message_text .= "\n\nFaults:\n";
|
||||
foreach ($obj['faults'] as $k => $faults) {
|
||||
$message_text .= "#" . $k . " " . $faults['string'] . "\n";
|
||||
}
|
||||
}
|
||||
$data['notification[long_message]'] = $message_text;
|
||||
$curl = curl_init();
|
||||
set_curl_proxy($curl);
|
||||
curl_setopt($curl, CURLOPT_URL, 'https://new.boxcar.io/api/notifications');
|
||||
curl_setopt($curl, CURLOPT_SAFE_UPLOAD, true);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
||||
$ret = curl_exec($curl);
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
if ($code != 201) {
|
||||
var_dump("Boxcar returned error"); //FIXME: proper debugging
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
71
LibreNMS/Alert/Transport/Canopsis.php
Normal file
71
LibreNMS/Alert/Transport/Canopsis.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
namespace LibreNMS\Alert\Transport;
|
||||
|
||||
use LibreNMS\Interfaces\Alert\Transport;
|
||||
|
||||
class Canopsis implements Transport
|
||||
{
|
||||
public function deliverAlert($obj, $opts)
|
||||
{
|
||||
// Configurations
|
||||
$host = $opts["host"];
|
||||
$port = $opts["port"];
|
||||
$user = $opts["user"];
|
||||
$pass = $opts["passwd"];
|
||||
$vhost = $opts["vhost"];
|
||||
$exchange = "canopsis.events";
|
||||
|
||||
// Connection
|
||||
$conn = new \PhpAmqpLib\Connection\AMQPConnection($host, $port, $user, $pass, $vhost);
|
||||
$ch = $conn->channel();
|
||||
|
||||
// Declare exchange (if not exist)
|
||||
// exchange_declare($exchange, $type, $passive=false, $durable=false, $auto_delete=true, $internal=false, $nowait=false, $arguments=null, $ticket=null)
|
||||
$ch->exchange_declare($exchange, 'topic', false, true, false);
|
||||
|
||||
// Create Canopsis event, see: https://github.com/capensis/canopsis/wiki/Event-specification
|
||||
switch ($obj['severity']) {
|
||||
case "ok":
|
||||
$state = 0;
|
||||
break;
|
||||
case "warning":
|
||||
$state = 1;
|
||||
break;
|
||||
case "critical":
|
||||
$state = 2;
|
||||
break;
|
||||
default:
|
||||
$state = 3;
|
||||
}
|
||||
$msg_body = array(
|
||||
"timestamp" => time(),
|
||||
"connector" => "librenms",
|
||||
"connector_name" => "LibreNMS1",
|
||||
"event_type" => "check",
|
||||
"source_type" => "resource",
|
||||
"component" => $obj['hostname'],
|
||||
"resource" => $obj['faults'][1]['storage_descr'],
|
||||
"state" => $state,
|
||||
"state_type" => 1,
|
||||
"output" => $obj['msg'],
|
||||
"display_name" => "librenms"
|
||||
);
|
||||
$msg_raw = json_encode($msg_body);
|
||||
|
||||
// Build routing key
|
||||
if ($msg_body['source_type'] == "resource") {
|
||||
$msg_rk = $msg_rk . "." . $msg_body['resource'];
|
||||
} else {
|
||||
$msg_rk = $msg_body['connector'] . "." . $msg_body['connector_name'] . "." . $msg_body['event_type'] . "." . $msg_body['source_type'] . "." . $msg_body['component'];
|
||||
}
|
||||
|
||||
// Publish Event
|
||||
$msg = new \PhpAmqpLib\Message\AMQPMessage($msg_raw, array('content_type' => 'application/json', 'delivery_mode' => 2));
|
||||
$ch->basic_publish($msg, $exchange, $msg_rk);
|
||||
|
||||
// Close connection
|
||||
$ch->close();
|
||||
$conn->close();
|
||||
return true;
|
||||
}
|
||||
}
|
47
LibreNMS/Alert/Transport/Ciscospark.php
Normal file
47
LibreNMS/Alert/Transport/Ciscospark.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/*
|
||||
* LibreNMS
|
||||
*
|
||||
* Copyright (c) 2017 Søren Friis Rosiak <sorenrosiak@gmail.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. Please see LICENSE.txt at the top level of
|
||||
* the source code distribution for details.
|
||||
*/
|
||||
namespace LibreNMS\Alert\Transport;
|
||||
|
||||
use LibreNMS\Interfaces\Alert\Transport;
|
||||
|
||||
class Ciscospark implements Transport
|
||||
{
|
||||
public function deliverAlert($obj, $opts)
|
||||
{
|
||||
$token = $opts['token'];
|
||||
$roomId = $opts['roomid'];
|
||||
$text = strip_tags($obj['msg']);
|
||||
$data = array(
|
||||
'roomId' => $roomId,
|
||||
'text' => $text
|
||||
);
|
||||
$curl = curl_init();
|
||||
set_curl_proxy($curl);
|
||||
curl_setopt($curl, CURLOPT_URL, 'https://api.ciscospark.com/v1/messages');
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
|
||||
'Content-type' => 'application/json',
|
||||
'Expect:',
|
||||
'Authorization: Bearer ' . $token
|
||||
));
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
||||
$ret = curl_exec($curl);
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
|
||||
if ($code != 200) {
|
||||
var_dump("Cisco Spark returned Error, retry later");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -1,3 +1,4 @@
|
||||
<?php
|
||||
/* 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
|
||||
@@ -20,20 +21,29 @@
|
||||
* @package LibreNMS
|
||||
* @subpackage Alerts
|
||||
*/
|
||||
namespace LibreNMS\Alert\Transport;
|
||||
|
||||
$url = 'https://platform.clickatell.com/messages/http/send?apiKey='.$opts['token'].'&to='.implode(',',$opts['to']).'&content='.urlencode($obj['title']);
|
||||
use LibreNMS\Interfaces\Alert\Transport;
|
||||
|
||||
$curl = curl_init($url);
|
||||
set_curl_proxy($curl);
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET");
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
class Clickatell implements Transport
|
||||
{
|
||||
public function deliverAlert($obj, $opts)
|
||||
{
|
||||
$url = 'https://platform.clickatell.com/messages/http/send?apiKey=' . $opts['token'] . '&to=' . implode(',', $opts['to']) . '&content=' . urlencode($obj['title']);
|
||||
|
||||
$ret = curl_exec($curl);
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
if( $code > 200 ) {
|
||||
if( $debug ) {
|
||||
$curl = curl_init($url);
|
||||
set_curl_proxy($curl);
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET");
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
|
||||
$ret = curl_exec($curl);
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
if ($code > 200) {
|
||||
if ($debug) {
|
||||
var_dump($ret);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
@@ -1,3 +1,4 @@
|
||||
<?php
|
||||
/* Copyright (C) 2014 Daniel Preussker <f0o@devilcode.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
|
||||
@@ -20,6 +21,15 @@
|
||||
* @package LibreNMS
|
||||
* @subpackage Alerts
|
||||
*/
|
||||
namespace LibreNMS\Alert\Transport;
|
||||
|
||||
var_dump($obj);
|
||||
return true;
|
||||
use LibreNMS\Interfaces\Alert\Transport;
|
||||
|
||||
class Dummy implements Transport
|
||||
{
|
||||
public function deliverAlert($obj, $opts)
|
||||
{
|
||||
var_dump($obj);
|
||||
return true;
|
||||
}
|
||||
}
|
187
LibreNMS/Alert/Transport/Elasticsearch.php
Normal file
187
LibreNMS/Alert/Transport/Elasticsearch.php
Normal file
@@ -0,0 +1,187 @@
|
||||
<?php
|
||||
/* LibreNMS
|
||||
*
|
||||
* Copyright (C) 2017 Paul Blasquez <pblasquez@gmail.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/>. */
|
||||
namespace LibreNMS\Alert\Transport;
|
||||
|
||||
use LibreNMS\Interfaces\Alert\Transport;
|
||||
|
||||
class Elasticsearch implements Transport
|
||||
{
|
||||
public function deliverAlert($obj, $opts)
|
||||
{
|
||||
$es_host = '127.0.0.1';
|
||||
$es_port = 9200;
|
||||
$index = strftime("librenms-%Y.%m.%d");
|
||||
$type = 'alert';
|
||||
$severity = $obj['severity'];
|
||||
$device = device_by_id_cache($obj['device_id']); // for event logging
|
||||
|
||||
if (!empty($opts['es_host'])) {
|
||||
if (preg_match("/[a-zA-Z]/", $opts['es_host'])) {
|
||||
$es_host = gethostbyname($opts['es_host']);
|
||||
if ($es_host === $opts['es_host']) {
|
||||
return "Alphanumeric hostname found but does not resolve to an IP.";
|
||||
}
|
||||
} elseif (filter_var($opts['es_host'], FILTER_VALIDATE_IP)) {
|
||||
$es_host = $opts['es_host'];
|
||||
} else {
|
||||
return "Elasticsearch host is not a valid IP: " . $opts['es_host'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($opts['es_port']) && preg_match("/^\d+$/", $opts['es_port'])) {
|
||||
$es_port = $opts['es_port'];
|
||||
}
|
||||
|
||||
if (!empty($opts['es_index'])) {
|
||||
$index = strftime($opts['es_index']);
|
||||
}
|
||||
|
||||
$host = $es_host . ':' . $es_port . '/' . $index . '/' . $type;
|
||||
|
||||
switch ($obj['state']) {
|
||||
case 0:
|
||||
$state = "ok";
|
||||
break;
|
||||
case 1:
|
||||
$state = $severity;
|
||||
break;
|
||||
case 2:
|
||||
$state = "acknowledged";
|
||||
break;
|
||||
case 3:
|
||||
$state = "worse";
|
||||
break;
|
||||
case 4:
|
||||
$state = "better";
|
||||
break;
|
||||
}
|
||||
|
||||
$data = array(
|
||||
'@timestamp' => strftime("%Y-%m-%dT%T"),
|
||||
"host" => gethostname(),
|
||||
"location" => $obj['location'],
|
||||
"title" => $obj['name'],
|
||||
"message" => $obj['string'],
|
||||
"device_id" => $obj['device_id'],
|
||||
"device_name" => $obj['hostname'],
|
||||
"device_hardware" => $obj['hardware'],
|
||||
"device_version" => $obj['version'],
|
||||
"state" => $state,
|
||||
"severity" => $severity,
|
||||
"first_occurrence" => $obj['timestamp'],
|
||||
"entity_type" => "device",
|
||||
"entity_tab" => "overview",
|
||||
"entity_id" => $obj['device_id'],
|
||||
"entity_name" => $obj['hostname'],
|
||||
"entity_descr" => $obj['sysDescr'],
|
||||
);
|
||||
|
||||
if (!empty($obj['faults'])) {
|
||||
foreach ($obj['faults'] as $k => $v) {
|
||||
$curl = curl_init();
|
||||
$data['message'] = $v['string'];
|
||||
switch (true) {
|
||||
case (array_key_exists('port_id', $v)):
|
||||
$data['entity_type'] = 'port';
|
||||
$data['entity_tab'] = 'port';
|
||||
$data['entity_id'] = $v['port_id'];
|
||||
$data['entity_name'] = $v['ifName'];
|
||||
$data['entity_descr'] = $v['ifAlias'];
|
||||
break;
|
||||
case (array_key_exists('sensor_id', $v)):
|
||||
$data['entity_type'] = $v['sensor_class'];
|
||||
$data['entity_tab'] = 'health';
|
||||
$data['entity_id'] = $v['sensor_id'];
|
||||
$data['entity_name'] = $v['sensor_descr'];
|
||||
$data['entity_descr'] = $v['sensor_type'];
|
||||
break;
|
||||
case (array_key_exists('mempool_id', $v)):
|
||||
$data['entity_type'] = 'mempool';
|
||||
$data['entity_tab'] = 'health';
|
||||
$data['entity_id'] = $v['mempool_id'];
|
||||
$data['entity_name'] = $v['mempool_index'];
|
||||
$data['entity_descr'] = $v['mempool_descr'];
|
||||
break;
|
||||
case (array_key_exists('storage_id', $v)):
|
||||
$data['entity_type'] = 'storage';
|
||||
$data['entity_tab'] = 'health';
|
||||
$data['entity_id'] = $v['storage_id'];
|
||||
$data['entity_name'] = $v['storage_index'];
|
||||
$data['entity_descr'] = $v['storage_descr'];
|
||||
break;
|
||||
case (array_key_exists('processor_id', $v)):
|
||||
$data['entity_type'] = 'processor';
|
||||
$data['entity_tab'] = 'health';
|
||||
$data['entity_id'] = $v['processor_id'];
|
||||
$data['entity_name'] = $v['processor_type'];
|
||||
$data['entity_descr'] = $v['processor_descr'];
|
||||
break;
|
||||
case (array_key_exists('bgpPeer_id', $v)):
|
||||
$data['entity_type'] = 'bgp';
|
||||
$data['entity_tab'] = 'routing';
|
||||
$data['entity_id'] = $v['bgpPeer_id'];
|
||||
$data['entity_name'] = 'local: ' . $v['bgpPeerLocalAddr'] . ' - AS' . $obj['bgpLocalAs'];
|
||||
$data['entity_descr'] = 'remote: ' . $v['bgpPeerIdentifier'] . ' - AS' . $v['bgpPeerRemoteAs'];
|
||||
break;
|
||||
case (array_key_exists('tunnel_id', $v)):
|
||||
$data['entity_type'] = 'ipsec_tunnel';
|
||||
$data['entity_tab'] = 'routing';
|
||||
$data['entity_id'] = $v['tunnel_id'];
|
||||
$data['entity_name'] = $v['tunnel_name'];
|
||||
$data['entity_descr'] = 'local: ' . $v['local_addr'] . ':' . $v['local_port'] . ', remote: ' . $v['peer_addr'] . ':' . $v['peer_port'];
|
||||
break;
|
||||
default:
|
||||
$data['entity_type'] = 'generic';
|
||||
break;
|
||||
}
|
||||
$alert_message = json_encode($data);
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
|
||||
if ($opts['es_proxy'] === true) {
|
||||
set_curl_proxy($curl);
|
||||
}
|
||||
curl_setopt($curl, CURLOPT_URL, $host);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($curl, CURLOPT_POST, true);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $alert_message);
|
||||
|
||||
$ret = curl_exec($curl);
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
if ($code != 200 && $code != 201) {
|
||||
return $host . ' returned HTTP Status code ' . $code . ' for ' . $alert_message;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$curl = curl_init();
|
||||
$alert_message = json_encode($data);
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
|
||||
if ($opts['es_proxy'] === true) {
|
||||
set_curl_proxy($curl);
|
||||
}
|
||||
curl_setopt($curl, CURLOPT_URL, $host);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($curl, CURLOPT_POST, true);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $alert_message);
|
||||
|
||||
$ret = curl_exec($curl);
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
if ($code != 200 && $code != 201) {
|
||||
return $host . ' returned HTTP Status code ' . $code . ' for ' . $alert_message;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
102
LibreNMS/Alert/Transport/Hipchat.php
Normal file
102
LibreNMS/Alert/Transport/Hipchat.php
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
/* Copyright (C) 2014 Daniel Preussker <f0o@devilcode.org>, Tyler Christiansen <code@tylerc.me>
|
||||
* 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/>. */
|
||||
|
||||
/*
|
||||
* API Transport
|
||||
* @author Tyler Christiansen <code@tylerc.me>
|
||||
* @copyright 2014 Daniel Preussker, Tyler Christiansen, LibreNMS
|
||||
* @license GPL
|
||||
* @package LibreNMS
|
||||
* @subpackage Alerts
|
||||
*/
|
||||
namespace LibreNMS\Alert\Transport;
|
||||
|
||||
use LibreNMS\Interfaces\Alert\Transport;
|
||||
|
||||
class Hipchat implements Transport
|
||||
{
|
||||
public function deliverAlert($obj, $opts)
|
||||
{
|
||||
// loop through each room
|
||||
foreach ($opts as $option) {
|
||||
$version = 1;
|
||||
if (stripos($option['url'], "v2")) {
|
||||
$version = 2;
|
||||
}
|
||||
|
||||
// Generate our URL from the base URL + room_id and the auth token if the version is 2.
|
||||
$url = $option['url'];
|
||||
if ($version == 2) {
|
||||
$url .= "/" . urlencode($option["room_id"]) . "/notification?auth_token=" . urlencode($option["auth_token"]);
|
||||
}
|
||||
foreach ($obj as $key => $value) {
|
||||
$api = str_replace("%" . $key, $method == "get" ? urlencode($value) : $value, $api);
|
||||
}
|
||||
$curl = curl_init();
|
||||
|
||||
if (empty($obj["msg"])) {
|
||||
return "Empty Message";
|
||||
}
|
||||
|
||||
if (empty($option["message_format"])) {
|
||||
$option["message_format"] = 'text';
|
||||
}
|
||||
|
||||
// Sane default of making the message color green if the message indicates
|
||||
// that the alert recovered. If it rebooted, make it yellow.
|
||||
if (stripos($obj["msg"], "recovered")) {
|
||||
$color = "green";
|
||||
} elseif (stripos($obj["msg"], "rebooted")) {
|
||||
$color = "yellow";
|
||||
} else {
|
||||
if (empty($option["color"]) || $option["color"] == 'u') {
|
||||
$color = 'red';
|
||||
} else {
|
||||
$color = $option["color"];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$data[] = "message=" . urlencode($obj["msg"]);
|
||||
if ($version == 1) {
|
||||
$data[] = "room_id=" . urlencode($option["room_id"]);
|
||||
}
|
||||
$data[] = "from=" . urlencode($option["from"]);
|
||||
$data[] = "color=" . urlencode($color);
|
||||
$data[] = "notify=" . urlencode($option["notify"]);
|
||||
$data[] = "message_format=" . urlencode($option["message_format"]);
|
||||
|
||||
$data = implode('&', $data);
|
||||
set_curl_proxy($curl);
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($curl, CURLOPT_POST, true);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
|
||||
'Content-Type: application/x-www-form-urlencoded',
|
||||
));
|
||||
$ret = curl_exec($curl);
|
||||
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
if ($code != 200 && $code != 204) {
|
||||
var_dump("API '$url' returned Error");
|
||||
var_dump("Params: " . $message);
|
||||
var_dump("Return: " . $ret);
|
||||
return 'HTTP Status code ' . $code;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -1,3 +1,4 @@
|
||||
<?php
|
||||
/* Copyright (C) 2014 Daniel Preussker <f0o@devilcode.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
|
||||
@@ -20,15 +21,25 @@
|
||||
* @package LibreNMS
|
||||
* @subpackage Alerts
|
||||
*/
|
||||
namespace LibreNMS\Alert\Transport;
|
||||
|
||||
$f = $config['install_dir']."/.ircbot.alert";
|
||||
if( file_exists($f) && filetype($f) == "fifo" ) {
|
||||
$f = fopen($f,"w+");
|
||||
$r = fwrite($f,json_encode($obj)."\n");
|
||||
use LibreNMS\Interfaces\Alert\Transport;
|
||||
|
||||
class Irc implements Transport
|
||||
{
|
||||
public function deliverAlert($obj, $opts)
|
||||
{
|
||||
global $config;
|
||||
$f = $config['install_dir'] . "/.ircbot.alert";
|
||||
if (file_exists($f) && filetype($f) == "fifo") {
|
||||
$f = fopen($f, "w+");
|
||||
$r = fwrite($f, json_encode($obj) . "\n");
|
||||
$f = fclose($f);
|
||||
if( $r === false ) {
|
||||
if ($r === false) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
78
LibreNMS/Alert/Transport/Jira.php
Normal file
78
LibreNMS/Alert/Transport/Jira.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/* Copyright (C) 2015 Aldemir Akpinar <aldemir.akpinar@gmail.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/>. */
|
||||
|
||||
/**
|
||||
* Jira API Transport
|
||||
* @author Aldemir Akpinar <aldemir.akpinar@gmail.com>
|
||||
* @copyright 2017 Aldemir Akpinar, LibreNMS
|
||||
* @license GPL
|
||||
* @package LibreNMS
|
||||
* @subpackage Alerts
|
||||
*/
|
||||
namespace LibreNMS\Alert\Transport;
|
||||
|
||||
use LibreNMS\Interfaces\Alert\Transport;
|
||||
|
||||
class Jira implements Transport
|
||||
{
|
||||
public function deliverAlert($obj, $opts)
|
||||
{
|
||||
// Don't create tickets for resolutions
|
||||
if ($obj['severity'] == 'recovery' && $obj['msg'] != 'This is a test alert') {
|
||||
return true;
|
||||
}
|
||||
|
||||
$device = device_by_id_cache($obj['device_id']); // for event logging
|
||||
|
||||
$username = $opts['username'];
|
||||
$password = $opts['password'];
|
||||
$prjkey = $opts['prjkey'];
|
||||
$issuetype = $opts['issuetype'];
|
||||
$details = "Librenms alert for: " . $obj['hostname'];
|
||||
$description = $obj['msg'];
|
||||
$url = $opts['url'] . '/rest/api/latest/issue';
|
||||
$curl = curl_init();
|
||||
|
||||
$data = array("project" => array("key" => $prjkey),
|
||||
"summary" => $details,
|
||||
"description" => $description,
|
||||
"issuetype" => array("name" => $issuetype));
|
||||
$postdata = array("fields" => $data);
|
||||
$datastring = json_encode($postdata);
|
||||
|
||||
set_curl_proxy($curl);
|
||||
|
||||
$headers = array('Accept: application/json', 'Content-Type: application/json');
|
||||
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt($curl, CURLOPT_USERPWD, "$username:$password");
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($curl, CURLOPT_VERBOSE, 1);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $datastring);
|
||||
|
||||
$ret = curl_exec($curl);
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
if ($code == 200) {
|
||||
$jiraout = json_decode($ret, true);
|
||||
d_echo("Created jira issue " . $jiraout['key'] . " for " . $device);
|
||||
return true;
|
||||
} else {
|
||||
d_echo("Jira connection error: " . serialize($ret));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,3 +1,4 @@
|
||||
<?php
|
||||
/* Copyright (C) 2014 Daniel Preussker <f0o@devilcode.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
|
||||
@@ -20,5 +21,15 @@
|
||||
* @package LibreNMS
|
||||
* @subpackage Alerts
|
||||
*/
|
||||
namespace LibreNMS\Alert\Transport;
|
||||
|
||||
return send_mail($obj['contacts'], $obj['title'], $obj['msg'], ($config['email_html'] == 'true') ? true : false );
|
||||
use LibreNMS\Interfaces\Alert\Transport;
|
||||
|
||||
class Mail implements Transport
|
||||
{
|
||||
public function deliverAlert($obj, $opts)
|
||||
{
|
||||
global $config;
|
||||
return send_mail($obj['contacts'], $obj['title'], $obj['msg'], ($config['email_html'] == 'true') ? true : false);
|
||||
}
|
||||
}
|
46
LibreNMS/Alert/Transport/Msteams.php
Normal file
46
LibreNMS/Alert/Transport/Msteams.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/*
|
||||
* LibreNMS
|
||||
*
|
||||
* Copyright (c) 2016 Søren Friis Rosiak <sorenrosiak@gmail.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. Please see LICENSE.txt at the top level of
|
||||
* the source code distribution for details.
|
||||
*/
|
||||
namespace LibreNMS\Alert\Transport;
|
||||
|
||||
use LibreNMS\Interfaces\Alert\Transport;
|
||||
|
||||
class Msteams implements Transport
|
||||
{
|
||||
public function deliverAlert($obj, $opts)
|
||||
{
|
||||
$url = $opts['url'];
|
||||
$color = ($obj['state'] == 0 ? '#00FF00' : '#FF0000');
|
||||
$data = array(
|
||||
'title' => ($obj['name'] ? $obj['name'] . ' on ' . $obj['hostname'] : $obj['title']),
|
||||
'themeColor' => $color,
|
||||
'text' => strip_tags($obj['msg'])
|
||||
);
|
||||
$curl = curl_init();
|
||||
set_curl_proxy($curl);
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
|
||||
'Content-type' => 'application/json',
|
||||
'Expect:'
|
||||
));
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
|
||||
$ret = curl_exec($curl);
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
|
||||
if ($code != 200) {
|
||||
var_dump("Microsoft Teams returned Error, retry later");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
58
LibreNMS/Alert/Transport/Nagios.php
Normal file
58
LibreNMS/Alert/Transport/Nagios.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/* Copyright (C) 2014 Daniel Preussker <f0o@devilcode.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/>. */
|
||||
|
||||
/**
|
||||
* Nagios Transport
|
||||
* @author f0o <f0o@devilcode.org>
|
||||
* @copyright 2014 f0o, LibreNMS
|
||||
* @license GPL
|
||||
* @package LibreNMS
|
||||
* @subpackage Alerts
|
||||
*/
|
||||
namespace LibreNMS\Alert\Transport;
|
||||
|
||||
use LibreNMS\Interfaces\Alert\Transport;
|
||||
|
||||
class Nagios implements Transport
|
||||
{
|
||||
public function deliverAlert($obj, $opts)
|
||||
{
|
||||
/*
|
||||
host_perfdata_file_template=
|
||||
[HOSTPERFDATA]\t
|
||||
$TIMET$\t
|
||||
$HOSTNAME$\t
|
||||
HOST\t
|
||||
$HOSTSTATE$\t
|
||||
$HOSTEXECUTIONTIME$\t
|
||||
$HOSTLATENCY$\t
|
||||
$HOSTOUTPUT$\t
|
||||
$HOSTPERFDATA$
|
||||
*/
|
||||
|
||||
$format = '';
|
||||
$format .= "[HOSTPERFDATA]\t";
|
||||
$format .= $obj['timestamp'] . "\t";
|
||||
$format .= $obj['hostname'] . "\t";
|
||||
$format .= md5($obj['rule']) . "\t"; //FIXME: Better entity
|
||||
$format .= ($obj['state'] ? $obj['severity'] : "ok") . "\t";
|
||||
$format .= "0\t";
|
||||
$format .= "0\t";
|
||||
$format .= str_replace("\n", "", nl2br($obj['msg'])) . "\t";
|
||||
$format .= "NULL"; //FIXME: What's the HOSTPERFDATA equivalent for LibreNMS? Oo
|
||||
$format .= "\n";
|
||||
return file_put_contents($opts, $format);
|
||||
}
|
||||
}
|
53
LibreNMS/Alert/Transport/Opsgenie.php
Executable file
53
LibreNMS/Alert/Transport/Opsgenie.php
Executable file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/* 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
|
||||
*/
|
||||
namespace LibreNMS\Alert\Transport;
|
||||
|
||||
use LibreNMS\Interfaces\Alert\Transport;
|
||||
|
||||
class Opsgenie implements Transport
|
||||
{
|
||||
public function deliverAlert($obj, $opts)
|
||||
{
|
||||
$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;
|
||||
}
|
||||
}
|
58
LibreNMS/Alert/Transport/Osticket.php
Normal file
58
LibreNMS/Alert/Transport/Osticket.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/*
|
||||
* LibreNMS
|
||||
*
|
||||
* Copyright (c) 2016 Søren Friis Rosiak <sorenrosiak@gmail.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. Please see LICENSE.txt at the top level of
|
||||
* the source code distribution for details.
|
||||
*/
|
||||
namespace LibreNMS\Alert\Transport;
|
||||
|
||||
use LibreNMS\Interfaces\Alert\Transport;
|
||||
|
||||
class Osticket implements Transport
|
||||
{
|
||||
public function deliverAlert($obj, $opts)
|
||||
{
|
||||
global $config;
|
||||
|
||||
$url = $opts['url'];
|
||||
$token = $opts['token'];
|
||||
|
||||
foreach (parse_email($config['email_from']) as $from => $from_name) {
|
||||
$email = $from_name . ' <' . $from . '>';
|
||||
break;
|
||||
}
|
||||
|
||||
$protocol = array(
|
||||
'name' => 'LibreNMS',
|
||||
'email' => $email,
|
||||
'subject' => ($obj['name'] ? $obj['name'] . ' on ' . $obj['hostname'] : $obj['title']),
|
||||
'message' => strip_tags($obj['msg']),
|
||||
'ip' => $_SERVER['REMOTE_ADDR'],
|
||||
'attachments' => array(),
|
||||
);
|
||||
$curl = curl_init();
|
||||
set_curl_proxy($curl);
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
|
||||
'Content-type' => 'application/json',
|
||||
'Expect:',
|
||||
'X-API-Key: ' . $token
|
||||
));
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($protocol));
|
||||
$ret = curl_exec($curl);
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
|
||||
if ($code != 201) {
|
||||
var_dump("osTicket returned Error, retry later");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
62
LibreNMS/Alert/Transport/Pagerduty.php
Normal file
62
LibreNMS/Alert/Transport/Pagerduty.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
/* Copyright (C) 2015 Daniel Preussker <f0o@devilcode.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/>. */
|
||||
|
||||
/**
|
||||
* PagerDuty Generic-API Transport
|
||||
* @author f0o <f0o@devilcode.org>
|
||||
* @copyright 2015 f0o, LibreNMS
|
||||
* @license GPL
|
||||
* @package LibreNMS
|
||||
* @subpackage Alerts
|
||||
*/
|
||||
namespace LibreNMS\Alert\Transport;
|
||||
|
||||
use LibreNMS\Interfaces\Alert\Transport;
|
||||
|
||||
class Pagerduty implements Transport
|
||||
{
|
||||
public function deliverAlert($obj, $opts)
|
||||
{
|
||||
$protocol = array(
|
||||
'service_key' => $opts,
|
||||
'incident_key' => ($obj['id'] ? $obj['id'] : $obj['uid']),
|
||||
'description' => ($obj['name'] ? $obj['name'] . ' on ' . $obj['hostname'] : $obj['title']),
|
||||
'client' => 'LibreNMS',
|
||||
);
|
||||
if ($obj['state'] == 0) {
|
||||
$protocol['event_type'] = 'resolve';
|
||||
} elseif ($obj['state'] == 2) {
|
||||
$protocol['event_type'] = 'acknowledge';
|
||||
} else {
|
||||
$protocol['event_type'] = 'trigger';
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
53
LibreNMS/Alert/Transport/Playsms.php
Normal file
53
LibreNMS/Alert/Transport/Playsms.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/* 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/>. */
|
||||
|
||||
/**
|
||||
* PlaySMS API Transport
|
||||
* @author f0o <f0o@librenms.org>
|
||||
* @copyright 2015 f0o, LibreNMS
|
||||
* @license GPL
|
||||
* @package LibreNMS
|
||||
* @subpackage Alerts
|
||||
*/
|
||||
namespace LibreNMS\Alert\Transport;
|
||||
|
||||
use LibreNMS\Interfaces\Alert\Transport;
|
||||
|
||||
class Playsms implements Transport
|
||||
{
|
||||
public function deliverAlert($obj, $opts)
|
||||
{
|
||||
$data = array("u" => $opts['user'], "h" => $opts['token'], "to" => implode(',', $opts['to']), "msg" => $obj['title']);
|
||||
if (!empty($opts['from'])) {
|
||||
$data["from"] = $opts['from'];
|
||||
}
|
||||
$url = $opts['url'] . '&op=pv&' . http_build_query($data);
|
||||
$curl = curl_init($url);
|
||||
|
||||
set_curl_proxy($curl);
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET");
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
|
||||
$ret = curl_exec($curl);
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
if ($code > 202) {
|
||||
if ($debug) {
|
||||
var_dump($ret);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
58
LibreNMS/Alert/Transport/Pushbullet.php
Normal file
58
LibreNMS/Alert/Transport/Pushbullet.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/* 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/>. */
|
||||
|
||||
/**
|
||||
* Pushbullet API Transport
|
||||
* @author f0o <f0o@librenms.org>
|
||||
* @copyright 2015 f0o, LibreNMS
|
||||
* @license GPL
|
||||
* @package LibreNMS
|
||||
* @subpackage Alerts
|
||||
*/
|
||||
namespace LibreNMS\Alert\Transport;
|
||||
|
||||
use LibreNMS\Interfaces\Alert\Transport;
|
||||
|
||||
class Pushbullet implements Transport
|
||||
{
|
||||
public function deliverAlert($obj, $opts)
|
||||
{
|
||||
// Note: At this point it might be useful to iterate through $obj['contacts'] and send each of them a note ?
|
||||
|
||||
$data = array("type" => "note", "title" => $obj['title'], "body" => $obj['msg']);
|
||||
$data = json_encode($data);
|
||||
|
||||
$curl = curl_init('https://api.pushbullet.com/v2/pushes');
|
||||
set_curl_proxy($curl);
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
|
||||
'Content-Type: application/json',
|
||||
'Content-Length: ' . strlen($data),
|
||||
'Authorization: Bearer ' . $opts,
|
||||
));
|
||||
|
||||
$ret = curl_exec($curl);
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
if ($code > 201) {
|
||||
if ($debug) {
|
||||
var_dump($ret);
|
||||
}
|
||||
return 'HTTP Status code ' . $code;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
103
LibreNMS/Alert/Transport/Pushover.php
Normal file
103
LibreNMS/Alert/Transport/Pushover.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/* Copyright (C) 2015 James Campbell <neokjames@gmail.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/>. */
|
||||
|
||||
/* Copyright (C) 2015 Daniel Preussker <f0o@devilcode.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/>. */
|
||||
|
||||
/**
|
||||
* Pushover API Transport
|
||||
* @author neokjames <neokjames@gmail.com>
|
||||
* @copyright 2015 neokjames, f0o, LibreNMS
|
||||
* @license GPL
|
||||
* @package LibreNMS
|
||||
* @subpackage Alerts
|
||||
*/
|
||||
namespace LibreNMS\Alert\Transport;
|
||||
|
||||
use LibreNMS\Interfaces\Alert\Transport;
|
||||
|
||||
class Pushover implements Transport
|
||||
{
|
||||
public function deliverAlert($obj, $opts)
|
||||
{
|
||||
foreach ($opts as $api) {
|
||||
$data = array();
|
||||
$data['token'] = $api['appkey'];
|
||||
$data['user'] = $api['userkey'];
|
||||
switch ($obj['severity']) {
|
||||
case "critical":
|
||||
$severity = "Critical";
|
||||
$data['priority'] = 1;
|
||||
if (!empty($api['sound_critical'])) {
|
||||
$data['sound'] = $api['sound_critical'];
|
||||
}
|
||||
break;
|
||||
case "warning":
|
||||
$severity = "Warning";
|
||||
$data['priority'] = 0;
|
||||
if (!empty($api['sound_warning'])) {
|
||||
$data['sound'] = $api['sound_warning'];
|
||||
}
|
||||
break;
|
||||
}
|
||||
switch ($obj['state']) {
|
||||
case 0:
|
||||
$title_text = "OK";
|
||||
if (!empty($api['sound_ok'])) {
|
||||
$data['sound'] = $api['sound_ok'];
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
$title_text = $severity;
|
||||
break;
|
||||
case 2:
|
||||
$title_text = "Acknowledged";
|
||||
break;
|
||||
}
|
||||
$data['title'] = $title_text . " - " . $obj['hostname'] . " - " . $obj['name'];
|
||||
$message_text = "Timestamp: " . $obj['timestamp'];
|
||||
if (!empty($obj['faults'])) {
|
||||
$message_text .= "\n\nFaults:\n";
|
||||
foreach ($obj['faults'] as $k => $faults) {
|
||||
$message_text .= "#" . $k . " " . $faults['string'] . "\n";
|
||||
}
|
||||
}
|
||||
$data['message'] = $message_text;
|
||||
$curl = curl_init();
|
||||
set_curl_proxy($curl);
|
||||
curl_setopt($curl, CURLOPT_URL, 'https://api.pushover.net/1/messages.json');
|
||||
curl_setopt($curl, CURLOPT_SAFE_UPLOAD, true);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
||||
$ret = curl_exec($curl);
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
if ($code != 200) {
|
||||
var_dump("Pushover returned error"); //FIXME: proper debugging
|
||||
return 'HTTP Status code ' . $code;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
70
LibreNMS/Alert/Transport/Rocket.php
Normal file
70
LibreNMS/Alert/Transport/Rocket.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
/* Copyright (C) 2014 Daniel Preussker <f0o@devilcode.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/>. */
|
||||
|
||||
/**
|
||||
* API Transport
|
||||
* @author ToeiRei <vbauer@stargazer.at>
|
||||
* @copyright 2017 ToeiRei, LibreNMS work based on the work of f0o. It's his work.
|
||||
* @license GPL
|
||||
* @package LibreNMS
|
||||
* @subpackage Alerts
|
||||
*/
|
||||
namespace LibreNMS\Alert\Transport;
|
||||
|
||||
use LibreNMS\Interfaces\Alert\Transport;
|
||||
|
||||
class Rocket implements Transport
|
||||
{
|
||||
public function deliverAlert($obj, $opts)
|
||||
{
|
||||
foreach ($opts as $tmp_api) {
|
||||
$host = $tmp_api['url'];
|
||||
$curl = curl_init();
|
||||
$rocket_msg = strip_tags($obj['msg']);
|
||||
$color = ($obj['state'] == 0 ? '#00FF00' : '#FF0000');
|
||||
$data = array(
|
||||
'attachments' => array(
|
||||
0 => array(
|
||||
'fallback' => $rocket_msg,
|
||||
'color' => $color,
|
||||
'title' => $obj['title'],
|
||||
'text' => $rocket_msg,
|
||||
)
|
||||
),
|
||||
'channel' => $tmp_api['channel'],
|
||||
'username' => $tmp_api['username'],
|
||||
'icon_url' => $tmp_api['icon_url'],
|
||||
'icon_emoji' => $tmp_api['icon_emoji'],
|
||||
);
|
||||
$alert_message = json_encode($data);
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
|
||||
set_curl_proxy($curl);
|
||||
curl_setopt($curl, CURLOPT_URL, $host);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($curl, CURLOPT_POST, true);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $alert_message);
|
||||
|
||||
$ret = curl_exec($curl);
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
if ($code != 200) {
|
||||
var_dump("API '$host' returned Error"); //FIXME: propper debuging
|
||||
var_dump("Params: " . $alert_message); //FIXME: propper debuging
|
||||
var_dump("Return: " . $ret); //FIXME: propper debuging
|
||||
return 'HTTP Status code ' . $code;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
71
LibreNMS/Alert/Transport/Slack.php
Normal file
71
LibreNMS/Alert/Transport/Slack.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/* Copyright (C) 2014 Daniel Preussker <f0o@devilcode.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/>. */
|
||||
|
||||
/**
|
||||
* API Transport
|
||||
* @author f0o <f0o@devilcode.org>
|
||||
* @copyright 2014 f0o, LibreNMS
|
||||
* @license GPL
|
||||
* @package LibreNMS
|
||||
* @subpackage Alerts
|
||||
*/
|
||||
namespace LibreNMS\Alert\Transport;
|
||||
|
||||
use LibreNMS\Interfaces\Alert\Transport;
|
||||
|
||||
class Slack implements Transport
|
||||
{
|
||||
public function deliverAlert($obj, $opts)
|
||||
{
|
||||
foreach ($opts as $tmp_api) {
|
||||
$host = $tmp_api['url'];
|
||||
$curl = curl_init();
|
||||
$slack_msg = strip_tags($obj['msg']);
|
||||
$color = ($obj['state'] == 0 ? '#00FF00' : '#FF0000');
|
||||
$data = array(
|
||||
'attachments' => array(
|
||||
0 => array(
|
||||
'fallback' => $slack_msg,
|
||||
'color' => $color,
|
||||
'title' => $obj['title'],
|
||||
'text' => $slack_msg,
|
||||
'mrkdwn_in' => array('text', 'fallback')
|
||||
)
|
||||
),
|
||||
'channel' => $tmp_api['channel'],
|
||||
'username' => $tmp_api['username'],
|
||||
'icon_url' => $tmp_api['icon_url'],
|
||||
'icon_emoji' => $tmp_api['icon_emoji'],
|
||||
);
|
||||
$alert_message = json_encode($data);
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
|
||||
set_curl_proxy($curl);
|
||||
curl_setopt($curl, CURLOPT_URL, $host);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($curl, CURLOPT_POST, true);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $alert_message);
|
||||
|
||||
$ret = curl_exec($curl);
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
if ($code != 200) {
|
||||
var_dump("API '$host' returned Error"); //FIXME: propper debuging
|
||||
var_dump("Params: " . $alert_message); //FIXME: propper debuging
|
||||
var_dump("Return: " . $ret); //FIXME: propper debuging
|
||||
return 'HTTP Status code ' . $code;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -1,3 +1,4 @@
|
||||
<?php
|
||||
/* 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
|
||||
@@ -20,23 +21,32 @@
|
||||
* @package LibreNMS
|
||||
* @subpackage Alerts
|
||||
*/
|
||||
namespace LibreNMS\Alert\Transport;
|
||||
|
||||
$params = array(
|
||||
use LibreNMS\Interfaces\Alert\Transport;
|
||||
|
||||
class Smseagle implements Transport
|
||||
{
|
||||
public function deliverAlert($obj, $opts)
|
||||
{
|
||||
$params = array(
|
||||
'login' => $opts['user'],
|
||||
'pass' => $opts['token'],
|
||||
'to' => implode(',',$opts['to']),
|
||||
'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);
|
||||
);
|
||||
$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);
|
||||
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") {
|
||||
$ret = curl_exec($curl);
|
||||
if (substr($ret, 0, 2) == "OK") {
|
||||
return true;
|
||||
} else {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
119
LibreNMS/Alert/Transport/Syslog.php
Normal file
119
LibreNMS/Alert/Transport/Syslog.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
/* LibreNMS
|
||||
*
|
||||
* Copyright (C) 2017 Paul Blasquez <pblasquez@gmail.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/>. */
|
||||
namespace LibreNMS\Alert\Transport;
|
||||
|
||||
use LibreNMS\Interfaces\Alert\Transport;
|
||||
|
||||
class Syslog implements Transport
|
||||
{
|
||||
public function deliverAlert($obj, $opts)
|
||||
{
|
||||
$syslog_host = '127.0.0.1';
|
||||
$syslog_port = 514;
|
||||
$state = "Unknown";
|
||||
$facility = 24; // Default facility is 3 * 8 (daemon)
|
||||
$severity = 6; // Default severity is 6 (Informational)
|
||||
$sev_txt = "OK";
|
||||
$device = device_by_id_cache($obj['device_id']); // for event logging
|
||||
|
||||
if (!empty($opts['syslog_facility']) && preg_match("/^\d+$/", $opts['syslog_facility'])) {
|
||||
$facility = (int)$opts['syslog_facility'] * 8;
|
||||
} else {
|
||||
log_event("Syslog facility is not an integer: " . $opts['syslog_facility'], $device, 'poller', 5);
|
||||
}
|
||||
if (!empty($opts['syslog_host'])) {
|
||||
if (preg_match("/[a-zA-Z]/", $opts['syslog_host'])) {
|
||||
$syslog_host = gethostbyname($opts['syslog_host']);
|
||||
if ($syslog_host === $opts['syslog_host']) {
|
||||
log_event("Alphanumeric hostname found but does not resolve to an IP.", $device, 'poller', 5);
|
||||
return false;
|
||||
}
|
||||
} elseif (filter_var($opts['syslog_host'], FILTER_VALIDATE_IP)) {
|
||||
$syslog_host = $opts['syslog_host'];
|
||||
} else {
|
||||
log_event("Syslog host is not a valid IP: " . $opts['syslog_host'], $device, 'poller', 5);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
log_event("Syslog host is empty.", $device, 'poller');
|
||||
}
|
||||
if (!empty($opts['syslog_port']) && preg_match("/^\d+$/", $opts['syslog_port'])) {
|
||||
$syslog_port = $opts['syslog_port'];
|
||||
} else {
|
||||
log_event("Syslog port is not an integer.", $device, 'poller', 5);
|
||||
}
|
||||
|
||||
switch ($obj['severity']) {
|
||||
case "critical":
|
||||
$severity = 2;
|
||||
$sev_txt = "Critical";
|
||||
break;
|
||||
case "warning":
|
||||
$severity = 4;
|
||||
$sev_txt = "Warning";
|
||||
break;
|
||||
}
|
||||
|
||||
switch ($obj['state']) {
|
||||
case 0:
|
||||
$state = "OK";
|
||||
$severity = 6;
|
||||
break;
|
||||
case 1:
|
||||
$state = $sev_txt;
|
||||
break;
|
||||
case 2:
|
||||
$state = "Acknowledged";
|
||||
$severity = 6;
|
||||
break;
|
||||
}
|
||||
|
||||
$priority = $facility + $severity;
|
||||
|
||||
$syslog_prefix = '<'
|
||||
. $priority
|
||||
. '> '
|
||||
. date('M d H:i:s ')
|
||||
. gethostname()
|
||||
. ' librenms'
|
||||
. '['
|
||||
. $obj['device_id']
|
||||
. ']: '
|
||||
. $obj['hostname']
|
||||
. ': ['
|
||||
. $state
|
||||
. '] '
|
||||
. $obj['name'];
|
||||
|
||||
if (($socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP)) === false) {
|
||||
log_event("socket_create() failed: reason: " . socket_strerror(socket_last_error()), $device, 'poller', 5);
|
||||
return false;
|
||||
} else {
|
||||
if (!empty($obj['faults'])) {
|
||||
foreach ($obj['faults'] as $k => $v) {
|
||||
$syslog_msg = $syslog_prefix . ' - ' . $v['string'];
|
||||
socket_sendto($socket, $syslog_msg, strlen($syslog_msg), 0, $syslog_host, $syslog_port);
|
||||
}
|
||||
} else {
|
||||
$syslog_msg = $syslog_prefix;
|
||||
socket_sendto($socket, $syslog_msg, strlen($syslog_msg), 0, $syslog_host, $syslog_port);
|
||||
}
|
||||
socket_close($socket);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
51
LibreNMS/Alert/Transport/Telegram.php
Normal file
51
LibreNMS/Alert/Transport/Telegram.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* transport-telegram.inc.php
|
||||
*
|
||||
* LibreNMS Telegram alerting transport
|
||||
*
|
||||
* 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/>.
|
||||
*
|
||||
* @package LibreNMS
|
||||
* @link http://librenms.org
|
||||
* @copyright 2017 Neil Lathwood
|
||||
* @author Neil Lathwood <neil@lathwood.co.uk>
|
||||
*/
|
||||
namespace LibreNMS\Alert\Transport;
|
||||
|
||||
use LibreNMS\Interfaces\Alert\Transport;
|
||||
|
||||
class Telegram implements Transport
|
||||
{
|
||||
public function deliverAlert($obj, $opts)
|
||||
{
|
||||
foreach ($opts as $chat_id => $data) {
|
||||
$curl = curl_init();
|
||||
set_curl_proxy($curl);
|
||||
$text = urlencode($obj['msg']);
|
||||
print_r($data);
|
||||
curl_setopt($curl, CURLOPT_URL, ("https://api.telegram.org/bot{$data['token']}/sendMessage?chat_id={$data['chat_id']}&text=$text"));
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
$ret = curl_exec($curl);
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
if ($code != 200) {
|
||||
var_dump("API '$host' returned Error"); //FIXME: propper debuging
|
||||
var_dump("Params: " . $api); //FIXME: propper debuging
|
||||
var_dump("Return: " . $ret); //FIXME: propper debuging
|
||||
return 'HTTP Status code ' . $code;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
66
LibreNMS/Alert/Transport/Victorops.php
Normal file
66
LibreNMS/Alert/Transport/Victorops.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/* Copyright (C) 2015 Daniel Preussker <f0o@devilcode.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/>. */
|
||||
|
||||
/**
|
||||
* VictorOps Generic-API Transport - Based on PagerDuty transport
|
||||
* @author f0o <f0o@devilcode.org>
|
||||
* @author laf <neil@librenms.org>
|
||||
* @copyright 2015 f0o, laf, LibreNMS
|
||||
* @license GPL
|
||||
* @package LibreNMS
|
||||
* @subpackage Alerts
|
||||
*/
|
||||
namespace LibreNMS\Alert\Transport;
|
||||
|
||||
use LibreNMS\Interfaces\Alert\Transport;
|
||||
|
||||
class Victorops implements Transport
|
||||
{
|
||||
public function deliverAlert($obj, $opts)
|
||||
{
|
||||
$url = $opts['url'];
|
||||
|
||||
$protocol = array(
|
||||
'entity_id' => ($obj['id'] ? $obj['id'] : $obj['uid']),
|
||||
'state_start_time' => strtotime($obj['timestamp']),
|
||||
'monitoring_tool' => 'librenms',
|
||||
);
|
||||
if ($obj['state'] == 0) {
|
||||
$protocol['message_type'] = 'recovery';
|
||||
} elseif ($obj['state'] == 2) {
|
||||
$protocol['message_type'] = 'acknowledgement';
|
||||
} elseif ($obj['state'] == 1) {
|
||||
$protocol['message_type'] = 'critical';
|
||||
}
|
||||
|
||||
foreach ($obj['faults'] as $fault => $data) {
|
||||
$protocol['state_message'] .= $data['string'];
|
||||
}
|
||||
|
||||
$curl = curl_init();
|
||||
set_curl_proxy($curl);
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
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("VictorOps returned Error, retry later"); //FIXME: propper debuging
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
38
LibreNMS/Interfaces/Alert/Transport.php
Normal file
38
LibreNMS/Interfaces/Alert/Transport.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* Transport.php
|
||||
*
|
||||
* An interface for the transport of alerts.
|
||||
*
|
||||
* 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/>.
|
||||
*
|
||||
* @package LibreNMS
|
||||
* @link http://librenms.org
|
||||
* @copyright 2017 Robrecht Plaisier
|
||||
* @author Robbrecht Plaisier <librenms@mcq8.be>
|
||||
*/
|
||||
|
||||
namespace LibreNMS\Interfaces\Alert;
|
||||
|
||||
interface Transport
|
||||
{
|
||||
/**
|
||||
* Gets called when an alert is sent
|
||||
*
|
||||
* @param $alert_data array An array created by DescribeAlert
|
||||
* @param $opts array|true The options from $config['alert']['transports'][$transport]
|
||||
* @return bool Returns if the call was successful
|
||||
*/
|
||||
public function deliverAlert($alert_data, $opts);
|
||||
}
|
@@ -2,7 +2,7 @@ source: Alerting/Transports.md
|
||||
|
||||
# Transports
|
||||
|
||||
Transports are located within `includes/alerts/transports.*.php` and defined as well as configured via ~~`$config['alert']['transports']['Example'] = 'Some Options'`~~.
|
||||
Transports are located within `LibreNMS/Alert/Transport/` and defined as well as configured via ~~`$config['alert']['transports']['Example'] = 'Some Options'`~~.
|
||||
|
||||
Contacts will be gathered automatically and passed to the configured transports.
|
||||
By default the Contacts will be only gathered when the alert triggers and will ignore future changes in contacts for the incident. If you want contacts to be re-gathered before each dispatch, please set ~~`$config['alert']['fixed-contacts'] = false;`~~ in your config.php.
|
||||
|
@@ -46,11 +46,12 @@ $obj = array(
|
||||
|
||||
$status = 'error';
|
||||
|
||||
if (file_exists($config['install_dir']."/includes/alerts/transport.".$transport.".php")) {
|
||||
$class = 'LibreNMS\\Alert\\Transport\\' . ucfirst($transport);
|
||||
if (class_exists($class)) {
|
||||
$opts = $config['alert']['transports'][$transport];
|
||||
if ($opts) {
|
||||
eval('$tmp = function($obj,$opts) { global $config; '.file_get_contents($config['install_dir'].'/includes/alerts/transport.'.$transport.'.php').' return false; };');
|
||||
$tmp = $tmp($obj, $opts);
|
||||
$instance = new $class;
|
||||
$tmp = $instance->deliverAlert($obj, $opts);
|
||||
if ($tmp) {
|
||||
$status = 'ok';
|
||||
}
|
||||
|
@@ -854,13 +854,14 @@ function ExtTransports($obj)
|
||||
if (is_array($opts)) {
|
||||
$opts = array_filter($opts);
|
||||
}
|
||||
if (($opts === true || !empty($opts)) && $opts != false && file_exists($config['install_dir'].'/includes/alerts/transport.'.$transport.'.php')) {
|
||||
$class = 'LibreNMS\\Alert\\Transport\\' . ucfirst($transport);
|
||||
if (($opts === true || !empty($opts)) && $opts != false && class_exists($class)) {
|
||||
$obj['transport'] = $transport;
|
||||
$msg = FormatAlertTpl($obj);
|
||||
$obj['msg'] = $msg;
|
||||
echo $transport.' => ';
|
||||
eval('$tmp = function($obj,$opts) { global $config; '.file_get_contents($config['install_dir'].'/includes/alerts/transport.'.$transport.'.php').' return false; };');
|
||||
$tmp = $tmp($obj, $opts);
|
||||
$instance = new $class;
|
||||
$tmp = $instance->deliverAlert($obj, $opts);
|
||||
$prefix = array( 0=>"recovery", 1=>$obj['severity']." alert", 2=>"acknowledgment" );
|
||||
$prefix[3] = &$prefix[0];
|
||||
$prefix[4] = &$prefix[0];
|
||||
|
@@ -1,49 +0,0 @@
|
||||
/* Copyright (C) 2014 Daniel Preussker <f0o@devilcode.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/>. */
|
||||
|
||||
/**
|
||||
* API Transport
|
||||
* @author f0o <f0o@devilcode.org>
|
||||
* @copyright 2014 f0o, LibreNMS
|
||||
* @license GPL
|
||||
* @package LibreNMS
|
||||
* @subpackage Alerts
|
||||
*/
|
||||
|
||||
foreach( $opts as $method=>$apis ) {
|
||||
// var_dump($method); //FIXME: propper debuging
|
||||
foreach( $apis as $api ) {
|
||||
// var_dump($api); //FIXME: propper debuging
|
||||
list($host, $api) = explode("?",$api,2);
|
||||
foreach( $obj as $k=>$v ) {
|
||||
$api = str_replace("%".$k,$method == "get" ? urlencode($v) : $v, $api);
|
||||
}
|
||||
// var_dump($api); //FIXME: propper debuging
|
||||
$curl = curl_init();
|
||||
set_curl_proxy($curl);
|
||||
curl_setopt($curl, CURLOPT_URL, ($method == "get" ? $host."?".$api : $host) );
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, strtoupper($method));
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $api);
|
||||
$ret = curl_exec($curl);
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
if( $code != 200 ) {
|
||||
var_dump("API '$host' returned Error"); //FIXME: propper debuging
|
||||
var_dump("Params: ".$api); //FIXME: propper debuging
|
||||
var_dump("Return: ".$ret); //FIXME: propper debuging
|
||||
return 'HTTP Status code '.$code;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
@@ -1,91 +0,0 @@
|
||||
/* Copyright (C) 2015 James Campbell <neokjames@gmail.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/>. */
|
||||
|
||||
/* Copyright (C) 2015 Daniel Preussker <f0o@devilcode.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/>. */
|
||||
|
||||
/**
|
||||
* Boxcar API Transport
|
||||
* @author trick77 <jan@trick77.com>
|
||||
* @copyright 2015 trick77, neokjames, f0o, LibreNMS
|
||||
* @license GPL
|
||||
* @package LibreNMS
|
||||
* @subpackage Alerts
|
||||
*/
|
||||
|
||||
foreach( $opts as $api ) {
|
||||
$data = array();
|
||||
$data['user_credentials'] = $api['access_token'];
|
||||
$data['notification[source_name]'] = $config['project_id'];
|
||||
switch( $obj['severity'] ) {
|
||||
case "critical":
|
||||
$severity = "Critical";
|
||||
if( !empty( $api['sound_critical'] ) ) {
|
||||
$data['notification[sound]'] = $api['sound_critical'];
|
||||
}
|
||||
break;
|
||||
case "warning":
|
||||
$severity = "Warning";
|
||||
if( !empty( $api['sound_warning'] ) ) {
|
||||
$data['notification[sound]'] = $api['sound_warning'];
|
||||
}
|
||||
break;
|
||||
}
|
||||
switch( $obj['state'] ) {
|
||||
case 0:
|
||||
$title_text = "OK";
|
||||
if( !empty( $api['sound_ok'] ) ) {
|
||||
$data['notification[sound]'] = $api['sound_ok'];
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
$title_text = $severity;
|
||||
break;
|
||||
case 2:
|
||||
$title_text = "Acknowledged";
|
||||
break;
|
||||
}
|
||||
$data['notification[title]'] = $title_text." - ".$obj['hostname']." - ".$obj['name'];
|
||||
$message_text = "Timestamp: ".$obj['timestamp'];
|
||||
if( !empty( $obj['faults'] ) ) {
|
||||
$message_text .= "\n\nFaults:\n";
|
||||
foreach($obj['faults'] as $k => $faults) {
|
||||
$message_text .= "#".$k." ".$faults['string']."\n";
|
||||
}
|
||||
}
|
||||
$data['notification[long_message]'] = $message_text;
|
||||
$curl = curl_init();
|
||||
set_curl_proxy($curl);
|
||||
curl_setopt($curl, CURLOPT_URL, 'https://new.boxcar.io/api/notifications');
|
||||
curl_setopt($curl, CURLOPT_SAFE_UPLOAD, true);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
||||
$ret = curl_exec($curl);
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
if( $code != 201 ) {
|
||||
var_dump("Boxcar returned error"); //FIXME: proper debugging
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
@@ -1,57 +0,0 @@
|
||||
|
||||
// Configurations
|
||||
$host = $opts["host"];
|
||||
$port = $opts["port"];
|
||||
$user = $opts["user"];
|
||||
$pass = $opts["passwd"];
|
||||
$vhost = $opts["vhost"];
|
||||
$exchange = "canopsis.events";
|
||||
|
||||
// Connection
|
||||
$conn = new PhpAmqpLib\Connection\AMQPConnection($host, $port, $user, $pass, $vhost);
|
||||
$ch = $conn->channel();
|
||||
|
||||
// Declare exchange (if not exist)
|
||||
// exchange_declare($exchange, $type, $passive=false, $durable=false, $auto_delete=true, $internal=false, $nowait=false, $arguments=null, $ticket=null)
|
||||
$ch->exchange_declare($exchange, 'topic', false, true, false);
|
||||
|
||||
// Create Canopsis event, see: https://github.com/capensis/canopsis/wiki/Event-specification
|
||||
switch ($obj['severity'])
|
||||
{
|
||||
case "ok": $state = 0;
|
||||
break;
|
||||
case "warning": $state = 1;
|
||||
break;
|
||||
case "critical": $state = 2;
|
||||
break;
|
||||
default: $state = 3;
|
||||
}
|
||||
$msg_body = array(
|
||||
"timestamp" => time(),
|
||||
"connector" => "librenms",
|
||||
"connector_name" => "LibreNMS1",
|
||||
"event_type" => "check",
|
||||
"source_type" => "resource",
|
||||
"component" => $obj['hostname'],
|
||||
"resource" => $obj['faults'][1]['storage_descr'],
|
||||
"state" => $state,
|
||||
"state_type" => 1,
|
||||
"output" => $obj['msg'],
|
||||
"display_name" => "librenms"
|
||||
);
|
||||
$msg_raw = json_encode($msg_body);
|
||||
|
||||
// Build routing key
|
||||
if ($msg_body['source_type'] == "resource")
|
||||
$msg_rk = $msg_rk . "." . $msg_body['resource'];
|
||||
else
|
||||
$msg_rk = $msg_body['connector'].".".$msg_body['connector_name'].".".$msg_body['event_type'].".".$msg_body['source_type'].".".$msg_body['component'];
|
||||
|
||||
// Publish Event
|
||||
$msg = new PhpAmqpLib\Message\AMQPMessage($msg_raw, array('content_type' => 'application/json', 'delivery_mode' => 2));
|
||||
$ch->basic_publish($msg, $exchange, $msg_rk);
|
||||
|
||||
// Close connection
|
||||
$ch->close();
|
||||
$conn->close();
|
||||
return true;
|
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* LibreNMS
|
||||
*
|
||||
* Copyright (c) 2017 Søren Friis Rosiak <sorenrosiak@gmail.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. Please see LICENSE.txt at the top level of
|
||||
* the source code distribution for details.
|
||||
*/
|
||||
|
||||
$token = $opts['token'];
|
||||
$roomId = $opts['roomid'];
|
||||
$text = strip_tags($obj['msg']);
|
||||
$data = array(
|
||||
'roomId' => $roomId,
|
||||
'text' => $text
|
||||
);
|
||||
$curl = curl_init();
|
||||
set_curl_proxy($curl);
|
||||
curl_setopt($curl, CURLOPT_URL, 'https://api.ciscospark.com/v1/messages');
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
|
||||
'Content-type' => 'application/json',
|
||||
'Expect:',
|
||||
'Authorization: Bearer '.$token
|
||||
));
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
||||
$ret = curl_exec($curl);
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
|
||||
if ($code != 200) {
|
||||
var_dump("Cisco Spark returned Error, retry later");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
@@ -1,181 +0,0 @@
|
||||
/* LibreNMS
|
||||
*
|
||||
* Copyright (C) 2017 Paul Blasquez <pblasquez@gmail.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/>. */
|
||||
|
||||
$es_host = '127.0.0.1';
|
||||
$es_port = 9200;
|
||||
$index = strftime("librenms-%Y.%m.%d");
|
||||
$type = 'alert';
|
||||
$severity = $obj['severity'];
|
||||
$device = device_by_id_cache($obj['device_id']); // for event logging
|
||||
|
||||
if (!empty($opts['es_host'])) {
|
||||
if (preg_match("/[a-zA-Z]/", $opts['es_host'])) {
|
||||
$es_host = gethostbyname($opts['es_host']);
|
||||
if ($es_host === $opts['es_host']) {
|
||||
return "Alphanumeric hostname found but does not resolve to an IP.";
|
||||
}
|
||||
} elseif (filter_var($opts['es_host'], FILTER_VALIDATE_IP)) {
|
||||
$es_host = $opts['es_host'];
|
||||
} else {
|
||||
return "Elasticsearch host is not a valid IP: " . $opts['es_host'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($opts['es_port']) && preg_match("/^\d+$/", $opts['es_port'])) {
|
||||
$es_port = $opts['es_port'];
|
||||
}
|
||||
|
||||
if (!empty($opts['es_index'])) {
|
||||
$index = strftime($opts['es_index']);
|
||||
}
|
||||
|
||||
$host = $es_host.':'.$es_port.'/'.$index.'/'.$type;
|
||||
|
||||
switch( $obj['state'] ) {
|
||||
case 0:
|
||||
$state = "ok";
|
||||
break;
|
||||
case 1:
|
||||
$state = $severity;
|
||||
break;
|
||||
case 2:
|
||||
$state = "acknowledged";
|
||||
break;
|
||||
case 3:
|
||||
$state = "worse";
|
||||
break;
|
||||
case 4:
|
||||
$state = "better";
|
||||
break;
|
||||
}
|
||||
|
||||
$data = array(
|
||||
'@timestamp' => strftime("%Y-%m-%dT%T"),
|
||||
"host" => gethostname(),
|
||||
"location" => $obj['location'],
|
||||
"title" => $obj['name'],
|
||||
"message" => $obj['string'],
|
||||
"device_id" => $obj['device_id'],
|
||||
"device_name" => $obj['hostname'],
|
||||
"device_hardware" => $obj['hardware'],
|
||||
"device_version" => $obj['version'],
|
||||
"state" => $state,
|
||||
"severity" => $severity,
|
||||
"first_occurrence" => $obj['timestamp'],
|
||||
"entity_type" => "device",
|
||||
"entity_tab" => "overview",
|
||||
"entity_id" => $obj['device_id'],
|
||||
"entity_name" => $obj['hostname'],
|
||||
"entity_descr" => $obj['sysDescr'],
|
||||
);
|
||||
|
||||
if( !empty( $obj['faults'] ) ) {
|
||||
foreach($obj['faults'] as $k => $v) {
|
||||
$curl = curl_init();
|
||||
$data['message'] = $v['string'];
|
||||
switch (true) {
|
||||
case (array_key_exists('port_id', $v)):
|
||||
$data['entity_type'] = 'port';
|
||||
$data['entity_tab'] = 'port';
|
||||
$data['entity_id'] = $v['port_id'];
|
||||
$data['entity_name'] = $v['ifName'];
|
||||
$data['entity_descr'] = $v['ifAlias'];
|
||||
break;
|
||||
case (array_key_exists('sensor_id', $v)):
|
||||
$data['entity_type'] = $v['sensor_class'];
|
||||
$data['entity_tab'] = 'health';
|
||||
$data['entity_id'] = $v['sensor_id'];
|
||||
$data['entity_name'] = $v['sensor_descr'];
|
||||
$data['entity_descr'] = $v['sensor_type'];
|
||||
break;
|
||||
case (array_key_exists('mempool_id', $v)):
|
||||
$data['entity_type'] = 'mempool';
|
||||
$data['entity_tab'] = 'health';
|
||||
$data['entity_id'] = $v['mempool_id'];
|
||||
$data['entity_name'] = $v['mempool_index'];
|
||||
$data['entity_descr'] = $v['mempool_descr'];
|
||||
break;
|
||||
case (array_key_exists('storage_id', $v)):
|
||||
$data['entity_type'] = 'storage';
|
||||
$data['entity_tab'] = 'health';
|
||||
$data['entity_id'] = $v['storage_id'];
|
||||
$data['entity_name'] = $v['storage_index'];
|
||||
$data['entity_descr'] = $v['storage_descr'];
|
||||
break;
|
||||
case (array_key_exists('processor_id', $v)):
|
||||
$data['entity_type'] = 'processor';
|
||||
$data['entity_tab'] = 'health';
|
||||
$data['entity_id'] = $v['processor_id'];
|
||||
$data['entity_name'] = $v['processor_type'];
|
||||
$data['entity_descr'] = $v['processor_descr'];
|
||||
break;
|
||||
case (array_key_exists('bgpPeer_id', $v)):
|
||||
$data['entity_type'] = 'bgp';
|
||||
$data['entity_tab'] = 'routing';
|
||||
$data['entity_id'] = $v['bgpPeer_id'];
|
||||
$data['entity_name'] = 'local: '.$v['bgpPeerLocalAddr'].' - AS'.$obj['bgpLocalAs'];
|
||||
$data['entity_descr'] = 'remote: '.$v['bgpPeerIdentifier'].' - AS'.$v['bgpPeerRemoteAs'];
|
||||
break;
|
||||
case (array_key_exists('tunnel_id', $v)):
|
||||
$data['entity_type'] = 'ipsec_tunnel';
|
||||
$data['entity_tab'] = 'routing';
|
||||
$data['entity_id'] = $v['tunnel_id'];
|
||||
$data['entity_name'] = $v['tunnel_name'];
|
||||
$data['entity_descr'] = 'local: '.$v['local_addr'].':'.$v['local_port'].', remote: '.$v['peer_addr'].':'.$v['peer_port'];
|
||||
break;
|
||||
default:
|
||||
$data['entity_type'] = 'generic';
|
||||
break;
|
||||
}
|
||||
$alert_message = json_encode($data);
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
|
||||
'Content-Type: application/json')
|
||||
);
|
||||
if ($opts['es_proxy'] === true) {
|
||||
set_curl_proxy($curl);
|
||||
}
|
||||
curl_setopt($curl, CURLOPT_URL, $host);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($curl, CURLOPT_POST,true);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $alert_message );
|
||||
|
||||
$ret = curl_exec($curl);
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
if( $code != 200 && $code != 201 ) {
|
||||
return $host.' returned HTTP Status code '.$code.' for '.$alert_message;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$curl = curl_init();
|
||||
$alert_message = json_encode($data);
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
|
||||
'Content-Type: application/json')
|
||||
);
|
||||
if ($opts['es_proxy'] === true) {
|
||||
set_curl_proxy($curl);
|
||||
}
|
||||
curl_setopt($curl, CURLOPT_URL, $host);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($curl, CURLOPT_POST,true);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $alert_message );
|
||||
|
||||
$ret = curl_exec($curl);
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
if( $code != 200 && $code != 201 ) {
|
||||
return $host.' returned HTTP Status code '.$code.' for '.$alert_message;
|
||||
}
|
||||
}
|
||||
return true;
|
@@ -1,92 +0,0 @@
|
||||
/* Copyright (C) 2014 Daniel Preussker <f0o@devilcode.org>, Tyler Christiansen <code@tylerc.me>
|
||||
* 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/>. */
|
||||
|
||||
/*
|
||||
* API Transport
|
||||
* @author Tyler Christiansen <code@tylerc.me>
|
||||
* @copyright 2014 Daniel Preussker, Tyler Christiansen, LibreNMS
|
||||
* @license GPL
|
||||
* @package LibreNMS
|
||||
* @subpackage Alerts
|
||||
*/
|
||||
|
||||
// loop through each room
|
||||
foreach($opts as $option) {
|
||||
$version = 1;
|
||||
if (stripos($option['url'], "v2")) {
|
||||
$version = 2;
|
||||
}
|
||||
|
||||
// Generate our URL from the base URL + room_id and the auth token if the version is 2.
|
||||
$url = $option['url'];
|
||||
if ($version == 2) {
|
||||
$url .= "/".urlencode($option["room_id"])."/notification?auth_token=".urlencode($option["auth_token"]);
|
||||
}
|
||||
foreach($obj as $key=>$value) {
|
||||
$api = str_replace("%".$key, $method == "get" ? urlencode($value) : $value, $api);
|
||||
}
|
||||
$curl = curl_init();
|
||||
|
||||
if (empty($obj["msg"])) {
|
||||
return "Empty Message";
|
||||
}
|
||||
|
||||
if (empty($option["message_format"])) {
|
||||
$option["message_format"] = 'text';
|
||||
}
|
||||
|
||||
// Sane default of making the message color green if the message indicates
|
||||
// that the alert recovered. If it rebooted, make it yellow.
|
||||
if(stripos($obj["msg"], "recovered")) {
|
||||
$color = "green";
|
||||
} elseif(stripos($obj["msg"], "rebooted")) {
|
||||
$color = "yellow";
|
||||
} else {
|
||||
if (empty($option["color"]) || $option["color"] == 'u') {
|
||||
$color = 'red';
|
||||
} else {
|
||||
$color = $option["color"];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$data[] = "message=".urlencode($obj["msg"]);
|
||||
if ($version == 1) {
|
||||
$data[] = "room_id=".urlencode($option["room_id"]);
|
||||
}
|
||||
$data[] = "from=".urlencode($option["from"]);
|
||||
$data[] = "color=".urlencode($color);
|
||||
$data[] = "notify=".urlencode($option["notify"]);
|
||||
$data[] = "message_format=".urlencode($option["message_format"]);
|
||||
|
||||
$data = implode('&', $data);
|
||||
set_curl_proxy($curl);
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($curl, CURLOPT_POST, true);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
|
||||
'Content-Type: application/x-www-form-urlencoded',
|
||||
));
|
||||
$ret = curl_exec($curl);
|
||||
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
if($code != 200 && $code != 204) {
|
||||
var_dump("API '$url' returned Error");
|
||||
var_dump("Params: " . $message);
|
||||
var_dump("Return: " . $ret);
|
||||
return 'HTTP Status code '.$code;
|
||||
}
|
||||
}
|
||||
return true;
|
@@ -1,68 +0,0 @@
|
||||
/* Copyright (C) 2015 Aldemir Akpinar <aldemir.akpinar@gmail.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/>. */
|
||||
|
||||
/**
|
||||
* Jira API Transport
|
||||
* @author Aldemir Akpinar <aldemir.akpinar@gmail.com>
|
||||
* @copyright 2017 Aldemir Akpinar, LibreNMS
|
||||
* @license GPL
|
||||
* @package LibreNMS
|
||||
* @subpackage Alerts
|
||||
*/
|
||||
|
||||
// Don't create tickets for resolutions
|
||||
if($obj['severity'] == 'recovery' && $obj['msg'] != 'This is a test alert') {
|
||||
return True;
|
||||
}
|
||||
|
||||
$device = device_by_id_cache($obj['device_id']); // for event logging
|
||||
|
||||
$username = $opts['username'];
|
||||
$password = $opts['password'];
|
||||
$prjkey = $opts['prjkey'];
|
||||
$issuetype = $opts['issuetype'];
|
||||
$details = "Librenms alert for: ".$obj['hostname'];
|
||||
$description = $obj['msg'];
|
||||
$url = $opts['url'].'/rest/api/latest/issue';
|
||||
$curl = curl_init();
|
||||
|
||||
$data = array("project" => array("key" => $prjkey),
|
||||
"summary" => $details,
|
||||
"description" => $description,
|
||||
"issuetype" => array("name" => $issuetype));
|
||||
$postdata = array("fields" => $data);
|
||||
$datastring = json_encode($postdata);
|
||||
|
||||
set_curl_proxy($curl);
|
||||
|
||||
$headers = array('Accept: application/json', 'Content-Type: application/json');
|
||||
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt($curl, CURLOPT_USERPWD, "$username:$password");
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($curl, CURLOPT_VERBOSE, 1);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $datastring);
|
||||
|
||||
$ret = curl_exec($curl);
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
if( $code == 200 ) {
|
||||
$jiraout = json_decode($ret, true);
|
||||
d_echo("Created jira issue ".$jiraout['key']." for ".$device);
|
||||
return true;
|
||||
} else {
|
||||
d_echo("Jira connection error: ".serialize($ret));
|
||||
return false;
|
||||
}
|
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* LibreNMS
|
||||
*
|
||||
* Copyright (c) 2016 Søren Friis Rosiak <sorenrosiak@gmail.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. Please see LICENSE.txt at the top level of
|
||||
* the source code distribution for details.
|
||||
*/
|
||||
|
||||
$url = $opts['url'];
|
||||
$color = ($obj['state'] == 0 ? '#00FF00' : '#FF0000');
|
||||
$data = array(
|
||||
'title' => ($obj['name'] ? $obj['name'] . ' on ' . $obj['hostname'] : $obj['title']) ,
|
||||
'themeColor' => $color ,
|
||||
'text' => strip_tags($obj['msg'])
|
||||
);
|
||||
$curl = curl_init();
|
||||
set_curl_proxy($curl);
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
|
||||
'Content-type' => 'application/json',
|
||||
'Expect:'
|
||||
));
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
|
||||
$ret = curl_exec($curl);
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
|
||||
if ($code != 200) {
|
||||
var_dump("Microsoft Teams returned Error, retry later");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
@@ -1,48 +0,0 @@
|
||||
/* Copyright (C) 2014 Daniel Preussker <f0o@devilcode.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/>. */
|
||||
|
||||
/**
|
||||
* Nagios Transport
|
||||
* @author f0o <f0o@devilcode.org>
|
||||
* @copyright 2014 f0o, LibreNMS
|
||||
* @license GPL
|
||||
* @package LibreNMS
|
||||
* @subpackage Alerts
|
||||
*/
|
||||
|
||||
/*
|
||||
host_perfdata_file_template=
|
||||
[HOSTPERFDATA]\t
|
||||
$TIMET$\t
|
||||
$HOSTNAME$\t
|
||||
HOST\t
|
||||
$HOSTSTATE$\t
|
||||
$HOSTEXECUTIONTIME$\t
|
||||
$HOSTLATENCY$\t
|
||||
$HOSTOUTPUT$\t
|
||||
$HOSTPERFDATA$
|
||||
*/
|
||||
|
||||
$format = '';
|
||||
$format .= "[HOSTPERFDATA]\t";
|
||||
$format .= $obj['timestamp']."\t";
|
||||
$format .= $obj['hostname']."\t";
|
||||
$format .= md5($obj['rule'])."\t"; //FIXME: Better entity
|
||||
$format .= ($obj['state'] ? $obj['severity'] : "ok")."\t";
|
||||
$format .= "0\t";
|
||||
$format .= "0\t";
|
||||
$format .= str_replace("\n","",nl2br($obj['msg']))."\t";
|
||||
$format .= "NULL"; //FIXME: What's the HOSTPERFDATA equivalent for LibreNMS? Oo
|
||||
$format .= "\n";
|
||||
return file_put_contents($opts, $format);
|
@@ -1,43 +0,0 @@
|
||||
/* 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,46 +0,0 @@
|
||||
/*
|
||||
* LibreNMS
|
||||
*
|
||||
* Copyright (c) 2016 Søren Friis Rosiak <sorenrosiak@gmail.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. Please see LICENSE.txt at the top level of
|
||||
* the source code distribution for details.
|
||||
*/
|
||||
|
||||
$url = $opts['url'];
|
||||
$token = $opts['token'];
|
||||
|
||||
foreach (parse_email($config['email_from']) as $from => $from_name) {
|
||||
$email = $from_name . ' <' . $from . '>';
|
||||
break;
|
||||
}
|
||||
|
||||
$protocol = array(
|
||||
'name' => 'LibreNMS',
|
||||
'email' => $email,
|
||||
'subject' => ($obj['name'] ? $obj['name'] . ' on ' . $obj['hostname'] : $obj['title']) ,
|
||||
'message' => strip_tags($obj['msg']) ,
|
||||
'ip' => $_SERVER['REMOTE_ADDR'],
|
||||
'attachments' => array() ,
|
||||
);
|
||||
$curl = curl_init();
|
||||
set_curl_proxy($curl);
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
|
||||
'Content-type' => 'application/json',
|
||||
'Expect:',
|
||||
'X-API-Key: ' . $token
|
||||
));
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($protocol));
|
||||
$ret = curl_exec($curl);
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
|
||||
if ($code != 201) {
|
||||
var_dump("osTicket returned Error, retry later");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
@@ -1,54 +0,0 @@
|
||||
/* Copyright (C) 2015 Daniel Preussker <f0o@devilcode.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/>. */
|
||||
|
||||
/**
|
||||
* PagerDuty Generic-API Transport
|
||||
* @author f0o <f0o@devilcode.org>
|
||||
* @copyright 2015 f0o, LibreNMS
|
||||
* @license GPL
|
||||
* @package LibreNMS
|
||||
* @subpackage Alerts
|
||||
*/
|
||||
|
||||
$protocol = array(
|
||||
'service_key' => $opts,
|
||||
'incident_key' => ($obj['id'] ? $obj['id'] : $obj['uid']),
|
||||
'description' => ($obj['name'] ? $obj['name'].' on '.$obj['hostname'] : $obj['title']),
|
||||
'client' => 'LibreNMS',
|
||||
);
|
||||
if( $obj['state'] == 0 ) {
|
||||
$protocol['event_type'] = 'resolve';
|
||||
}
|
||||
elseif( $obj['state'] == 2 ) {
|
||||
$protocol['event_type'] = 'acknowledge';
|
||||
}
|
||||
else {
|
||||
$protocol['event_type'] = 'trigger';
|
||||
}
|
||||
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;
|
@@ -1,43 +0,0 @@
|
||||
/* 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/>. */
|
||||
|
||||
/**
|
||||
* PlaySMS API Transport
|
||||
* @author f0o <f0o@librenms.org>
|
||||
* @copyright 2015 f0o, LibreNMS
|
||||
* @license GPL
|
||||
* @package LibreNMS
|
||||
* @subpackage Alerts
|
||||
*/
|
||||
|
||||
$data = array("u" => $opts['user'], "h" => $opts['token'], "to" => implode(',',$opts['to']), "msg" => $obj['title']);
|
||||
if (!empty($opts['from'])) {
|
||||
$data["from"] = $opts['from'];
|
||||
}
|
||||
$url = $opts['url'].'&op=pv&'.http_build_query($data);
|
||||
$curl = curl_init($url);
|
||||
|
||||
set_curl_proxy($curl);
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET");
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
|
||||
$ret = curl_exec($curl);
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
if( $code > 202 ) {
|
||||
if( $debug ) {
|
||||
var_dump($ret);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
@@ -1,48 +0,0 @@
|
||||
/* 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/>. */
|
||||
|
||||
/**
|
||||
* Pushbullet API Transport
|
||||
* @author f0o <f0o@librenms.org>
|
||||
* @copyright 2015 f0o, LibreNMS
|
||||
* @license GPL
|
||||
* @package LibreNMS
|
||||
* @subpackage Alerts
|
||||
*/
|
||||
|
||||
// Note: At this point it might be useful to iterate through $obj['contacts'] and send each of them a note ?
|
||||
|
||||
$data = array("type" => "note", "title" => $obj['title'], "body" => $obj['msg']);
|
||||
$data = json_encode($data);
|
||||
|
||||
$curl = curl_init('https://api.pushbullet.com/v2/pushes');
|
||||
set_curl_proxy($curl);
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
|
||||
'Content-Type: application/json',
|
||||
'Content-Length: '.strlen($data),
|
||||
'Authorization: Bearer '.$opts,
|
||||
));
|
||||
|
||||
$ret = curl_exec($curl);
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
if( $code > 201 ) {
|
||||
if( $debug ) {
|
||||
var_dump($ret);
|
||||
}
|
||||
return 'HTTP Status code '.$code;
|
||||
}
|
||||
return true;
|
@@ -1,93 +0,0 @@
|
||||
/* Copyright (C) 2015 James Campbell <neokjames@gmail.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/>. */
|
||||
|
||||
/* Copyright (C) 2015 Daniel Preussker <f0o@devilcode.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/>. */
|
||||
|
||||
/**
|
||||
* Pushover API Transport
|
||||
* @author neokjames <neokjames@gmail.com>
|
||||
* @copyright 2015 neokjames, f0o, LibreNMS
|
||||
* @license GPL
|
||||
* @package LibreNMS
|
||||
* @subpackage Alerts
|
||||
*/
|
||||
|
||||
foreach( $opts as $api ) {
|
||||
$data = array();
|
||||
$data['token'] = $api['appkey'];
|
||||
$data['user'] = $api['userkey'];
|
||||
switch( $obj['severity'] ) {
|
||||
case "critical":
|
||||
$severity = "Critical";
|
||||
$data['priority'] = 1;
|
||||
if( !empty( $api['sound_critical'] ) ) {
|
||||
$data['sound'] = $api['sound_critical'];
|
||||
}
|
||||
break;
|
||||
case "warning":
|
||||
$severity = "Warning";
|
||||
$data['priority'] = 0;
|
||||
if( !empty( $api['sound_warning'] ) ) {
|
||||
$data['sound'] = $api['sound_warning'];
|
||||
}
|
||||
break;
|
||||
}
|
||||
switch( $obj['state'] ) {
|
||||
case 0:
|
||||
$title_text = "OK";
|
||||
if( !empty( $api['sound_ok'] ) ) {
|
||||
$data['sound'] = $api['sound_ok'];
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
$title_text = $severity;
|
||||
break;
|
||||
case 2:
|
||||
$title_text = "Acknowledged";
|
||||
break;
|
||||
}
|
||||
$data['title'] = $title_text." - ".$obj['hostname']." - ".$obj['name'];
|
||||
$message_text = "Timestamp: ".$obj['timestamp'];
|
||||
if( !empty( $obj['faults'] ) ) {
|
||||
$message_text .= "\n\nFaults:\n";
|
||||
foreach($obj['faults'] as $k => $faults) {
|
||||
$message_text .= "#".$k." ".$faults['string']."\n";
|
||||
}
|
||||
}
|
||||
$data['message'] = $message_text;
|
||||
$curl = curl_init();
|
||||
set_curl_proxy($curl);
|
||||
curl_setopt($curl, CURLOPT_URL, 'https://api.pushover.net/1/messages.json');
|
||||
curl_setopt($curl, CURLOPT_SAFE_UPLOAD, true);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
||||
$ret = curl_exec($curl);
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
if( $code != 200 ) {
|
||||
var_dump("Pushover returned error"); //FIXME: proper debugging
|
||||
return 'HTTP Status code '.$code;
|
||||
}
|
||||
}
|
||||
return true;
|
@@ -1,62 +0,0 @@
|
||||
/* Copyright (C) 2014 Daniel Preussker <f0o@devilcode.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/>. */
|
||||
|
||||
/**
|
||||
* API Transport
|
||||
* @author ToeiRei <vbauer@stargazer.at>
|
||||
* @copyright 2017 ToeiRei, LibreNMS work based on the work of f0o. It's his work.
|
||||
* @license GPL
|
||||
* @package LibreNMS
|
||||
* @subpackage Alerts
|
||||
*/
|
||||
|
||||
foreach( $opts as $tmp_api ) {
|
||||
$host = $tmp_api['url'];
|
||||
$curl = curl_init();
|
||||
$rocket_msg = strip_tags($obj['msg']);
|
||||
$color = ($obj['state'] == 0 ? '#00FF00' : '#FF0000');
|
||||
$data = array(
|
||||
'attachments' => array(
|
||||
0 => array(
|
||||
'fallback' => $rocket_msg,
|
||||
'color' => $color,
|
||||
'title' => $obj['title'],
|
||||
'text' => $rocket_msg,
|
||||
)
|
||||
),
|
||||
'channel' => $tmp_api['channel'],
|
||||
'username' => $tmp_api['username'],
|
||||
'icon_url' => $tmp_api['icon_url'],
|
||||
'icon_emoji' => $tmp_api['icon_emoji'],
|
||||
);
|
||||
$alert_message = json_encode($data);
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
|
||||
'Content-Type: application/json')
|
||||
);
|
||||
set_curl_proxy($curl);
|
||||
curl_setopt($curl, CURLOPT_URL, $host);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($curl, CURLOPT_POST,true);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $alert_message );
|
||||
|
||||
$ret = curl_exec($curl);
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
if( $code != 200 ) {
|
||||
var_dump("API '$host' returned Error"); //FIXME: propper debuging
|
||||
var_dump("Params: ".$alert_message); //FIXME: propper debuging
|
||||
var_dump("Return: ".$ret); //FIXME: propper debuging
|
||||
return 'HTTP Status code '.$code;
|
||||
}
|
||||
}
|
||||
return true;
|
@@ -1,63 +0,0 @@
|
||||
/* Copyright (C) 2014 Daniel Preussker <f0o@devilcode.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/>. */
|
||||
|
||||
/**
|
||||
* API Transport
|
||||
* @author f0o <f0o@devilcode.org>
|
||||
* @copyright 2014 f0o, LibreNMS
|
||||
* @license GPL
|
||||
* @package LibreNMS
|
||||
* @subpackage Alerts
|
||||
*/
|
||||
|
||||
foreach( $opts as $tmp_api ) {
|
||||
$host = $tmp_api['url'];
|
||||
$curl = curl_init();
|
||||
$slack_msg = strip_tags($obj['msg']);
|
||||
$color = ($obj['state'] == 0 ? '#00FF00' : '#FF0000');
|
||||
$data = array(
|
||||
'attachments' => array(
|
||||
0 => array(
|
||||
'fallback' => $slack_msg,
|
||||
'color' => $color,
|
||||
'title' => $obj['title'],
|
||||
'text' => $slack_msg,
|
||||
'mrkdwn_in' => ['text', 'fallback']
|
||||
)
|
||||
),
|
||||
'channel' => $tmp_api['channel'],
|
||||
'username' => $tmp_api['username'],
|
||||
'icon_url' => $tmp_api['icon_url'],
|
||||
'icon_emoji' => $tmp_api['icon_emoji'],
|
||||
);
|
||||
$alert_message = json_encode($data);
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
|
||||
'Content-Type: application/json')
|
||||
);
|
||||
set_curl_proxy($curl);
|
||||
curl_setopt($curl, CURLOPT_URL, $host);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($curl, CURLOPT_POST,true);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $alert_message );
|
||||
|
||||
$ret = curl_exec($curl);
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
if( $code != 200 ) {
|
||||
var_dump("API '$host' returned Error"); //FIXME: propper debuging
|
||||
var_dump("Params: ".$alert_message); //FIXME: propper debuging
|
||||
var_dump("Return: ".$ret); //FIXME: propper debuging
|
||||
return 'HTTP Status code '.$code;
|
||||
}
|
||||
}
|
||||
return true;
|
@@ -1,110 +0,0 @@
|
||||
/* LibreNMS
|
||||
*
|
||||
* Copyright (C) 2017 Paul Blasquez <pblasquez@gmail.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/>. */
|
||||
|
||||
$syslog_host = '127.0.0.1';
|
||||
$syslog_port = 514;
|
||||
$state = "Unknown";
|
||||
$facility = 24; // Default facility is 3 * 8 (daemon)
|
||||
$severity = 6; // Default severity is 6 (Informational)
|
||||
$sev_txt = "OK";
|
||||
$device = device_by_id_cache($obj['device_id']); // for event logging
|
||||
|
||||
if (!empty($opts['syslog_facility']) && preg_match("/^\d+$/", $opts['syslog_facility'])) {
|
||||
$facility = (int)$opts['syslog_facility'] * 8;
|
||||
} else {
|
||||
log_event("Syslog facility is not an integer: " . $opts['syslog_facility'], $device, 'poller', 5);
|
||||
}
|
||||
if (!empty($opts['syslog_host'])) {
|
||||
if (preg_match("/[a-zA-Z]/", $opts['syslog_host'])) {
|
||||
$syslog_host = gethostbyname($opts['syslog_host']);
|
||||
if ($syslog_host === $opts['syslog_host']) {
|
||||
log_event("Alphanumeric hostname found but does not resolve to an IP.", $device, 'poller', 5);
|
||||
return false;
|
||||
}
|
||||
} elseif (filter_var($opts['syslog_host'], FILTER_VALIDATE_IP)) {
|
||||
$syslog_host = $opts['syslog_host'];
|
||||
} else {
|
||||
log_event("Syslog host is not a valid IP: " . $opts['syslog_host'], $device, 'poller', 5);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
log_event("Syslog host is empty.", $device, 'poller');
|
||||
}
|
||||
if (!empty($opts['syslog_port']) && preg_match("/^\d+$/", $opts['syslog_port'])) {
|
||||
$syslog_port = $opts['syslog_port'];
|
||||
} else {
|
||||
log_event("Syslog port is not an integer.", $device, 'poller', 5);
|
||||
}
|
||||
|
||||
switch( $obj['severity'] ) {
|
||||
case "critical":
|
||||
$severity = 2;
|
||||
$sev_txt = "Critical";
|
||||
break;
|
||||
case "warning":
|
||||
$severity = 4;
|
||||
$sev_txt = "Warning";
|
||||
break;
|
||||
}
|
||||
|
||||
switch( $obj['state'] ) {
|
||||
case 0:
|
||||
$state = "OK";
|
||||
$severity = 6;
|
||||
break;
|
||||
case 1:
|
||||
$state = $sev_txt;
|
||||
break;
|
||||
case 2:
|
||||
$state = "Acknowledged";
|
||||
$severity = 6;
|
||||
break;
|
||||
}
|
||||
|
||||
$priority = $facility + $severity;
|
||||
|
||||
$syslog_prefix = '<'
|
||||
. $priority
|
||||
. '> '
|
||||
. date('M d H:i:s ')
|
||||
. gethostname()
|
||||
. ' librenms'
|
||||
. '['
|
||||
. $obj['device_id']
|
||||
. ']: '
|
||||
. $obj['hostname']
|
||||
. ': ['
|
||||
. $state
|
||||
. '] '
|
||||
. $obj['name']
|
||||
;
|
||||
|
||||
if (($socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP)) === false) {
|
||||
log_event("socket_create() failed: reason: " . socket_strerror(socket_last_error()), $device, 'poller', 5);
|
||||
return false;
|
||||
} else {
|
||||
if( !empty( $obj['faults'] ) ) {
|
||||
foreach($obj['faults'] as $k => $v) {
|
||||
$syslog_msg = $syslog_prefix . ' - ' . $v['string'];
|
||||
socket_sendto($socket, $syslog_msg, strlen($syslog_msg), 0, $syslog_host, $syslog_port);
|
||||
}
|
||||
} else {
|
||||
$syslog_msg = $syslog_prefix;
|
||||
socket_sendto($socket, $syslog_msg, strlen($syslog_msg), 0, $syslog_host, $syslog_port);
|
||||
}
|
||||
socket_close($socket);
|
||||
}
|
||||
return true;
|
@@ -1,41 +0,0 @@
|
||||
/**
|
||||
* transport-telegram.inc.php
|
||||
*
|
||||
* LibreNMS Telegram alerting transport
|
||||
*
|
||||
* 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/>.
|
||||
*
|
||||
* @package LibreNMS
|
||||
* @link http://librenms.org
|
||||
* @copyright 2017 Neil Lathwood
|
||||
* @author Neil Lathwood <neil@lathwood.co.uk>
|
||||
*/
|
||||
|
||||
foreach ($opts as $chat_id => $data) {
|
||||
$curl = curl_init();
|
||||
set_curl_proxy($curl);
|
||||
$text = urlencode($obj['msg']);
|
||||
print_r($data);
|
||||
curl_setopt($curl, CURLOPT_URL, ("https://api.telegram.org/bot{$data['token']}/sendMessage?chat_id={$data['chat_id']}&text=$text") );
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
$ret = curl_exec($curl);
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
if( $code != 200 ) {
|
||||
var_dump("API '$host' returned Error"); //FIXME: propper debuging
|
||||
var_dump("Params: ".$api); //FIXME: propper debuging
|
||||
var_dump("Return: ".$ret); //FIXME: propper debuging
|
||||
return 'HTTP Status code '.$code;
|
||||
}
|
||||
}
|
||||
return true;
|
@@ -1,58 +0,0 @@
|
||||
/* Copyright (C) 2015 Daniel Preussker <f0o@devilcode.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/>. */
|
||||
|
||||
/**
|
||||
* VictorOps Generic-API Transport - Based on PagerDuty transport
|
||||
* @author f0o <f0o@devilcode.org>
|
||||
* @author laf <neil@librenms.org>
|
||||
* @copyright 2015 f0o, laf, LibreNMS
|
||||
* @license GPL
|
||||
* @package LibreNMS
|
||||
* @subpackage Alerts
|
||||
*/
|
||||
|
||||
$url = $opts['url'];
|
||||
|
||||
$protocol = array(
|
||||
'entity_id' => ($obj['id'] ? $obj['id'] : $obj['uid']),
|
||||
'state_start_time' => strtotime($obj['timestamp']),
|
||||
'monitoring_tool' => 'librenms',
|
||||
);
|
||||
if( $obj['state'] == 0 ) {
|
||||
$protocol['message_type'] = 'recovery';
|
||||
}
|
||||
elseif( $obj['state'] == 2 ) {
|
||||
$protocol['message_type'] = 'acknowledgement';
|
||||
}
|
||||
elseif ($obj['state'] == 1) {
|
||||
$protocol['message_type'] = 'critical';
|
||||
}
|
||||
|
||||
foreach( $obj['faults'] as $fault=>$data ) {
|
||||
$protocol['state_message'] .= $data['string'];
|
||||
}
|
||||
|
||||
$curl = curl_init();
|
||||
set_curl_proxy($curl);
|
||||
curl_setopt($curl, CURLOPT_URL, $url );
|
||||
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("VictorOps returned Error, retry later"); //FIXME: propper debuging
|
||||
return false;
|
||||
}
|
||||
return true;
|
Reference in New Issue
Block a user