$name) {
$values['id_report'] = $id;
$result = (bool)process_sql_insert('treport_content', $values);
ui_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) {
ui_print_error_message(
sprintf(
__("Error create '%s' report, the name exist and there aren't free name."),
$reportElement->name));
break;
}
else if ($loops != 30) {
ui_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 {
ui_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) {
ui_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);
ui_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);
ui_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);
ui_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);
ui_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);
ui_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;
foreach ($xml->xpath('/visual_map') as $visual_map) {
if (isset($visual_map->name)) {
$values['name'] = (string)$visual_map->name;
}
else {
ui_print_error_message(
__("Error create '%s' visual map, lost tag name."));
break;
}
$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) {
ui_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) {
ui_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);
ui_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