2011-03-22 Miguel de Dios <miguel.dedios@artica.es>

* 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.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4113 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2011-03-22 09:23:04 +00:00
parent c4aa91189d
commit 63b61c9013
4 changed files with 1013 additions and 41 deletions

View File

@ -1,3 +1,11 @@
2011-03-22 Miguel de Dios <miguel.dedios@artica.es>
* 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 <junichi@rworks.jp>
* extras/pandoradb_migrate_v3.2_to_v4.0.sql: Added missing ';'.

View File

@ -0,0 +1,373 @@
<?php
//Pandora FMS- http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2010 Artica Soluciones Tecnologicas
// 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.
if (isset($_GET['get_ptr'])) {
if ($_GET['get_ptr'] == 1) {
if (file_exists("../include/config.php"))
require ("../include/config.php");
else {
//TODO FIX AND SET AS RELATIVE DIRECTORY
if (file_exists("/var/www/pandora_console/include/config.php"))
require ("/var/www/pandora_console/include/config.php");
if (file_exists("/srv/www/htdocs/pandora_console/include/config.php"))
require ("/srv/www/htdocs/pandora_console/include/config.php");
}
if (! isset ($_SESSION["id_usuario"])) {
session_start ();
session_write_close ();
}
// Login check
if (!isset($_SESSION["id_usuario"])) {
$config['id_user'] = null;
}
else {
$config['id_user'] = $_SESSION["id_usuario"];
}
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');
header("Content-type: binary");
header("Content-Disposition: attachment; filename=\"".get_name_xml_resource($hook_enterprise)) . "\"";
header("Pragma: no-cache");
header("Expires: 0");
output_xml_resource($hook_enterprise);
}
}
else {
add_godmode_menu_option (__('Resource exportation'), 'PM','gservers','');
add_extension_godmode_function('resource_exportation_extension_main');
}
function output_xml_resource($hook_enterprise) {
global $config;
$type = get_parameter('type');
$id = (int)get_parameter('id');
switch ($type) {
case 'report':
output_xml_report($id);
break;
case 'visual_console':
output_xml_visual_console($id);
break;
default:
if ($hook_enterprise === true)
return enterprise_output_xml_resource($type, $id);
break;
}
}
function output_xml_report($id) {
$report = get_db_row('treport', 'id_report', $id);
echo '<?xml version="1.0" encoding="UTF-8" ?>' . "\n";
echo "<report>\n";
echo "<name><![CDATA[" . safe_output($report['name']) . "]]></name>\n";
if (isset($report['description']))
echo "<description><![CDATA[" . safe_output($report['description']) . "]]></description>\n";
$group = get_db_value('nombre', 'tgrupo', 'id_grupo', $report['id_group']);
echo "<group><![CDATA[" . safe_output($group) . "]]></group>\n";
$items = get_db_all_rows_field_filter('treport_content', 'id_report', $report['id_report']);
foreach ($items as $item) {
echo "<item>\n";
echo "<type>" . safe_output($item['type']) . "</type>\n";
echo "<description>" . safe_output($item['description']) . "</description>\n";
echo "<period>" . safe_output($item['period']) . "</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 "<module><![CDATA[" . safe_output($module) . "]]></module>\n";
}
if (isset($agent))
echo "<agent><![CDATA[" . $agent . "]]></agent>\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 "<graph><![CDATA[" . safe_output($graph) . "]]></graph>\n";
break;
case 3:
case 'SLA':
echo "<only_display_wrong>" . $item['only_display_wrong'] . "</only_display_wrong>\n";
echo "<monday>" . $item['monday'] . "</monday>\n";
echo "<tuesday>" . $item['tuesday'] . "</tuesday>\n";
echo "<wednesday>" . $item['wednesday'] . "</wednesday>\n";
echo "<thursday>" . $item['thursday'] . "</thursday>\n";
echo "<friday>" . $item['friday'] . "</friday>\n";
echo "<saturday>" . $item['saturday'] . "</saturday>\n";
echo "<sunday>" . $item['sunday'] . "</sunday>\n";
echo "<time_from>" . $item['time_from'] . "</time_from>\n";
echo "<time_to>" . $item['time_to'] . "</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 "<sla>";
echo "<agent><![CDATA[" . $agent . "]]></agent>\n";
echo "<module><![CDATA[" . safe_output($module) . "]]></module>\n";
echo "<sla_max>" . $sla['sla_max'] . "</sla_max>\n";
echo "<sla_min>" . $sla['sla_min'] . "</sla_min>\n";
echo "<sla_limit>" . $sla['sla_limit'] . "</sla_limit>\n";
echo "</sla>";
}
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 "<text><![CDATA[" . safe_output($item['text']) . "]]></text>\n";
break;
case 'sql':
echo "<header_definition><![CDATA[" . safe_output($item['header_definition']) . "]]></header_definition>\n";
if (!empty($item['external_source'])) {
echo "<sql><![CDATA[" . safe_output($item['external_source']) . "]]></sql>\n";
}
else {
$sql = get_db_value('sql', 'treport_custom_sql', 'id', $item['treport_custom_sql_id']);
echo "<sql>" . safe_output($sql) . "</sql>\n";
}
break;
case 'sql_graph_pie':
case 'sql_graph_vbar':
case 'sql_graph_hbar':
echo "<header_definition>" . safe_output($item['header_definition']) . "</header_definition>\n";
if (!empty($item['external_source'])) {
echo "<sql>" . safe_output($item['external_source']) . "</sql>\n";
}
else {
$sql = get_db_value('sql', 'treport_custom_sql', 'id', $item['treport_custom_sql_id']);
echo "<sql>" . safe_output($sql) . "</sql>\n";
}
break;
case 'event_report_group':
$group = get_db_value('nombre', 'tgrupo', 'id_grupo', $item['id_agent']);
echo "<group><![CDATA[" . safe_output($group) . "]]></group>\n";
break;
case 'event_report_module':
break;
case 'alert_report_module':
break;
case 'alert_report_agent':
break;
case 'url':
echo "<url><![CDATA[" . safe_output($values["external_source"]) . "]]></url>";
break;
case 'database_serialized':
echo "<header_definition><![CDATA[" . safe_output($item["header_definition"]) . "]]></header_definition>";
echo "<line_separator><![CDATA[" . safe_output($item["line_separator"]) . "]]></line_separator>";
echo "<column_separator><![CDATA[" . safe_output($item["header_definition"]) . "]]></column_separator>";
break;
case 'TTRT':
break;
case 'TTO':
break;
case 'MTBF':
break;
case 'MTTR':
break;
}
echo "</item>\n";
}
echo "</report>\n";
}
function output_xml_visual_console($id) {
$visual_map = get_db_row('tlayout', 'id', $id);
echo '<?xml version="1.0" encoding="UTF-8" ?>' . "\n";
echo "<visual_map>\n";
echo "<name><![CDATA[" . safe_output($visual_map['name']) . "]]></name>\n";
if ($visual_map['id_group'] != 0) {
$group = get_db_value('nombre', 'tgrupo', 'id_grupo', $visual_map['id_group']);
echo "<group><![CDATA[" . safe_output($group) . "]]></group>\n";
}
echo "<background><![CDATA[" . safe_output($visual_map['background']) . "]]></background>\n";
echo "<height>" . safe_output($visual_map['height']) . "</height>\n";
echo "<width>" . safe_output($visual_map['width']) . "</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 "<item>\n";
echo "<other_id>" . $item['id'] . "</other_id>\n"; //OLD ID USE FOR parent item
if (!empty($item['label'])) {
echo "<label><![CDATA[" . safe_output($item['label']) . "]]></label>\n";
}
echo "<x>" . $item['pos_x'] . "</x>\n";
echo "<y>" . $item['pos_y'] . "</y>\n";
echo "<type>" . $item['type'] . "</type>\n";
if ($item['width'] != 0) {
echo "<width>" . $item['width'] . "</width>\n";
}
if ($item['height'] != 0) {
echo "<height>" . $item['height'] . "</height>\n";
}
if (!empty($item['image'])) {
echo "<image>" . $item['image'] . "</image>\n";
}
if ($item['period'] != 0) {
echo "<period>" . $item['period'] . "</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 "<module><![CDATA[" . safe_output($module) . "]]></module>\n";
}
}
if (!empty($agent)) {
echo "<agent><![CDATA[" . $agent . "]]></agent>\n";
}
if ($item['id_layout_linked'] != 0) {
echo "<id_layout_linked>" . $item['id_layout_linked'] . "</id_layout_linked>\n";
}
if ($item['parent_item'] != 0) {
echo "<parent_item>" . $item['parent_item'] . "</parent_item>\n";
}
if (!empty($item['label_color'])) {
echo "<label_color>" . $item['label_color'] . "</label_color>\n";
}
echo "</item>\n";
}
echo "</visual_map>\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 "<div class=notify>";
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 "</div>";
echo "<br /><br />";
$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);
?>
<script type="text/javascript">
function export_to_ptr(type) {
id = $("select#" + type + " option:selected").val();
url = location.href.split('index');
url = url[0] + 'extensions/resource_exportation.php?get_ptr=1&type=' + type
+ '&id=' + id;
location.href=url;
}
</script>
<?php
}
?>

View File

@ -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>OTHER_ID</other_id>
// and have too <parent_item>OTHER_ID</parent_item>
// 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 "<div class=notify>";
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. " .
"<br><br>You can get more resurces in our <a href='%s'>Public Resource Library</a>") ,
"http://pandorafms.org/index.php?sec=community&sec2=repository&lng=en");
echo "</div>";
echo "<br /><br />";
// Upload form
echo "<form name='submit_plugin' method='post' enctype='multipart/form-data'>";
echo '<table class="databox" id="table1" width="50%" border="0" cellpadding="4" cellspacing="4">';
echo "<tr><td class='datos'><input type='file' name='resource_upload' />";
echo "<td class='datos'><input type='submit' class='sub next' value='".__('Upload')."' />";
echo "</form></table>";
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 "<div class=notify>";
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. " .
"<br><br>You can get more resurces in our <a href='%s'>Public Resource Library</a>") ,
"http://pandorafms.org/index.php?sec=community&sec2=repository&lng=en");
echo "</div>";
echo "<br /><br />";
// Upload form
echo "<form name='submit_plugin' method='post' enctype='multipart/form-data'>";
echo '<table class="databox" id="table1" width="50%" border="0" cellpadding="4" cellspacing="4">';
echo "<tr>";
echo "<td colspan='2' class='datos'><input type='file' name='resource_upload' />";
echo "</tr>";
echo "<tr>";
echo "<td>" . __('Group filter: ') . "</td>";
echo "<td>";
print_select_groups(false, "AW", true, 'group');
echo "</td>";
echo "<td class='datos'><input type='submit' class='sub next' value='".__('Upload')."' />";
echo "</tr>";
echo "</table>";
echo "</form>";
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');
?>

View File

@ -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);