Added macros to event response
This commit is contained in:
parent
463013b06a
commit
6461f029ee
|
@ -3714,6 +3714,14 @@ function events_get_response_target(
|
|||
) {
|
||||
global $config;
|
||||
|
||||
include_once $config['homedir'].'/vendor/autoload.php';
|
||||
|
||||
try {
|
||||
$eventObjt = new PandoraFMS\Event($event_id);
|
||||
} catch (Exception $e) {
|
||||
$eventObjt = new PandoraFMS\Event();
|
||||
}
|
||||
|
||||
// If server_id > 0, it's a metaconsole query.
|
||||
$meta = $server_id > 0 || is_metaconsole();
|
||||
$event_table = events_get_events_table($meta, $history);
|
||||
|
@ -3911,9 +3919,54 @@ function events_get_response_target(
|
|||
}
|
||||
|
||||
if (strpos($target, '_event_instruction_') !== false) {
|
||||
// Fallback to module instructions if not defined in event.
|
||||
$instructions = [];
|
||||
|
||||
foreach ([
|
||||
'warning_instructions',
|
||||
'critical_instructions',
|
||||
'unknown_instructions',
|
||||
] as $i) {
|
||||
$instructions[$i] = $event[$i];
|
||||
if (empty($instructions[$i]) === true
|
||||
&& $eventObjt->module() !== null
|
||||
) {
|
||||
try {
|
||||
$instructions[$i] = $eventObjt->module()->{$i}();
|
||||
} catch (Exception $e) {
|
||||
// Method not found.
|
||||
$instructions[$i] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$target = str_replace(
|
||||
'_event_instruction_',
|
||||
events_display_instructions($event['event_type'], $event, false),
|
||||
events_display_instructions(
|
||||
$event['event_type'],
|
||||
$instructions,
|
||||
false
|
||||
),
|
||||
$target
|
||||
);
|
||||
}
|
||||
|
||||
if (strpos($target, '_data_') !== false
|
||||
&& $eventObj->module() !== null
|
||||
) {
|
||||
$target = str_replace(
|
||||
'_data_',
|
||||
$eventObjt->module()->lastValue(),
|
||||
$target
|
||||
);
|
||||
}
|
||||
|
||||
if (strpos($target, '_moduledescription_') !== false
|
||||
&& $eventObj->module() !== null
|
||||
) {
|
||||
$target = str_replace(
|
||||
'_moduledescription_',
|
||||
io_safe_output($eventObjt->module()->description()),
|
||||
$target
|
||||
);
|
||||
}
|
||||
|
|
|
@ -33,40 +33,91 @@ global $config;
|
|||
require_once $config['homedir'].'/include/functions_events.php';
|
||||
|
||||
/**
|
||||
* PandoraFMS Group entity.
|
||||
* PandoraFMS event entity.
|
||||
*/
|
||||
class Event extends Entity
|
||||
{
|
||||
|
||||
/**
|
||||
* List of available ajax methods.
|
||||
* Agent related to this event.
|
||||
*
|
||||
* @var array
|
||||
* @var \PandoraFMS\Agent
|
||||
*/
|
||||
private static $ajaxMethods = [];
|
||||
private $linkedAgent;
|
||||
|
||||
/**
|
||||
* Module related to this event.
|
||||
*
|
||||
* @var \PandoraFMS\Module
|
||||
*/
|
||||
private $linkedModule;
|
||||
|
||||
|
||||
/**
|
||||
* Builds a PandoraFMS\Group object from a group id.
|
||||
* Builds a PandoraFMS\Event object from given event id.
|
||||
*
|
||||
* @param integer $id_group Group Id.
|
||||
* @param integer $event_id Event Id.
|
||||
*/
|
||||
public function __construct(?int $id_group=null)
|
||||
public function __construct(?int $event_id=null)
|
||||
{
|
||||
$table = 'tevento';
|
||||
if ((bool) \is_metaconsole() === true) {
|
||||
$table = 'tmetaconsole_event';
|
||||
}
|
||||
|
||||
if ($id_group === 0) {
|
||||
if ($event_id === 0) {
|
||||
parent::__construct($table);
|
||||
} else if (is_numeric($id_group) === true) {
|
||||
parent::__construct($table, ['id_grupo' => $id_group]);
|
||||
} else if (is_numeric($event_id) === true) {
|
||||
parent::__construct($table, ['id_evento' => $event_id]);
|
||||
} else {
|
||||
// Empty skel.
|
||||
parent::__construct($table);
|
||||
}
|
||||
|
||||
if ($this->id_agente() !== null) {
|
||||
$this->linkedAgent = new Agent($this->id_agente());
|
||||
}
|
||||
|
||||
if ($this->id_agentmodule() !== null) {
|
||||
$this->linkedModule = new Module($this->id_agentmodule());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get/set linked agent.
|
||||
*
|
||||
* @param Agent|null $agent New agent to link.
|
||||
*
|
||||
* @return Agent|null Agent or null if set operation.
|
||||
*/
|
||||
public function agent(?Agent $agent=null) : ?Agent
|
||||
{
|
||||
if ($agent === null) {
|
||||
return $this->linkedAgent;
|
||||
}
|
||||
|
||||
$this->linkedAgent = $agent;
|
||||
$this->id_agentmodule($agent->id_agentmodule());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get/set linked agent.
|
||||
*
|
||||
* @param Module|null $module New module to link.
|
||||
*
|
||||
* @return Module|null module or null if set operation.
|
||||
*/
|
||||
public function module(?Module $module=null) : ?Module
|
||||
{
|
||||
if ($module === null) {
|
||||
return $this->linkedModule;
|
||||
}
|
||||
|
||||
$this->linkedModule = $module;
|
||||
$this->id_agentmodule($module->id_agentmodule());
|
||||
}
|
||||
|
||||
|
||||
|
@ -83,7 +134,8 @@ class Event extends Entity
|
|||
* @param boolean $return_sql Return sql or execute it.
|
||||
* @param string $having Having.
|
||||
*
|
||||
* @return array|string|falsse Found events or SQL query or error.
|
||||
* @return array|string|false Found events or SQL query or error.
|
||||
* @throws \Exception On error.
|
||||
*/
|
||||
public static function search(
|
||||
array $fields,
|
||||
|
@ -121,10 +173,10 @@ class Event extends Entity
|
|||
global $config;
|
||||
|
||||
if (isset($config['centralized_management']) === true
|
||||
&& $config['centralized_management'] > 0
|
||||
&& (bool) $config['centralized_management'] === true
|
||||
) {
|
||||
throw new \Exception(
|
||||
get_class($this).' error, cannot be modified while centralized management environment.'
|
||||
'error, cannot save in centralized management environment.'
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -147,30 +199,4 @@ class Event extends Entity
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return error message to target.
|
||||
*
|
||||
* @param string $msg Error message.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function error(string $msg)
|
||||
{
|
||||
echo json_encode(['error' => $msg]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Verifies target method is allowed to be called using AJAX call.
|
||||
*
|
||||
* @param string $method Method to be invoked via AJAX.
|
||||
*
|
||||
* @return boolean Available (true), or not (false).
|
||||
*/
|
||||
public static function ajaxMethod(string $method):bool
|
||||
{
|
||||
return in_array($method, self::$ajaxMethods) === true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ use PandoraFMS\Agent;
|
|||
use PandoraFMS\ModuleType;
|
||||
|
||||
/**
|
||||
* PandoraFMS agent entity.
|
||||
* PandoraFMS module entity.
|
||||
*/
|
||||
class Module extends Entity
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue