diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 861cc7bbea..baf794b4f6 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,11 @@ +2011-03-22 Miguel de Dios + + * include/functions_reporting.php: cleaned source code style. + + * extensions/resource_registration.php, + extensions/resource_exportation.php: added first version of extension to + import and export reports and visual console. + 2011-03-22 Junichi Satoh * extras/pandoradb_migrate_v3.2_to_v4.0.sql: Added missing ';'. diff --git a/pandora_console/extensions/resource_exportation.php b/pandora_console/extensions/resource_exportation.php new file mode 100644 index 0000000000..ea7c5b5b46 --- /dev/null +++ b/pandora_console/extensions/resource_exportation.php @@ -0,0 +1,373 @@ +' . "\n"; + echo "\n"; + echo "\n"; + if (isset($report['description'])) + echo "\n"; + $group = get_db_value('nombre', 'tgrupo', 'id_grupo', $report['id_group']); + echo "\n"; + $items = get_db_all_rows_field_filter('treport_content', 'id_report', $report['id_report']); + foreach ($items as $item) { + echo "\n"; + echo "" . safe_output($item['type']) . "\n"; + echo "" . safe_output($item['description']) . "\n"; + echo "" . safe_output($item['period']) . "\n"; + if ($item['id_agent'] != 0) { + $agent = get_agent_name($item['id_agent']); + } + if ($item['id_agent_module'] != 0) { + $module = get_db_value('nombre', 'tagente_modulo', 'id_agente_modulo', $item['id_agent_module']); + $id_agent = get_db_value('id_agente', 'tagente_modulo', 'id_agente_modulo', $item['id_agent_module']); + $agent = get_agent_name($item['id_agent']); + + echo "\n"; + } + if (isset($agent)) + echo "\n"; + $agent = null; + switch (safe_output($item['type'])) { + case 1: + case 'simple_graph': + break; + case 'simple_baseline_graph': + break; + case 2: + case 'custom_graph': + $graph = get_db_value('name', 'tgraph', 'id_graph', $item['id_gs']); + echo "\n"; + break; + case 3: + case 'SLA': + echo "" . $item['only_display_wrong'] . "\n"; + echo "" . $item['monday'] . "\n"; + echo "" . $item['tuesday'] . "\n"; + echo "" . $item['wednesday'] . "\n"; + echo "" . $item['thursday'] . "\n"; + echo "" . $item['friday'] . "\n"; + echo "" . $item['saturday'] . "\n"; + echo "" . $item['sunday'] . "\n"; + echo "" . $item['time_from'] . "\n"; + echo "" . $item['time_to'] . "\n"; + + $slas = get_db_all_rows_field_filter('treport_content_sla_combined', 'id_report_content', $item['id_rc']); + if ($slas === false) $slas = array(); + + foreach ($slas as $sla) { + $module = get_db_value('nombre', 'tagente_modulo', 'id_agente_modulo', $sla['id_agent_module']); + $id_agent = get_db_value('id_agente', 'tagente_modulo', 'id_agente_modulo', $sla['id_agent_module']); + $agent = get_agent_name($item['id_agent']); + echo ""; + echo "\n"; + echo "\n"; + echo "" . $sla['sla_max'] . "\n"; + echo "" . $sla['sla_min'] . "\n"; + echo "" . $sla['sla_limit'] . "\n"; + echo ""; + } + break; + case 6: + case 'monitor_report': + break; + case 7: + case 'avg_value': + break; + case 8: + case 'max_value': + break; + case 9: + case 'min_value': + break; + case 10: + case 'sumatory': + break; + case 'agent_detailed_event': + case 'event_report_agent': + break; + case 'text': + echo "\n"; + break; + case 'sql': + echo "\n"; + if (!empty($item['external_source'])) { + echo "\n"; + } + else { + $sql = get_db_value('sql', 'treport_custom_sql', 'id', $item['treport_custom_sql_id']); + echo "" . safe_output($sql) . "\n"; + } + break; + case 'sql_graph_pie': + case 'sql_graph_vbar': + case 'sql_graph_hbar': + echo "" . safe_output($item['header_definition']) . "\n"; + if (!empty($item['external_source'])) { + echo "" . safe_output($item['external_source']) . "\n"; + } + else { + $sql = get_db_value('sql', 'treport_custom_sql', 'id', $item['treport_custom_sql_id']); + echo "" . safe_output($sql) . "\n"; + } + break; + case 'event_report_group': + $group = get_db_value('nombre', 'tgrupo', 'id_grupo', $item['id_agent']); + echo "\n"; + break; + case 'event_report_module': + break; + case 'alert_report_module': + break; + case 'alert_report_agent': + break; + case 'url': + echo ""; + break; + case 'database_serialized': + echo ""; + echo ""; + echo ""; + break; + case 'TTRT': + break; + case 'TTO': + break; + case 'MTBF': + break; + case 'MTTR': + break; + } + echo "\n"; + } + echo "\n"; +} + +function output_xml_visual_console($id) { + $visual_map = get_db_row('tlayout', 'id', $id); + + echo '' . "\n"; + echo "\n"; + echo "\n"; + if ($visual_map['id_group'] != 0) { + $group = get_db_value('nombre', 'tgrupo', 'id_grupo', $visual_map['id_group']); + echo "\n"; + } + echo "\n"; + echo "" . safe_output($visual_map['height']) . "\n"; + echo "" . safe_output($visual_map['width']) . "\n"; + $items = get_db_all_rows_field_filter('tlayout_data', 'id_layout', $visual_map['id']); + if ($items === false) $items = array(); + foreach ($items as $item){ + echo "\n"; + echo "" . $item['id'] . "\n"; //OLD ID USE FOR parent item + if (!empty($item['label'])) { + echo "\n"; + } + echo "" . $item['pos_x'] . "\n"; + echo "" . $item['pos_y'] . "\n"; + echo "" . $item['type'] . "\n"; + if ($item['width'] != 0) { + echo "" . $item['width'] . "\n"; + } + if ($item['height'] != 0) { + echo "" . $item['height'] . "\n"; + } + if (!empty($item['image'])) { + echo "" . $item['image'] . "\n"; + } + if ($item['period'] != 0) { + echo "" . $item['period'] . "\n"; + } + $agent = ''; + if ($item['id_agent'] != 0) { + $agent = get_agent_name($item['id_agent']); + } + if (isset($item['id_agente_modulo'])) { + if ($item['id_agente_modulo'] != 0) { + $module = get_db_value('nombre', 'tagente_modulo', 'id_agente_modulo', $item['id_agente_modulo']); + $id_agent = get_db_value('id_agente', 'tagente_modulo', 'id_agente_modulo', $item['id_agente_modulo']); + $agent = get_agent_name($id_agent); + + echo "\n"; + } + } + if (!empty($agent)) { + echo "\n"; + } + if ($item['id_layout_linked'] != 0) { + echo "" . $item['id_layout_linked'] . "\n"; + } + if ($item['parent_item'] != 0) { + echo "" . $item['parent_item'] . "\n"; + } + if (!empty($item['label_color'])) { + echo "" . $item['label_color'] . "\n"; + } + echo "\n"; + } + echo "\n"; +} + +function get_name_xml_resource($hook_enterprise) { + global $config; + + $type = get_parameter('type'); + $id = (int)get_parameter('id'); + + switch ($type) { + case 'report': + $name = get_db_value('name', 'treport', 'id_report', $id); + break; + case 'visual_console': + $name = get_db_value('name', 'tlayout', 'id', $id); + break; + default: + if ($hook_enterprise === true) + return enterprise_get_name_xml_resource($type, $id); + break; + } + + $file = $name . ".ptr"; + + return $file; +} + +function get_xml_resource() { + global $config; + + $hook_enterprise = enterprise_include ('extensions/resource_exportation/functions.php'); +} + +function resource_exportation_extension_main() { + global $config; + + if (! check_acl ($config['id_user'], 0, "PM") && ! is_user_admin ($config['id_user'])) { + pandora_audit("ACL Violation", "Trying to access Setup Management"); + require ("general/noaccess.php"); + return; + } + + $hook_enterprise = enterprise_include ('extensions/resource_exportation/functions.php'); + + print_page_header (__('Resource exportation'), "images/extensions.png", false, "", true, "" ); + + echo "
"; + echo __("This extension makes exportation of resource template more easy. " . + "Here you can export as a resource template in Pandora FMS 3.x format (.ptr). "); + echo "
"; + + echo "

"; + + $table = null; + $table->width = '50%'; + $table->style[0] = 'width: 30%;'; + $table->style[1] = 'width: 10%;'; + $table->class = "databox_color"; + $table->data[0][0] = __('Report'); + $table->data[0][1] = print_select_from_sql('SELECT id_report, name FROM treport', 'report', '', '', '', 0, true); + $table->data[0][2] = print_button(__('Export'), '', false, 'export_to_ptr(\'report\');', 'class="sub"', true); + $table->data[1][0] = __('Visual console'); + $table->data[1][1] = print_select_from_sql('SELECT id, name FROM tlayout', 'visual_console', '', '', '', 0, true); + $table->data[1][2] = print_button(__('Export'), '', false, 'export_to_ptr(\'visual_console\');', 'class="sub"', true); + + if ($hook_enterprise === true) + add_rows_for_enterprise($table->data); + + print_table($table); + + ?> + + \ No newline at end of file diff --git a/pandora_console/extensions/resource_registration.php b/pandora_console/extensions/resource_registration.php index f45b8b9e71..fcf79668bb 100644 --- a/pandora_console/extensions/resource_registration.php +++ b/pandora_console/extensions/resource_registration.php @@ -26,52 +26,560 @@ In the xml is the tag "module_source" */ -function resource_registration_extension_main() { +require_once ($config['homedir'].'/include/functions_agents.php'); +enterprise_include ('include/functions_local_components.php'); + +function insert_item_report($report_id, $values) { + foreach ($report_id as $id => $name) { + $values['id_report'] = $id; + $result = (bool)process_sql_insert('treport_content', $values); + + print_result_message($result, + sprintf(__("Success add '%s' item in report '%s'."), $values['type'], $name), + sprintf(__("Error create '%s' item in report '%s'."), $values['type'], $name)); + } +} + +function process_upload_xml_report($xml, $group_filter = 0) { + foreach ($xml->xpath('/report') as $reportElement) { + + $values = array(); + + if (isset($reportElement->name)) { + $values['name'] = $reportElement->name; + + $posible_name = $values['name']; + $exist = true; + $loops = 30; //Loops to exit or tries + while ($exist && $loops > 0) { + $exist = (bool)get_db_row_filter('treport', array('name' => safe_input($posible_name))); + + if ($exist) { + $loops--; + $posible_name = $values['name'] . " (" . (30 - $loops) . ")"; + } + } + + if ($exist) { + print_error_message( + sprintf( + __("Error create '%s' report, the name exist and there aren't free name."), + $reportElement->name)); + break; + } + else if ($loops != 30) { + print_error_message( + sprintf( + __("Warning create '%s' report, the name exist, the report have a name %s."), + $reportElement->name, $posible_name)); + } + + $values['name'] = safe_input($posible_name); + } + else { + print_error_message(__("Error the report haven't name.")); + break; + } + + $id_group = get_db_value('id_grupo', 'tgrupo', 'nombre', $reportElement->group); + if ($id_group === false) { + print_error_message(__("Error the report haven't group.")); + break; + } + + if (isset($reportElement->description)) + $values['description'] = $reportElement->description; + + $id_report = process_sql_insert ('treport', $values); + + print_result_message($id_report, + sprintf(__("Success create '%s' report."), $posible_name), + sprintf(__("Error create '%s' report."), $posible_name)); + + if ($id_report) { + pandora_audit("Report management", "Create report " . $id_report, false, false); + } + else { + pandora_audit("Report management", "Fail to create report", false, false); + break; + } + + foreach ($reportElement->item as $item) { + $item = (array)$item; + + $values = array(); + $values['id_report'] = $id_report; + if (isset($item['description'])) + $values['description'] = safe_input($item['description']); + if (isset($item['period'])) + $values['period'] = safe_input($item['period']); + if (isset($item['type'])) + $values['type'] = safe_input($item['type']); + + $agents_item= array(); + if (isset($item['agent'])) { + $agents = get_agents(array('id_grupo' => $group_filter), array('id_agente', 'nombre')); + + $agent_clean = str_replace(array('[', ']'), '', $item['agent']); + $regular_expresion = ($agent_clean != $item['agent']); + + foreach ($agents as $agent) { + if ($regular_expresion) { + if ((bool)preg_match("/" . $agent_clean . "/", safe_output($agent['nombre']))) { + $agents_item[$agent['id_agente']]['name'] = $agent['nombre']; + } + } + else { + if ($agent_clean == safe_output($agent['nombre'])) { + $agents_item[$agent['id_agente']]['name'] = $agent['nombre']; + } + } + } + } + if (isset($item['module'])) { + $module_clean = str_replace(array('[', ']'), '', $item['module']); + $regular_expresion = ($module_clean != $item['module']); + + foreach ($agents_item as $id => $agent) { + $modules = get_db_all_rows_filter('tagente_modulo', + array('id_agente' => $id), array('id_agente_modulo', 'nombre')); + + $agents_item[$id]['modules'] = array(); + + foreach ($modules as $module) { + if ($regular_expresion) { + if ((bool)preg_match("/" . $module_clean . "/", safe_output($module['nombre']))) { + $agents_item[$id]['modules'][$module['id_agente_modulo']]['name'] = + $module['nombre']; + } + } + else { + if ($module_clean == safe_output($module['nombre'])) { + $agents_item[$id]['modules'][$module['id_agente_modulo']]['name'] = + $module['nombre']; + } + } + } + } + } + + switch ($item['type']) { + case 1: + case 'simple_graph': + break; + case 'simple_baseline_graph': + break; + case 2: + case 'custom_graph': + $group = get_db_value('id_grupo', 'tgrupo', 'nombre', safe_input($item['graph'])); + $values['id_gs'] = $group; + break; + case 3: + case 'SLA': + if (isset($item['only_display_wrong'])) + $values['only_display_wrong'] = (string)$item['only_display_wrong']; + if (isset($item['monday'])) + $values['monday'] = (string)$item['monday']; + if (isset($item['tuesday'])) + $values['tuesday'] = (string)$item['tuesday']; + if (isset($item['wednesday'])) + $values['wednesday'] = (string)$item['wednesday']; + if (isset($item['thursday'])) + $values['thursday'] = (string)$item['thursday']; + if (isset($item['friday'])) + $values['friday'] = (string)$item['friday']; + if (isset($item['saturday'])) + $values['saturday'] = (string)$item['saturday']; + if (isset($item['sunday'])) + $values['sunday'] = (string)$item['sunday']; + if (isset($item['time_from'])) + $values['time_from'] = (string)$item['time_from']; + if (isset($item['time_to'])) + $values['time_to'] = (string)$item['time_to']; + + $slas = array(); + if (!isset($item['sla'])) { + $item['sla'] = array(); + } + foreach ($item['sla'] as $sla_xml) { + if (isset($sla_xml->agent)) { + $agents = get_agents(array('id_grupo' => $group_filter), array('id_agente', 'nombre')); + + $agent_clean = str_replace(array('[', ']'), '', $sla_xml->agent); + $regular_expresion = ($agent_clean != $sla_xml->agent); + + foreach ($agents as $agent) { + $id_agent = false; + if ($regular_expresion) { + if ((bool)preg_match("/" . $agent_clean . "/", safe_output($agent['nombre']))) { + $id_agent = $agent['id_agente']; + } + else { + if ($agent_clean == safe_output($agent['nombre'])) { + $id_agent = $agent['id_agente']; + } + } + } + + if ($id_agent) { + if (isset($sla_xml->module)) { + $module_clean = str_replace(array('[', ']'), '', $sla_xml->module); + $regular_expresion = ($module_clean != $sla_xml->module); + + $modules = get_db_all_rows_filter('tagente_modulo', + array('id_agente' => $id_agent), array('id_agente_modulo', 'nombre')); + + foreach ($modules as $module) { + if ($regular_expresion) { + if ((bool)preg_match("/" . $module_clean . "/", safe_output($module['nombre']))) { + $slas[] = array( + 'id_agent_module' => $module['id_agente_modulo'], + 'sla_max' => (string)$sla_xml->sla_max, + 'sla_min' => (string)$sla_xml->sla_min, + 'sla_limit' => (string)$sla_xml->sla_limit + ); + } + } + else { + if ($module_clean == safe_output($module['nombre'])) { + $slas[] = array( + 'id_agent_module' => $module['id_agente_modulo'], + 'sla_max' => (string)$sla_xml->sla_max, + 'sla_min' => (string)$sla_xml->sla_min, + 'sla_limit' => (string)$sla_xml->sla_limit + ); + } + } + } + } + } + } + } + } + break; + case 6: + case 'monitor_report': + break; + case 7: + case 'avg_value': + break; + case 8: + case 'max_value': + break; + case 9: + case 'min_value': + break; + case 10: + case 'sumatory': + break; + case 'agent_detailed_event': + case 'event_report_agent': + break; + case 'text': + $values['text'] = safe_input($item['text']); + break; + case 'sql': + $values['header_definition'] = safe_input($item['header_definition']); + $values['external_source'] = safe_input($item['sql']); + break; + case 'sql_graph_pie': + case 'sql_graph_vbar': + case 'sql_graph_hbar': + $values['header_definition'] = safe_input($item['header_definition']); + $values['external_source'] = safe_input($item['sql']); + break; + case 'event_report_group': + $values['id_agent'] = get_db_value('id_grupo', 'tgrupo', 'nombre', safe_input($item->group)); + break; + case 'event_report_module': + break; + case 'alert_report_module': + break; + case 'alert_report_agent': + break; + case 'url': + $values["external_source"] = safe_input($item['url']); + break; + case 'database_serialized': + $values['header_definition'] = safe_input($item['header_definition']); + $values['line_separator'] = safe_input($item['line_separator']); + $values['column_separator'] = safe_input($item['column_separator']); + break; + case 'TTRT': + break; + case 'TTO': + break; + case 'MTBF': + break; + case 'MTTR': + break; + } + + if (empty($agents_item)) { + $id_content = process_sql_insert ('treport_content', $values); + print_result_message($id_content, + sprintf(__("Success add '%s' content."), $values['type']), + sprintf(__("Error add '%s' action."), $values['type'])); + + if ($item['type'] == 'SLA') { + foreach ($slas as $sla) { + $sla['id_report_content'] = $id_content; + $result = process_sql_insert ('treport_content_sla_combined', $sla); + print_result_message($result, + sprintf(__("Success add '%s' SLA."), $sla['id_agent_module']), + sprintf(__("Error add '%s' SLA."), $sla['id_agent_module'])); + + } + + } + } + else { + foreach ($agents_item as $id_agent => $agent) { + if (empty($agent['modules'])) { + $values['id_agent'] = $id_agent; + $id_content = process_sql_insert ('treport_content', $values); + print_result_message($id_content, + sprintf(__("Success add '%s' content."), $values['type']), + sprintf(__("Error add '%s' action."), $values['type'])); + } + else { + foreach ($agent['modules'] as $id_module => $module) { + $values['id_agent_module'] = $id_module; + $values['id_agent'] = $id_agent; + + $id_content = process_sql_insert ('treport_content', $values); + print_result_message($id_content, + sprintf(__("Success add '%s' content."), $values['type']), + sprintf(__("Error add '%s' action."), $values['type'])); + } + } + } + } + } + } +} + +function process_upload_xml_visualmap($xml, $filter_group = 0) { global $config; - if (! check_acl ($config['id_user'], 0, "PM") && ! is_user_admin ($config['id_user'])) { - pandora_audit("ACL Violation", "Trying to access Setup Management"); - require ("general/noaccess.php"); - return; - } - - require_once($config['homedir'] . '/include/functions_network_components.php'); - require_once($config['homedir'] . '/include/functions_db.php'); - enterprise_include_once('include/functions_local_components.php'); - - print_page_header (__('Resource registration'), "images/extensions.png", false, "", true, "" ); - - if (!extension_loaded("libxml")) { - print_error_message(_("Error, please install the PHP libXML in the system.")); + foreach ($xml->xpath('/visual_map') as $visual_map) { + if (isset($visual_map->name)) { + $values['name'] = (string)$visual_map->name; + } + else { + print_error_message( + __("Error create '%s' visual map, lost tag name.")); + break; + } - return; + $values['id_group'] = 0; + if (isset($visual_map->group)) { + $id_group = get_db_value('id_grupo', 'tgrupo', 'nombre', safe_input($visual_map->group)); + if ($id_group !== false) $values['id_group'] = $id_group; + } + + if (isset($visual_map->background)) + $values['background'] = (string)$visual_map->background; + + $values['width'] = 0; + if (isset($visual_map->width)) + $values['width'] = (string)$visual_map->width; + + $values['height'] = 0; + if (isset($visual_map->height)) + $values['height'] = (string)$visual_map->height; + + $posible_name = $values['name']; + $exist = true; + $loops = 30; //Loops to exit or tries + while ($exist && $loops > 0) { + $exist = (bool)get_db_row_filter('tlayout', array('name' => safe_input($posible_name))); + + if ($exist) { + $loops--; + $posible_name = $values['name'] . " (" . (30 - $loops) . ")"; + } + } + + if ($exist) { + print_error_message( + sprintf( + __("Error create '%s' visual map, the name exist and there aren't free name."), + $values['name'])); + continue; + } + else if ($loops != 30) { + print_error_message( + sprintf( + __("Warning create '%s' visual map, the name exist, the report have a name %s."), + $values['name'], $posible_name)); + } + + $values['name'] = safe_input($posible_name); + $id_visual_map = process_sql_insert('tlayout', $values); + + print_result_message((bool)$id_visual_map, + sprintf(__("Success create '%s' visual map."), $posible_name), + sprintf(__("Error create '%s' visual map."), $posible_name)); + + if ($id_visual_map !== false) { + pandora_audit('CREATE VISUAL CONSOLE', $id_visual_map, $config['id_user']); + } + else { + break; + } + + $relation_other_ids = array(); + + foreach ($visual_map->item as $item) { + $no_agents = true; + + if (isset($item->agent)) { + $agent_clean = str_replace(array('[', ']'), '', $item->agent); + $regular_expresion = ($agent_clean != $item->agent); + + $agents = get_agents(array('id_grupo' => $filter_group), array('id_agente', 'nombre')); + if ($agents === false) $agents = array(); + $temp = array(); + foreach ($agents as $agent) { + $temp[$agent['id_agente']] = $agent['nombre']; + } + $agents = $temp; + + $agents_in_item = array(); + foreach ($agents as $id => $agent) { + if ($regular_expresion) { + if ((bool)preg_match("/" . $agent_clean . "/", safe_input($agent))) { + $agents_in_item[$id]['name'] = $agent; + $no_agents = false; + } + } + else { + if ($agent_clean == safe_input($agent)) { + $agents_in_item[$id]['name'] = $agent; + $no_agents = false; + break; + } + } + } + } + + $no_modules = true; + if (isset($item->module)) { + $module_clean = str_replace(array('[', ']'), '', $item->module); + $regular_expresion = ($module_clean != $item->module); + + foreach ($agents_in_item as $id => $agent) { + $modules = get_db_all_rows_filter('tagente_modulo', + array('id_agente' => $id), array('id_agente_modulo', 'nombre')); + + $modules_in_item = array(); + foreach ($modules as $module) { + if ($regular_expresion) { + if ((bool)preg_match("/" . $module_clean . "/", safe_input($module['nombre']))) { + $modules_in_item[$module['id_agente_modulo']] = $module['nombre']; + $no_modules = false; + } + } + else { + if ($module_clean == safe_input($module['nombre'])) { + $modules_in_item[$module['id_agente_modulo']] = $module['nombre']; + $no_modules = false; + break; + } + } + } + + $agents_in_item[$id]['modules'] = $modules_in_item; + } + } + + $values = array(); + + $values['id_layout'] = $id_visual_map; + if (isset($item->label)) + $values['label'] = safe_input($item->label); + if (isset($item->x)) + $values['pos_x'] = (string)$item->x; + if (isset($item->y)) + $values['pos_y'] = (string)$item->y; + if (isset($item->height)) + $values['height'] = (string)$item->height; + if (isset($item->width)) + $values['width'] = (string)$item->width; + if (isset($item->image)) + $values['image'] = (string)$item->image; + if (isset($item->period)) + $values['period'] = (string)$item->period; + if (isset($item->label_color)) + $values['label_color'] = (string)$item->label_color; + if (isset($item->parent_item)) { + //Hack for link the items use the OTHER_ID + // and have too OTHER_ID + // then $relation_other_ids[OTHER_ID] have the item_id in DB. + $values['parent_item'] = (string)$relation_other_ids[(string)$item->parent_item]; + } + if (isset($item->map_linked)) + $values['id_layout_linked'] = (string)$item->map_linked; + if (isset($item->type)) + $values['type'] = (string)$item->type; + + if ($no_agents) { + $id_item = process_sql_insert('tlayout_data', $values); + + print_result_message((bool)$id_item, + sprintf(__("Success create item type '%d' visual map."), $values['type']), + sprintf(__("Error create item type '%d' visual map."), $values['type'])); + + if ($id_item !== false) { + pandora_audit('CREATE ITEM VISUAL CONSOLE', $values['id_layout'] . " - " . $id_item, $config['id_user']); + } + } + else { + foreach ($agents_in_item as $id => $agent) { + if ($no_modules) { + $values['id_agent'] = $id; + + $id_item = process_sql_insert('tlayout_data', $values); + + if (isset($item->other_id)) { + $relation_other_ids[(string)$item->other_id] = $id_item; + } + + print_result_message((bool)$id_item, + sprintf(__("Success create item for agent '%s' visual map."), $agent['name']), + sprintf(__("Error create item for agent '%s' visual map."), $agent['name'])); + + if ($id_item !== false) { + pandora_audit('CREATE ITEM VISUAL CONSOLE', $values['id_layout'] . " - " . $id_item, $config['id_user']); + } + } + else { + foreach ($agent['modules'] as $id_module => $module) { + $values['id_agent'] = $id; + $values['id_agente_modulo'] = $id_module; + + process_sql_insert('tlayout_data', $values); + + print_result_message((bool)$id_item, + sprintf(__("Success create item for agent '%s' visual map."), $agent['name']), + sprintf(__("Error create item for agent '%s' visual map."), $agent['name'])); + + if ($id_item !== false) { + pandora_audit('CREATE ITEM VISUAL CONSOLE', $values['id_layout'] . " - " . $id_item, $config['id_user']); + } + } + } + } + } + } } - - echo "
"; - printf(__("This extension makes registration of resource template more easy. " . - "Here you can upload a resource template in Pandora FMS 3.x format (.ptr). " . - "Please refer to documentation on how to obtain and use Pandora FMS resources. " . - "

You can get more resurces in our Public Resource Library") , - "http://pandorafms.org/index.php?sec=community&sec2=repository&lng=en"); - echo "
"; - - echo "

"; - - // Upload form - echo "
"; - echo ''; - echo "
"; - echo ""; - echo "
"; - - if (!isset ($_FILES['resource_upload']['tmp_name'])) { - return; - } - $xml = simplexml_load_file($_FILES['resource_upload']['tmp_name']); - +} + +function process_upload_xml_component($xml) { //Extract components $components = array(); - foreach ($xml->xpath('//component') as $componentElement) { + foreach ($xml->xpath('/component') as $componentElement) { $name = safe_input((string)$componentElement->name); $id_os = (int)$componentElement->id_os; $os_version = safe_input((string)$componentElement->os_version); @@ -254,7 +762,6 @@ function resource_registration_extension_main() { } //Extract the template - $templateElement = $xml->xpath('//template'); if (!empty($templateElement)) { $templateElement = $templateElement[0]; @@ -273,6 +780,82 @@ function resource_registration_extension_main() { } } +function process_upload_xml($xml) { + $hook_enterprise = enterprise_include ('extensions/resource_registration/functions.php'); + + //Extract component + process_upload_xml_component($xml); + + $group_filter = get_parameter('group'); + + //Extract visual map + process_upload_xml_visualmap($xml, $group_filter); + + + //Extract policies + if ($hook_enterprise === true) + process_upload_xml_policy($xml, $group_filter); + + + //Extract reports + process_upload_xml_report($xml, $group_filter); +} + +function resource_registration_extension_main() { + global $config; + + if (! check_acl ($config['id_user'], 0, "PM") && ! is_user_admin ($config['id_user'])) { + pandora_audit("ACL Violation", "Trying to access Setup Management"); + require ("general/noaccess.php"); + return; + } + + require_once($config['homedir'] . '/include/functions_network_components.php'); + require_once($config['homedir'] . '/include/functions_db.php'); + enterprise_include_once('include/functions_local_components.php'); + + print_page_header (__('Resource registration'), "images/extensions.png", false, "", true, "" ); + + if (!extension_loaded("libxml")) { + print_error_message(_("Error, please install the PHP libXML in the system.")); + + return; + } + + echo "
"; + printf(__("This extension makes registration of resource template more easy. " . + "Here you can upload a resource template in Pandora FMS 3.x format (.ptr). " . + "Please refer to documentation on how to obtain and use Pandora FMS resources. " . + "

You can get more resurces in our Public Resource Library") , + "http://pandorafms.org/index.php?sec=community&sec2=repository&lng=en"); + echo "
"; + + echo "

"; + + // Upload form + echo "
"; + echo ''; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo "
"; + echo "
" . __('Group filter: ') . ""; + print_select_groups(false, "AW", true, 'group'); + echo ""; + echo "
"; + echo "
"; + + if (!isset ($_FILES['resource_upload']['tmp_name'])) { + return; + } + $xml = simplexml_load_file($_FILES['resource_upload']['tmp_name'], NULL, LIBXML_NOCDATA); + + process_upload_xml($xml); +} + add_godmode_menu_option (__('Resource registration'), 'PM','gservers',''); add_extension_godmode_function('resource_registration_extension_main'); ?> \ No newline at end of file diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index fd23aa9cb2..4ae8da8c9c 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -1828,8 +1828,12 @@ function render_report_html_item ($content, $table, $report, $mini = false) { array_push ($table->data, $data); // Put description at the end of the module (if exists) +<<<<<<< .mine + if ($content["description"] != "") { +======= $table->colspan[2][0] = 3; if ($content["description"] != ""){ +>>>>>>> .r4112 $data_desc = array(); $data_desc[0] = $content["description"]; array_push ($table->data, $data_desc); @@ -1866,8 +1870,12 @@ function render_report_html_item ($content, $table, $report, $mini = false) { $n = array_push ($table->data, $data); // Put description at the end of the module (if exists) +<<<<<<< .mine + if ($content["description"] != "") { +======= $table->colspan[1][0] = 3; if ($content["description"] != ""){ +>>>>>>> .r4112 $data_desc = array(); $data_desc[0] = $content["description"]; array_push ($table->data, $data_desc);