2013-03-20 Miguel de Dios <miguel.dedios@artica.es>

* mobile/index.php, mobile/operation/events.php,
	mobile/operation/alerts.php, include/functions_agents.php,
	include/functions_alerts.php,
	operation/agentes/alerts_status.functions.php: added first version
	of alert view.




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7875 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2013-03-20 17:41:35 +00:00
parent 69a4a5e67a
commit dba1396900
7 changed files with 376 additions and 7 deletions

View File

@ -1,3 +1,11 @@
2013-03-20 Miguel de Dios <miguel.dedios@artica.es>
* mobile/index.php, mobile/operation/events.php,
mobile/operation/alerts.php, include/functions_agents.php,
include/functions_alerts.php,
operation/agentes/alerts_status.functions.php: added first version
of alert view.
2013-03-20 Ramon Novoa <rnovoa@artica.es>
* godmode/servers/modificar_server.php: Added support for braa_retries.

View File

@ -23,6 +23,103 @@ require_once($config['homedir'] . "/include/functions_agents.php");
require_once($config['homedir'] . '/include/functions_modules.php');
require_once($config['homedir'] . '/include/functions_users.php');
function alerts_get_alerts($id_group = 0, $free_search = "", $status = "all", $standby = -1, $acl = false, $total = false) {
$sql = "";
$alerts = array();
//----------- Group ------------------------------------------------
if ($id_group != 0) {
if ($acl !== false) {
$groups = users_get_groups (false, $acl, false);
if (array_key_exists($id_group, $groups)) {
$group_query = " AND t3.id_grupo = " . $id_group . " ";
}
else {
//Set to fail the query
$group_query = " AND 1=0 ";
}
}
else {
$group_query = " AND t3.id_grupo = " . $id_group . " ";
}
}
else {
if ($acl !== false) {
$groups = users_get_groups (false, $acl, false);
$id_groups = array_keys($groups);
$group_query = " AND t3.id_grupo IN (" . implode(',', $id_groups) . ") ";
}
else {
$group_query = "";
}
}
//------------ Status ----------------------------------------------
switch ($status) {
case "notfired":
$status_query = ' AND t0.times_fired = 0 AND t0.disabled = 0';
break;
case "fired":
$status_query = ' AND t0.times_fired > 0 AND t0.disabled = 0';
break;
case "disabled":
$status_query = ' AND t0.disabled = 1';
break;
case "all_enabled":
$status_query = ' AND t0.disabled = 0';
break;
default:
$status_query = '';
break;
}
//----------- Standby ----------------------------------------------
$standby_query = '';
if ($standby != -1) {
$status_query .= ' AND t0.standby = ' . $standby . ' ';
}
//----------- Free search ------------------------------------------
$free_search = io_safe_input($free_search);
//----------- Make the query ---------------------------------------
if ($total) {
$sql = 'SELECT COUNT(*)';
}
else {
$sql = 'SELECT *, t2.nombre AS module_name,
t3.nombre AS agent_name, t1.name AS template_name,
t0.disabled AS alert_disabled ';
}
$sql .= '
FROM talert_template_modules AS t0
INNER JOIN talert_templates AS t1
ON t0.id_alert_template = t1.id
INNER JOIN tagente_modulo AS t2
ON t0.id_agent_module = t2.id_agente_modulo
INNER JOIN tagente AS t3
ON t2.id_agente = t3.id_agente
WHERE 1=1
' . $status_query . ' ' . $standby_query . ' ' . $group_query . '
AND (t1.name LIKE "%' . $free_search . '%"
OR t2.nombre LIKE "%' . $free_search . '%"
OR t3.nombre LIKE "%' . $free_search . '%")';
$row_alerts = db_get_all_rows_sql($sql);
if ($total) {
return reset($row_alerts[0]);
}
else {
return $row_alerts;
}
}
/**
* Get fired status from any alert of agent in group.
*

View File

@ -29,6 +29,7 @@ require_once('operation/home.php');
require_once('operation/tactical.php');
require_once('operation/groups.php');
require_once('operation/events.php');
require_once('operation/alerts.php');
$enterpriseHook = enterprise_include('mobile/include/enterprise.class.php');
$system = System::getInstance();
@ -97,6 +98,10 @@ switch ($action) {
$events = new Events();
$events->show();
break;
case 'alerts':
$alerts = new Alerts();
$alerts->show();
break;
}
break;
}

View File

@ -0,0 +1,259 @@
<?php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2010 Artica Soluciones Tecnologicas
// Please see http://pandorafms.org for full contribution list
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation for version 2.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
class Alerts {
private $correct_acl = false;
private $default = true;
private $free_search = '';
private $group = 0;
private $status = 'all';
private $standby = -1;
private $alert_status_items = null;
private $alert_standby_items = null;
function __construct() {
$this->alert_status_items = array(
'all_enabled' => __('All (Enabled)'),
'all' => __('All'),
'fired' => __('Fired'),
'notfired' => __('Not fired'),
'disabled' => __('Disabled'));
$this->alert_standby_items = array(
'-1' => __('All'),
'1' => __('Standby on'),
'0' => __('Standby off'));
$system = System::getInstance();
if ($system->checkACL("LM")) {
$this->correct_acl = true;
}
else {
$this->correct_acl = false;
}
}
private function alertsGetFilters() {
$system = System::getInstance();
$this->free_search = $system->getRequest('free_search', '');
if ($this->free_search != '') {
$this->default = false;
}
$this->status = $system->getRequest('status', __("Status"));
if ($this->status === __("Status")) {
$this->status = 'all';
}
else {
$this->default = false;
}
$this->group = $system->getRequest('group', __("Group"));
if ($this->group === __("Group")) {
$this->group = 0;
}
else {
$this->default = false;
}
$this->standby = $system->getRequest('standby', __('Stand by'));
if ($this->standby === __('Stand by')) {
$this->standby = -1;
}
else {
$this->default = false;
}
}
public function ajax($parameter2 = false) {
$system = System::getInstance();
if (!$this->correct_acl) {
return;
}
else {
switch ($parameter2) {
case 'xxxx':
break;
}
}
}
public function show() {
if (!$this->correct_acl) {
$this->show_fail_acl();
}
else {
$this->alertsGetFilters();
$this->show_alerts();
}
}
private function show_fail_acl() {
$ui = Ui::getInstance();
$ui->createPage();
$ui->addDialog(__('You don\'t have access to this page'),
__('Access to this page is restricted to authorized users only, please contact system administrator if you need assistance. <br><br>Please know that all attempts to access this page are recorded in security logs of Pandora System Database'));
$ui->showPage();
}
private function show_alerts() {
$ui = Ui::getInstance();
$ui->createPage();
$ui->createDefaultHeader(__("PandoraFMS: Alerts"));
$ui->showFooter(false);
$ui->beginContent();
$filter_title = sprintf(__('Filter Alerts by %s'),
$this->filterAlertsGetString());
$ui->contentBeginCollapsible($filter_title);
$ui->beginForm();
$options = array(
'name' => 'page',
'type' => 'hidden',
'value' => 'alerts'
);
$ui->formAddInput($options);
$system = System::getInstance();
$groups = users_get_groups_for_select(
$system->getConfig('id_user'), "ER", true, true, false, 'id_grupo');
$options = array(
'name' => 'group',
'title' => __('Group'),
'label' => __('Group'),
'items' => $groups,
'selected' => $this->group
);
$ui->formAddSelectBox($options);
$options = array(
'name' => 'free_search',
'value' => $this->free_search,
'placeholder' => __('Free search')
);
$ui->formAddInputSearch($options);
$options = array(
'name' => 'status',
'title' => __('Status'),
'label' => __('Status'),
'items' => $this->alert_status_items,
'selected' => $this->status
);
$ui->formAddSelectBox($options);
$options = array(
'name' => 'standby',
'title' => __('Stand by'),
'label' => __('Stand by'),
'items' => $this->alert_standby_items,
'selected' => $this->standby
);
$ui->formAddSelectBox($options);
$options = array(
'icon' => 'refresh',
'icon_pos' => 'right',
'text' => __('Apply Filter')
);
$ui->formAddSubmitButton($options);
$html = $ui->getEndForm();
$ui->contentCollapsibleAddItem($html);
$ui->contentEndCollapsible();
$this->listAlertsHtml();
$ui->endContent();
$ui->showPage();
}
private function listAlertsHtml () {
$countAlerts = alerts_get_alerts($this->group,
$this->free_search, $this->status, $this->standby, "LM", true);
$alerts = alerts_get_alerts($this->group,
$this->free_search, $this->status, $this->standby, "LM");
$table = array();
foreach ($alerts as $alert) {
if ($alert['alert_disabled']) {
$disabled_style = "<i style='color: grey;'>%s</i>";
}
else {
$disabled_style = "%s";
}
if ($alert["times_fired"] > 0) {
$status = STATUS_ALERT_FIRED;
$title = __('Alert fired').' '.$alert["times_fired"].' '.__('times');
}
elseif ($alert["disabled"] > 0) {
$status = STATUS_ALERT_DISABLED;
$title = __('Alert disabled');
}
else {
$status = STATUS_ALERT_NOT_FIRED;
$title = __('Alert not fired');
}
$row = array();
$row[__('Agent')] = sprintf($disabled_style,
'<a href="">' . io_safe_output($alert['agent_name'])) . '</a>';
$row[__('Module')] = sprintf($disabled_style,
io_safe_output($alert['module_name']));
$row[__('Template')] = sprintf($disabled_style,
io_safe_output($alert['template_name']));
$row[__('Last Fired')] = sprintf($disabled_style,
ui_print_timestamp ($alert["last_fired"], true));
$row[__('Status')] = ui_print_status_image($status, $title, true);
$table[] = $row;
}
$ui = UI::getInstance();
if (empty($table)) {
$ui->contentAddHtml('<p style="color: #ff0000;">' . __('No alerts') . '</p>');
}
else {
$tableHTML = new Table();
$tableHTML->importFromHash($table);
$ui->contentAddHtml($tableHTML->getHTML());
}
}
private function filterAlertsGetString() {
if ($this->default) {
return __("(Default)");
}
else {
$status_text = $this->alert_status_items[$this->status];
$standby_text = $this->alert_standby_items[$this->standby];
$group_text = groups_get_name($this->group, true);
return sprintf(__('(Status: %s - Standby: %s - Group: %s - Free Search: %s)'),
$status_text, $standby_text, $group_text, $this->free_search);
}
}
}
?>

View File

@ -188,7 +188,7 @@ class Events {
$ui->createDefaultHeader(__("PandoraFMS: Events"));
$ui->showFooter(false);
$ui->beginContent();
$filter_title = sprintf(__('Filter Events by %s'), $this->filterEventsGetString());
$filter_title = sprintf(__('Filter Events by %s'), $this->filterEventsGetString());
$ui->contentBeginCollapsible($filter_title);
$ui->beginForm();
$options = array(
@ -374,7 +374,7 @@ class Events {
$field_agent = __('Agent');
foreach ($events_db as $event) {
$row = array();
$row[$field_event_name] = $event['evento'];
$row[$field_event_name] = io_safe_output($event['evento']);
switch ($event['estado']) {
case 0:
$img_st = "images/star.png";

View File

@ -68,7 +68,7 @@ function printFormFilterAlert($id_group, $filter, $free_search, $url, $filter_st
$data .= html_print_table ($table, true);
$data .= '</form>';
if($return) {
if ($return) {
return $data;
}
else {