diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 13cb304285..d5fff45e37 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,24 @@ +2012-01-23 Juan Manuel Ramon + + * include/functions_agents.php + operation/incidents/incident.php + operation/incidents/incident_detail.php + operation/agentes/ver_agente.php + godmode/agentes/agent_incidents.php + godmode/agentes/configurar_agente.php: Added the possibility to add + agent to an incident and added new tab in agent view if the agent + has incidents associated. + + * pandoradb.postgreSQL.sql + pandoradb.oracle.sql + pandoradb.sql + extras/pandoradb_migrate_4.0.x_to_4.1.mysql.sql + extras/pandoradb_migrate_4.0.x_to_4.1.oracle.sql + extras/pandoradb_migrate_4.0.x_to_4.1.postgreSQL.sql: modified + table tincidencia. + + Pending task: # 3472447 + 2012-01-23 Vanessa Gil * operation/agentes/estado_agente.php diff --git a/pandora_console/extras/pandoradb_migrate_4.0.x_to_4.1.mysql.sql b/pandora_console/extras/pandoradb_migrate_4.0.x_to_4.1.mysql.sql index 394c6a7032..760e26c37a 100644 --- a/pandora_console/extras/pandoradb_migrate_4.0.x_to_4.1.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_4.0.x_to_4.1.mysql.sql @@ -53,3 +53,8 @@ CREATE TABLE IF NOT EXISTS `tnetflow_report_content` ( ALTER TABLE `tusuario` ADD COLUMN `disabled` int(4) NOT NULL DEFAULT 0; +-- ----------------------------------------------------- +-- Table `tincidencia` +-- ----------------------------------------------------- + +ALTER TABLE `tincidencia` ADD COLUMN `id_agent` int(10) unsigned NULL default 0; diff --git a/pandora_console/extras/pandoradb_migrate_4.0.x_to_4.1.oracle.sql b/pandora_console/extras/pandoradb_migrate_4.0.x_to_4.1.oracle.sql index f1a5bab71c..1ebfe2ed9f 100644 --- a/pandora_console/extras/pandoradb_migrate_4.0.x_to_4.1.oracle.sql +++ b/pandora_console/extras/pandoradb_migrate_4.0.x_to_4.1.oracle.sql @@ -54,3 +54,9 @@ show_graph VARCHAR2(60), CREATE SEQUENCE tnetflow_report_content_s INCREMENT BY 1 START WITH 1; CREATE OR REPLACE TRIGGER tnetflow_report_content_inc BEFORE INSERT ON tnetflow_report_content REFERENCING NEW AS NEW FOR EACH ROW BEGIN SELECT tnetflow_report_content_s.nextval INTO :NEW.ID_RC FROM dual; END tnetflow_report_content_inc;; + +-- ----------------------------------------------------- +-- Table `tincidencia` +-- ----------------------------------------------------- + +alter table tincidencia add (id_agent NUMBER(10,0) default 0 NULL); diff --git a/pandora_console/extras/pandoradb_migrate_4.0.x_to_4.1.postgreSQL.sql b/pandora_console/extras/pandoradb_migrate_4.0.x_to_4.1.postgreSQL.sql index 9619ccf3bb..d4b648af7f 100644 --- a/pandora_console/extras/pandoradb_migrate_4.0.x_to_4.1.postgreSQL.sql +++ b/pandora_console/extras/pandoradb_migrate_4.0.x_to_4.1.postgreSQL.sql @@ -43,3 +43,8 @@ CREATE TABLE "tnetflow_report_content" ( "order" INTEGER NOT NULL default 0 ); +-- ----------------------------------------------------- +-- Table `tincidencia` +-- ----------------------------------------------------- + +ALTER TABLE "tincidencia" ADD COLUMN "id_agent" INTEGER(10) NULL DEFAULT 0; diff --git a/pandora_console/godmode/agentes/agent_incidents.php b/pandora_console/godmode/agentes/agent_incidents.php new file mode 100644 index 0000000000..b822d96c1f --- /dev/null +++ b/pandora_console/godmode/agentes/agent_incidents.php @@ -0,0 +1,130 @@ +'.__('No incidents associated to this agent').'
'; + return; +} + +// Show pagination +ui_pagination ($count, $url, $offset, 0, false, 'offset'); //($count + $offset) it's real count of incidents because it's use LIMIT $offset in query. +echo '
'; + +// Show headers +$table->width = "100%"; +$table->class = "databox"; +$table->cellpadding = 4; +$table->cellspacing = 4; +$table->head = array (); +$table->data = array (); +$table->size = array (); +$table->align = array (); + +$table->head[0] = __('ID'); +$table->head[1] = __('Status'); +$table->head[2] = __('Incident'); +$table->head[3] = __('Priority'); +$table->head[4] = __('Group'); +$table->head[5] = __('Updated'); +$table->head[6] = __('Source'); +$table->head[7] = __('Owner'); + +$table->size[0] = 43; +$table->size[7] = 50; + +$table->align[1] = "center"; +$table->align[3] = "center"; +$table->align[4] = "center"; + +$rowPair = true; +$iterator = 0; +foreach ($result as $row) { + if ($rowPair) + $table->rowclass[$iterator] = 'rowPair'; + else + $table->rowclass[$iterator] = 'rowOdd'; + $rowPair = !$rowPair; + $iterator++; + + $data = array(); + + $data[0] = ''.$row["id_incidencia"].''; + $attach = incidents_get_attach ($row["id_incidencia"]); + + if (!empty ($attach)) + $data[0] .= '  '.html_print_image ("images/attachment.png", true, array ("style" => "align:middle;")); + + $data[1] = incidents_print_status_img ($row["estado"], true); + $data[2] = ''.substr(io_safe_output($row["titulo"]),0,45).''; + $data[3] = incidents_print_priority_img ($row["prioridad"], true); + $data[4] = ui_print_group_icon ($row["id_grupo"], true); + $data[5] = ui_print_timestamp ($row["actualizacion"], true); + $data[6] = $row["origen"]; + $data[7] = ui_print_username ($row["id_usuario"], true); + + array_push ($table->data, $data); +} +html_print_table ($table); + +echo ''; +unset ($table); +echo '

'; + +echo '
 
'; +?> diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index ec4edcb72f..01afa63fc6 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -247,7 +247,7 @@ if ($id_agente) { if($tab == 'alert') $alerttab['active'] = true; else - $alerttab['active'] = false; + $alerttab['active'] = false; /* Template tab */ $templatetab['text'] = '' @@ -295,10 +295,29 @@ if ($id_agente) { $gistab['active'] = false; } + $total_incidents = agents_get_count_incidents($id_agente); + + /* Incident tab */ + if ($config['integria_enabled'] == 0 and $total_incidents > 0){ + $incidenttab['text'] = '' + . html_print_image ("images/book_edit.png", true, array ("title" =>__('Incidents'))) + . ''; + + if($tab == 'incident') + $incidenttab['active'] = true; + else + $incidenttab['active'] = false; + } + $onheader = array('view' => $viewtab, 'separator' => "", 'main' => $maintab, 'module' => $moduletab, 'alert' => $alerttab, 'template' => $templatetab, 'inventory' => $inventorytab, 'collection'=> $collectiontab, 'group' => $grouptab, 'gis' => $gistab); + // Only if the agent has incidents associated show incidents tab + if ($total_incidents){ + $onheader['incident'] = $incidenttab; + } + foreach($config['extensions'] as $extension) { if (isset($extension['extension_god_tab'])) { $image = $extension['extension_god_tab']['icon']; @@ -345,6 +364,9 @@ if ($id_agente) { case "gis": $tab_description = '- ' . __('Gis') . ui_print_help_icon('gis_tab', true); break; + case "incident": + $tab_description = '- ' . __('Incidents'); + break; case "extension": $id_extension = get_parameter('id_extension', ''); switch ($id_extension){ @@ -1065,6 +1087,9 @@ switch ($tab) { case "gis": require("agent_conf_gis.php"); break; + case "incident": + require("agent_incidents.php"); + break; case "extension": $found = false; foreach($config['extensions'] as $extension) { diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index c430418f87..ebba182771 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -1808,4 +1808,19 @@ function agents_get_agent_group ($id_agent) { return (int) db_get_value ('id_grupo', 'tagente', 'id_agente', (int) $id_agent); } +/** + * This function gets the count of incidents attached to the agent + * + * @param int The agent id + * + * @return mixed The incidents attached or false + */ +function agents_get_count_incidents ($id_agent) { + if (empty($id_agent)){ + return false; + } + + return db_get_value('count(*)', 'tincidencia', 'id_agent', $id_agent); +} + ?> diff --git a/pandora_console/operation/agentes/ver_agente.php b/pandora_console/operation/agentes/ver_agente.php index 3d63723cdf..16d23f562e 100644 --- a/pandora_console/operation/agentes/ver_agente.php +++ b/pandora_console/operation/agentes/ver_agente.php @@ -580,6 +580,20 @@ if ($config['activate_gis']) { $gistab['active'] = false; } +$total_incidents = agents_get_count_incidents($id_agente); + + /* Incident tab */ +if ($config['integria_enabled'] == 0 and $total_incidents > 0){ + $incidenttab['text'] = '' + . html_print_image ("images/book_edit.png", true, array ("title" =>__('Incidents'))) + . ''; + + if($tab == 'incident') + $incidenttab['active'] = true; + else + $incidenttab['active'] = false; +} + $custom_fields['text']= '' . html_print_image("images/note.png", true, array("title" => __('Custom fields'))) . ''; @@ -607,6 +621,11 @@ $onheader = array('manage' => $managetab, 'separator' => "", 'main' => $maintab, 'inventory' => $inventorytab, 'collection' => $collectiontab, 'group' => $grouptab, 'gis' => $gistab, 'custom' => $custom_fields, 'graphs' => $graphs, 'policy' => $policyTab); +// If the agent has incidents associated +if ($total_incidents){ + $onheader['incident'] = $incidenttab; +} + foreach($config['extensions'] as $extension) { if (isset($extension['extension_ope_tab'])) { @@ -677,7 +696,10 @@ switch($tab) { break; case "policy": $header_description = ' - ' . __('Policy'); - break; + break; + case "incident": + $header_description = ' - ' . __('Incident'); + break; } ui_print_page_header (__('Agent').' - '.mb_substr(agents_get_name($id_agente),0,25) . $header_description, $icon, false, "", false, $onheader); @@ -723,6 +745,9 @@ switch ($tab) { case "graphs"; require("operation/agentes/graphs.php"); break; + case "incident": + require("godmode/agentes/agent_incidents.php"); + break; case "extension": $found = false; foreach($config['extensions'] as $extension) { diff --git a/pandora_console/operation/incidents/incident.php b/pandora_console/operation/incidents/incident.php index 2e7e22d14c..0a45e43a0b 100755 --- a/pandora_console/operation/incidents/incident.php +++ b/pandora_console/operation/incidents/incident.php @@ -88,9 +88,10 @@ elseif ($action == "update") { $estado = get_parameter ("estado_form", 0); $grupo = get_parameter ("grupo_form", 1); $usuario = get_parameter ("usuario_form", $config["id_user"]); + $id_agent = get_parameter ("incident_agents"); - $sql = sprintf ("UPDATE tincidencia SET titulo = '%s', origen = '%s', estado = %d, id_grupo = %d, id_usuario = '%s', prioridad = %d, descripcion = '%s', id_lastupdate = '%s' WHERE id_incidencia = %d", - $titulo, $origen, $estado, $grupo, $usuario, $prioridad, $descripcion, $config["id_user"], $id_inc); + $sql = sprintf ("UPDATE tincidencia SET titulo = '%s', origen = '%s', estado = %d, id_grupo = %d, id_usuario = '%s', prioridad = %d, descripcion = '%s', id_lastupdate = '%s', id_agent = %d WHERE id_incidencia = %d", + $titulo, $origen, $estado, $grupo, $usuario, $prioridad, $descripcion, $config["id_user"], $id_agent, $id_inc); $result = db_process_sql ($sql); if ($result !== false) { @@ -120,8 +121,9 @@ elseif ($action == "insert") { $prioridad = get_parameter ("prioridad_form"); $id_creator = $config['id_user']; $estado = get_parameter ("estado_form"); - $sql = sprintf ("INSERT INTO tincidencia (inicio, actualizacion, titulo, descripcion, id_usuario, origen, estado, prioridad, id_grupo, id_creator) VALUES - (NOW(), NOW(), '%s', '%s', '%s', '%s', %d, %d, '%s', '%s')", $titulo, $descripcion, $config["id_user"], $origen, $estado, $prioridad, $grupo, $config["id_user"]); + $id_agent = get_parameter ("incident_agents"); + $sql = sprintf ("INSERT INTO tincidencia (inicio, actualizacion, titulo, descripcion, id_usuario, origen, estado, prioridad, id_grupo, id_creator, id_agent) VALUES + (NOW(), NOW(), '%s', '%s', '%s', '%s', %d, %d, '%s', '%s', %d)", $titulo, $descripcion, $config["id_user"], $origen, $estado, $prioridad, $grupo, $config["id_user"], $id_agent); $id_inc = db_process_sql ($sql, "insert_id"); if ($id_inc === false) { @@ -161,6 +163,11 @@ $prioridad = (int) get_parameter ("prioridad", -1); if ($prioridad != -1) //-1 = All $filter .= sprintf (" AND prioridad = %d", $prioridad); +$agent_search = (int) get_parameter("agent_search"); +if ($agent_search != 0){ + $filter .= sprintf(" AND id_agent = %d", $agent_search); +} + $offset = (int) get_parameter ("offset", 0); $groups = users_get_groups ($config["id_user"], "IR"); @@ -171,14 +178,17 @@ $sql = "SELECT * FROM tincidencia WHERE ORDER BY actualizacion DESC LIMIT ".$offset.",".$config["block_size"]; $result = db_get_all_rows_sql ($sql); + +$count_sql = "SELECT count(*) FROM tincidencia WHERE + id_grupo IN (".implode (",",array_keys ($groups)).")".$filter." + ORDER BY actualizacion DESC"; + +$count = db_get_value_sql ($count_sql); + if (empty ($result)) { $result = array (); $count = 0; } -else { - $count = count ($result); -} - echo '
'; @@ -214,6 +224,20 @@ echo ''; html_print_select (users_get_info (), "usuario", $usuario, 'javascript:this.form.submit();', __('All users'), "", false, false, false, "w155"); +echo ''; + +$agents_incidents = agents_get_agents(false, array('id_agente', 'nombre')); + +if ($agents_incidents === false){ + $agents_incidents = array(); +} + +foreach ($agents_incidents as $agent_incident){ + $result_agent_incidents[$agent_incident['id_agente']] = $agent_incident['nombre']; +} + +html_print_select ($result_agent_incidents, "agent_search", $agent_search, 'javascript:this.form.submit();', __('All agents'), "", false, false, false, "w155"); + echo ''; html_print_select_groups($config["id_user"], "IR", true, "grupo", $grupo, 'javascript:this.form.submit();', '', '',false,false,false,'w155'); @@ -248,7 +272,7 @@ if ($count < 1) { $url .= "&texto=".$texto; // Show pagination - ui_pagination ($count + $offset, $url, $offset, 15, false); //($count + $offset) it's real count of incidents because it's use LIMIT $offset in query. + ui_pagination ($count, $url, $offset, 0, false); //($count + $offset) it's real count of incidents because it's use LIMIT $offset in query. echo '
'; // Show headers diff --git a/pandora_console/operation/incidents/incident_detail.php b/pandora_console/operation/incidents/incident_detail.php index d885d8e324..008dad62ec 100755 --- a/pandora_console/operation/incidents/incident_detail.php +++ b/pandora_console/operation/incidents/incident_detail.php @@ -50,6 +50,7 @@ if (isset ($_GET["id"])) { $id_grupo = $row["id_grupo"]; $id_creator = $row["id_creator"]; //creator $id_lastupdate = $row["id_lastupdate"]; //last updater + $id_agent = $row["id_agent"]; // Agent // Note add - everybody that can read incidents, can add notes if (isset ($_GET["insertar_nota"])) { @@ -179,6 +180,7 @@ elseif (isset ($_GET["insert_form"])) { $usuario = $config["id_user"]; $id_creator = $config["id_user"]; $id_grupo = 0; + $id_agent = 0; if (isset ($_GET["from_event"])) { $event = get_parameter ("from_event"); @@ -300,6 +302,20 @@ if (empty ($id_creator)) { echo $id_creator.' ('.get_user_fullname($id_creator).')'; } +$agents_incidents = agents_get_agents(false, array('id_agente', 'nombre')); + +if ($agents_incidents === false){ + $agents_incidents = array(); +} + +foreach ($agents_incidents as $agent_incident){ + $result_agent_incidents[$agent_incident['id_agente']] = $agent_incident['nombre']; +} + +echo ''.__('Agent').''; + +html_print_select ($result_agent_incidents, "incident_agents", $id_agent, '', __('None'), 0, false, false, false, 'w135', false); + echo ''; if ((check_acl ($config["id_user"], $id_grupo, "IM") == 1) OR ($usuario == $config["id_user"])) { diff --git a/pandora_console/pandoradb.oracle.sql b/pandora_console/pandoradb.oracle.sql index cc7024176e..006dc2f05a 100644 --- a/pandora_console/pandoradb.oracle.sql +++ b/pandora_console/pandoradb.oracle.sql @@ -534,7 +534,8 @@ CREATE TABLE tincidencia ( id_creator VARCHAR2(60) default NULL, id_lastupdate VARCHAR2(60) default NULL, id_agente_modulo NUMBER(19, 0) NOT NULL, - notify_email NUMBER(10, 0) default 0 NOT NULL + notify_email NUMBER(10, 0) default 0 NOT NULL, + id_agent NUMBER(19, 0) default 0 NULL ); CREATE INDEX tincidencia_id_1_idx ON tincidencia(id_usuario,id_incidencia); CREATE INDEX tincidencia_id_agente_mod_idx ON tincidencia(id_agente_modulo); diff --git a/pandora_console/pandoradb.postgreSQL.sql b/pandora_console/pandoradb.postgreSQL.sql index bdd24e69b3..c37cc7851f 100644 --- a/pandora_console/pandoradb.postgreSQL.sql +++ b/pandora_console/pandoradb.postgreSQL.sql @@ -420,7 +420,8 @@ CREATE TABLE "tincidencia" ( "id_creator" varchar(60) default NULL, "id_lastupdate" varchar(60) default NULL, "id_agente_modulo" BIGINT NOT NULL, - "notify_email" INTEGER NOT NULL default 0 + "notify_email" INTEGER NOT NULL default 0, + "id_agent" INTEGER(10) NULL default 0 ); CREATE INDEX "tincidencia_id_1_idx" ON "tincidencia"("id_usuario","id_incidencia"); CREATE INDEX "tincidencia_id_agente_modulo_idx" ON "tincidencia"("id_agente_modulo"); diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index e15d751709..059881e9f5 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -470,6 +470,7 @@ CREATE TABLE IF NOT EXISTS `tincidencia` ( `id_lastupdate` varchar(60) default NULL, `id_agente_modulo` bigint(100) NOT NULL, `notify_email` tinyint(3) unsigned NOT NULL default '0', + `id_agent` int(10) unsigned NULL default 0, PRIMARY KEY (`id_incidencia`), KEY `incident_index_1` (`id_usuario`,`id_incidencia`), KEY `id_agente_modulo` (`id_agente_modulo`)