columns = ['agent' => 1];
if ($system->checkACL($this->acl)) {
$this->correct_acl = true;
} else {
$this->correct_acl = false;
}
}
/**
* Set read only
*
* @return void
*/
public function setReadOnly()
{
$this->readOnly = true;
}
/**
* Ajax function.
*
* @param boolean $parameter2 Rarameters.
*
* @return void
*/
public function ajax($parameter2=false)
{
$system = System::getInstance();
if ($this->correct_acl === false) {
return;
} else {
switch ($parameter2) {
case 'get_events':
if ($system->getRequest('agent_events', '0') == 1) {
$this->disabledColumns(['agent']);
$filters = ['id_agent' => $system->getRequest('id_agent', 0)];
$this->setFilters($filters);
$this->setReadOnly();
}
$this->eventsGetFilters();
$page = $system->getRequest('page', 0);
$system = System::getInstance();
$listEvents = $this->getListEvents($page);
$events_db = $listEvents['events'];
$total_events = $listEvents['total'];
$events = [];
$end = 1;
foreach ($events_db as $event) {
$end = 0;
switch ($event['estado']) {
case 0:
$img_st = 'images/star-dark.svg';
break;
case 1:
$img_st = 'images/validate.svg';
break;
case 2:
$img_st = 'images/clock.svg';
break;
default:
// Not possible.
break;
}
if ($event['criticity'] === EVENT_CRIT_WARNING
|| $event['criticity'] === EVENT_CRIT_MAINTENANCE
|| $event['criticity'] === EVENT_CRIT_MINOR
) {
$img_st = str_replace('white.png', 'dark.png', $img_st);
}
$status_icon = html_print_image(
$img_st,
true,
['class' => 'main_menu_icon'],
false,
false,
false,
true
);
if (isset($event['server_id']) === false) {
$event['server_id'] = 0;
}
$row = [];
$row_0 = '';
$row_0 .= __('Event Name');
$row_0 .= '';
$row_0 .= '
',
$c['comment']
);
$comment .= '
'.$c['comment'].'
';
}
}
$event['comments'] = $comment;
echo json_encode(['correct' => 1, 'event' => $event]);
} else {
echo json_encode(['correct' => 0, 'event' => []]);
}
} catch (\Exception $e) {
// Unexistent agent.
if (is_metaconsole() === true
&& $server_id > 0
) {
$node->disconnect();
}
echo json_encode(['correct' => 0, 'event' => []]);
} finally {
if (is_metaconsole() === true
&& $server_id > 0
) {
$node->disconnect();
}
}
break;
case 'validate_event':
$system = System::getInstance();
$id_event = $system->getRequest('id_event', 0);
$server_id = $system->getRequest('server_id', 0);
try {
if (is_metaconsole() === true
&& $server_id > 0
) {
$node = new Node($server_id);
$node->connect();
}
if (events_change_status($id_event, EVENT_VALIDATE) === true) {
echo json_encode(['correct' => 1]);
} else {
echo json_encode(['correct' => 0]);
}
} catch (\Exception $e) {
// Unexistent agent.
if (is_metaconsole() === true
&& $server_id > 0
) {
$node->disconnect();
}
echo json_encode(['correct' => 0]);
} finally {
if (is_metaconsole() === true
&& $server_id > 0
) {
$node->disconnect();
}
}
break;
case 'process_event':
$system = System::getInstance();
$id_event = $system->getRequest('id_event', 0);
$server_id = $system->getRequest('server_id', 0);
try {
if (is_metaconsole() === true
&& $server_id > 0
) {
$node = new Node($server_id);
$node->connect();
}
if (events_change_status($id_event, EVENT_PROCESS) === true) {
echo json_encode(['correct' => 1]);
} else {
echo json_encode(['correct' => 0]);
}
} catch (\Exception $e) {
// Unexistent agent.
if (is_metaconsole() === true
&& $server_id > 0
) {
$node->disconnect();
}
echo json_encode(['correct' => 0]);
} finally {
if (is_metaconsole() === true
&& $server_id > 0
) {
$node->disconnect();
}
}
break;
default:
// Not possible.
break;
}
}
}
/**
* Disable columns.
*
* @param array $columns Columns.
*
* @return void
*/
public function disabledColumns($columns=null)
{
if (empty($columns) === false) {
foreach ($columns as $column) {
$this->columns[$column] = 1;
}
}
}
/**
* Events get filters.
*
* @return void
*/
private function eventsGetFilters()
{
$system = System::getInstance();
$user = User::getInstance();
$this->default_filters['severity'] = true;
$this->default_filters['group'] = true;
$this->default_filters['type'] = true;
$this->default_filters['status'] = true;
$this->default_filters['free_search'] = true;
$this->default_filters['hours_old'] = true;
$this->hours_old = $system->getRequest('hours_old', 8);
if ($this->hours_old != 8) {
$this->default = false;
$this->default_filters['hours_old'] = false;
}
$this->free_search = $system->getRequest('free_search', '');
if ($this->free_search != '') {
$this->default = false;
$this->default_filters['free_search'] = false;
}
$this->status = $system->getRequest('status', __('Status'));
if (($this->status === __('Status')) || ($this->status == 3)) {
$this->status = 3;
} else {
$this->status = (int) $this->status;
$this->default = false;
$this->default_filters['status'] = false;
}
$this->type = $system->getRequest('type', __('Type'));
if ($this->type === __('Type')) {
$this->type = 'all';
} else {
$this->default = false;
$this->default_filters['type'] = false;
}
$this->group = $system->getRequest('group', __('Group'));
if (!$user->isInGroup($this->acl, $this->group)) {
$this->group = 0;
}
if (($this->group === __('Group')) || ($this->group == 0)) {
$this->group = 0;
} else {
$this->default = false;
$this->default_filters['group'] = false;
}
$this->severity = $system->getRequest('severity', __('Severity'));
if ($this->severity === __('Severity')) {
$this->severity = -1;
} else {
$this->default = false;
$this->default_filters['severity'] = false;
}
$this->filter = $system->getRequest('filter', 0);
if ($this->filter != 0) {
$this->default = false;
}
// The user set a preset filter.
if ($this->filter > 0) {
// $this->loadPresetFilter();
}
$this->limit = $system->getRequest('limit', -1);
}
/**
* Set filters.
*
* @param array $filters Filters.
*
* @return void
*/
public function setFilters($filters)
{
if (isset($filters['id_agent']) === true) {
$this->id_agent = $filters['id_agent'];
}
if (isset($filters['all_events']) === true) {
$this->all_events = $filters['all_events'];
}
}
/**
* Show.
*
* @return void
*/
public function show()
{
if (!$this->correct_acl) {
$this->showFailAcl();
} else {
$this->eventsGetFilters();
$this->showEvents();
}
}
/**
* Show fail.
*
* @return void
*/
private function showFailAcl()
{
$error['type'] = 'onStart';
$error['title_text'] = __('You don\'t have access to this page');
$error['content_text'] = System::getDefaultACLFailText();
if (class_exists('HomeEnterprise') === true) {
$home = new HomeEnterprise();
} else {
$home = new Home();
}
$home->show($error);
}
/**
* Event dialog error.
*
* @param array $options Options.
*
* @return array Array.
*/
public function getEventDialogErrorOptions($options)
{
$options['type'] = 'hidden';
$options['dialog_id'] = 'detail_event_dialog_error';
$options['title_text'] = __('ERROR: Event detail');
$options['content_text'] = ''.__('Error connecting to DB.').'';
return $options;
}
/**
* Event dialog options.
*
* @return array
*/
public function getEventDialogOptions()
{
$ui = Ui::getInstance();
$options['type'] = 'hidden';
$options['dialog_id'] = 'detail_event_dialog';
$options['title_close_button'] = true;
$options['title_text'] = __('Event detail');
// Content.
ob_start();
?>
'.__('No events').'
'; if (!$return) { $ui->contentAddHtml($table->getHTML()); $ui->contentAddHtml( '