mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-31 01:35:36 +02:00
WIP Services
This commit is contained in:
parent
032faf8c0c
commit
c07daa3199
@ -6,6 +6,10 @@ ALTER TABLE `tservice` ADD COLUMN `unknown_as_critical` tinyint(1) NOT NULL defa
|
|||||||
|
|
||||||
UPDATE `tservice` SET `auto_calculate`=0;
|
UPDATE `tservice` SET `auto_calculate`=0;
|
||||||
|
|
||||||
|
UPDATE `tservice` SET `cps`= `cps` - 1 WHERE `cps` > 0;
|
||||||
|
UPDATE `tagente` SET `cps`= `cps` - 1 WHERE `cps` > 0;
|
||||||
|
UPDATE `tagente_modulo` SET `cps`= `cps` - 1 WHERE `cps` > 0;
|
||||||
|
|
||||||
ALTER TABLE `tmensajes` ADD COLUMN `hidden_sent` TINYINT(1) UNSIGNED DEFAULT 0;
|
ALTER TABLE `tmensajes` ADD COLUMN `hidden_sent` TINYINT(1) UNSIGNED DEFAULT 0;
|
||||||
|
|
||||||
COMMIT;
|
COMMIT;
|
||||||
|
@ -211,6 +211,90 @@ class Agent extends Entity
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculates cascade protection service value for this service.
|
||||||
|
*
|
||||||
|
* @return integer CPS value.
|
||||||
|
*/
|
||||||
|
public function calculateCPS()
|
||||||
|
{
|
||||||
|
if ($this->cps() < 0) {
|
||||||
|
return $this->cps();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1. check parents.
|
||||||
|
$direct_parents = db_get_all_rows_sql(
|
||||||
|
sprintf(
|
||||||
|
'SELECT id_service, cps, cascade_protection
|
||||||
|
FROM `tservice_element` te
|
||||||
|
INNER JOIN `tservice` t ON te.id_service = t.id
|
||||||
|
WHERE te.id_agent = %d',
|
||||||
|
$this->id_agente()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (is_metaconsole() === false
|
||||||
|
&& has_metaconsole() === true
|
||||||
|
) {
|
||||||
|
$mc_parents = [];
|
||||||
|
global $config;
|
||||||
|
$mc_db_conn = \enterprise_hook(
|
||||||
|
'metaconsole_load_external_db',
|
||||||
|
[
|
||||||
|
[
|
||||||
|
'dbhost' => $config['replication_dbhost'],
|
||||||
|
'dbuser' => $config['replication_dbuser'],
|
||||||
|
'dbpass' => io_output_password(
|
||||||
|
$config['replication_dbpass']
|
||||||
|
),
|
||||||
|
'dbname' => $config['replication_dbname'],
|
||||||
|
],
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($mc_db_conn === NOERR) {
|
||||||
|
$mc_parents = db_get_all_rows_sql(
|
||||||
|
sprintf(
|
||||||
|
'SELECT id_service,
|
||||||
|
cps,
|
||||||
|
cascade_protection
|
||||||
|
FROM `tservice_element` te
|
||||||
|
INNER JOIN `tservice` t ON te.id_service = t.id
|
||||||
|
WHERE te.id_agent = %d',
|
||||||
|
$this->id_agente()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Restore the default connection.
|
||||||
|
\enterprise_hook('metaconsole_restore_db');
|
||||||
|
}
|
||||||
|
|
||||||
|
$cps = 0;
|
||||||
|
|
||||||
|
if (is_array($direct_parents) === false) {
|
||||||
|
$direct_parents = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_array($mc_parents) === false) {
|
||||||
|
$mc_parents = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Merge all parents (node and meta).
|
||||||
|
$parents = array_merge($direct_parents, $mc_parents);
|
||||||
|
|
||||||
|
foreach ($parents as $parent) {
|
||||||
|
$cps += $parent['cps'];
|
||||||
|
if (((bool) $parent['cascade_protection']) === true) {
|
||||||
|
$cps++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $cps;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a module in current agent.
|
* Creates a module in current agent.
|
||||||
*
|
*
|
||||||
|
@ -162,7 +162,13 @@ class Module extends Entity
|
|||||||
$this->idNode = $id_node;
|
$this->idNode = $id_node;
|
||||||
|
|
||||||
enterprise_include_once('include/functions_metaconsole.php');
|
enterprise_include_once('include/functions_metaconsole.php');
|
||||||
\metaconsole_connect(null, $this->idNode);
|
\enterprise_hook(
|
||||||
|
'metaconsole_connect',
|
||||||
|
[
|
||||||
|
null,
|
||||||
|
$this->idNode,
|
||||||
|
]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_numeric($id_agent_module) === true
|
if (is_numeric($id_agent_module) === true
|
||||||
@ -182,7 +188,7 @@ class Module extends Entity
|
|||||||
$this->linkedAgent = new Agent($this->id_agente());
|
$this->linkedAgent = new Agent($this->id_agente());
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
if ($this->idNode !== null) {
|
if ($this->idNode !== null) {
|
||||||
\metaconsole_restore_db();
|
\enterprise_hook('metaconsole_restore_db');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unexistent agent.
|
// Unexistent agent.
|
||||||
@ -203,9 +209,10 @@ class Module extends Entity
|
|||||||
$this->status = new ModuleStatus($this->fields['id_agente_modulo']);
|
$this->status = new ModuleStatus($this->fields['id_agente_modulo']);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->status = new Modulestatus();
|
$this->status = new Modulestatus();
|
||||||
if ($this->idNode !== null) {
|
}
|
||||||
\metaconsole_restore_db();
|
|
||||||
}
|
if ($this->idNode !== null) {
|
||||||
|
\enterprise_hook('metaconsole_restore_db');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -386,7 +393,13 @@ class Module extends Entity
|
|||||||
$updates = $this->fields;
|
$updates = $this->fields;
|
||||||
if ($this->idNode !== null) {
|
if ($this->idNode !== null) {
|
||||||
enterprise_include_once('include/functions_metaconsole.php');
|
enterprise_include_once('include/functions_metaconsole.php');
|
||||||
\metaconsole_connect(null, $this->idNode);
|
\enterprise_hook(
|
||||||
|
'metaconsole_connect',
|
||||||
|
[
|
||||||
|
null,
|
||||||
|
$this->idNode,
|
||||||
|
]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$rs = \db_process_sql_update(
|
$rs = \db_process_sql_update(
|
||||||
@ -399,7 +412,7 @@ class Module extends Entity
|
|||||||
$error = $config['dbconnection']->error;
|
$error = $config['dbconnection']->error;
|
||||||
|
|
||||||
if ($this->idNode !== null) {
|
if ($this->idNode !== null) {
|
||||||
\metaconsole_restore_db();
|
\enterprise_hook('metaconsole_restore_db');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($rs === false) {
|
if ($rs === false) {
|
||||||
@ -420,7 +433,13 @@ class Module extends Entity
|
|||||||
|
|
||||||
if ($this->idNode !== null) {
|
if ($this->idNode !== null) {
|
||||||
enterprise_include_once('include/functions_metaconsole.php');
|
enterprise_include_once('include/functions_metaconsole.php');
|
||||||
\metaconsole_connect(null, $this->idNode);
|
\enterprise_hook(
|
||||||
|
'metaconsole_connect',
|
||||||
|
[
|
||||||
|
null,
|
||||||
|
$this->idNode,
|
||||||
|
]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$rs = \modules_create_agent_module(
|
$rs = \modules_create_agent_module(
|
||||||
@ -433,7 +452,7 @@ class Module extends Entity
|
|||||||
$error = $config['dbconnection']->error;
|
$error = $config['dbconnection']->error;
|
||||||
|
|
||||||
if ($this->idNode !== null) {
|
if ($this->idNode !== null) {
|
||||||
\metaconsole_restore_db();
|
\enterprise_hook('metaconsole_restore_db');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($rs === false) {
|
if ($rs === false) {
|
||||||
@ -458,7 +477,13 @@ class Module extends Entity
|
|||||||
{
|
{
|
||||||
if ($this->idNode !== null) {
|
if ($this->idNode !== null) {
|
||||||
enterprise_include_once('include/functions_metaconsole.php');
|
enterprise_include_once('include/functions_metaconsole.php');
|
||||||
\metaconsole_connect(null, $this->idNode);
|
\enterprise_hook(
|
||||||
|
'metaconsole_connect',
|
||||||
|
[
|
||||||
|
null,
|
||||||
|
$this->idNode,
|
||||||
|
]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
\modules_delete_agent_module(
|
\modules_delete_agent_module(
|
||||||
@ -466,7 +491,7 @@ class Module extends Entity
|
|||||||
);
|
);
|
||||||
|
|
||||||
if ($this->idNode !== null) {
|
if ($this->idNode !== null) {
|
||||||
\metaconsole_restore_db();
|
\enterprise_hook('metaconsole_restore_db');
|
||||||
}
|
}
|
||||||
|
|
||||||
unset($this->fields);
|
unset($this->fields);
|
||||||
@ -520,52 +545,82 @@ class Module extends Entity
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates CPS value and updates its content.
|
* Calculates cascade protection service value for this service.
|
||||||
*
|
*
|
||||||
* @return integer CPS value set.
|
* @return integer CPS value.
|
||||||
*/
|
*/
|
||||||
public function calculateCPS()
|
public function calculateCPS()
|
||||||
{
|
{
|
||||||
$cps = 0;
|
if ($this->cps() < 0) {
|
||||||
|
return $this->cps();
|
||||||
if (class_exists('\PandoraFMS\Enterprise\Service') === false) {
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if is child of services in local console.
|
// 1. check parents.
|
||||||
$service_parents = \db_get_all_rows_filter(
|
$direct_parents = db_get_all_rows_sql(
|
||||||
'tservice_element',
|
sprintf(
|
||||||
[ 'id_agente_modulo' => $this->id_agente_modulo() ],
|
'SELECT id_service, cps, cascade_protection
|
||||||
'id_service'
|
FROM `tservice_element` te
|
||||||
|
INNER JOIN `tservice` t ON te.id_service = t.id
|
||||||
|
WHERE te.id_agente_modulo = %d',
|
||||||
|
$this->id_agente_modulo()
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (is_array($service_parents) === true) {
|
if (is_metaconsole() === false
|
||||||
foreach ($service_parents as $ref) {
|
&& has_metaconsole() === true
|
||||||
$service = new \PandoraFMS\Enterprise\Service(
|
) {
|
||||||
$ref['id_service']
|
$mc_parents = [];
|
||||||
);
|
|
||||||
if (((bool) $service->cascade_protection()) === true) {
|
|
||||||
$cps += $service->cps();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if is child of services in metaconsole.
|
|
||||||
if (is_metaconsole() === false) {
|
|
||||||
global $config;
|
global $config;
|
||||||
|
$mc_db_conn = \enterprise_hook(
|
||||||
$nodo_connect = \metaconsole_load_external_db(
|
'metaconsole_load_external_db',
|
||||||
[
|
[
|
||||||
'dbhost' => $config['replication_dbhost'],
|
[
|
||||||
'dbuser' => $config['replication_dbuser'],
|
'dbhost' => $config['replication_dbhost'],
|
||||||
'dbpass' => \io_output_password(
|
'dbuser' => $config['replication_dbuser'],
|
||||||
$config['replication_dbpass']
|
'dbpass' => io_output_password(
|
||||||
),
|
$config['replication_dbpass']
|
||||||
'dbname' => $config['replication_dbname'],
|
),
|
||||||
|
'dbname' => $config['replication_dbname'],
|
||||||
|
],
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
\metaconsole_restore_db();
|
if ($mc_db_conn === NOERR) {
|
||||||
|
$mc_parents = db_get_all_rows_sql(
|
||||||
|
sprintf(
|
||||||
|
'SELECT id_service,
|
||||||
|
cps,
|
||||||
|
cascade_protection
|
||||||
|
FROM `tservice_element` te
|
||||||
|
INNER JOIN `tservice` t ON te.id_service = t.id
|
||||||
|
WHERE te.id_agente_modulo = %d',
|
||||||
|
$this->id_agente_modulo()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Restore the default connection.
|
||||||
|
\enterprise_hook('metaconsole_restore_db');
|
||||||
|
}
|
||||||
|
|
||||||
|
$cps = 0;
|
||||||
|
|
||||||
|
if (is_array($direct_parents) === false) {
|
||||||
|
$direct_parents = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_array($mc_parents) === false) {
|
||||||
|
$mc_parents = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Merge all parents (node and meta).
|
||||||
|
$parents = array_merge($direct_parents, $mc_parents);
|
||||||
|
|
||||||
|
foreach ($parents as $parent) {
|
||||||
|
$cps += $parent['cps'];
|
||||||
|
if (((bool) $parent['cascade_protection']) === true) {
|
||||||
|
$cps++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $cps;
|
return $cps;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user