mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-28 00:04:37 +02:00
WIP Smart services
This commit is contained in:
parent
a8671078f1
commit
032faf8c0c
@ -27,6 +27,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// Begin.
|
// Begin.
|
||||||
|
require 'vendor/autoload.php';
|
||||||
|
|
||||||
define('AJAX', true);
|
define('AJAX', true);
|
||||||
|
|
||||||
if (!defined('__PAN_XHPROF__')) {
|
if (!defined('__PAN_XHPROF__')) {
|
||||||
|
@ -259,15 +259,24 @@ define('SERVICE_STATUS_NORMAL', 0);
|
|||||||
define('SERVICE_STATUS_CRITICAL', 1);
|
define('SERVICE_STATUS_CRITICAL', 1);
|
||||||
define('SERVICE_STATUS_WARNING', 2);
|
define('SERVICE_STATUS_WARNING', 2);
|
||||||
define('SERVICE_STATUS_ALERT', 4);
|
define('SERVICE_STATUS_ALERT', 4);
|
||||||
// Default weights.
|
// Default service weights.
|
||||||
define('SERVICE_WEIGHT_CRITICAL', 1);
|
define('SERVICE_WEIGHT_CRITICAL', 1);
|
||||||
define('SERVICE_WEIGHT_WARNING', 0.5);
|
define('SERVICE_WEIGHT_WARNING', 0.5);
|
||||||
define('SERVICE_SMART_WEIGHT_CRITICAL', 50);
|
define('SERVICE_SMART_WEIGHT_CRITICAL', 50);
|
||||||
define('SERVICE_SMART_WEIGHT_WARNING', 30);
|
define('SERVICE_SMART_WEIGHT_WARNING', 30);
|
||||||
|
// Default service element weights.
|
||||||
define('SERVICE_ELEMENT_WEIGHT_CRITICAL', 1);
|
define('SERVICE_ELEMENT_WEIGHT_CRITICAL', 1);
|
||||||
define('SERVICE_ELEMENT_WEIGHT_WARNING', 0.5);
|
define('SERVICE_ELEMENT_WEIGHT_WARNING', 0.5);
|
||||||
define('SERVICE_ELEMENT_WEIGHT_OK', 0);
|
define('SERVICE_ELEMENT_WEIGHT_OK', 0);
|
||||||
define('SERVICE_ELEMENT_WEIGHT_UNKNOWN', 0);
|
define('SERVICE_ELEMENT_WEIGHT_UNKNOWN', 0);
|
||||||
|
define('SERVICE_ELEMENT_SMART_CRITICAL', 100);
|
||||||
|
define('SERVICE_ELEMENT_SMART_WARNING', 50);
|
||||||
|
// Service element types.
|
||||||
|
define('SERVICE_ELEMENT_AGENT', 'agent');
|
||||||
|
define('SERVICE_ELEMENT_MODULE', 'module');
|
||||||
|
define('SERVICE_ELEMENT_SERVICE', 'service');
|
||||||
|
define('SERVICE_ELEMENT_DYNAMIC', 'dynamic');
|
||||||
|
|
||||||
// Modes.
|
// Modes.
|
||||||
define('SERVICE_MODE_MANUAL', 0);
|
define('SERVICE_MODE_MANUAL', 0);
|
||||||
define('SERVICE_MODE_SMART', 1);
|
define('SERVICE_MODE_SMART', 1);
|
||||||
|
@ -43,7 +43,7 @@ var TreeController = {
|
|||||||
var $group = $("<ul></ul>");
|
var $group = $("<ul></ul>");
|
||||||
|
|
||||||
// First group
|
// First group
|
||||||
if (typeof rootGroup != "undefinded" && rootGroup == true) {
|
if (typeof rootGroup != "undefined" && rootGroup == true) {
|
||||||
$group
|
$group
|
||||||
.addClass("tree-root")
|
.addClass("tree-root")
|
||||||
.hide()
|
.hide()
|
||||||
|
@ -54,19 +54,38 @@ class Agent extends Entity
|
|||||||
/**
|
/**
|
||||||
* Builds a PandoraFMS\Agent object from a agent id.
|
* Builds a PandoraFMS\Agent object from a agent id.
|
||||||
*
|
*
|
||||||
* @param integer $id_agent Agent Id.
|
* @param integer $id_agent Agent Id.
|
||||||
* @param boolean $load_modules Load all modules of this agent. Be careful.
|
* @param boolean $load_modules Load all modules of this agent.
|
||||||
|
* @param integer|null $id_node Metaconsole only. ID node.
|
||||||
*/
|
*/
|
||||||
public function __construct(?int $id_agent=null, ?bool $load_modules=false)
|
public function __construct(
|
||||||
{
|
?int $id_agent=null,
|
||||||
|
?bool $load_modules=false,
|
||||||
|
?int $id_node=null
|
||||||
|
) {
|
||||||
|
$table = 'tagente';
|
||||||
|
$filter = ['id_agente' => $id_agent];
|
||||||
|
if (is_metaconsole() === true
|
||||||
|
&& $id_node !== null
|
||||||
|
) {
|
||||||
|
$table = 'tmetaconsole_agent';
|
||||||
|
$filter = [
|
||||||
|
'id_agente' => $id_agent,
|
||||||
|
'id_tmetaconsole_setup' => (int) $id_node,
|
||||||
|
];
|
||||||
|
|
||||||
|
// Cannot load modules from metaconsole.
|
||||||
|
$load_modules = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (is_numeric($id_agent) === true
|
if (is_numeric($id_agent) === true
|
||||||
&& $id_agent > 0
|
&& $id_agent > 0
|
||||||
) {
|
) {
|
||||||
parent::__construct('tagente', ['id_agente' => $id_agent]);
|
parent::__construct($table, $filter);
|
||||||
if ($load_modules === true) {
|
if ($load_modules === true) {
|
||||||
$rows = \db_get_all_rows_filter(
|
$rows = \db_get_all_rows_filter(
|
||||||
'tagente_modulo',
|
'tagente_modulo',
|
||||||
['id_agente' => $id_agent]
|
$filter
|
||||||
);
|
);
|
||||||
|
|
||||||
if (is_array($rows) === true) {
|
if (is_array($rows) === true) {
|
||||||
@ -79,7 +98,7 @@ class Agent extends Entity
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Create empty skel.
|
// Create empty skel.
|
||||||
parent::__construct('tagente');
|
parent::__construct($table);
|
||||||
|
|
||||||
// New agent has no modules.
|
// New agent has no modules.
|
||||||
$this->modulesLoaded = true;
|
$this->modulesLoaded = true;
|
||||||
|
@ -30,6 +30,8 @@
|
|||||||
// Begin.
|
// Begin.
|
||||||
namespace PandoraFMS;
|
namespace PandoraFMS;
|
||||||
|
|
||||||
|
use PandoraFMS\Agent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PandoraFMS agent entity.
|
* PandoraFMS agent entity.
|
||||||
*/
|
*/
|
||||||
@ -43,6 +45,20 @@ class Module extends Entity
|
|||||||
*/
|
*/
|
||||||
private $status;
|
private $status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Agent where module is stored.
|
||||||
|
*
|
||||||
|
* @var PandoraFMS\Agent
|
||||||
|
*/
|
||||||
|
private $linkedAgent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Metaconsole setup id.
|
||||||
|
*
|
||||||
|
* @var integer
|
||||||
|
*/
|
||||||
|
private $idNode;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Search a module in db.
|
* Search a module in db.
|
||||||
@ -131,10 +147,24 @@ class Module extends Entity
|
|||||||
/**
|
/**
|
||||||
* Builds a PandoraFMS\Module object from given id.
|
* Builds a PandoraFMS\Module object from given id.
|
||||||
*
|
*
|
||||||
* @param integer $id_agent_module Module id.
|
* @param integer|null $id_agent_module Module id.
|
||||||
|
* @param boolean $link_agent Link agent object.
|
||||||
|
* @param integer|null $id_node Metaconsole only. ID node.
|
||||||
|
*
|
||||||
|
* @throws \Exception On error.
|
||||||
*/
|
*/
|
||||||
public function __construct(?int $id_agent_module=null)
|
public function __construct(
|
||||||
{
|
?int $id_agent_module=null,
|
||||||
|
bool $link_agent=false,
|
||||||
|
?int $id_node=null
|
||||||
|
) {
|
||||||
|
if ($id_node !== null) {
|
||||||
|
$this->idNode = $id_node;
|
||||||
|
|
||||||
|
enterprise_include_once('include/functions_metaconsole.php');
|
||||||
|
\metaconsole_connect(null, $this->idNode);
|
||||||
|
}
|
||||||
|
|
||||||
if (is_numeric($id_agent_module) === true
|
if (is_numeric($id_agent_module) === true
|
||||||
&& $id_agent_module > 0
|
&& $id_agent_module > 0
|
||||||
) {
|
) {
|
||||||
@ -142,17 +172,83 @@ class Module extends Entity
|
|||||||
'tagente_modulo',
|
'tagente_modulo',
|
||||||
['id_agente_modulo' => $id_agent_module]
|
['id_agente_modulo' => $id_agent_module]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ($this->nombre() === 'delete_pending') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($link_agent === true) {
|
||||||
|
try {
|
||||||
|
$this->linkedAgent = new Agent($this->id_agente());
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
if ($this->idNode !== null) {
|
||||||
|
\metaconsole_restore_db();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unexistent agent.
|
||||||
|
throw new \Exception(
|
||||||
|
__METHOD__.__(
|
||||||
|
' error: Module has no agent assigned.'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Create empty skel.
|
// Create empty skel.
|
||||||
parent::__construct('tagente_modulo');
|
parent::__construct('tagente_modulo');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->nombre() === 'delete_pending') {
|
try {
|
||||||
return null;
|
// Customize certain fields.
|
||||||
|
$this->status = new ModuleStatus($this->fields['id_agente_modulo']);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$this->status = new Modulestatus();
|
||||||
|
if ($this->idNode !== null) {
|
||||||
|
\metaconsole_restore_db();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return agent object where module is defined.
|
||||||
|
*
|
||||||
|
* @return PandoraFMS\Agent Where module is defined.
|
||||||
|
*/
|
||||||
|
public function agent()
|
||||||
|
{
|
||||||
|
if ($this->linkedAgent === null) {
|
||||||
|
try {
|
||||||
|
$this->linkedAgent = new Agent($this->id_agente());
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
// Unexistent agent.
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Customize certain fields.
|
return $this->linkedAgent;
|
||||||
$this->status = new ModuleStatus($this->fields['id_agente_modulo']);
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return last value reported by the module.
|
||||||
|
*
|
||||||
|
* @return mixed Data depending on module type.
|
||||||
|
*/
|
||||||
|
public function lastValue()
|
||||||
|
{
|
||||||
|
return $this->status->datos();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return last status reported by the module.
|
||||||
|
*
|
||||||
|
* @return mixed Data depending on module type.
|
||||||
|
*/
|
||||||
|
public function lastStatus()
|
||||||
|
{
|
||||||
|
return $this->status->estado();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -288,6 +384,10 @@ class Module extends Entity
|
|||||||
if ($this->fields['id_agente_modulo'] > 0) {
|
if ($this->fields['id_agente_modulo'] > 0) {
|
||||||
// Update.
|
// Update.
|
||||||
$updates = $this->fields;
|
$updates = $this->fields;
|
||||||
|
if ($this->idNode !== null) {
|
||||||
|
enterprise_include_once('include/functions_metaconsole.php');
|
||||||
|
\metaconsole_connect(null, $this->idNode);
|
||||||
|
}
|
||||||
|
|
||||||
$rs = \db_process_sql_update(
|
$rs = \db_process_sql_update(
|
||||||
'tagente_modulo',
|
'tagente_modulo',
|
||||||
@ -295,10 +395,16 @@ class Module extends Entity
|
|||||||
['id_agente_modulo' => $this->fields['id_agente_modulo']]
|
['id_agente_modulo' => $this->fields['id_agente_modulo']]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
global $config;
|
||||||
|
$error = $config['dbconnection']->error;
|
||||||
|
|
||||||
|
if ($this->idNode !== null) {
|
||||||
|
\metaconsole_restore_db();
|
||||||
|
}
|
||||||
|
|
||||||
if ($rs === false) {
|
if ($rs === false) {
|
||||||
global $config;
|
|
||||||
throw new \Exception(
|
throw new \Exception(
|
||||||
__METHOD__.' error: '.$config['dbconnection']->error
|
__METHOD__.' error: '.$error
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -312,16 +418,27 @@ class Module extends Entity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->idNode !== null) {
|
||||||
|
enterprise_include_once('include/functions_metaconsole.php');
|
||||||
|
\metaconsole_connect(null, $this->idNode);
|
||||||
|
}
|
||||||
|
|
||||||
$rs = \modules_create_agent_module(
|
$rs = \modules_create_agent_module(
|
||||||
$this->fields['id_agente'],
|
$this->fields['id_agente'],
|
||||||
$updates['nombre'],
|
$updates['nombre'],
|
||||||
$updates
|
$updates
|
||||||
);
|
);
|
||||||
|
|
||||||
|
global $config;
|
||||||
|
$error = $config['dbconnection']->error;
|
||||||
|
|
||||||
|
if ($this->idNode !== null) {
|
||||||
|
\metaconsole_restore_db();
|
||||||
|
}
|
||||||
|
|
||||||
if ($rs === false) {
|
if ($rs === false) {
|
||||||
global $config;
|
|
||||||
throw new \Exception(
|
throw new \Exception(
|
||||||
__METHOD__.' error: '.$config['dbconnection']->error
|
__METHOD__.' error: '.$error
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -339,10 +456,19 @@ class Module extends Entity
|
|||||||
*/
|
*/
|
||||||
public function delete()
|
public function delete()
|
||||||
{
|
{
|
||||||
|
if ($this->idNode !== null) {
|
||||||
|
enterprise_include_once('include/functions_metaconsole.php');
|
||||||
|
\metaconsole_connect(null, $this->idNode);
|
||||||
|
}
|
||||||
|
|
||||||
\modules_delete_agent_module(
|
\modules_delete_agent_module(
|
||||||
$this->id_agente_modulo()
|
$this->id_agente_modulo()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ($this->idNode !== null) {
|
||||||
|
\metaconsole_restore_db();
|
||||||
|
}
|
||||||
|
|
||||||
unset($this->fields);
|
unset($this->fields);
|
||||||
unset($this->status);
|
unset($this->status);
|
||||||
}
|
}
|
||||||
@ -393,4 +519,58 @@ class Module extends Entity
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculates CPS value and updates its content.
|
||||||
|
*
|
||||||
|
* @return integer CPS value set.
|
||||||
|
*/
|
||||||
|
public function calculateCPS()
|
||||||
|
{
|
||||||
|
$cps = 0;
|
||||||
|
|
||||||
|
if (class_exists('\PandoraFMS\Enterprise\Service') === false) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if is child of services in local console.
|
||||||
|
$service_parents = \db_get_all_rows_filter(
|
||||||
|
'tservice_element',
|
||||||
|
[ 'id_agente_modulo' => $this->id_agente_modulo() ],
|
||||||
|
'id_service'
|
||||||
|
);
|
||||||
|
|
||||||
|
if (is_array($service_parents) === true) {
|
||||||
|
foreach ($service_parents as $ref) {
|
||||||
|
$service = new \PandoraFMS\Enterprise\Service(
|
||||||
|
$ref['id_service']
|
||||||
|
);
|
||||||
|
if (((bool) $service->cascade_protection()) === true) {
|
||||||
|
$cps += $service->cps();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if is child of services in metaconsole.
|
||||||
|
if (is_metaconsole() === false) {
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
$nodo_connect = \metaconsole_load_external_db(
|
||||||
|
[
|
||||||
|
'dbhost' => $config['replication_dbhost'],
|
||||||
|
'dbuser' => $config['replication_dbuser'],
|
||||||
|
'dbpass' => \io_output_password(
|
||||||
|
$config['replication_dbpass']
|
||||||
|
),
|
||||||
|
'dbname' => $config['replication_dbname'],
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
\metaconsole_restore_db();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $cps;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,8 @@ if (!defined('__PAN_XHPROF__')) {
|
|||||||
define('__PAN_XHPROF__', 0);
|
define('__PAN_XHPROF__', 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
require 'vendor/autoload.php';
|
||||||
|
|
||||||
if (__PAN_XHPROF__ === 1) {
|
if (__PAN_XHPROF__ === 1) {
|
||||||
if (function_exists('tideways_xhprof_enable')) {
|
if (function_exists('tideways_xhprof_enable')) {
|
||||||
tideways_xhprof_enable();
|
tideways_xhprof_enable();
|
||||||
|
@ -15,8 +15,6 @@ if (! isset($config['id_user'])) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
require 'vendor/autoload.php';
|
|
||||||
|
|
||||||
use PandoraFMS\Dashboard\Manager;
|
use PandoraFMS\Dashboard\Manager;
|
||||||
|
|
||||||
require_once 'include/functions_menu.php';
|
require_once 'include/functions_menu.php';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user