pandorafms/pandora_console/include/lib/TacticalView/elements/SnmpTraps.php

138 lines
3.5 KiB
PHP
Raw Normal View History

2023-09-25 13:52:28 +02:00
<?php
/**
* SnmpTraps element for tactical view.
*
* @category General
* @package Pandora FMS
* @subpackage TacticalView
* @version 1.0.0
* @license See below
*
* ______ ___ _______ _______ ________
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
*
* ============================================================================
* Copyright (c) 2007-2023 Artica Soluciones Tecnologicas, http://www.artica.es
* This code is NOT free software. This code is NOT licenced under GPL2 licence
* You cannnot redistribute it without written permission of copyright holder.
* ============================================================================
*/
use PandoraFMS\TacticalView\Element;
/**
* SnmpTraps, this class contain all logic for this section.
*/
class SnmpTraps extends Element
{
/**
* Constructor
*/
public function __construct()
{
2023-09-27 13:30:56 +02:00
parent::__construct();
2023-09-25 13:52:28 +02:00
$this->title = __('SNMP Traps');
$this->ajaxMethods = [
'getQueues',
'getTotalSources',
];
$this->interval = 300000;
$this->refreshConfig = [
'queues' => [
'id' => 'total-queues',
'method' => 'getQueues',
],
'total-snmp' => [
'id' => 'total-snmp',
'method' => 'getTotalSources',
],
];
2023-09-25 13:52:28 +02:00
}
2023-10-03 10:31:57 +02:00
/**
* Check if snmp traps module exist.
*
* @return boolean
*/
public function isEnabled():bool
{
if (empty($this->monitoringAgent) === true) {
return false;
}
$existModule = modules_get_agentmodule_id(io_safe_input('snmp_trap_queue'), $this->monitoringAgent['id_agente']);
if ($existModule === false) {
return false;
} else {
return true;
}
}
2023-09-25 13:52:28 +02:00
/**
* Returns the html of queues traps.
*
* @return string
*/
public function getQueues():string
{
2023-10-09 16:42:39 +02:00
if ($this->isEnabled() === true) {
$value = $this->valueMonitoring('snmp_trap_queue');
2024-01-17 12:25:57 +01:00
if (isset($value[0]['data']) === true) {
$total = round($value[0]['data']);
} else {
$total = __('N/A');
}
2023-10-09 16:42:39 +02:00
} else {
$total = __('N/A');
}
2023-09-25 13:52:28 +02:00
return html_print_div(
[
'content' => $total,
2023-09-25 13:52:28 +02:00
'class' => 'text-l',
'style' => 'margin: 0px 10px 10px 10px;',
'id' => 'total-queues',
2023-09-25 13:52:28 +02:00
],
true
);
}
/**
* Returns the html of total sources traps.
*
* @return string
*/
public function getTotalSources():string
{
2023-10-09 16:42:39 +02:00
if ($this->isEnabled() === true) {
$value = $this->valueMonitoring('total_trap');
2024-01-17 12:25:57 +01:00
if (isset($value[0]['data']) === true) {
$total = round($value[0]['data']);
} else {
$total = __('N/A');
}
2023-10-09 16:42:39 +02:00
} else {
$total = __('N/A');
}
2023-09-25 13:52:28 +02:00
return html_print_div(
[
'content' => $total,
2023-09-25 13:52:28 +02:00
'class' => 'text-l',
'style' => 'margin: 0px 10px 10px 10px;',
'id' => 'total-snmp',
2023-09-25 13:52:28 +02:00
],
true
);
}
}