Skip to content

Commit

Permalink
Merge branch 'master' into port
Browse files Browse the repository at this point in the history
  • Loading branch information
mpikzink authored Jan 19, 2025
2 parents 1764e45 + 3b8ac6f commit 3c46134
Show file tree
Hide file tree
Showing 350 changed files with 91,352 additions and 49,628 deletions.
27 changes: 26 additions & 1 deletion LibreNMS/Alert/Transport/Grafana.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,37 @@ public function deliverAlert(array $alert_data): bool
$data = [
'alert_uid' => $alert_data['id'] ?: $alert_data['uid'],
'title' => $alert_data['title'] ?? null,
'message' => $alert_data['msg'],
'image_url' => $graph_url,
'link_to_upstream_details' => Url::deviceUrl($device),
'state' => ($alert_data['state'] == AlertState::ACTIVE) ? 'alerting' : 'ok',
'raw_state' => $alert_data['state'],
'device_id' => $alert_data['device_id'],
'hostname' => $alert_data['hostname'],
'sysName' => $alert_data['sysName'],
'location' => $alert_data['location'],
'sysDescr' => $alert_data['sysDescr'],
'os' => $alert_data['os'],
'type' => $alert_data['type'],
'hardware' => $alert_data['hardware'],
'software' => $alert_data['software'] ?? '',
'features' => $alert_data['features'],
'serial' => $alert_data['serial'] ?? '',
'uptime' => $alert_data['uptime'],
'notes' => $alert_data['notes'],
'alert_notes' => $alert_data['alert_notes'],
'severity' => $alert_data['severity'],
'proc' => $alert_data['proc'],
'transport' => $alert_data['transport'] ?? '',
'transport_name' => $alert_data['transport_name'] ?? '',
];

$tmp_msg = json_decode($alert_data['msg'], true);
if (isset($tmp_msg['title']) && isset($tmp_msg['message'])) {
$data = array_merge($data, $tmp_msg);
} else {
$data['message'] = $alert_data['msg'];
}

$res = Http::client()->post($this->config['url'] ?? '', $data);

if ($res->successful()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use LibreNMS\Exceptions\AlertTransportDeliveryException;
use LibreNMS\Util\Http;

class Jiraservicemanagement extends Transport
class Jsm extends Transport
{
protected string $name = 'Jira Service Management';

Expand Down
136 changes: 136 additions & 0 deletions LibreNMS/Alert/Transport/ZenDuty.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<?php
/* Copyright (C) 2014 Daniel Preussker <[email protected]>, Tyler Christiansen <[email protected]>
* 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 <https://www.gnu.org/licenses/>. */

/*
* API Transport
* @author Neil Lathwood, Configuration Services <[email protected]>
* @license GPL
* @package LibreNMS
* @subpackage Alerts
*/

namespace LibreNMS\Alert\Transport;

use LibreNMS\Alert\Transport;
use LibreNMS\Exceptions\AlertTransportDeliveryException;
use LibreNMS\Util\Http;

class ZenDuty extends Transport
{
protected string $name = 'ZenDuty';

public function deliverAlert(array $alert_data): bool
{
$url = $this->config['zenduty-url'];
// If the alert has recovered set to resolved
if ($alert_data['state'] == 0) {
$alert_type = 'resolved';
} elseif ($alert_data['state'] == 2) {
$alert_type = 'acknowledged';
} else {
$alert_type = $alert_data['severity'];
}
// Set the standard data ZD expects to see
$msg = (json_decode($alert_data['msg'], true)) ? json_decode($alert_data['msg'], true) : $alert_data['msg'];
$data = [
'message' => $alert_data['title'],
'alert_type' => $alert_type,
'entity_id' => $alert_data['alert_id'],
'payload' => [
'hostname' => $alert_data['hostname'],
'sysName' => $alert_data['sysName'],
'id' => $alert_data['id'],
'uid' => $alert_data['uid'],
'sysDescr' => $alert_data['sysDescr'],
'os' => $alert_data['os'],
'type' => $alert_type,
'ip' => $alert_data['ip'],
'hardware' => $alert_data['hardware'],
'version' => $alert_data['version'],
'uptime' => $alert_data['uptime'],
'uptime_short' => $alert_data['uptime_short'],
'timestamp' => $alert_data['timestamp'],
'description' => $alert_data['description'],
'title' => $alert_data['title'],
'msg' => $msg,
'state' => $alert_data['state'],
],
'urls' => [
[
'link_url' => route('device', ['device' => $alert_data['device_id']]),
'link_text' => $alert_data['hostname'],
],
],
];

if (isset($this->config['sla_id'])) {
$data['sla'] = $this->config['sla_id'];
}

if (isset($this->config['escalation_policy_id'])) {
$data['escalation_policy'] = $this->config['escalation_policy_id'];
}

$tmp_msg = json_decode($alert_data['msg'], true);
if (isset($tmp_msg['message']) && isset($tmp_msg['summary'])) {
$data = array_merge($data, $tmp_msg);
} else {
$data['summary'] = $alert_data['msg'];
}

$client = Http::client();

$res = $client->withHeaders(
[
'Content-Type' => 'application/json',
]
)->acceptJson()->post($url, $data);

if ($res->successful()) {
return true;
}

throw new AlertTransportDeliveryException($alert_data, $res->status(), $res->body(), $data['message'], $data);
}

public static function configTemplate(): array
{
return [
'config' => [
[
'title' => 'ZenDuty WebHook',
'name' => 'zenduty-url',
'descr' => 'ZenDuty WebHook',
'type' => 'text',
],
[
'title' => 'SLA ID',
'name' => 'sla_id',
'descr' => 'Unique ID of the SLA',
'type' => 'text',
],
[
'title' => 'Escalation Policy ID',
'name' => 'escalation_policy_id',
'descr' => 'Unique ID of the Escalation Policy',
'type' => 'text',
],
],
'validation' => [
'zenduty-url' => 'required|url',
],
];
}
}
4 changes: 2 additions & 2 deletions LibreNMS/Authentication/HttpAuthAuthorizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function userExists($username, $throw_exception = false)
return true;
}

if (Config::has('http_auth_guest') && parent::userExists(Config::get('http_auth_guest'))) {
if (Config::get('http_auth_guest') && parent::userExists(Config::get('http_auth_guest'))) {
return true;
}

Expand All @@ -42,7 +42,7 @@ public function getUserid($username)
return $user_id;
}

if (Config::has('http_auth_guest')) {
if (Config::get('http_auth_guest')) {
return parent::getUserid(Config::get('http_auth_guest'));
}

Expand Down
3 changes: 2 additions & 1 deletion LibreNMS/Billing.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use DateTime;
use DateTimeZone;
use Illuminate\Support\Str;
use LibreNMS\Util\Number;

class Billing
Expand All @@ -20,7 +21,7 @@ public static function formatBytesShort($value): string

public static function getDates($dayofmonth, $months = 0): array
{
$dayofmonth = zeropad($dayofmonth);
$dayofmonth = Str::padLeft($dayofmonth, 2, '0');
$year = date('Y');
$month = date('m');

Expand Down
Loading

0 comments on commit 3c46134

Please sign in to comment.