diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 5e7692cf92..9f23f6344a 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,23 @@ +2010-08-25 Sergio Martin + + * pandoradb.sql + operation/agentes/estado_generalagente.php + operation/agentes/custom_fields.php + operation/agentes/ver_agente.php + operation/agentes/agent_fields.php + extras/pandoradb_migrate_v3.1_to_v3.2.sql + godmode/agentes/fields_manager.php + godmode/agentes/configurar_agente.php + godmode/agentes/configure_field.php + godmode/agentes/agent_manager.php + godmode/menu.php: Added the custom field feature + including agents custom fields managment, agent + custom field viewer, custom fields added at the + agent configuration, customization of the custom + fields to display it in the agent details and + the creation of two new tables into the sql scripts + All for pending task: 3052918 + 2010-08-24 Sergio Martin * extensions/module_groups/icon_menu.png diff --git a/pandora_console/extras/pandoradb_migrate_v3.1_to_v3.2.sql b/pandora_console/extras/pandoradb_migrate_v3.1_to_v3.2.sql index 3f3652e71c..9fec66b8bf 100644 --- a/pandora_console/extras/pandoradb_migrate_v3.1_to_v3.2.sql +++ b/pandora_console/extras/pandoradb_migrate_v3.1_to_v3.2.sql @@ -94,3 +94,28 @@ l', 'onchange', 'unknown'); ALTER TABLE trecon_task ADD `snmp_community` varchar(64) NOT NULL default 'public'; +-- ----------------------------------------------------- +-- Table `tagent_custom_fields` +-- ----------------------------------------------------- + +CREATE TABLE IF NOT EXISTS `tagent_custom_fields` ( + `id_field` int(10) unsigned NOT NULL auto_increment, + `name` varchar(45) NOT NULL default '', + `display_on_front` tinyint(1) NOT NULL default 0, + PRIMARY KEY (`id_field`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- ----------------------------------------------------- +-- Table `tagent_custom_data` +-- ----------------------------------------------------- + +CREATE TABLE IF NOT EXISTS `tagent_custom_data` ( + `id_field` int(10) unsigned NOT NULL, + `id_agent` int(10) unsigned NOT NULL, + `description` text default '', + FOREIGN KEY (`id_field`) REFERENCES tagent_custom_fields(`id_field`) + ON UPDATE CASCADE ON DELETE CASCADE, + FOREIGN KEY (`id_agent`) REFERENCES tagente(`id_agente`) + ON UPDATE CASCADE ON DELETE CASCADE, + PRIMARY KEY (`id_field`, `id_agent`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 diff --git a/pandora_console/godmode/agentes/agent_manager.php b/pandora_console/godmode/agentes/agent_manager.php index ff562e3b9b..183c9cb95f 100644 --- a/pandora_console/godmode/agentes/agent_manager.php +++ b/pandora_console/godmode/agentes/agent_manager.php @@ -92,7 +92,7 @@ $table->class = "databox_color"; $table->head = array (); $table->style = array (); -$table->style[0] = 'font-weight: bold'; +$table->style[0] = 'font-weight: bold; width: 150px;'; $table->data = array (); $table->data[0][0] = __('Agent name') . @@ -168,39 +168,50 @@ $table->data[6][0] = __('Server'); $table->data[6][1] = print_select (get_server_names (), 'server_name', $server_name, '', $none, 0, true); -// Custom ID -$table->data[7][0] = __('Custom ID'); -$table->data[7][1] = print_input_text ('custom_id', $custom_id, '', 16, 255, true); - // Description -$table->data[8][0] = __('Description'); -$table->data[8][1] = print_input_text ('comentarios', $comentarios, '', 45, 255, true); +$table->data[7][0] = __('Description'); +$table->data[7][1] = print_input_text ('comentarios', $comentarios, '', 45, 255, true); + +print_table ($table); +unset($table); + +$table->width = '95%'; +$table->class = "databox_color"; + +$table->head = array (); +$table->style = array (); +$table->style[0] = 'font-weight: bold; width: 150px;'; +$table->data = array (); + +// Custom ID +$table->data[0][0] = __('Custom ID'); +$table->data[0][1] = print_input_text ('custom_id', $custom_id, '', 16, 255, true); // Learn mode / Normal mode -$table->data[9][0] = __('Module definition').print_help_icon("module_definition", true); -$table->data[9][1] = __('Learning mode').' '.print_radio_button_extended ("modo", 1, '', $modo, false, '', 'style="margin-right: 40px;"', true); -$table->data[9][1] .= __('Normal mode').' '.print_radio_button_extended ("modo", 0, '', $modo, false, '', 'style="margin-right: 40px;"', true); +$table->data[1][0] = __('Module definition').print_help_icon("module_definition", true); +$table->data[1][1] = __('Learning mode').' '.print_radio_button_extended ("modo", 1, '', $modo, false, '', 'style="margin-right: 40px;"', true); +$table->data[1][1] .= __('Normal mode').' '.print_radio_button_extended ("modo", 0, '', $modo, false, '', 'style="margin-right: 40px;"', true); // Status (Disabled / Enabled) -$table->data[10][0] = __('Status'); -$table->data[10][1] = __('Disabled').' '.print_radio_button_extended ("disabled", 1, '', $disabled, false, '', 'style="margin-right: 40px;"', true); -$table->data[10][1] .= __('Active').' '.print_radio_button_extended ("disabled", 0, '', $disabled, false, '', 'style="margin-right: 40px;"', true); +$table->data[2][0] = __('Status'); +$table->data[2][1] = __('Disabled').' '.print_radio_button_extended ("disabled", 1, '', $disabled, false, '', 'style="margin-right: 40px;"', true); +$table->data[2][1] .= __('Active').' '.print_radio_button_extended ("disabled", 0, '', $disabled, false, '', 'style="margin-right: 40px;"', true); // Remote configuration -$table->data[11][0] = __('Remote configuration'); +$table->data[3][0] = __('Remote configuration'); if (!$new_agent) { if (file_exists ($filename['md5'])) { - $table->data[11][1] = date ("F d Y H:i:s", fileatime ($filename['md5'])); + $table->data[3][1] = date ("F d Y H:i:s", fileatime ($filename['md5'])); // Delete remote configuration - $table->data[11][1] .= ''; - $table->data[11][1] .= print_image ("images/cross.png", true).''; + $table->data[3][1] .= ''; + $table->data[3][1] .= print_image ("images/cross.png", true).''; } else - $table->data[11][1] = ''.__('Not available').''; + $table->data[3][1] = ''.__('Not available').''; } else - $table->data[11][1] = ''.__('Not available').''; + $table->data[3][1] = ''.__('Not available').''; $listIcons = getArrayListIcons(); @@ -209,8 +220,8 @@ foreach ($listIcons as $index => $value) $arraySelectIcon[$index] = $index; $path = 'images/gis_map/icons/'; //TODO set better method the path -$table->data[12][0] = __('Agent icon'); -$table->data[12][1] = print_select($arraySelectIcon, "icon_path", $icon_path, "changeIcons();", __('None'), '', true) . +$table->data[4][0] = __('Agent icon'); +$table->data[4][1] = print_select($arraySelectIcon, "icon_path", $icon_path, "changeIcons();", __('None'), '', true) . ' ' . __('Without status') . ': ' . ' ' . __('Default') . ': ' . ' ' . __('Ok') . ': ' . @@ -218,12 +229,44 @@ $table->data[12][1] = print_select($arraySelectIcon, "icon_path", $icon_path, "c ' ' . __('Warning') . ': '; if ($config['activate_gis']) { - $table->data[13][0] = __('Ignore new GIS data:'); - $table->data[13][1] = __('Disabled').' '.print_radio_button_extended ("update_gis_data", 0, '', $update_gis_data, false, '', 'style="margin-right: 40px;"', true); - $table->data[13][1] .= __('Active').' '.print_radio_button_extended ("update_gis_data", 1, '', $update_gis_data, false, '', 'style="margin-right: 40px;"', true); + $table->data[5][0] = __('Ignore new GIS data:'); + $table->data[5][1] = __('Disabled').' '.print_radio_button_extended ("update_gis_data", 0, '', $update_gis_data, false, '', 'style="margin-right: 40px;"', true); + $table->data[5][1] .= __('Active').' '.print_radio_button_extended ("update_gis_data", 1, '', $update_gis_data, false, '', 'style="margin-right: 40px;"', true); } -print_table ($table); +toggle(print_table ($table, true), __('Advanced options')); +unset($table); + +$table->width = '95%'; +$table->class = "databox_color"; + +$table->head = array (); +$table->style = array (); +$table->style[0] = 'font-weight: bold; width: 150px;'; +$table->data = array (); + +$fields = get_db_all_fields_in_table('tagent_custom_fields'); + +if($fields === false) $fields = array(); + +foreach ($fields as $field) { + + $data[0] = ''.$field['name'].''; + + $custom_value = get_db_value_filter('description', 'tagent_custom_data', array('id_field' => $field['id_field'], 'id_agent' => $id_agente)); + + if($custom_value === false) { + $custom_value = ''; + } + + $data[1] = print_textarea ('customvalue_'.$field['id_field'], 2, 65, $custom_value, 'style="min-height: 30px;"', true); + + array_push ($table->data, $data); +} + +if(!empty($fields)) { + toggle(print_table ($table, true), __('Custom fields')); +} echo '
'; if ($id_agente) { diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index f925484184..1e2c3e3b88 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -129,6 +129,16 @@ if ($create_agent) { $icon_path = (string) get_parameter_post ("icon_path",''); $update_gis_data = (int) get_parameter_post("update_gis_data", 0); + $fields = get_db_all_fields_in_table('tagent_custom_fields'); + + if($fields === false) $fields = array(); + + $field_values = array(); + + foreach($fields as $field) { + $field_values[$field['id_field']] = (string) get_parameter_post ('customvalue_'.$field['id_field'], ''); + } + // Check if agent exists (BUG WC-50518-2) if ($nombre_agente == "") { $agent_creation_error = __('No agent name specified'); @@ -150,6 +160,11 @@ if ($create_agent) { 'update_gis_data' => $update_gis_data)); enterprise_hook ('update_agent', array ($id_agente)); if ($id_agente !== false) { + // Create custom fields for this agent + foreach($field_values as $key => $value) { + process_sql_insert ('tagent_custom_data', + array('id_field' => $key,'id_agent' => $id_agente, 'description' => $value)); + } // Create address for this agent in taddress agent_add_address ($id_agente, $direccion_agente); @@ -349,8 +364,10 @@ if (isset( $_GET["fix_module"])) { __('Error normalizing module %s', $error)); } +$update_agent = (bool) get_parameter ('update_agent'); + // Update AGENT -if (isset($_POST["update_agent"])) { // if modified some agent paramenter +if ($update_agent) { // if modified some agent paramenter $id_agente = (int) get_parameter_post ("id_agente"); $nombre_agente = str_replace('`','‘',(string) get_parameter_post ("agente", "")); $direccion_agente = (string) get_parameter_post ("direccion", ''); @@ -377,6 +394,31 @@ if (isset($_POST["update_agent"])) { // if modified some agent paramenter $icon_path = (string) get_parameter_post ("icon_path",''); $update_gis_data = (int) get_parameter_post("update_gis_data", 0); + $fields = get_db_all_fields_in_table('tagent_custom_fields'); + + if($fields === false) $fields = array(); + + $field_values = array(); + + foreach($fields as $field) { + $field_values[$field['id_field']] = (string) get_parameter_post ('customvalue_'.$field['id_field'], ''); + } + + + foreach($field_values as $key => $value) { + $old_value = get_db_all_rows_filter('tagent_custom_data', array('id_agent' => $id_agente, 'id_field' => $key)); + + if($old_value === false) { + // Create custom field if not exist + process_sql_insert ('tagent_custom_data', + array('id_field' => $key,'id_agent' => $id_agente, 'description' => $value)); + }else { + process_sql_update ('tagent_custom_data', + array('description' => $value), + array('id_field' => $key,'id_agent' => $id_agente)); + } + } + //Verify if there is another agent with the same name but different ID if ($nombre_agente == "") { echo '

'.__('No agent name specified').'

'; diff --git a/pandora_console/godmode/agentes/configure_field.php b/pandora_console/godmode/agentes/configure_field.php new file mode 100755 index 0000000000..f4c28bc5fc --- /dev/null +++ b/pandora_console/godmode/agentes/configure_field.php @@ -0,0 +1,64 @@ + $id_field)); + $name = $field['name']; + $display_on_front = $field['display_on_front']; + print_page_header (__("Update agent custom field"), "images/note.png", false, "", true, ""); +} else { + print_page_header (__("Create agent custom field"), "images/note.png", false, "", true, ""); +} + +$table->width = '450px'; +$table->data = array (); +$table->data[0][0] = __('Name'); +$table->data[0][1] = print_input_text ('name', $name, '', 35, 100, true); + +$table->data[1][0] = __('Display on front').print_help_tip (__('The fields with display on front enabled will be displayed into the agent details'), true); +$table->data[1][1] = print_checkbox ('display_on_front', 1, $display_on_front, true); + +echo '
'; +print_table ($table); +echo '
'; + +if ($id_field) { + print_input_hidden ('update_field', 1); + print_input_hidden ('id_field', $id_field); + print_submit_button (__('Update'), 'updbutton', false, 'class="sub upd"'); +} else { + print_input_hidden ('create_field', 1); + print_submit_button (__('Create'), 'crtbutton', false, 'class="sub wand"'); +} + +echo '
'; +echo '
'; +?> diff --git a/pandora_console/godmode/agentes/fields_manager.php b/pandora_console/godmode/agentes/fields_manager.php new file mode 100644 index 0000000000..a34de01c32 --- /dev/null +++ b/pandora_console/godmode/agentes/fields_manager.php @@ -0,0 +1,127 @@ +".__('Field successfully created').""; + } else { + echo "

".__('There was a problem creating field')."

"; } +} + +/* Update field */ +if ($update_field) { + /*Check if name field is empty*/ + if( $name != "") { + $sql = sprintf ('UPDATE tagent_custom_fields SET name = "%s", + display_on_front = %d + WHERE id_field = %d', + $name, $display_on_front, $id_field); + $result = process_sql ($sql); + } else { + $result = false; + } + + if ($result !== false) { + echo "

".__('Field successfully updated')."

"; + } else { + echo "

".__('There was a problem modifying field')."

"; + } +} + +/* Delete field */ +if ($delete_field) { + $sql = sprintf ('DELETE FROM tagent_custom_fields WHERE id_field = %d', $id_field); + $result = process_sql ($sql); + + if (!$result) + echo "

".__('There was a problem deleting field')."

"; + else + echo "

".__('Field successfully deleted')."

"; +} + + +$table->width = '65%'; +$table->head = array (); +$table->head[0] = __('Field'); +$table->head[1] = __('Display on front').print_help_tip (__('The fields with display on front enabled will be displayed into the agent details'), true); +$table->head[2] = __('Actions'); +$table->align = array (); +$table->align[1] = 'center'; +$table->align[2] = 'center'; +$table->data = array (); + +$fields = get_db_all_fields_in_table('tagent_custom_fields'); + +if($fields === false) $fields = array(); + +foreach ($fields as $field) { + + $data[0] = ''.$field['name'].''; + + if($field['display_on_front']) { + $data[1] = print_image('images/tick.png', true); + }else { + $data[1] = print_image('images/delete.png', true); + } + + $data[2] = '' . __('Edit') . ''; + $data[2] .= '' . __('Delete') . ''; + + array_push ($table->data, $data); +} + +print_table ($table); + +echo '
'; +echo '
'; +print_submit_button (__('Create field'), 'crt', false, 'class="sub next"'); +echo '
'; +echo '
'; + +?> diff --git a/pandora_console/godmode/menu.php b/pandora_console/godmode/menu.php index 1aa2bddc6f..ffb01d77f2 100644 --- a/pandora_console/godmode/menu.php +++ b/pandora_console/godmode/menu.php @@ -36,6 +36,7 @@ if (give_acl ($config['id_user'], 0, "AW")) { $sub["godmode/groups/modu_group_list"]["text"] = __('Module groups'); $sub["godmode/agentes/planned_downtime"]["text"] = __('Scheduled downtime'); + $sub["godmode/agentes/fields_manager"]["text"] = __('Manage custom fields'); } enterprise_hook('agents_submenu'); diff --git a/pandora_console/operation/agentes/agent_fields.php b/pandora_console/operation/agentes/agent_fields.php new file mode 100755 index 0000000000..c5cf449865 --- /dev/null +++ b/pandora_console/operation/agentes/agent_fields.php @@ -0,0 +1,59 @@ +'.__('There was a problem loading agent').''; + return; +} + +if (! give_acl ($config["id_user"], $agent["id_grupo"], "AR")) { + audit_db ($config["id_user"], $_SERVER['REMOTE_ADDR'], "ACL Violation", + "Trying to access Agent General Information"); + require_once ("general/noaccess.php"); + return; +} +print_page_header (__('Agent custom fields'), 'images/note.png', false, "", false); + +echo ''; +// Custom fields +$fields = get_db_all_rows_filter('tagent_custom_fields', array('display_on_front' => 1)); + +foreach($fields as $field) { + echo ''; + $custom_value = get_db_value_filter('description', 'tagent_custom_data', array('id_field' => $field['id_field'], 'id_agent' => $id_agente)); + if($custom_value === false || $custom_value == '') { + $custom_value = '-'.__('empty').'-'; + } + echo ''; +} + +//End of table +echo '
'.$field['name'].print_help_tip (__('Custom field'), true).''.$custom_value.'
'; +?> diff --git a/pandora_console/operation/agentes/custom_fields.php b/pandora_console/operation/agentes/custom_fields.php new file mode 100644 index 0000000000..96248075b8 --- /dev/null +++ b/pandora_console/operation/agentes/custom_fields.php @@ -0,0 +1,79 @@ +'.__('There was a problem loading agent').''; + return; +} + +if (! give_acl ($config["id_user"], $agent["id_grupo"], "AR")) { + audit_db ($config["id_user"], $_SERVER['REMOTE_ADDR'], "ACL Violation", + "Trying to access Agent General Information"); + require_once ("general/noaccess.php"); + return; +} + +$table->width = '65%'; +$table->head = array (); +$table->head[0] = __('Field'); +$table->head[1] = __('Display on front').print_help_tip (__('The fields with display on front enabled will be displayed into the agent details'), true); +$table->head[2] = __('Description'); +$table->align = array (); +$table->align[1] = 'center'; +$table->align[2] = 'center'; +$table->data = array (); + +$fields = get_db_all_fields_in_table('tagent_custom_fields'); + +if($fields === false) $fields = array(); + +foreach ($fields as $field) { + + $data[0] = ''.$field['name'].''; + + if($field['display_on_front']) { + $data[1] = print_image('images/tick.png', true); + }else { + $data[1] = print_image('images/delete.png', true); + } + + $custom_value = get_db_value_filter('description', 'tagent_custom_data', array('id_field' => $field['id_field'], 'id_agent' => $id_agente)); + + if($custom_value === false || $custom_value == '') { + $custom_value = '-'.__('empty').'-'; + } + + $data[2] = $custom_value; + + array_push ($table->data, $data); +} + +print_table ($table); +?> diff --git a/pandora_console/operation/agentes/estado_generalagente.php b/pandora_console/operation/agentes/estado_generalagente.php index 6a80bf14c4..007062b77a 100644 --- a/pandora_console/operation/agentes/estado_generalagente.php +++ b/pandora_console/operation/agentes/estado_generalagente.php @@ -160,6 +160,18 @@ $progress = getNextAgentContact($id_agente); echo ''.__('Next agent contact').''; echo ''; +// Custom fields +$fields = get_db_all_rows_filter('tagent_custom_fields', array('display_on_front' => 1)); + +foreach($fields as $field) { + echo ''.$field['name'].print_help_tip (__('Custom field'), true).''; + $custom_value = get_db_value_filter('description', 'tagent_custom_data', array('id_field' => $field['id_field'], 'id_agent' => $id_agente)); + if($custom_value === false || $custom_value == '') { + $custom_value = '-'.__('empty').'-'; + } + echo ''.$custom_value.''; +} + //End of table echo '
'; ?> diff --git a/pandora_console/operation/agentes/ver_agente.php b/pandora_console/operation/agentes/ver_agente.php index d6ba77f094..01bb766e43 100644 --- a/pandora_console/operation/agentes/ver_agente.php +++ b/pandora_console/operation/agentes/ver_agente.php @@ -383,12 +383,28 @@ if ($config['activate_gis']) { $gistab['active'] = false; } -$onheader = array('manage' => $managetab, 'separator' => "", 'main' => $maintab, 'data' => $datatab, 'alert' => $alerttab, 'sla' => $slatab, 'inventory' => $inventorytab, 'collection' => $collectiontab, 'group' => $grouptab, 'gis' => $gistab); +$custom_fields['text']= '' + . print_image("images/note.png", true, array("title" => __('Custom fields'))) + . ''; + +if ($tab == 'custom_fields') { + $custom_fields['active'] = true; +} else { + $custom_fields['active'] = false; +} + +$onheader = array('manage' => $managetab, 'separator' => "", 'main' => $maintab, + 'data' => $datatab, 'alert' => $alerttab, 'sla' => $slatab, + 'inventory' => $inventorytab, 'collection' => $collectiontab, + 'group' => $grouptab, 'gis' => $gistab, 'custom' => $custom_fields); print_page_header (__('Agent').' - '.mb_substr(get_agent_name($id_agente),0,25), $icon, false, "", false, $onheader); switch ($tab) { + case "custom_fields": + require ("custom_fields.php"); + break; case "gis": require ("gis_view.php"); break; @@ -416,7 +432,7 @@ switch ($tab) { case "inventory": enterprise_include ('operation/agentes/agent_inventory.php'); break; - case 'collection': + case "collection": enterprise_include ('operation/agentes/collection_view.php'); break; } diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 4d8907ef7e..a33895756d 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -1132,10 +1132,35 @@ CREATE TABLE IF NOT EXISTS `tnetwork_map` ( -- Table `tsnmp_filter` -- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `tsnmp_filter` ( +CREATE TABLE IF NOT EXISTS `tsnmp_filter` ( `id_snmp_filter` int(10) unsigned NOT NULL auto_increment, `description` varchar(255) default '', `filter` varchar(255) default '', PRIMARY KEY (`id_snmp_filter`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +-- ----------------------------------------------------- +-- Table `tagent_custom_fields` +-- ----------------------------------------------------- + +CREATE TABLE IF NOT EXISTS `tagent_custom_fields` ( + `id_field` int(10) unsigned NOT NULL auto_increment, + `name` varchar(45) NOT NULL default '', + `display_on_front` tinyint(1) NOT NULL default 0, + PRIMARY KEY (`id_field`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- ----------------------------------------------------- +-- Table `tagent_custom_data` +-- ----------------------------------------------------- + +CREATE TABLE IF NOT EXISTS `tagent_custom_data` ( + `id_field` int(10) unsigned NOT NULL, + `id_agent` int(10) unsigned NOT NULL, + `description` text default '', + FOREIGN KEY (`id_field`) REFERENCES tagent_custom_fields(`id_field`) + ON UPDATE CASCADE ON DELETE CASCADE, + FOREIGN KEY (`id_agent`) REFERENCES tagente(`id_agente`) + ON UPDATE CASCADE ON DELETE CASCADE, + PRIMARY KEY (`id_field`, `id_agent`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8;