columns = ['agent' => 1];
if ($system->checkACL($this->acl)) {
$this->correct_acl = true;
} else {
$this->correct_acl = false;
}
}
public function setReadOnly()
{
$this->readOnly = true;
}
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();
} else {
$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_white.png';
break;
case 1:
$img_st = 'images/tick_white.png';
break;
case 2:
$img_st = 'images/hourglass_white.png';
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, false, false, false, false, true);
$row = [];
$row[] = ''.__('Event Name').'
',
$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;
}
}
}
public function disabledColumns($columns=null)
{
if (!empty($columns)) {
foreach ($columns as $column) {
$this->columns[$column] = 1;
}
}
}
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;
}
if ($system->getRequest('filter', __('Preset Filters')) === __('Preset Filters')) {
// Set filter as default user event filter (only first time)
$this->filter = db_get_value('default_event_filter', 'tusuario', 'id_user', $system->getConfig('id_user'));
// Use user set default filter if admin set default filter is "none"
if ($this->filter == 0) {
$this->filter = db_get_value('id_filter', 'tusuario', 'id_user', $system->getConfig('id_user'));
}
} else {
$this->filter = $system->getRequest('filter', __('Preset Filters'));
}
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);
}
public function setFilters($filters)
{
if (isset($filters['id_agent'])) {
$this->id_agent = $filters['id_agent'];
}
if (isset($filters['all_events'])) {
$this->all_events = $filters['all_events'];
}
}
private function loadPresetFilter()
{
$filter = db_get_row('tevent_filter', 'id_filter', $this->filter);
$this->free_search = null;
$this->hours_old = null;
$this->status = null;
$this->type = null;
$this->severity = null;
if ($filter !== false && empty($filter) === false) {
$this->free_search = $filter['search'];
$this->hours_old = $filter['event_view_hr'];
$this->status = $filter['status'];
$this->type = $filter['event_type'];
$this->severity = $filter['severity'];
}
}
public function show()
{
if (!$this->correct_acl) {
$this->show_fail_acl();
} else {
$this->eventsGetFilters();
$this->show_events();
}
}
private function show_fail_acl()
{
$error['type'] = 'onStart';
$error['title_text'] = __('You don\'t have access to this page');
$error['content_text'] = System::getDefaultACLFailText();
if (class_exists('HomeEnterprise')) {
$home = new HomeEnterprise();
} else {
$home = new Home();
}
$home->show($error);
}
public function get_event_dialog_error_options($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;
}
public function get_event_dialog_options()
{
$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( '