mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Linting (#12677)
* Fix Canopsis Transport * Lint Hipchat * Lint IRCBot.php * Misc * Update Hipchat.php * Update Notification.php
This commit is contained in:
@@ -3,6 +3,9 @@
|
||||
namespace LibreNMS\Alert\Transport;
|
||||
|
||||
use LibreNMS\Alert\Transport;
|
||||
use PhpAmqpLib\Connection\AMQPStreamConnection;
|
||||
use PhpAmqpLib\Exchange\AMQPExchangeType;
|
||||
use PhpAmqpLib\Message\AMQPMessage;
|
||||
|
||||
class Canopsis extends Transport
|
||||
{
|
||||
@@ -30,12 +33,12 @@ class Canopsis extends Transport
|
||||
$exchange = 'canopsis.events';
|
||||
|
||||
// Connection
|
||||
$conn = new \PhpAmqpLib\Connection\AMQPConnection($host, $port, $user, $pass, $vhost);
|
||||
$conn = new AMQPStreamConnection($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);
|
||||
$ch->exchange_declare($exchange, AMQPExchangeType::TOPIC, false, true, false);
|
||||
|
||||
// Create Canopsis event, see: https://github.com/capensis/canopsis/wiki/Event-specification
|
||||
switch ($obj['severity']) {
|
||||
@@ -66,6 +69,7 @@ class Canopsis extends Transport
|
||||
$msg_raw = json_encode($msg_body);
|
||||
|
||||
// Build routing key
|
||||
$msg_rk = '';
|
||||
if ($msg_body['source_type'] == 'resource') {
|
||||
$msg_rk = $msg_rk . '.' . $msg_body['resource'];
|
||||
} else {
|
||||
@@ -73,7 +77,7 @@ class Canopsis extends Transport
|
||||
}
|
||||
|
||||
// Publish Event
|
||||
$msg = new \PhpAmqpLib\Message\AMQPMessage($msg_raw, ['content_type' => 'application/json', 'delivery_mode' => 2]);
|
||||
$msg = new AMQPMessage($msg_raw, ['content_type' => 'application/json', 'delivery_mode' => 2]);
|
||||
$ch->basic_publish($msg, $exchange, $msg_rk);
|
||||
|
||||
// Close connection
|
||||
|
@@ -50,9 +50,7 @@ class Hipchat extends Transport
|
||||
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'])) {
|
||||
|
@@ -82,6 +82,7 @@ class QueryBuilderParser implements \JsonSerializable
|
||||
|
||||
protected $builder;
|
||||
protected $schema;
|
||||
private $tables;
|
||||
|
||||
private function __construct(array $builder)
|
||||
{
|
||||
|
@@ -29,6 +29,10 @@ use Permissions;
|
||||
|
||||
class IRCBot
|
||||
{
|
||||
private $config;
|
||||
|
||||
private $user;
|
||||
|
||||
private $last_activity = 0;
|
||||
|
||||
private $data = '';
|
||||
@@ -78,6 +82,14 @@ class IRCBot
|
||||
|
||||
private $floodcount = 0;
|
||||
|
||||
private $max_retry = 5;
|
||||
|
||||
private $nickwait;
|
||||
|
||||
private $buff;
|
||||
|
||||
private $tokens;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->log('Setting up IRC-Bot..');
|
||||
@@ -802,7 +814,7 @@ class IRCBot
|
||||
|
||||
foreach ($tmp as $logline) {
|
||||
$response = $logline['datetime'] . ' ';
|
||||
$response .= $this->_color($hostid['hostname'], null, null, 'bold') . ' ';
|
||||
$response .= $this->_color($logline['hostname'], null, null, 'bold') . ' ';
|
||||
if ($this->config['irc_alert_utf8']) {
|
||||
if (preg_match('/critical alert/', $logline['message'])) {
|
||||
$response .= preg_replace('/critical alert/', $this->_color('critical alert', 'red'), $logline['message']) . ' ';
|
||||
|
@@ -72,7 +72,9 @@ class OS implements Module
|
||||
$deviceModel->hardware = ($hardware ?? $deviceModel->hardware) ?: null;
|
||||
$deviceModel->features = ($features ?? $deviceModel->features) ?: null;
|
||||
$deviceModel->serial = ($serial ?? $deviceModel->serial) ?: null;
|
||||
|
||||
if (! empty($location)) { // legacy support, remove when no longer needed
|
||||
/** @phpstan-ignore-next-line */
|
||||
$deviceModel->setLocation($location);
|
||||
optional($deviceModel->location)->save();
|
||||
}
|
||||
|
@@ -63,7 +63,7 @@ class Notification extends Model
|
||||
$read = new NotificationAttrib;
|
||||
$read->user_id = \Auth::user()->user_id;
|
||||
$read->key = $name;
|
||||
$read->value = 1;
|
||||
$read->value = '1';
|
||||
$this->attribs()->save($read);
|
||||
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user