'; $sizhfin = ''; } $date_text = ""; if (!empty($date)) { $date_text = date($config["date_format"], $date); } else if (!empty($from) && !empty($to)) { $date_text = "(" . human_time_description_raw ($period) . ") " . __("From:") . " " . date($config["date_format"], $from) . "
" . __("To:") . " " . date($config["date_format"], $to); } else if ($period > 0) { $date_text = human_time_description_raw($period); } else if ($period === 0) { $date_text = __('Last data'); } $data = array(); if (empty($subtitle) && (empty($date_text))) { $data[] = $sizh . $title . $sizhfin; $table->colspan[0][0] = 3; } else if (empty($subtitle)) { $data[] = $sizh . $title . $sizhfin; $data[] = "
" . $sizh . $date_text . $sizhfin . "
"; $table->colspan[0][1] = 2; } else if (empty($date_text)) { $data[] = $sizh . $title . $sizhfin; $data[] = $sizh . $subtitle . $sizhfin; $table->colspan[0][1] = 2; } else { $data[] = $sizh . $title . $sizhfin; $data[] = $sizh . $subtitle . $sizhfin; $data[] = "
" . $sizh . $date_text . $sizhfin . "
"; } array_push ($table->data, $data); } function reporting_html_print_report($report, $mini = false) { foreach ($report['contents'] as $key => $item) { $table->size = array (); $table->style = array (); $table->width = '98%'; $table->class = 'databox'; $table->rowclass = array (); $table->rowclass[0] = 'datos3'; $table->data = array (); $table->head = array (); $table->style = array (); $table->colspan = array (); $table->rowstyle = array (); reporting_html_header($table, $mini, $item['title'], $item['subtitle'], $item['date']['period'], $item['date']['date'], $item['date']['from'], $item['date']['to']); if ($item["description"] != "") { $table->data['description_row']['description'] = $item["description"]; $table->colspan['description_row']['description'] = 3; } switch ($item['type']) { case 'availability': reporting_html_availability($table, $item); break; case 'general': reporting_html_general($table, $item); break; case 'sql': reporting_html_sql($table, $item); break; case 'simple_graph': reporting_html_graph($table, $item); break; case 'custom_graph': reporting_html_graph($table, $item); break; case 'text': reporting_html_text($table, $item); break; case 'url': reporting_html_url($table, $item, $key); break; case 'max_value': reporting_html_max_value($table, $item, $mini); break; case 'avg_value': reporting_html_avg_value($table, $item, $mini); break; case 'min_value': reporting_html_min_value($table, $item, $mini); break; case 'sumatory': reporting_html_sum_value($table, $item, $mini); break; case 'MTTR': reporting_html_MTTR_value($table, $item, $mini, true, true); break; case 'MTBF': reporting_html_MTBF_value($table, $item, $mini, true, true); break; case 'TTO': reporting_html_TTO_value($table, $item, $mini, false, true); break; case 'TTRT': reporting_html_TTRT_value($table, $item, $mini, false, true); break; case 'agent_configuration': reporting_html_agent_configuration($table, $item); break; case 'projection_graph': reporting_html_graph($table, $item); break; case 'prediction_date': reporting_html_prediction_date($table, $item, $mini); break; case 'simple_baseline_graph': reporting_html_graph($table, $item); break; case 'netflow_area': reporting_html_graph($table, $item); break; case 'netflow_pie': reporting_html_graph($table, $item); break; case 'netflow_data': reporting_html_graph($table, $item); break; case 'netflow_statistics': reporting_html_graph($table, $item); break; case 'netflow_summary': reporting_html_graph($table, $item); break; case 'monitor_report': reporting_html_monitor_report($table, $item, $mini); break; case 'sql_graph_vbar': reporting_html_sql_graph($table, $item); break; case 'sql_graph_hbar': reporting_html_sql_graph($table, $item); break; case 'sql_graph_pie': reporting_html_sql_graph($table, $item); break; case 'alert_report_module': reporting_html_alert_report_module($table, $item); break; case 'alert_report_agent': reporting_html_alert_report_agent($table, $item); break; case 'alert_report_group': reporting_html_alert_report_group($table, $item); break; case 'network_interfaces_report': reporting_html_network_interfaces_report($table, $item); break; case 'group_configuration': reporting_html_group_configuration($table, $item); break; case 'database_serialized': reporting_html_database_serialized($table, $item); break; case 'agent_detailed_event': case 'event_report_agent': reporting_html_event_report_agent($table, $item); break; case 'group_report': reporting_html_group_report($table, $item); break; case 'exception': reporting_html_exception($table, $item); break; case 'agent_module': reporting_html_agent_module($table, $item); break; case 'inventory': reporting_html_inventory($table, $item); break; case 'inventory_changes': reporting_html_inventory_changes($table, $item); break; case 'event_report_module': reporting_html_event_report_module($table, $item); break; case 'event_report_group': reporting_html_event_report_group($table, $item); break; case 'top_n': reporting_html_top_n($table, $item); break; case 'SLA': reporting_html_SLA($table, $item, $mini); break; case 'SLA_monthly': reporting_enterprise_html_SLA_monthly($table, $item, $mini); break; case 'SLA_services': reporting_enterprise_html_SLA_services($table, $item, $mini); break; } if ($item['type'] == 'agent_module') echo '
'; html_print_table($table); if ($item['type'] == 'agent_module') echo '
'; } } function reporting_html_SLA($table, $item, $mini) { if ($mini) { $font_size = '1.5'; } else { $font_size = '3'; } if (!empty($item['failed'])) { $table->colspan['sla']['cell'] = 3; $table->data['sla']['cell'] = $item['failed']; } else { if (!empty($item['planned_downtimes'])) { $table1->width = '99%'; $table1->align = array(); $table1->align[0] = 'left'; $table1->align[1] = 'left'; $table1->align[2] = 'left'; $table1->align[3] = 'left'; $table1->data = array (); $table1->head = array (); $table1->head[0] = __('Name'); $table1->head[1] = __('Description'); $table1->head[2] = __('Execution'); $table1->head[3] = __('Dates'); foreach ($item['planned_downtimes'] as $downtime) { $row = array(); $row[] = $downtime['name']; $row[] = $downtime['description']; $row[] = $downtime['execution']; $row[] = $downtime['dates']; $table1->data[] = $row; } $table->colspan['planned_downtime']['cell'] = 3; $table->data['planned_downtime']['cell'] = html_print_table($table1, true); } $table1->width = '99%'; $table1->align = array(); $table1->align[0] = 'left'; $table1->align[1] = 'left'; $table1->align[2] = 'right'; $table1->align[3] = 'right'; $table1->align[4] = 'right'; $table1->align[5] = 'right'; $table1->data = array (); $table1->head = array (); $table1->head[0] = __('Agent'); $table1->head[1] = __('Module'); $table1->head[2] = __('Max/Min Values'); $table1->head[3] = __('SLA Limit'); $table1->head[4] = __('SLA Compliance'); $table1->head[5] = __('Status'); foreach ($item['data'] as $sla) { $row = array(); $row[] = $sla['agent']; $row[] = $sla['module']; $row[] = $sla['max'] . " / " . $sla['min']; $row[] = $sla['sla_limit'] . "%"; if ($sla['sla_value_unknown']) { $row[] = '' . ' - ' . ''; $row[] = '' . __('Unknown') . ''; } elseif ($sla['sla_status']) { $row[] = '' . $sla['sla_value'] . "%" . ''; $row[] = '' . __('OK') . ''; } else { $row[] = '' . $sla['sla_value'] . "%" . ''; $row[] = '' . __('Fail') . ''; } $table1->data[] = $row; } $table->colspan['sla']['cell'] = 3; $table->data['sla']['cell'] = html_print_table($table1, true); if (!empty($item['charts'])) { $table1 = null; $table1->width = '99%'; $table1->data = array (); foreach ($item['charts'] as $chart) { $table1->data[] = array( $chart['agent'] . "
" . $chart['module'], $chart['chart']); } $table->colspan['charts']['cell'] = 3; $table->data['charts']['cell'] = html_print_table($table1, true); } } } function reporting_html_top_n($table, $item) { if (!empty($item['failed'])) { $table->colspan['top_n']['cell'] = 3; $table->data['top_n']['cell'] = $item['failed']; } else { $table1->width = '99%'; $table1->align = array(); $table1->align[0] = 'left'; $table1->align[1] = 'left'; $table1->align[2] = 'right'; $table1->data = array (); $table1->head = array (); $table1->head[0] = __('Agent'); $table1->head[1] = __('Module'); $table1->head[2] = __('Value'); foreach ($item['data'] as $top) { $row = array(); $row[] = $top['agent']; $row[] = $top['module']; $row[] = $top['formated_value']; $table1->data[] = $row; } $table->colspan['top_n']['cell'] = 3; $table->data['top_n']['cell'] = html_print_table($table1, true); if (!empty($item['charts']['pie'])) { $table->colspan['char_pie']['cell'] = 3; $table->data['char_pie']['cell'] = $item['charts']['pie']; } if (!empty($item['charts']['bars'])) { $table->colspan['char_bars']['cell'] = 3; $table->data['char_bars']['cell'] = $item['charts']['bars']; } if (!empty($item['resume'])) { $table1 = null; $table1->width = '99%'; $table1->align = array(); $table1->align[0] = 'center'; $table1->align[1] = 'center'; $table1->align[2] = 'center'; $table1->data = array (); $table1->head = array (); $table1->head[0] = __('Min Value'); $table1->head[1] = __('Average Value'); $table1->head[2] = __('Max Value'); $row = array(); $row[] = $item['resume']['min']['formated_value']; $row[] = $item['resume']['avg']['formated_value']; $row[] = $item['resume']['max']['formated_value']; $table1->data[] = $row; $table->colspan['resume']['cell'] = 3; $table->data['resume']['cell'] = html_print_table($table1, true); } } } function reporting_html_event_report_group($table, $item) { global $config; if (!empty($item['failed'])) { $table->colspan['events']['cell'] = 3; $table->data['events']['cell'] = $item['failed']; } else { $table1->width = '99%'; $table1->align = array(); $table1->align[0] = 'center'; $table1->align[2] = 'center'; $table1->data = array (); $table1->head = array (); $table1->head[0] = __('Status'); $table1->head[1] = __('Name'); $table1->head[2] = __('Type'); $table1->head[3] = __('Agent'); $table1->head[4] = __('Criticity'); $table1->head[5] = __('Val. by'); $table1->head[6] = __('Timestamp'); foreach ($item['data'] as $k => $event) { //First pass along the class of this row $table1->cellclass[$k][1] = $table1->cellclass[$k][3] = $table1->cellclass[$k][4] = $table1->cellclass[$k][5] = $table1->cellclass[$k][6] = get_priority_class ($event["criticity"]); $data = array (); // Colored box switch ($event['estado']) { case 0: $img_st = "images/star.png"; $title_st = __('New event'); break; case 1: $img_st = "images/tick.png"; $title_st = __('Event validated'); break; case 2: $img_st = "images/hourglass.png"; $title_st = __('Event in process'); break; } $data[] = html_print_image ($img_st, true, array ("class" => "image_status", "width" => 16, "title" => $title_st, "id" => 'status_img_' . $event["id_evento"])); $data[] = ui_print_truncate_text( io_safe_output($event['evento']), 140, false, true); //$data[1] = $event['event_type']; $data[] = events_print_type_img ($event["event_type"], true); if (!empty($event['id_agente'])) $data[] = agents_get_name($event['id_agente']); else $data[] = __('Pandora System'); $data[] = get_priority_name ($event['criticity']); if (empty($event['id_usuario']) && $event['estado'] == EVENT_VALIDATE) { $data[] = '' . __('System') . ''; } else { $user_name = db_get_value ('fullname', 'tusuario', 'id_user', $event['id_usuario']); $data[] = io_safe_output($user_name); } $data[] = '' . date($config['date_format'], $event['timestamp_rep']) . ''; array_push ($table1->data, $data); } $table->colspan['events']['cell'] = 3; $table->data['events']['cell'] = html_print_table($table1, true); if (!empty($item['chart']['by_agent'])) { $table1 = null; $table1->width = '99%'; $table1->head = array (); $table1->head[0] = __('Events by agent'); $table1->data[0][0] = $item['chart']['by_agent']; $table->colspan['chart_by_agent']['cell'] = 3; $table->cellstyle['chart_by_agent']['cell'] = 'text-align: center;'; $table->data['chart_by_agent']['cell'] = html_print_table($table1, true); } if (!empty($item['chart']['by_user_validator'])) { $table1 = null; $table1->width = '99%'; $table1->head = array (); $table1->head[0] = __('Events by user validator'); $table1->data[0][0] = $item['chart']['by_user_validator']; $table->colspan['chart_by_user_validator']['cell'] = 3; $table->cellstyle['chart_by_user_validator']['cell'] = 'text-align: center;'; $table->data['chart_by_user_validator']['cell'] = html_print_table($table1, true); } if (!empty($item['chart']['by_criticity'])) { $table1 = null; $table1->width = '99%'; $table1->head = array (); $table1->head[0] = __('Events by criticity'); $table1->data[0][0] = $item['chart']['by_criticity']; $table->colspan['chart_by_criticity']['cell'] = 3; $table->cellstyle['chart_by_criticity']['cell'] = 'text-align: center;'; $table->data['chart_by_criticity']['cell'] = html_print_table($table1, true); } if (!empty($item['chart']['validated_vs_unvalidated'])) { $table1 = null; $table1->width = '99%'; $table1->head = array (); $table1->head[0] = __('Events validated vs unvalidated'); $table1->data[0][0] = $item['chart']['validated_vs_unvalidated']; $table->colspan['chart_validated_vs_unvalidated']['cell'] = 3; $table->cellstyle['chart_validated_vs_unvalidated']['cell'] = 'text-align: center;'; $table->data['chart_validated_vs_unvalidated']['cell'] = html_print_table($table1, true); } } } function reporting_html_event_report_module($table, $item) { global $config; if (!empty($item['failed'])) { $table->colspan['events']['cell'] = 3; $table->data['events']['cell'] = $item['failed']; } else { $table1->width = '99%'; $table1->data = array (); $table1->head = array (); $table1->head[0] = __('Status'); $table1->head[1] = __('Event name'); $table1->head[2] = __('Event type'); $table1->head[3] = __('Criticity'); $table1->head[4] = __('Count'); $table1->head[5] = __('Timestamp'); $table1->style[0] = 'text-align: center;'; $table1->style[4] = 'text-align: center;'; foreach ($item['data'] as $i => $event) { $data = array(); $table1->cellclass[$i][1] = $table1->cellclass[$i][2] = $table1->cellclass[$i][3] = $table1->cellclass[$i][4] = $table1->cellclass[$i][5] = get_priority_class($event["criticity"]); // Colored box switch ($event['estado']) { case 0: $img_st = "images/star.png"; $title_st = __('New event'); break; case 1: $img_st = "images/tick.png"; $title_st = __('Event validated'); break; case 2: $img_st = "images/hourglass.png"; $title_st = __('Event in process'); break; } $data[0] = html_print_image ($img_st, true, array ("class" => "image_status", "width" => 16, "title" => $title_st, "id" => 'status_img_' . $event["id_evento"])); $data[1] = io_safe_output($event['evento']); $data[2] = $event['event_type']; $data[3] = get_priority_name ($event['criticity']); $data[4] = $event['event_rep']; $data[5] = date($config['date_format'], $event['timestamp_rep']); $table1->data[] = $data; } $table->colspan['events']['cell'] = 3; $table->data['events']['cell'] = html_print_table($table1, true); } } function reporting_html_inventory_changes($table, $item) { if (!empty($item['failed'])) { $table->colspan['failed']['cell'] = 3; $table->cellstyle['failed']['cell'] = 'text-align: center;'; $table->data['failed']['cell'] = $item['failed']; } else { foreach ($item['data'] as $module_item) { $table1 = null; $table1->width = '99%'; $table1->cellstyle[0][0] = $table1->cellstyle[0][1] = 'background: #373737; color: #FFF;'; $table1->data[0][0] = $module_item['agent']; $table1->data[0][1] = $module_item['module']; $table1->cellstyle[1][0] = 'background: #373737; color: #FFF;'; $table1->data[1][0] = $module_item['date']; $table1->colspan[1][0] = 2; $table1->cellstyle[2][0] = 'background: #373737; color: #FFF; text-align: center;'; $table1->data[2][0] = __('Added'); $table1->colspan[2][0] = 2; $table1->data = array_merge($table1->data, $module_item['added']); $table1->cellstyle[3 + count($module_item['added'])][0] = 'background: #373737; color: #FFF; text-align: center;'; $table1->data[3 + count($module_item['added'])][0] = __('Deleted'); $table1->colspan[3 + count($module_item['added'])][0] = 2; $table1->data = array_merge($table1->data, $module_item['deleted']); $table->colspan[ $module_item['agent'] . "_" .$module_item['module']]['cell'] = 3; $table->data[ $module_item['agent'] . "_" .$module_item['module']]['cell'] = html_print_table($table1, true); } } } function reporting_html_inventory($table, $item) { if (!empty($item['failed'])) { $table->colspan['failed']['cell'] = 3; $table->cellstyle['failed']['cell'] = 'text-align: center;'; $table->data['failed']['cell'] = $item['failed']; } else { foreach ($item['data'] as $module_item) { $table1 = null; $table1->width = '99%'; $first = reset($module_item['data']); $count_columns = count($first); $table1->cellstyle[0][0] = 'background: #373737; color: #FFF;'; $table1->data[0][0] = $module_item['agent_name']; if ($count_columns == 1) $table1->colspan[0][0] = $count_columns + 1; // + columm date else $table1->colspan[0][0] = $count_columns; $table1->cellstyle[1][0] = $table1->cellstyle[1][1] = 'background: #373737; color: #FFF;'; $table1->data[1][0] = $module_item['name']; if ($count_columns - 1 > 0) $table1->colspan[1][0] = $count_columns - 1; $table1->data[1][1] = $module_item['timestamp']; $table1->cellstyle[2] = array_pad( array(), $count_columns, 'background: #373737; color: #FFF;'); $table1->data[2] = array_keys($first); if ($count_columns - 1 == 0) { $table1->colspan[2][0] = $count_columns + 1; // + columm date; } $table1->data = array_merge($table1->data, $module_item['data']); $table->colspan[ $module_item['name'] . "_" .$module_item['id_agente']]['cell'] = 3; $table->data[ $module_item['name'] . "_" .$module_item['id_agente']]['cell'] = html_print_table($table1, true); } } } function reporting_html_agent_module($table, $item) { $table->colspan['agent_module']['cell'] = 3; $table->cellstyle['agent_module']['cell'] = 'text-align: center;'; if (!empty($item['failed'])) { $table->data['agent_module']['cell'] = $item['failed']; } else { $table_data = ''; $table_data .= ""; $first = reset($item['data']); $list_modules = $first['modules']; foreach ($list_modules as $module_name => $module) { $file_name = string2image( ui_print_truncate_text($module_name, 'module_small', false, true, false, '...'), false, false, 6, 270, '#B1B1B1', 'FFF', 4, 0); $table_data .= '"; } foreach ($item['data'] as $row) { $table_data .= ""; switch ($row['agent_status']) { case 4: // Alert fired status $rowcolor = COL_ALERTFIRED; $textcolor = '#000'; break; case 1: // Critical status $rowcolor = COL_CRITICAL; $textcolor = '#FFF'; break; case 2: // Warning status $rowcolor = COL_WARNING; $textcolor = '#000'; break; case 0: // Normal status $rowcolor = COL_NORMAL; $textcolor = '#FFF'; break; case 3: case -1: default: // Unknown status $rowcolor = COL_UNKNOWN; $textcolor = '#FFF'; break; } $file_name = string2image( ui_print_truncate_text($row['agent_name'], 'agent_small', false, true, false, '...'), false, false, 6, 0, $rowcolor, $textcolor, 4, 0); $table_data .= ""; foreach ($row['modules'] as $module) { if (is_null($module)) { $table_data .= ""; } else { $table_data .= ""; } } } $table_data .= "
" . __("Agents") . " / " . __("Modules") . "' . html_print_image($file_name, true, array('title' => $module_name)) . "
" . html_print_image($file_name, true, array('title' => $row['agent_name'])) . ""; switch ($module) { case 0: $table_data .= ui_print_status_image( 'module_ok.png', __("%s in %s : NORMAL", $module['name'], $row['agent_name']), true, array('width' => '20px', 'height' => '20px')); break; case 1: $table_data .= ui_print_status_image( 'module_critical.png', __("%s in %s : CRITICAL", $module['name'], $row['agent_name']), true, array('width' => '20px', 'height' => '20px')); break; case 2: $table_data .= ui_print_status_image( 'module_warning.png', __("%s in %s : WARNING", $module['name'], $row['agent_name']), true, array('width' => '20px', 'height' => '20px')); break; case 3: $table_data .= ui_print_status_image( 'module_unknown.png', __("%s in %s : UNKNOWN", $module['name'], $row['agent_name']), true, array('width' => '20px', 'height' => '20px')); break; case 4: $table_data .= ui_print_status_image( 'module_alertsfired.png', __("%s in %s : ALERTS FIRED", $module['name'], $row['agent_name']), true, array('width' => '20px', 'height' => '20px')); break; } $table_data .= "
"; $table_data .= "
"; $table_data .= ""; $table_data .= ""; $table_data .= ""; $table_data .= ""; $table_data .= ""; $table_data .= ""; $table_data .= ""; $table_data .= "
" . __('Legend') . "
" . __("Orange cell when the module has fired alerts") . "
" . __("Red cell when the module has a critical status") . "
" . __("Yellow cell when the module has a warning status") . "
" . __("Green cell when the module has a normal status") . "
" . __("Grey cell when the module has an unknown status") . "
"; $table_data .= "
"; $table->data['agent_module']['cell'] = $table_data; } } function reporting_html_exception($table, $item) { if (!empty($item['failed'])) { $table->colspan['group_report']['cell'] = 3; $table->cellstyle['group_report']['cell'] = 'text-align: center;'; $table->data['group_report']['cell'] = $item['failed']; } else { $table1->width = '99%'; $table1->align = array(); $table1->align['agent'] = 'left'; $table1->align['module'] = 'left'; $table1->align['operation'] = 'left'; $table1->align['value'] = 'right'; $table1->data = array (); $table1->head = array (); $table1->head['agent'] = __('Agent'); $table1->head['module'] = __('Module'); $table1->head['operation'] = __('Operation'); $table1->head['value'] = __('Value'); foreach ($item['data'] as $data) { $row = array(); $row['agent'] = $data['agent']; $row['module'] = $data['module']; $row['operation'] = $data['operation']; $row['value'] = $data['formated_value']; $table1->data[] = $row; } $table->colspan['data']['cell'] = 3; $table->cellstyle['data']['cell'] = 'text-align: center;'; $table->data['data']['cell'] = html_print_table($table1, true); if (!empty($item['chart'])) { $table->colspan['chart_pie']['cell'] = 3; $table->cellstyle['chart_pie']['cell'] = 'text-align: center;'; $table->data['chart_pie']['cell'] = $item["chart"]["pie"]; $table->colspan['chart_hbar']['cell'] = 3; $table->cellstyle['chart_hbar']['cell'] = 'text-align: center;'; $table->data['chart_hbar']['cell'] = $item["chart"]["hbar"]; } if (!empty($item['resume'])) { $table1 = null; $table1->width = '99%'; $table1->align = array(); $table1->align['min'] = 'right'; $table1->align['avg'] = 'right'; $table1->align['max'] = 'right'; $table1->head = array (); $table1->head['min'] = __('Min Value'); $table1->head['avg'] = __('Average Value'); $table1->head['max'] = __('Max Value'); $table1->data = array (); $table1->data[] = array( 'min' => $item['resume']['min']['formated_value'], 'avg' => $item['resume']['avg']['formated_value'], 'max' => $item['resume']['max']['formated_value']); $table->colspan['resume']['cell'] = 3; $table->cellstyle['resume']['cell'] = 'text-align: center;'; $table->data['resume']['cell'] = html_print_table($table1, true); } } } function reporting_html_group_report($table, $item) { global $config; $table->colspan['group_report']['cell'] = 3; $table->cellstyle['group_report']['cell'] = 'text-align: center;'; $table->data['group_report']['cell'] = "
" . __('Total') . "
" . __('Unknown') . "
" . __('Agents') . "
" . $item["data"]['group_stats']['total_agents'] . "
" . $item["data"]['group_stats']['agents_unknown'] . "
" . __('Total') . "
" . __('Normal') . "
" . __('Critical') . "
" . __('Warning') . "
" . __('Unknown') . "
" . __('Not init') . "
" . __('Monitors') . "
" . $item["data"]['group_stats']['monitor_checks'] . "
" . $item["data"]['group_stats']['monitor_ok'] ."
" . $item["data"]['group_stats']['monitor_critical'] . "
" . $item["data"]['group_stats']['monitor_warning'] . "
" . $item["data"]['group_stats']['monitor_unknown'] . "
" . $item["data"]['group_stats']['monitor_not_init'] . "
" . __('Defined') . "
" . __('Fired') . "
" . __('Alerts') . "
" . $item["data"]['group_stats']['monitor_alerts'] . "
" . $item["data"]['group_stats']['monitor_alerts_fired'] . "
" . __('Last %s', human_time_description_raw($item['date']['period'])) . "
" . __('Events') . "
" . $item["data"]["count_events"] . "
"; } function reporting_html_event_report_agent($table, $item) { global $config; $table1->width = '99%'; $table1->align = array(); $table1->align[0] = 'center'; $table1->align[1] = 'center'; $table1->align[3] = 'center'; $table1->data = array (); $table1->head = array (); $table1->head[0] = __('Status'); $table1->head[1] = __('Count'); $table1->head[2] = __('Name'); $table1->head[3] = __('Type'); $table1->head[4] = __('Criticity'); $table1->head[5] = __('Val. by'); $table1->head[6] = __('Timestamp'); foreach ($item['data'] as $i => $event) { $table1->cellclass[$i][1] = $table1->cellclass[$i][2] = $table1->cellclass[$i][4] = $table1->cellclass[$i][5] = $table1->cellclass[$i][6] = get_priority_class ($event["criticity"]); $data = array (); // Colored box switch ($event['status']) { case 0: $img_st = "images/star.png"; $title_st = __('New event'); break; case 1: $img_st = "images/tick.png"; $title_st = __('Event validated'); break; case 2: $img_st = "images/hourglass.png"; $title_st = __('Event in process'); break; } $data[] = html_print_image ($img_st, true, array ("class" => "image_status", "width" => 16, "title" => $title_st)); $data[] = $event['count']; $data[] = ui_print_truncate_text( io_safe_output($event['name']), 140, false, true); //$data[] = $event['event_type']; $data[] = events_print_type_img ($event["type"], true); $data[] = get_priority_name ($event['criticity']); if (empty($event['validated_by']) && $event['status'] == EVENT_VALIDATE) { $data[] = '' . __('System') . ''; } else { $user_name = db_get_value ('fullname', 'tusuario', 'id_user', $event['validated_by']); $data[] = io_safe_output($user_name); } $data[] = '' . date($config['date_format'], $event['timestamp']) . ''; array_push ($table1->data, $data); } $table->colspan['event_list']['cell'] = 3; $table->cellstyle['event_list']['cell'] = 'text-align: center;'; $table->data['event_list']['cell'] = html_print_table($table1, true); if (!empty($item['chart']['by_user_validator'])) { $table1 = null; $table1->width = '99%'; $table1->head = array (); $table1->head[0] = __('Events validated by user'); $table1->data[0][0] = $item['chart']['by_user_validator']; $table->colspan['chart_by_user_validator']['cell'] = 3; $table->cellstyle['chart_by_user_validator']['cell'] = 'text-align: center;'; $table->data['chart_by_user_validator']['cell'] = html_print_table($table1, true); } if (!empty($item['chart']['by_criticity'])) { $table1 = null; $table1->width = '99%'; $table1->head = array (); $table1->head[0] = __('Events by criticity'); $table1->data[0][0] = $item['chart']['by_criticity']; $table->colspan['chart_by_criticity']['cell'] = 3; $table->cellstyle['chart_by_criticity']['cell'] = 'text-align: center;'; $table->data['chart_by_criticity']['cell'] = html_print_table($table1, true); } if (!empty($item['chart']['validated_vs_unvalidated'])) { $table1 = null; $table1->width = '99%'; $table1->head = array (); $table1->head[0] = __('Amount events validated'); $table1->data[0][0] = $item['chart']['validated_vs_unvalidated']; $table->colspan['chart_validated_vs_unvalidated']['cell'] = 3; $table->cellstyle['chart_validated_vs_unvalidated']['cell'] = 'text-align: center;'; $table->data['chart_validated_vs_unvalidated']['cell'] = html_print_table($table1, true); } } function reporting_html_database_serialized($table, $item) { $table1->width = '100%'; $table1->head = array (__('Date')); if (!empty($item['keys'])) { $table1->head = array_merge($table1->head, $item['keys']); } $table1->style[0] = 'text-align: left'; $table1->data = array (); foreach ($item['data'] as $data) { foreach ($data['data'] as $data_unserialied) { $row = array($data['date']); $row = array_merge($row, $data_unserialied); $table1->data[] = $row; } } $table->colspan['database_serialized']['cell'] = 3; $table->cellstyle['database_serialized']['cell'] = 'text-align: center;'; $table->data['database_serialized']['cell'] = html_print_table($table1, true); } function reporting_html_group_configuration($table, $item) { $table1->width = '100%'; $table1->head = array (); $table1->data = array (); $cell = ""; foreach ($item['data'] as $agent) { $table2->width = '100%'; $table2->data = array (); reporting_html_agent_configuration(&$table2, array('data' => $agent)); $cell .= html_print_table($table2, true); } $table->colspan['group_configuration']['cell'] = 3; $table->cellstyle['group_configuration']['cell'] = 'text-align: center;'; $table->data['group_configuration']['cell'] = $cell; } function reporting_html_network_interfaces_report($table, $item) { if ($item['error']) { $table->colspan['interfaces']['cell'] = 3; $table->cellstyle['interfaces']['cell'] = 'text-align: left;'; $table->data['interfaces']['cell'] = __('The group has no agents or none of the agents has any network interface'); } else { foreach ($item['data'] as $agent) { $table_agent = new StdCLass(); $table_agent->width = '100%'; $table_agent->data = array(); $table_agent->head = array(); $table_agent->head[0] = sprintf(__("Agent '%s'"), $agent['name']); $table_agent->headstyle = array(); $table_agent->headstyle[0] = 'font-size: 16px;'; $table_agent->style[0] = 'text-align: center'; $table_agent->data['interfaces'] = ""; foreach ($agent['interfaces'] as $interface) { $table_interface = new StdClass(); $table_interface->width = '100%'; $table_interface->data = array(); $table_interface->rowstyle = array(); $table_interface->head = array(); $table_interface->cellstyle = array(); $table_interface->title = sprintf(__("Interface '%s' throughput graph"), $interface['name']); $table_interface->head['ip'] = __('IP'); $table_interface->head['mac'] = __('Mac'); $table_interface->head['status'] = __('Actual status'); $table_interface->style['ip'] = 'text-align: left'; $table_interface->style['mac'] = 'text-align: left'; $table_interface->style['status'] = 'width: 150px; text-align: center'; $data = array(); $data['ip'] = !empty($interface['ip']) ? $interface['ip'] : "--"; $data['mac'] = !empty($interface['mac']) ? $interface['mac'] : "--"; $data['status'] = $interface['status_image']; $table_interface->data['data'] = $data; if (!empty($interface['chart'])) { $table_interface->data['graph'] = $interface['chart']; $table_interface->colspan['graph'][0] = 3; $table_interface->cellstyle['graph'][0] = 'text-align: center;'; } $table_agent->data['interfaces'] .= html_print_table($table_interface, true); $table_agent->colspan[$interface_name][0] = 3; } $id = uniq_id(); $table->data['agents'][$id] = html_print_table($table_agent, true); $table->colspan[$id][0] = 3; } } } function reporting_html_alert_report_group($table, $item) { $table->colspan['alerts']['cell'] = 3; $table->cellstyle['alerts']['cell'] = 'text-align: left;'; $table1->width = '99%'; $table1->head = array (); $table1->head['agent'] = __('Agent'); $table1->head['module'] = __('Module'); $table1->head['template'] = __('Template'); $table1->head['actions'] = __('Actions'); $table1->head['fired'] = __('Fired'); $table1->data = array (); foreach ($item['data'] as $alert) { $row = array(); $row['agent'] = $alert['agent']; $row['module'] = $alert['module']; $row['template'] = $alert['template']; $row['actions'] = $alert['template']; $row['actions'] = ''; $row['fired'] = ''; $table1->data[] = $row; } $table->data['alerts']['cell'] = html_print_table($table1, true); } function reporting_html_alert_report_agent($table, $item) { $table->colspan['alerts']['cell'] = 3; $table->cellstyle['alerts']['cell'] = 'text-align: left;'; $table1->width = '99%'; $table1->head = array (); $table1->head['module'] = __('Module'); $table1->head['template'] = __('Template'); $table1->head['actions'] = __('Actions'); $table1->head['fired'] = __('Fired'); $table1->data = array (); foreach ($item['data'] as $alert) { $row = array(); $row['module'] = $alert['module']; $row['template'] = $alert['template']; $row['actions'] = $alert['template']; $row['actions'] = ''; $row['fired'] = ''; $table1->data[] = $row; } $table->data['alerts']['cell'] = html_print_table($table1, true); } function reporting_html_alert_report_module($table, $item) { $table->colspan['alerts']['cell'] = 3; $table->cellstyle['alerts']['cell'] = 'text-align: left;'; $table1->width = '99%'; $table1->head = array (); $table1->head['template'] = __('Template'); $table1->head['actions'] = __('Actions'); $table1->head['fired'] = __('Fired'); $table1->data = array (); foreach ($item['data'] as $alert) { $row = array(); $row['template'] = $alert['template']; $row['actions'] = $alert['template']; $row['actions'] = ''; $row['fired'] = ''; $table1->data[] = $row; } $table->data['alerts']['cell'] = html_print_table($table1, true); } function reporting_html_sql_graph($table, $item) { $table->colspan['chart']['cell'] = 3; $table->cellstyle['chart']['cell'] = 'text-align: center;'; $table->data['chart']['cell'] = $item['chart']; } function reporting_html_monitor_report($table, $item, $mini) { if ($mini) { $font_size = '1.5'; } else { $font_size = '3'; } $table->colspan['module']['cell'] = 3; $table->cellstyle['module']['cell'] = 'text-align: center;'; $table1->width = '99%'; $table1->head = array (); $table1->data = array (); if ($item['data']['unknown'] == 1) { $table1->data['data']['unknown'] = '

'; $table1->data['data']['unknown'] .= __('Unknown') . "

"; } else { $table1->data['data']['ok'] = '

'; $table1->data['data']['ok'] .= html_print_image("images/module_ok.png", true) . ' ' . __('OK') . ': ' . $item['data']["ok"]["formated_value"].' %

'; $table1->data['data']['fail'] = '

'; $table1->data['data']['fail'] .= html_print_image("images/module_critical.png", true) . ' ' . __('Not OK') . ': ' . $item['data']["fail"]["formated_value"] . ' % ' . '

'; } $table->data['module']['cell'] = html_print_table($table1, true); } function reporting_html_graph($table, $item) { $table->colspan['chart']['cell'] = 3; $table->cellstyle['chart']['cell'] = 'text-align: center;'; $table->data['chart']['cell'] = $item['chart']; } function reporting_html_prediction_date($table, $item, $mini) { reporting_html_value($table, $item, $mini, true); } function reporting_html_agent_configuration(&$table, $item) { $table->colspan['agent']['cell'] = 3; $table->cellstyle['agent']['cell'] = 'text-align: left;'; $table1->width = '99%'; $table1->head = array (); $table1->head['name'] = __('Agent name'); $table1->head['group'] = __('Group'); $table1->head['os'] = __('OS'); $table1->head['address'] = __('IP'); $table1->head['description'] = __('Description'); $table1->head['status'] = __('Status'); $table1->data = array (); $row = array(); $row['name'] = $item['data']['name']; $row['group'] = $item['data']['group_icon']; $row['address'] = $item['data']['os_icon']; $row['os'] = $item['data']['address']; $row['description'] = $item['data']['description']; if ($item['data']['enabled']) { $row['status'] = __('Enabled'); } else { $row['status'] = __('Disabled'); } $table1->data[] = $row; $table->data['agent']['cell'] = html_print_table($table1, true); $table->colspan['modules']['cell'] = 3; $table->cellstyle['modules']['cell'] = 'text-align: left;'; if (empty($item['data']['modules'])) { $table->data['modules']['cell'] = __('Empty modules'); } else { $table1->width = '99%'; $table1->head = array (); $table1->head['name'] = __('Name'); $table1->head['type'] = __('Type'); $table1->head['warning_critical'] = __('Warning
Critical'); $table1->head['threshold'] = __('Threshold'); $table1->head['group_icon'] = __('Group'); $table1->head['description'] = __('Description'); $table1->head['interval'] = __('Interval'); $table1->head['unit'] = __('Unit'); $table1->head['status'] = __('Status'); $table1->head['tags'] = __('Tags'); $table1->align = array(); $table1->align['name'] = 'left'; $table1->align['type'] = 'center'; $table1->align['warning_critical'] = 'right'; $table1->align['threshold'] = 'right'; $table1->align['group_icon'] = 'center'; $table1->align['description'] = 'left'; $table1->align['interval'] = 'right'; $table1->align['unit'] = 'left'; $table1->align['status'] = 'center'; $table1->align['tags'] = 'left'; $table1->data = array (); foreach ($item['data']['modules'] as $module) { $row = array(); $row['name'] = $module['name']; $row['type'] = $module['type_icon']; $row['warning_critical'] = $module['max_warning'] . " / " . $module['min_warning'] . "
" . $module['max_critical'] . " / " . $module['min_critical']; $row['threshold'] = $module['threshold']; $row['group_icon'] = ui_print_group_icon($item['data']['group'], true); $row['description'] = $module['description']; $row['interval'] = $module['interval']; $row['unit'] = $module['unit']; $row['status'] = $module['status_icon']; $row['tags'] = implode(",", $module['tags']); $table1->data[] = $row; } $table->data['modules']['cell'] = html_print_table($table1, true); } } function reporting_html_TTO_value(&$table, $item, $mini, $only_value = false, $check_empty = false) { reporting_html_value($table, $item, $mini); } function reporting_html_MTBF_value(&$table, $item, $mini, $only_value = false, $check_empty = false) { reporting_html_value($table, $item, $mini); } function reporting_html_MTTR_value(&$table, $item, $mini, $only_value = false, $check_empty = false) { reporting_html_value($table, $item, $mini); } function reporting_html_sum_value(&$table, $item, $mini) { reporting_html_value($table, $item, $mini); } function reporting_html_avg_value(&$table, $item, $mini) { reporting_html_value($table, $item, $mini); } function reporting_html_max_value(&$table, $item, $mini) { reporting_html_value($table, $item, $mini); } function reporting_html_min_value(&$table, $item, $mini) { reporting_html_value($table, $item, $mini); } function reporting_html_value(&$table, $item, $mini, $only_value = false, $check_empty = false) { if ($mini) { $font_size = '1.5'; } else { $font_size = '3'; } $table->colspan['data']['cell'] = 3; $table->cellstyle['data']['cell'] = 'text-align: left;'; $table->data['data']['cell'] = '

'; if ($check_empty && empty($item['data']['value'])) { $table->data['data']['cell'] .= __('Unknown'); } elseif ($only_value) { $table->data['data']['cell'] .= $item['data']['value']; } else { $table->data['data']['cell'] .= $item['data']['formated_value']; } $table->data['data']['cell'] .= '

'; } function reporting_html_url(&$table, $item, $key) { $table->colspan['data']['cell'] = 3; $table->cellstyle['data']['cell'] = 'text-align: left;'; $table->data['data']['cell'] = ' '; // TODO: make this dynamic and get the height if the iframe to resize this item $table->data['data']['cell'] .= ' '; } function reporting_html_text(&$table, $item) { $table->colspan['data']['cell'] = 3; $table->cellstyle['data']['cell'] = 'text-align: left;'; $table->data['data']['cell'] = $item['data']; } function reporting_html_availability(&$table, $item) { if (!empty($item["data"])) { $table1->width = '99%'; $table1->data = array (); $table1->head = array (); $table1->head[0] = __('Agent'); // HACK it is saved in show_graph field. // Show interfaces instead the modules if ($item['kind_availability'] == 'address') { $table1->head[1] = __('IP Address'); } else { $table1->head[1] = __('Module'); } $table1->head[2] = __('# Checks'); $table1->head[3] = __('# Failed'); $table1->head[4] = __('% Fail'); $table1->head[5] = __('Poling time'); $table1->head[6] = __('Time unavailable'); $table1->head[7] = __('% Ok'); $table1->style[0] = 'text-align: left'; $table1->style[1] = 'text-align: left'; $table1->style[2] = 'text-align: right'; $table1->style[3] = 'text-align: right'; $table1->style[4] = 'text-align: right'; $table1->style[5] = 'text-align: right'; $table1->style[6] = 'text-align: right'; $table1->style[7] = 'text-align: right'; foreach ($item['data'] as $row) { $table_row = array(); $table_row[] = $row['agent']; $table_row[] = $row['availability_item']; $table_row[] = $row['checks']; $table_row[] = $row['failed']; $table_row[] = $row['fail']; $table_row[] = $row['poling_time']; $table_row[] = $row['time_unavaliable']; $table_row[] = $row['ok']; $table1->data[] = $table_row; } } else { $table->colspan['error']['cell'] = 3; $table->data['error']['cell'] = __('There are no Agent/Modules defined'); } $table->colspan[1][0] = 3; $data = array(); $data[0] = html_print_table($table1, true); array_push ($table->data, $data); if ($item['resume'] && !empty($item["data"])) { $table1->width = '99%'; $table1->data = array (); $table1->head = array (); $table1->style = array(); $table1->head['min_text'] = ''; $table1->head['min'] = __('Min Value'); $table1->head['avg'] = __('Average Value'); $table1->head['max_text'] = ''; $table1->head['max'] = __('Max Value'); $table1->style['min_text'] = 'text-align: left'; $table1->style['min'] = 'text-align: right'; $table1->style['avg'] = 'text-align: right'; $table1->style['max_text'] = 'text-align: left'; $table1->style['max'] = 'text-align: right'; $table1->data[] = array( 'min_text' => $item['resume']['min_text'], 'min' => format_numeric($item['resume']['min'], 2) . "%", 'avg' => format_numeric($item['resume']['avg'], 2) . "%", 'max_text' => $item['resume']['max_text'], 'max' => format_numeric($item['resume']['max'], 2) . "%" ); $table->colspan[2][0] = 3; $data = array(); $data[0] = html_print_table($table1, true); array_push ($table->data, $data); } } function reporting_html_general(&$table, $item) { if (!empty($item["data"])) { switch ($item['subtype']) { case REPORT_GENERAL_NOT_GROUP_BY_AGENT: $table1->width = '99%'; $table1->data = array (); $table1->head = array (); $table1->head[0] = __('Agent'); $table1->head[1] = __('Module'); if ($item['date']['period'] != 0) { $table1->head[2] = __('Operation'); } $table1->head[3] = __('Value'); $table1->style[0] = 'text-align: left'; $table1->style[1] = 'text-align: left'; $table1->style[2] = 'text-align: left'; $table1->style[3] = 'text-align: left'; foreach ($item['data'] as $row) { $table1->data[] = array( $row['agent'], $row['module'], $row['value']); } break; case REPORT_GENERAL_GROUP_BY_AGENT: $list_modules = array(); foreach ($item['data'] as $modules) { foreach ($modules as $name => $value) { $list_modules[$name] = null; } } $list_modules = array_keys($list_modules); $table1->width = '99%'; $table1->data = array (); $table1->head = array_merge(array(__('Agent')), $list_modules); foreach ($item['data'] as $agent => $modules) { $row = array(); $row['agent'] = $agent; $table1->style['agent'] = 'text-align: left;'; foreach ($list_modules as $name) { $table1->style[$name] = 'text-align: right;'; if (isset($modules[$name])) { $row[$name] = $value; } else { $row[$name] = "--"; } } $table1->data[] = $row; } break; } $table->colspan['data']['cell'] = 3; $table->cellstyle['data']['cell'] = 'text-align: center;'; $table->data['data']['cell'] = html_print_table($table1, true); } else { $table->colspan['error']['cell'] = 3; $table->data['error']['cell'] = __('There are no Agent/Modules defined'); } if ($item['resume'] && !empty($item["data"])) { $table_summary->width = '99%'; $table_summary->data = array (); $table_summary->head = array (); $table_summary->head_colspan = array (); $table_summary->align = array(); $table_summary->align[0] = 'left'; $table_summary->align[1] = 'right'; $table_summary->align[2] = 'right'; $table_summary->align[3] = 'left'; $table_summary->align[4] = 'right'; $table_summary->head_colspan[0] = 2; $table_summary->head[0] = __('Min Value'); $table_summary->head[1] = __('Average Value'); $table_summary->head_colspan[2] = 2; $table_summary->head[2] = __('Max Value'); $table_summary->data[0][0] = $item['min']['agent'] . ' - ' . $item['min']['module']; $table_summary->data[0][1] = $item['min']['formated_value']; $table_summary->data[0][2] = format_for_graph($item['avg_value'], 2); $table_summary->data[0][3] = $item['max']['agent'] . ' - ' . $item['max']['module']; $table_summary->data[0][4] = $item['max']['formated_value']; $table->colspan['summary_title']['cell'] = 3; $table->data['summary_title']['cell'] = '' . __('Summary') . ''; $table->colspan['summary_table']['cell'] = 3; $table->data['summary_table']['cell'] = html_print_table($table_summary, true); } } function reporting_html_sql(&$table, $item) { if (!$item['correct']) { $table->colspan['error']['cell'] = 3; $table->data['error']['cell'] = $item['error']; } else { $first = true; $table2->class = 'databox'; $table2->width = '100%'; foreach ($item['data'] as $row) { if ($first) { $first = false; // Print the header foreach ($row as $key => $value) { $table2->head[] = $key; } } $table2->data[] = $row; } $table->colspan['data']['cell'] = 3; $table->cellstyle['data']['cell'] = 'text-align: center;'; $table->data['data']['cell'] = html_print_table($table2, true); } } /** * Get the maximum value of an agent module in a period of time. * * @param int Agent module id to get the maximum value. * @param int Period of time to check (in seconds) * @param int Top date to check the values. Default current time. * * @return float The maximum module value in the interval. */ function reporting_get_agentmodule_data_max ($id_agent_module, $period=0, $date = 0) { global $config; // Initialize variables if (empty ($date)) $date = get_system_time (); $datelimit = $date - $period; $search_in_history_db = db_search_in_history_db($datelimit); $id_module_type = modules_get_agentmodule_type ($id_agent_module); $module_type = modules_get_moduletype_name ($id_module_type); $uncompressed_module = is_module_uncompressed ($module_type); // Get module data $interval_data = db_get_all_rows_sql ('SELECT * FROM tagente_datos WHERE id_agente_modulo = ' . (int) $id_agent_module . ' AND utimestamp > ' . (int) $datelimit . ' AND utimestamp < ' . (int) $date . ' ORDER BY utimestamp ASC', $search_in_history_db); if ($interval_data === false) $interval_data = array (); // Uncompressed module data if ($uncompressed_module) { // Compressed module data } else { // Get previous data $previous_data = modules_get_previous_data ($id_agent_module, $datelimit); if ($previous_data !== false) { $previous_data['utimestamp'] = $datelimit; array_unshift ($interval_data, $previous_data); } // Get next data $next_data = modules_get_next_data ($id_agent_module, $date); if ($next_data !== false) { $next_data['utimestamp'] = $date; array_push ($interval_data, $next_data); } else if (count ($interval_data) > 0) { // Propagate the last known data to the end of the interval $next_data = array_pop ($interval_data); array_push ($interval_data, $next_data); $next_data['utimestamp'] = $date; array_push ($interval_data, $next_data); } } // Set initial conditions if (empty($iterval_data)) { $max = 0; } else { if ($uncompressed_module || $interval_data[0]['utimestamp'] == $datelimit) { $max = $interval_data[0]['datos']; } else { $max = 0; } } foreach ($interval_data as $data) { if ($data['datos'] > $max) { $max = $data['datos']; } } return $max; } /** * Get the minimum value of an agent module in a period of time. * * @param int Agent module id to get the minimum value. * @param int Period of time to check (in seconds) * @param int Top date to check the values in Unix time. Default current time. * * @return float The minimum module value of the module */ function reporting_get_agentmodule_data_min ($id_agent_module, $period=0, $date = 0) { global $config; // Initialize variables if (empty ($date)) $date = get_system_time (); $datelimit = $date - $period; $search_in_history_db = db_search_in_history_db($datelimit); $id_module_type = modules_get_agentmodule_type ($id_agent_module); $module_type = modules_get_moduletype_name ($id_module_type); $uncompressed_module = is_module_uncompressed ($module_type); // Get module data $interval_data = db_get_all_rows_sql ('SELECT * FROM tagente_datos WHERE id_agente_modulo = ' . (int) $id_agent_module . ' AND utimestamp > ' . (int) $datelimit . ' AND utimestamp < ' . (int) $date . ' ORDER BY utimestamp ASC', $search_in_history_db); if ($interval_data === false) $interval_data = array (); // Uncompressed module data if ($uncompressed_module) { $min_necessary = 1; // Compressed module data } else { // Get previous data $previous_data = modules_get_previous_data ($id_agent_module, $datelimit); if ($previous_data !== false) { $previous_data['utimestamp'] = $datelimit; array_unshift ($interval_data, $previous_data); } // Get next data $next_data = modules_get_next_data ($id_agent_module, $date); if ($next_data !== false) { $next_data['utimestamp'] = $date; array_push ($interval_data, $next_data); } else if (count ($interval_data) > 0) { // Propagate the last known data to the end of the interval $next_data = array_pop ($interval_data); array_push ($interval_data, $next_data); $next_data['utimestamp'] = $date; array_push ($interval_data, $next_data); } } if (count ($interval_data) < 1) { return false; } // Set initial conditions $min = $interval_data[0]['datos']; foreach ($interval_data as $data) { if ($data['datos'] < $min) { $min = $data['datos']; } } return $min; } /** * Get the sum of values of an agent module in a period of time. * * @param int Agent module id to get the sumatory. * @param int Period of time to check (in seconds) * @param int Top date to check the values. Default current time. * * @return float The sumatory of the module values in the interval. */ function reporting_get_agentmodule_data_sum ($id_agent_module, $period = 0, $date = 0) { global $config; // Initialize variables if (empty ($date)) $date = get_system_time (); $datelimit = $date - $period; $search_in_history_db = db_search_in_history_db($datelimit); $id_module_type = db_get_value ('id_tipo_modulo', 'tagente_modulo', 'id_agente_modulo', $id_agent_module); $module_name = db_get_value ('nombre', 'ttipo_modulo', 'id_tipo', $id_module_type); $module_interval = modules_get_interval ($id_agent_module); $uncompressed_module = is_module_uncompressed ($module_name); // Wrong module type if (is_module_data_string ($module_name)) { return 0; } // Incremental modules are treated differently $module_inc = is_module_inc ($module_name); // Get module data $interval_data = db_get_all_rows_sql(' SELECT * FROM tagente_datos WHERE id_agente_modulo = ' . (int) $id_agent_module . ' AND utimestamp > ' . (int) $datelimit . ' AND utimestamp < ' . (int) $date . ' ORDER BY utimestamp ASC', $search_in_history_db); if ($interval_data === false) $interval_data = array (); // Uncompressed module data if ($uncompressed_module) { $min_necessary = 1; // Compressed module data } else { // Get previous data $previous_data = modules_get_previous_data ($id_agent_module, $datelimit); if ($previous_data !== false) { $previous_data['utimestamp'] = $datelimit; array_unshift ($interval_data, $previous_data); } // Get next data $next_data = modules_get_next_data ($id_agent_module, $date); if ($next_data !== false) { $next_data['utimestamp'] = $date; array_push ($interval_data, $next_data); } else if (count ($interval_data) > 0) { // Propagate the last known data to the end of the interval $next_data = array_pop ($interval_data); array_push ($interval_data, $next_data); $next_data['utimestamp'] = $date; array_push ($interval_data, $next_data); } $min_necessary = 2; } if (count ($interval_data) < $min_necessary) { return false; } // Set initial conditions $total = 0; if (! $uncompressed_module) { $previous_data = array_shift ($interval_data); } foreach ($interval_data as $data) { if ($uncompressed_module) { $total += $data['datos']; } else if ($module_inc) { $total += $previous_data['datos'] * ($data['utimestamp'] - $previous_data['utimestamp']); } else { $total += $previous_data['datos'] * ($data['utimestamp'] - $previous_data['utimestamp']) / $module_interval; } $previous_data = $data; } return $total; } /** * Get SLA of a module. * * @param int Agent module to calculate SLA * @param int Period to check the SLA compliance. * @param int Minimum data value the module in the right interval * @param int Maximum data value the module in the right interval. False will * ignore max value * @param int Beginning date of the report in UNIX time (current date by default). * @param array $dayWeek Array of days week to extract as array('monday' => false, 'tuesday' => true....), and by default is null. * @param string $timeFrom Time in the day to start to extract in mysql format, by default null. * @param string $timeTo Time in the day to end to extract in mysql format, by default null. * * @return float SLA percentage of the requested module. False if no data were * found */ function reporting_get_agentmodule_sla_day ($id_agent_module, $period = 0, $min_value = 1, $max_value = false, $date = 0, $daysWeek = null, $timeFrom = null, $timeTo = null) { global $config; if (empty($id_agent_module)) return false; // Initialize variables if (empty ($date)) { $date = get_system_time (); } if ($daysWeek === null) { $daysWeek = array(); } // Limit date to start searching data $datelimit = $date - $period; $search_in_history_db = db_search_in_history_db($datelimit); // Get interval data $sql = sprintf ('SELECT * FROM tagente_datos WHERE id_agente_modulo = %d AND utimestamp > %d AND utimestamp <= %d', $id_agent_module, $datelimit, $date); //Add the working times (mon - tue - wed ...) and from time to time $days = array(); //Translate to mysql week days if ($daysWeek) { foreach ($daysWeek as $key => $value) { if (!$value) { if ($key == 'monday') { $days[] = 2; } if ($key == 'tuesday') { $days[] = 3; } if ($key == 'wednesday') { $days[] = 4; } if ($key == 'thursday') { $days[] = 5; } if ($key == 'friday') { $days[] = 6; } if ($key == 'saturday') { $days[] = 7; } if ($key == 'sunday') { $days[] = 1; } } } } if (count($days) > 0) { $sql .= ' AND DAYOFWEEK(FROM_UNIXTIME(utimestamp)) NOT IN (' . implode(',', $days) . ')'; } if ($timeFrom < $timeTo) { $sql .= ' AND (TIME(FROM_UNIXTIME(utimestamp)) >= "' . $timeFrom . '" AND TIME(FROM_UNIXTIME(utimestamp)) <= "'. $timeTo . '")'; } elseif ($timeFrom > $timeTo) { $sql .= ' AND (TIME(FROM_UNIXTIME(utimestamp)) >= "' . $timeFrom . '" OR TIME(FROM_UNIXTIME(utimestamp)) <= "'. $timeTo . '")'; } $sql .= ' ORDER BY utimestamp ASC'; $interval_data = db_get_all_rows_sql ($sql, $search_in_history_db); if ($interval_data === false) { $interval_data = array (); } // Calculate planned downtime dates $downtime_dates = reporting_get_planned_downtimes_intervals($id_agent_module, $datelimit, $date); // Get previous data $previous_data = modules_get_previous_data ($id_agent_module, $datelimit); if ($previous_data !== false) { $previous_data['utimestamp'] = $datelimit; array_unshift ($interval_data, $previous_data); } // Get next data $next_data = modules_get_next_data ($id_agent_module, $date); if ($next_data !== false) { $next_data['utimestamp'] = $date; array_push ($interval_data, $next_data); } else if (count ($interval_data) > 0) { // Propagate the last known data to the end of the interval $next_data = array_pop ($interval_data); array_push ($interval_data, $next_data); $next_data['utimestamp'] = $date; array_push ($interval_data, $next_data); } if (count ($interval_data) < 2) { return false; } // Set initial conditions $bad_period = 0; $first_data = array_shift ($interval_data); // Do not count the empty start of an interval as 0 if ($first_data['utimestamp'] != $datelimit) { $period = $date - $first_data['utimestamp']; } $previous_utimestamp = $first_data['utimestamp']; if ((($max_value > $min_value AND ($first_data['datos'] > $max_value OR $first_data['datos'] < $min_value))) OR ($max_value <= $min_value AND $first_data['datos'] < $min_value)) { $previous_status = 1; foreach ($downtime_dates as $date_dt) { if (($date_dt['date_from'] <= $previous_utimestamp) AND ($date_dt['date_to'] >= $previous_utimestamp)) { $previous_status = 0; } } } else { $previous_status = 0; } foreach ($interval_data as $data) { // Previous status was critical if ($previous_status == 1) { $bad_period += $data['utimestamp'] - $previous_utimestamp; } if (array_key_exists('datos', $data)) { // Re-calculate previous status for the next data if ((($max_value > $min_value AND ($data['datos'] > $max_value OR $data['datos'] < $min_value))) OR ($max_value <= $min_value AND $data['datos'] < $min_value)) { $previous_status = 1; foreach ($downtime_dates as $date_dt) { if (($date_dt['date_from'] <= $data['utimestamp']) AND ($date_dt['date_to'] >= $data['utimestamp'])) { $previous_status = 0; } } } else { $previous_status = 0; } } $previous_utimestamp = $data['utimestamp']; } // Return the percentage of SLA compliance return (float) (100 - ($bad_period / $period) * 100); } /** * Get several SLA data for an agentmodule within a period divided on subperiods * * @param int Agent module to calculate SLA * @param int Period to check the SLA compliance. * @param int Minimum data value the module in the right interval * @param int Maximum data value the module in the right interval. False will * ignore max value * @param array $days Array of days week to extract as array('monday' => false, 'tuesday' => true....), and by default is null. * @param string $timeFrom Time in the day to start to extract in mysql format, by default null. * @param string $timeTo Time in the day to end to extract in mysql format, by default null. * * @return Array with values either 1, 2, 3 or 4 depending if the SLA percentage for this subperiod * is within the sla limits, on the edge, outside or with an unknown value. */ function reporting_get_agentmodule_sla_array ($id_agent_module, $period = 0, $min_value = 1, $max_value = false, $date = 0, $daysWeek = null, $timeFrom = null, $timeTo = null) { global $config; if (empty($id_agent_module)) return false; // Initialize variables if (empty ($date)) { $date = get_system_time (); } if ($daysWeek === null) { $daysWeek = array(); } // Hotfix: The edge values are confuse to the users $percent = 0; // Limit date to start searching data $datelimit = $date - $period; $search_in_history_db = db_search_in_history_db($datelimit); // Get interval data $sql = sprintf ('SELECT * FROM tagente_datos WHERE id_agente_modulo = %d AND utimestamp > %d AND utimestamp <= %d', $id_agent_module, $datelimit, $date); //Add the working times (mon - tue - wed ...) and from time to time $days = array(); //Translate to mysql week days if ($daysWeek) { foreach ($daysWeek as $key => $value) { if (!$value) { if ($key == 'monday') { $days[] = 2; } if ($key == 'tuesday') { $days[] = 3; } if ($key == 'wednesday') { $days[] = 4; } if ($key == 'thursday') { $days[] = 5; } if ($key == 'friday') { $days[] = 6; } if ($key == 'saturday') { $days[] = 7; } if ($key == 'sunday') { $days[] = 1; } } } } if (count($days) > 0) { $sql .= ' AND DAYOFWEEK(FROM_UNIXTIME(utimestamp)) NOT IN (' . implode(',', $days) . ')'; } if ($timeFrom != $timeTo) { if ($timeFrom < $timeTo) { $sql .= ' AND (TIME(FROM_UNIXTIME(utimestamp)) >= "' . $timeFrom . '" AND TIME(FROM_UNIXTIME(utimestamp)) <= "'. $timeTo . '")'; } elseif ($timeFrom > $timeTo) { $sql .= ' AND (TIME(FROM_UNIXTIME(utimestamp)) >= "' . $timeFrom . '" OR TIME(FROM_UNIXTIME(utimestamp)) <= "'. $timeTo . '")'; } } $sql .= ' ORDER BY utimestamp ASC'; $interval_data = db_get_all_rows_sql ($sql, $search_in_history_db); if ($interval_data === false) { $interval_data = array (); } // Indexing data $interval_data_indexed = array(); foreach($interval_data as $idata) { $interval_data_indexed[$idata['utimestamp']]['data'] = $idata['datos']; } //-----------Calculate unknown status events------------------------ $events_unknown = db_get_all_rows_filter ('tevento', array ('id_agentmodule' => $id_agent_module, "utimestamp > $datelimit", "utimestamp < $date", 'order' => 'utimestamp ASC'), array ('id_evento', 'evento', 'timestamp', 'utimestamp', 'event_type')); if ($events_unknown === false) { $events_unknown = array (); } // Add unknown periods to data for ($i = 0; isset($events_unknown[$i]); $i++) { $eu = $events_unknown[$i]; if ($eu['event_type'] == 'going_unknown') { $interval_data_indexed[$eu['utimestamp']]['data'] = 0; $interval_data_indexed[$eu['utimestamp']]['status'] = 4; // Search the corresponding recovery event. for ($j = $i+1; isset($events_unknown[$j]); $j++) { $eu = $events_unknown[$j]; if ($eu['event_type'] != 'going_unknown' && substr ($eu['event_type'], 0, 5) == 'going') { $interval_data_indexed[$eu['utimestamp']]['data'] = 0; $interval_data_indexed[$eu['utimestamp']]['status'] = 6; // Do not process read events again. $i = $j; break; } } } } // Get the last event before inverval to know if graph start on unknown $prev_event = db_get_row_filter ('tevento', array ('id_agentmodule' => $id_agent_module, "utimestamp <= $datelimit", 'order' => 'utimestamp DESC')); if (isset($prev_event['event_type']) && $prev_event['event_type'] == 'going_unknown') { $start_unknown = true; } else { $start_unknown = false; } //------------------------------------------------------------------ //-----------------Set limits of the interval----------------------- // Get previous data (This adds the first data if the begin of module data is after the begin time interval) $previous_data = modules_get_previous_data ($id_agent_module, $datelimit); if ($previous_data !== false ) { $previous_value = $previous_data['datos']; // if ((($previous_value > ($min_value - $percent)) && ($previous_value < ($min_value + $percent))) || // (($previous_value > ($max_value - $percent)) && ($previous_value < ($max_value + $percent)))) {//2 when value is within the edges // $previous_known_status = 2; // } // else if (($previous_value >= ($min_value + $percent)) && ($previous_value <= ($max_value - $percent))) { //1 when value is OK $previous_known_status = 1; } elseif (($previous_value <= ($min_value - $percent)) || ($previous_value >= ($max_value + $percent))) { //3 when value is Wrong $previous_known_status = 3; } } // If the starting of the graph is unknown we set it if ($start_unknown) { $interval_data_indexed[$datelimit]['data'] = 0; $interval_data_indexed[$datelimit]['status'] = 4; } else { if ($previous_data !== false ) { $interval_data_indexed[$datelimit]['data'] = $previous_data['datos']; } else { // If there are not data befor interval set unknown $interval_data_indexed[$datelimit]['data'] = 0; $interval_data_indexed[$datelimit]['status'] = 4; $previous_known_status = 1; // Assume the module was in normal status if there is no previous data. } } // Get next data (This adds data before the interval of the report) $next_data = modules_get_next_data ($id_agent_module, $date); if ($next_data !== false) { $interval_data_indexed[$date]['data'] = $previous_data['datos']; } else if (count ($interval_data_indexed) > 0) { // Propagate the last known data to the end of the interval (if there is no module data at the end point) ksort($interval_data_indexed); $last_data = end($interval_data_indexed); $interval_data_indexed[$date] = $last_data; } //------------------------------------------------------------------ //--------Calculate planned downtime dates-------------------------- $downtime_dates = reporting_get_planned_downtimes_intervals($id_agent_module, $datelimit, $date); foreach ($downtime_dates as $downtime_date) { // Delete data of the planned downtime and put the last data on the upper limit $interval_data_indexed[$downtime_date['date_from']]['data'] = 0; $interval_data_indexed[$downtime_date['date_from']]['status'] = 5; $interval_data_indexed[$downtime_date['date_to']]['data'] = 0; $interval_data_indexed[$downtime_date['date_to']]['status'] = 4; $last_downtime_data = false; foreach ($interval_data_indexed as $idi_timestamp => $idi) { if ($idi_timestamp != $downtime_date['date_from'] && $idi_timestamp != $downtime_date['date_to'] && $idi_timestamp >= $downtime_date['date_from'] && $idi_timestamp <= $downtime_date['date_to']) { $last_downtime_data = $idi['data']; unset($interval_data_indexed[$idi_timestamp]); } } // Set the last data of the interval as limit if ($last_downtime_data !== false) { $interval_data_indexed[$downtime_date['date_to']]['data'] = $last_downtime_data; } } //------------------------------------------------------------------ // Sort the array ksort($interval_data_indexed); // We need more or equal two points if (count ($interval_data_indexed) < 2) { return false; } //Get the percentage for the limits $diff = $max_value - $min_value; // Get module type $id_module_type = db_get_value('id_tipo_modulo', 'tagente_modulo', 'id_agente_modulo', $id_agent_module); // If module is boolean don't create translation intervals (on the edge intervals) // if ($id_module_type == 2 or $id_module_type == 6 or $id_module_type == 9 or $id_module_type == 18){ // $percent = 0; // } // else { // // Getting 10% of $diff --> $percent = ($diff/100)*10, so... // $percent = $diff / 10; // } //Set initial conditions $first_data = array_shift ($interval_data); $previous_utimestamp = $date - $period; $previous_value = $first_data ['datos']; $previous_status = 0; if (isset($first_data['status'])) { // 4 for the Unknown value and 5 for planned downtime $previous_status = $first_data['status']; } // elseif ((($previous_value > ($min_value - $percent)) && ($previous_value < ($min_value + $percent))) || // (($previous_value > ($max_value - $percent)) && ($previous_value < ($max_value + $percent)))) {//2 when value is within the edges // $previous_status = 2; // } elseif (($previous_value >= ($min_value + $percent)) && ($previous_value <= ($max_value - $percent))) { //1 when value is OK $previous_status = 1; } elseif (($previous_value <= ($min_value - $percent)) || ($previous_value >= ($max_value + $percent))) { //3 when value is Wrong $previous_status = 3; } $data_colors = array(); $i = 0; foreach ($interval_data_indexed as $utimestamp => $data) { $change = false; $value = $data['data']; if (isset($data['status'])) { // Leaving unkown status. if ($data['status'] == 6) { $status = $previous_known_status; } // 4 unknown, 5 planned downtime. else { $status = $data['status']; } } // elseif ((($value > ($min_value - $percent)) && ($value < ($min_value + $percent))) || // (($value > ($max_value - $percent)) && ($value < ($max_value + $percent)))) { //2 when value is within the edges // $status = 2; // } elseif (($value >= ($min_value + $percent)) && ($value <= ($max_value - $percent))) { //1 when value is OK $status = 1; } elseif (($value <= ($min_value - $percent)) || ($value >= ($max_value + $percent))) { //3 when value is Wrong $status = 3; } if ($status != $previous_status) { $change = true; $data_colors[$i]['data'] = $previous_status; $data_colors[$i]['utimestamp'] = $utimestamp - $previous_utimestamp; $i++; $previous_status = $status; $previous_utimestamp = $utimestamp; } // Save the last known status. if ($status <= 3) { $previous_known_status = $status; } } if ($change == false) { $data_colors[$i]['data'] = $previous_status; $data_colors[$i]['utimestamp'] = $date - $previous_utimestamp; } return $data_colors; } /** * Get the planned downtimes that affect the passed modules on an specific datetime range. * * @param int Start date in utimestamp. * @param int End date in utimestamp. * @param array The agent modules ids. * * @return Array with the planned downtimes that are executed in any moment of the range selected and affect the * agent modules selected. */ function reporting_get_planned_downtimes ($start_date, $end_date, $id_agent_modules = false) { $start_time = date("H:i:s", $start_date); $end_time = date("H:i:s", $end_date); $start_day = date("d", $start_date); $end_day = date("d", $end_date); $start_month = date("m", $start_date); $end_month = date("m", $end_date); if ($start_date > $end_date) { return false; } if ($end_date - $start_date >= SECONDS_1MONTH) { // If the date range is larger than 1 month, every monthly planned downtime will be inside $periodically_monthly_w = "type_periodicity = 'monthly'"; } else { // Check if the range is larger than the planned downtime execution, or if its start or end // is inside the planned downtime execution. // The start and end time is very important. $periodically_monthly_w = "type_periodicity = 'monthly' AND (((periodically_day_from > '$start_day' OR (periodically_day_from = '$start_day' AND periodically_time_from >= '$start_time')) AND (periodically_day_to < '$end_day' OR (periodically_day_to = '$end_day' AND periodically_time_to <= '$end_time'))) OR ((periodically_day_from < '$start_day' OR (periodically_day_from = '$start_day' AND periodically_time_from <= '$start_time')) AND (periodically_day_to > '$start_day' OR (periodically_day_to = '$start_day' AND periodically_time_to >= '$start_time'))) OR ((periodically_day_from < '$end_day' OR (periodically_day_from = '$end_day' AND periodically_time_from <= '$end_time')) AND (periodically_day_to > '$end_day' OR (periodically_day_to = '$end_day' AND periodically_time_to >= '$end_time'))))"; } $periodically_weekly_days = array(); $date_aux = $start_date; $i = 0; if (($end_date - $start_date) >= SECONDS_1WEEK) { // If the date range is larger than 7 days, every weekly planned downtime will be inside. for ($i = 0; $i < 7; $i++) { $weekday_actual = strtolower(date('l', $date_aux)); $periodically_weekly_days[] = "($weekday_actual = 1)"; $date_aux += SECONDS_1DAY; } } else if (($end_date - $start_date) <= SECONDS_1DAY && $start_day == $end_day) { // If the date range is smaller than 1 day, the start and end days can be equal or consecutive. // If they are equal, the execution times have to be contained in the date range times or contain // the start or end time of the date range. $weekday_actual = strtolower(date('l', $start_date)); $periodically_weekly_days[] = "($weekday_actual = 1 AND ((periodically_time_from > '$start_time' AND periodically_time_to < '$end_time') OR (periodically_time_from = '$start_time' OR (periodically_time_from < '$start_time' AND periodically_time_to >= '$start_time')) OR (periodically_time_from = '$end_time' OR (periodically_time_from < '$end_time' AND periodically_time_to >= '$end_time'))))"; } else { while ($date_aux <= $end_date && $i < 7) { $weekday_actual = strtolower(date('l', $date_aux)); $day_num_actual = date('d', $date_aux); if ($date_aux == $start_date) { $periodically_weekly_days[] = "($weekday_actual = 1 AND periodically_time_to >= '$start_time')"; } else if ($day_num_actual == $end_day) { $periodically_weekly_days[] = "($weekday_actual = 1 AND periodically_time_from <= '$end_time')"; } else { $periodically_weekly_days[] = "($weekday_actual = 1)"; } $date_aux += SECONDS_1DAY; $i++; } } if (!empty($periodically_weekly_days)) { $periodically_weekly_w = "type_periodicity = 'weekly' AND (".implode(" OR ", $periodically_weekly_days).")"; $periodically_condition = "(($periodically_monthly_w) OR ($periodically_weekly_w))"; } else { $periodically_condition = "($periodically_monthly_w)"; } if ($id_agent_modules !== false) { if (empty($id_agent_modules)) return array(); $id_agent_modules_str = implode(",", $id_agent_modules); $sql_downtime = "SELECT DISTINCT(tpdr.id), tpdr.* FROM ( SELECT tpd.* FROM tplanned_downtime tpd, tplanned_downtime_agents tpda, tagente_modulo tam WHERE (tpd.id = tpda.id_downtime AND tpda.all_modules = 1 AND tpda.id_agent = tam.id_agente AND tam.id_agente_modulo IN ($id_agent_modules_str)) AND ((type_execution = 'periodically' AND $periodically_condition) OR (type_execution = 'once' AND ((date_from >= '$start_date' AND date_to <= '$end_date') OR (date_from <= '$start_date' AND date_to >= '$end_date') OR (date_from <= '$start_date' AND date_to >= '$start_date') OR (date_from <= '$end_date' AND date_to >= '$end_date')))) UNION ALL SELECT tpd.* FROM tplanned_downtime tpd, tplanned_downtime_modules tpdm WHERE (tpd.id = tpdm.id_downtime AND tpdm.id_agent_module IN ($id_agent_modules_str)) AND ((type_execution = 'periodically' AND $periodically_condition) OR (type_execution = 'once' AND ((date_from >= '$start_date' AND date_to <= '$end_date') OR (date_from <= '$start_date' AND date_to >= '$end_date') OR (date_from <= '$start_date' AND date_to >= '$start_date') OR (date_from <= '$end_date' AND date_to >= '$end_date')))) ) tpdr ORDER BY tpdr.id"; } else { $sql_downtime = "SELECT * FROM tplanned_downtime tpd, tplanned_downtime_modules tpdm WHERE (type_execution = 'periodically' AND $periodically_condition) OR (type_execution = 'once' AND ((date_from >= '$start_date' AND date_to <= '$end_date') OR (date_from <= '$start_date' AND date_to >= '$end_date') OR (date_from <= '$start_date' AND date_to >= '$start_date') OR (date_from <= '$end_date' AND date_to >= '$end_date')))"; } $downtimes = db_get_all_rows_sql($sql_downtime); if ($downtimes == false) { $downtimes = array(); } return $downtimes; } function reporting_get_stats_servers($tiny = true) { global $config; $server_performance = servers_get_performance(); // Alerts table $table_srv = html_get_predefined_table(); $table_srv->style[0] = $table_srv->style[2] = 'text-align: right; padding: 5px;'; $table_srv->style[1] = $table_srv->style[3] = 'text-align: left; padding: 5px;'; $tdata = array(); $tdata[0] = html_print_image('images/module.png', true, array('title' => __('Total running modules'), 'width' => '25px')); $tdata[1] = '' . format_numeric($server_performance ["total_modules"]) . ''; $tdata[2] = '' . format_numeric($server_performance ["total_modules_rate"], 2) . ''; $tdata[3] = html_print_image('images/module.png', true, array('title' => __('Ratio') . ': ' . __('Modules by second'), 'width' => '16px')) . '/sec '; $table_srv->rowclass[] = ''; $table_srv->data[] = $tdata; $tdata = array(); $tdata[0] = '
'; $table_srv->colspan[count($table_srv->data)][0] = 4; $table_srv->rowclass[] = ''; $table_srv->data[] = $tdata; $tdata = array(); $tdata[0] = html_print_image('images/database.png', true, array('title' => __('Local modules'), 'width' => '25px')); $tdata[1] = '' . format_numeric($server_performance ["total_local_modules"]) . ''; $tdata[2] = '' . format_numeric($server_performance ["local_modules_rate"], 2) . ''; $tdata[3] = html_print_image('images/module.png', true, array('title' => __('Ratio') . ': ' . __('Modules by second'), 'width' => '16px')) . '/sec '; $table_srv->rowclass[] = ''; $table_srv->data[] = $tdata; if ($tiny) { $tdata = array(); $tdata[0] = html_print_image('images/network.png', true, array('title' => __('Remote modules'), 'width' => '25px')); $tdata[1] = '' . format_numeric($server_performance ["total_remote_modules"]) . ''; $tdata[2] = '' . format_numeric($server_performance ["remote_modules_rate"], 2) . ''; $tdata[3] = html_print_image('images/module.png', true, array('title' => __('Ratio') . ': ' . __('Modules by second'), 'width' => '16px')) . '/sec '; $table_srv->rowclass[] = ''; $table_srv->data[] = $tdata; } else { if (isset($server_performance ["total_network_modules"])) { $tdata = array(); $tdata[0] = html_print_image('images/network.png', true, array('title' => __('Network modules'), 'width' => '25px')); $tdata[1] = '' . format_numeric($server_performance ["total_network_modules"]) . ''; $tdata[2] = '' . format_numeric($server_performance["network_modules_rate"], 2) . ''; $tdata[3] = html_print_image('images/module.png', true, array('title' => __('Ratio') . ': ' . __('Modules by second'), 'width' => '16px')) . '/sec '; $table_srv->rowclass[] = ''; $table_srv->data[] = $tdata; } if (isset($server_performance ["total_plugin_modules"])) { $tdata = array(); $tdata[0] = html_print_image('images/plugin.png', true, array('title' => __('Plugin modules'), 'width' => '25px')); $tdata[1] = '' . format_numeric($server_performance ["total_plugin_modules"]) . ''; $tdata[2] = '' . format_numeric($server_performance ["plugin_modules_rate"], 2) . ''; $tdata[3] = html_print_image('images/module.png', true, array('title' => __('Ratio') . ': ' . __('Modules by second'), 'width' => '16px')) . '/sec '; $table_srv->rowclass[] = ''; $table_srv->data[] = $tdata; } if (isset($server_performance ["total_prediction_modules"])) { $tdata = array(); $tdata[0] = html_print_image('images/chart_bar.png', true, array('title' => __('Prediction modules'), 'width' => '25px')); $tdata[1] = '' . format_numeric($server_performance ["total_prediction_modules"]) . ''; $tdata[2] = '' . format_numeric($server_performance ["prediction_modules_rate"], 2) . ''; $tdata[3] = html_print_image('images/module.png', true, array('title' => __('Ratio') . ': ' . __('Modules by second'), 'width' => '16px')) . '/sec '; $table_srv->rowclass[] = ''; $table_srv->data[] = $tdata; } if (isset($server_performance ["total_wmi_modules"])) { $tdata = array(); $tdata[0] = html_print_image('images/wmi.png', true, array('title' => __('WMI modules'), 'width' => '25px')); $tdata[1] = '' . format_numeric($server_performance ["total_wmi_modules"]) . ''; $tdata[2] = '' . format_numeric($server_performance ["wmi_modules_rate"], 2) . ''; $tdata[3] = html_print_image('images/module.png', true, array('title' => __('Ratio') . ': ' . __('Modules by second'), 'width' => '16px')) . '/sec '; $table_srv->rowclass[] = ''; $table_srv->data[] = $tdata; } if (isset($server_performance ["total_web_modules"])) { $tdata = array(); $tdata[0] = html_print_image('images/world.png', true, array('title' => __('Web modules'), 'width' => '25px')); $tdata[1] = '' . format_numeric($server_performance ["total_web_modules"]) . ''; $tdata[2] = '' . format_numeric($server_performance ["web_modules_rate"], 2) . ''; $tdata[3] = html_print_image('images/module.png', true, array('title' => __('Ratio') . ': ' . __('Modules by second'), 'width' => '16px')) . '/sec '; $table_srv->rowclass[] = ''; $table_srv->data[] = $tdata; } $tdata = array(); $tdata[0] = '
'; $table_srv->colspan[count($table_srv->data)][0] = 4; $table_srv->rowclass[] = ''; $table_srv->data[] = $tdata; switch ($config["dbtype"]) { case "mysql": $system_events = db_get_value_sql( 'SELECT SQL_NO_CACHE COUNT(id_evento) FROM tevento'); break; case "postgresql": case "oracle": $system_events = db_get_value_sql( 'SELECT COUNT(id_evento) FROM tevento'); break; } $tdata = array(); $tdata[0] = html_print_image('images/lightning_go.png', true, array('title' => __('Total events'), 'width' => '25px')); $tdata[1] = '' . format_numeric($system_events) . ''; $table_srv->colspan[count($table_srv->data)][1] = 3; $table_srv->rowclass[] = ''; $table_srv->data[] = $tdata; } $output = '
' . __('Server performance') . '' . html_print_table($table_srv, true) . '
'; return $output; } function reporting_get_stats_summary($data, $graph_width, $graph_height) { global $config; // Alerts table $table_sum = html_get_predefined_table(); $tdata = array(); $table_sum->colspan[count($table_sum->data)][0] = 2; $table_sum->colspan[count($table_sum->data)][2] = 2; $table_sum->cellstyle[count($table_sum->data)][0] = 'text-align: center;'; $table_sum->cellstyle[count($table_sum->data)][2] = 'text-align: center;'; $tdata[0] = '' . __('Module status') . ''; $tdata[2] = '' . __('Alert level') . ''; $table_sum->rowclass[] = ''; $table_sum->data[] = $tdata; $tdata = array(); $table_sum->colspan[count($table_sum->data)][0] = 2; $table_sum->colspan[count($table_sum->data)][2] = 2; $table_sum->cellstyle[count($table_sum->data)][0] = 'text-align: center;'; $table_sum->cellstyle[count($table_sum->data)][2] = 'text-align: center;'; if ($data["monitor_checks"] > 0) { $tdata[0] = '
' . graph_agent_status (false, $graph_width, $graph_height, true, true) . '
'; } else { $tdata[2] = html_print_image('images/image_problem.png', true, array('width' => $graph_width)); } if ($data["monitor_alerts"] > 0) { $tdata[2] = '
' . graph_alert_status ($data["monitor_alerts"], $data["monitor_alerts_fired"], $graph_width, $graph_height, true, true) . '
'; } else { $tdata[2] = html_print_image('images/image_problem.png', true, array('width' => $graph_width)); } $table_sum->rowclass[] = ''; $table_sum->data[] = $tdata; $output = '
' . __('Summary') . '' . html_print_table($table_sum, true) . '
'; return $output; } /** * Get an event reporting table. * * It construct a table object with all the events happened in a group * during a period of time. * * @param int Group id to get the report. * @param int Period of time to get the report. * @param int Beginning date of the report * @param int Flag to return or echo the report table (echo by default). * * @return object A table object */ function reporting_event_reporting ($id_group, $period, $date = 0, $return = false) { if (empty ($date)) { $date = get_system_time (); } elseif (!is_numeric ($date)) { $date = strtotime ($date); } $table->data = array (); $table->head = array (); $table->head[0] = __('Status'); $table->head[1] = __('Event name'); $table->head[2] = __('User ID'); $table->head[3] = __('Timestamp'); $events = events_get_group_events ($id_group, $period, $date); if (empty ($events)) { $events = array (); } foreach ($events as $event) { $data = array (); if ($event["estado"] == 0) $data[0] = html_print_image("images/dot_red.png", true); else $data[0] = html_print_image("images/dot_green.png", true); $data[1] = $event['evento']; $data[2] = $event['id_usuario'] != '0' ? $event['id_usuario'] : ''; $data[3] = $event["timestamp"]; array_push ($table->data, $data); } if (empty ($return)) html_print_table ($table); return $table; } /** * Get a table report from a alerts fired array. * * @param array Alerts fired array. * @see function get_alerts_fired () * * @return object A table object with a report of the fired alerts. */ function reporting_get_fired_alerts_table ($alerts_fired) { $agents = array (); global $config; require_once ($config["homedir"].'/include/functions_alerts.php'); foreach (array_keys ($alerts_fired) as $id_alert) { $alert_module = alerts_get_alert_agent_module ($id_alert); $template = alerts_get_alert_template ($id_alert); /* Add alerts fired to $agents_fired_alerts indexed by id_agent */ $id_agent = db_get_value ('id_agente', 'tagente_modulo', 'id_agente_modulo', $alert_module['id_agent_module']); if (!isset ($agents[$id_agent])) { $agents[$id_agent] = array (); } array_push ($agents[$id_agent], array ($alert_module, $template)); } $table->data = array (); $table->head = array (); $table->head[0] = __('Agent'); $table->head[1] = __('Alert description'); $table->head[2] = __('Times fired'); $table->head[3] = __('Priority'); foreach ($agents as $id_agent => $alerts) { $data = array (); foreach ($alerts as $tuple) { $alert_module = $tuple[0]; $template = $tuple[1]; if (! isset ($data[0])) $data[0] = agents_get_name ($id_agent); else $data[0] = ''; $data[1] = $template['name']; $data[2] = $alerts_fired[$alert_module['id']]; $data[3] = get_alert_priority ($alert_module['priority']); array_push ($table->data, $data); } } return $table; } /** * Get a report for alerts in a group of agents. * * It prints the numbers of alerts defined, fired and not fired in a group. * It also prints all the alerts that were fired grouped by agents. * * @param int $id_group Group to get info of the alerts. * @param int $period Period of time of the desired alert report. * @param int $date Beggining date of the report (current date by default). * @param bool $return Flag to return or echo the report (echo by default). * * @return string */ function reporting_alert_reporting ($id_group, $period = 0, $date = 0, $return = false) { global $config; $output = ''; $alerts = get_group_alerts ($id_group); $alerts_fired = get_alerts_fired ($alerts, $period, $date); $fired_percentage = 0; if (sizeof ($alerts) > 0) $fired_percentage = round (sizeof ($alerts_fired) / sizeof ($alerts) * 100, 2); $not_fired_percentage = 100 - $fired_percentage; $data = array (); $data[__('Alerts fired')] = $fired_percentage; $data[__('Alerts not fired')] = $not_fired_percentage; $output .= pie3d_graph(false, $data, 280, 150, __("other"), ui_get_full_url(false, false, false, false) . '/', ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", $config['fontpath'], $config['font_size']); $output .= ''.__('Alerts fired').': '.sizeof ($alerts_fired).'
'; $output .= ''.__('Total alerts monitored').': '.sizeof ($alerts).'
'; if (! sizeof ($alerts_fired)) { if (!$return) echo $output; return $output; } $table = reporting_get_fired_alerts_table ($alerts_fired); $table->width = '100%'; $table->class = 'databox'; $table->size = array (); $table->size[0] = '100px'; $table->style = array (); $table->style[0] = 'font-weight: bold'; $output .= html_print_table ($table, true); if (!$return) echo $output; return $output; } /** * Get a report for monitors modules in a group of agents. * * It prints the numbers of monitors defined, showing those which went up and down, in a group. * It also prints all the down monitors in the group. * * @param int $id_group Group to get info of the monitors. * @param int $period Period of time of the desired monitor report. * @param int $date Beginning date of the report in UNIX time (current date by default). * @param bool $return Flag to return or echo the report (by default). * * @return string */ function reporting_monitor_health ($id_group, $period = 0, $date = 0, $return = false) { if (empty ($date)) //If date is 0, false or empty $date = get_system_time (); $datelimit = $date - $period; $output = ''; $monitors = modules_get_monitors_in_group ($id_group); if (empty ($monitors)) //If monitors has returned false or an empty array return; $monitors_down = modules_get_monitors_down ($monitors, $period, $date); $down_percentage = round (count ($monitors_down) / count ($monitors) * 100, 2); $not_down_percentage = 100 - $down_percentage; $output .= ''.__('Total monitors').': '.count ($monitors).'
'; $output .= ''.__('Monitors down on period').': '.count ($monitors_down).'
'; $table = reporting_get_monitors_down_table ($monitors_down); $table->width = '100%'; $table->class = 'databox'; $table->size = array (); $table->size[0] = '100px'; $table->style = array (); $table->style[0] = 'font-weight: bold'; $table->size = array (); $table->size[0] = '100px'; $output .= html_print_table ($table, true); $data = array(); $data[__('Monitors OK')] = $down_percentage; $data[__('Monitors BAD')] = $not_down_percentage; $output .= pie3d_graph(false, $data, 280, 150, __("other"), ui_get_full_url(false, false, false, false) . '/', ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", $config['fontpath'], $config['font_size']); if (!$return) echo $output; return $output; } /** * Get a report table with all the monitors down. * * @param array An array with all the monitors down * @see function modules_get_monitors_down() * * @return object A table object with a monitors down report. */ function reporting_get_monitors_down_table ($monitors_down) { $table->data = array (); $table->head = array (); $table->head[0] = __('Agent'); $table->head[1] = __('Monitor'); $agents = array (); if ($monitors_down) { foreach ($monitors_down as $monitor) { /* Add monitors fired to $agents_fired_alerts indexed by id_agent */ $id_agent = $monitor['id_agente']; if (!isset ($agents[$id_agent])) { $agents[$id_agent] = array (); } array_push ($agents[$id_agent], $monitor); $monitors_down++; } foreach ($agents as $id_agent => $monitors) { $data = array (); foreach ($monitors as $monitor) { if (! isset ($data[0])) $data[0] = agents_get_name ($id_agent); else $data[0] = ''; if ($monitor['descripcion'] != '') { $data[1] = $monitor['descripcion']; } else { $data[1] = $monitor['nombre']; } array_push ($table->data, $data); } } } return $table; } /** * Get a general report of a group of agents. * * It shows the number of agents and no more things right now. * * @param int Group to get the report * @param bool Flag to return or echo the report (by default). * * @return HTML string with group report */ function reporting_print_group_reporting ($id_group, $return = false) { $agents = agents_get_group_agents ($id_group, false, "none"); $output = '' . sprintf(__('Agents in group: %s'), count($agents)) . '
'; if ($return === false) echo $output; return $output; } /** * Get a report table of the fired alerts group by agents. * * @param int Agent id to generate the report. * @param int Period of time of the report. * @param int Beginning date of the report in UNIX time (current date by default). * * @return object A table object with the alert reporting.. */ function reporting_get_agent_alerts_table ($id_agent, $period = 0, $date = 0) { global $config; $table->data = array (); $table->head = array (); $table->head[0] = __('Type'); $table->head[1] = __('Description'); $table->head[2] = __('Value'); $table->head[3] = __('Threshold'); $table->head[4] = __('Last fired'); $table->head[5] = __('Times fired'); require_once ($config["homedir"].'/include/functions_alerts.php'); $alerts = agents_get_alerts ($id_agent); foreach ($alerts['simple'] as $alert) { $fires = get_alert_fires_in_period ($alert['id'], $period, $date); if (! $fires) { continue; } $template = alerts_get_alert_template ($alert['id_alert_template']); $data = array (); $data[0] = alerts_get_alert_templates_type_name ($template['type']); $data[1] = $template['name']; switch ($template['type']) { case 'regex': if ($template['matches_value']) $data[2] = '≃ "'.$template['value'].'"'; else $data[2] = '≄ "'.$template['value'].'"'; break; case 'equal': case 'not_equal': $data[2] = $template['value']; break; case 'max-min': $data[2] = __('Min.').': '.$template['min_value']. ' '; $data[2] .= __('Max.').': '.$template['max_value']. ' '; break; case 'max': $data[2] = $template['max_value']; break; case 'min': $data[2] = $template['min_value']; break; } $data[3] = $template['time_threshold']; $data[4] = ui_print_timestamp (get_alert_last_fire_timestamp_in_period ($alert['id'], $period, $date), true); $data[5] = $fires; array_push ($table->data, $data); } return $table; } /** * Get a report of monitors in an agent. * * @param int Agent id to get the report * @param int Period of time of the report. * @param int Beginning date of the report in UNIX time (current date by default). * * @return object A table object with the report. */ function reporting_get_agent_monitors_table ($id_agent, $period = 0, $date = 0) { $n_a_string = __('N/A').'(*)'; $table->head = array (); $table->head[0] = __('Monitor'); $table->head[1] = __('Last failure'); $table->data = array (); $monitors = modules_get_monitors_in_agent ($id_agent); if ($monitors === false) { return $table; } foreach ($monitors as $monitor) { $downs = modules_get_monitor_downs_in_period ($monitor['id_agente_modulo'], $period, $date); if (! $downs) { continue; } $data = array (); if ($monitor['descripcion'] != $n_a_string && $monitor['descripcion'] != '') $data[0] = $monitor['descripcion']; else $data[0] = $monitor['nombre']; $data[1] = modules_get_last_down_timestamp_in_period ($monitor['id_agente_modulo'], $period, $date); array_push ($table->data, $data); } return $table; } /** * Get a report of all the modules in an agent. * * @param int Agent id to get the report. * @param int Period of time of the report * @param int Beginning date of the report in UNIX time (current date by default). * * @return object */ function reporting_get_agent_modules_table ($id_agent, $period = 0, $date = 0) { $table->data = array (); $n_a_string = __('N/A').'(*)'; $modules = agents_get_modules ($id_agent, array ("nombre", "descripcion")); if ($modules === false) $modules = array(); $data = array (); foreach ($modules as $module) { if ($module['descripcion'] != $n_a_string && $module['descripcion'] != '') $data[0] = $module['descripcion']; else $data[0] = $module['nombre']; array_push ($table->data, $data); } return $table; } /** * Get a detailed report of an agent * * @param int Agent to get the report. * @param int Period of time of the desired report. * @param int Beginning date of the report in UNIX time (current date by default). * @param bool Flag to return or echo the report (by default). * * @return string */ function reporting_get_agent_detailed ($id_agent, $period = 0, $date = 0, $return = false) { $output = ''; $n_a_string = __('N/A(*)'); /* Show modules in agent */ $output .= '
'; $output .= '

' . __('Agent') . ' - ' . agents_get_name ($id_agent) . '

'; $output .= '

'.__('Modules').'

'; $table_modules = reporting_get_agent_modules_table ($id_agent, $period, $date); $table_modules->width = '99%'; $output .= html_print_table ($table_modules, true); /* Show alerts in agent */ $table_alerts = reporting_get_agent_alerts_table ($id_agent, $period, $date); $table_alerts->width = '99%'; if (sizeof ($table_alerts->data)) { $output .= '

'.__('Alerts').'

'; $output .= html_print_table ($table_alerts, true); } /* Show monitor status in agent (if any) */ $table_monitors = reporting_get_agent_monitors_table ($id_agent, $period, $date); if (sizeof ($table_monitors->data) == 0) { $output .= '
'; if (! $return) echo $output; return $output; } $table_monitors->width = '99%'; $table_monitors->align = array (); $table_monitors->align[1] = 'right'; $table_monitors->size = array (); $table_monitors->align[1] = '10%'; $output .= '

'.__('Monitors').'

'; $output .= html_print_table ($table_monitors, true); $output .= ''; if (! $return) echo $output; return $output; } /** * Get a detailed report of agents in a group. * * @param mixed Group(s) to get the report * @param int Period * @param int Timestamp to start from * @param bool Flag to return or echo the report (by default). * * @return string */ function reporting_agents_get_group_agents_detailed ($id_group, $period = 0, $date = 0, $return = false) { $agents = agents_get_group_agents ($id_group, false, "none"); $output = ''; foreach ($agents as $agent_id => $agent_name) { $output .= reporting_get_agent_detailed ($agent_id, $period, $date, true); } if ($return === false) echo $output; return $output; } /** * This is the callback sorting function for SLA values descending * * @param array $a Array element 1 to compare * @param array $b Array element 2 to compare * */ function sla_value_desc_cmp($a, $b) { // This makes 'Unknown' values the lastest if (preg_match('/^(.)*Unknown(.)*$/', $a[5])) $a[6] = -1; if (preg_match('/^(.)*Unknown(.)*$/', $b[5])) $b[6] = -1; return ($a[6] < $b[6])? 1 : 0; } /** * This is the callback sorting function for SLA values ascending * * @param array $a Array element 1 to compare * @param array $b Array element 2 to compare * */ function sla_value_asc_cmp($a, $b) { // This makes 'Unknown' values the lastest if (preg_match('/^(.)*Unknown(.)*$/', $a[5])) $a[6] = -1; if (preg_match('/^(.)*Unknown(.)*$/', $b[5])) $b[6] = -1; return ($a[6] > $b[6])? 1 : 0; } /** * Make the header for each content. */ function reporting_header_content($mini, $content, $report, &$table, $title = false, $name = false, $period = false) { global $config; if ($mini) { $sizh = ''; $sizhfin = ''; } else { $sizh = '

'; $sizhfin = '

'; } $data = array(); $count_empty = 0; if ($title !== false) { $data[] = $sizh . $title . $sizhfin; } else $count_empty++; if ($name !== false) { $data[] = $sizh . $name . $sizhfin; } else $count_empty++; if ($period !== false && $content['period'] > 0) { $data[] = $sizh . $period . $sizhfin; } else if ($content['period'] == 0) { $es = json_decode($content['external_source'], true); if ($es['date'] == 0) { $date = __('Last data'); } else { $date = date($config["date_format"], $es['date']); } $data[] = "
" . $sizh . $date . $sizhfin . "
"; } else { $data[] = "
" . $sizh . "(" . human_time_description_raw ($content['period']) . ") " . __("From:") . " " . date($config["date_format"], $report["datetime"] - $content['period']) . "
" . __("To:") . " " . date($config["date_format"], $report["datetime"]) . "
" . $sizhfin . "
"; } $table->colspan[0][2 - $count_empty] = 1 + $count_empty; array_push ($table->data, $data); } /** * Get all the template graphs a user can see. * * @param $id_user User id to check. * @param $only_names Wheter to return only graphs names in an associative array * or all the values. * @param $returnAllGroup Wheter to return graphs of group All or not. * @param $privileges Privileges to check in user group * * @return template graphs of a an user. Empty array if none. */ function reporting_template_graphs_get_user ($id_user = 0, $only_names = false, $returnAllGroup = true, $privileges = 'RR') { global $config; if (!$id_user) { $id_user = $config['id_user']; } $groups = users_get_groups ($id_user, $privileges, $returnAllGroup); $all_templates = db_get_all_rows_in_table ('tgraph_template', 'name'); if ($all_templates === false) return array (); $templates = array (); foreach ($all_templates as $template) { if (!in_array($template['id_group'], array_keys($groups))) continue; if ($template["id_user"] != $id_user && $template['private']) continue; if ($template["id_group"] > 0) if (!isset($groups[$template["id_group"]])){ continue; } if ($only_names) { $templates[$template['id_graph_template']] = $template['name']; } else { $templates[$template['id_graph_template']] = $template; $templatesCount = db_get_value_sql("SELECT COUNT(id_gs_template) FROM tgraph_source_template WHERE id_template = " . $template['id_graph_template']); $templates[$template['id_graph_template']]['graphs_template_count'] = $templatesCount; } } return $templates; } function reporting_get_agents_by_status ($data, $graph_width = 250, $graph_height = 150, $links = false) { global $config; if ($links == false) { $links = array(); } $table_agent = html_get_predefined_table(); $agent_data = array(); $agent_data[0] = html_print_image('images/agent_critical.png', true, array('title' => __('Agents critical'))); $agent_data[1] = "".format_numeric($data['agent_critical']).""; $agent_data[2] = html_print_image('images/agent_warning.png', true, array('title' => __('Agents warning'))); $agent_data[3] = "".format_numeric($data['agent_warning']).""; $table_agent->data[] = $agent_data; $agent_data = array(); $agent_data[0] = html_print_image('images/agent_ok.png', true, array('title' => __('Agents ok'))); $agent_data[1] = "".format_numeric($data['agent_ok']).""; $agent_data[2] = html_print_image('images/agent_unknown.png', true, array('title' => __('Agents unknown'))); $agent_data[3] = "".format_numeric($data['agent_unknown']).""; $table_agent->data[] = $agent_data; $agent_data = array(); $agent_data[0] = html_print_image('images/agent_notinit.png', true, array('title' => __('Agents not init'))); $agent_data[1] = "".format_numeric($data['agent_not_init']).""; $agent_data[2] = ""; $agent_data[3] = ""; $table_agent->data[] = $agent_data; if (!defined('METACONSOLE')) { $agents_data = '
' . __('Agents by status') . '' . html_print_table($table_agent, true) . '
'; } else{ $table_agent->style=array(); $table_agent->class = "tactical_view"; $agents_data = '
' . __('Agents by status') . '' . html_print_table($table_agent, true) . '
'; } return $agents_data; } function reporting_get_total_agents_and_monitors ($data, $graph_width = 250, $graph_height = 150) { global $config; $total_agent = $data['agent_ok'] + $data['agent_warning'] + $data['agent_critical'] + $data['gent_unknown'] + $data['agent_not_init']; $total_module = $data['monitor_ok'] + $data['monitor_warning'] + $data['monitor_critical'] + $data['monitor_unknown'] + $data['monitor_not_init']; $table_total = html_get_predefined_table(); $total_data = array(); $total_data[0] = html_print_image('images/agent.png', true, array('title' => __('Total agents'))); $total_data[1] = $total_agent <= 0 ? '-' : $total_agent; $total_data[2] = html_print_image('images/module.png', true, array('title' => __('Monitor checks'))); $total_data[3] = $total_module <= 0 ? '-' : $total_module; $table_total->data[] = $total_data; $total_agent_module = '
' . __('Total agents and monitors') . '' . html_print_table($table_total, true) . '
'; return $total_agent_module; } function reporting_get_total_servers ($num_servers) { global $config; $table_node = html_get_predefined_table(); $node_data = array(); $node_data[0] = html_print_image('images/server_export.png', true, array('title' => __('Nodes'))); $node_data[1] = "".format_numeric($num_servers).""; $table_node->data[] = $node_data; if (!defined('METACONSOLE')){ $node_overview = '
' . __('Node overview') . '' . html_print_table($table_node, true) . '
'; }else{ $table_node->style = array(); $table_node->class = "tactical_view"; $node_overview = '
' . __('Node overview') . '' . html_print_table($table_node, true) . '
'; } return $node_overview; } function reporting_get_events ($data, $links = false) { global $config; $table_events->width = "100%"; if (defined('METACONSOLE')) $style = " vertical-align:middle;"; else $style = ""; if (defined('METACONSOLE')){ $table_events->style[0] = "background-color:#FC4444"; $table_events->data[0][0] = html_print_image('images/module_event_critical.png', true, array('title' => __('Critical events'))); $table_events->data[0][0] .= "   " . "" . format_numeric($data['critical']).""; $table_events->style[1] = "background-color:#FAD403"; $table_events->data[0][1] = html_print_image('images/module_event_warning.png', true, array('title' => __('Warning events'))); $table_events->data[0][1] .= "   " . "" . format_numeric($data['warning']).""; $table_events->style[2] = "background-color:#80BA27"; $table_events->data[0][2] = html_print_image('images/module_event_ok.png', true, array('title' => __('OK events'))); $table_events->data[0][2] .= "   " . "" . format_numeric($data['normal']).""; $table_events->style[3] = "background-color:#B2B2B2"; $table_events->data[0][3] = html_print_image('images/module_event_unknown.png', true, array('title' => __('Unknown events'))); $table_events->data[0][3] .= "   " . "" . format_numeric($data['unknown']).""; } else{ $table_events->data[0][0] = html_print_image('images/module_critical.png', true, array('title' => __('Critical events'))); $table_events->data[0][0] .= "   " . "". format_numeric($data['critical']).""; $table_events->data[0][1] = html_print_image('images/module_warning.png', true, array('title' => __('Warning events'))); $table_events->data[0][1] .= "   " . "". format_numeric($data['warning']).""; $table_events->data[0][2] = html_print_image('images/module_ok.png', true, array('title' => __('OK events'))); $table_events->data[0][2] .= "   " . "". format_numeric($data['normal']).""; $table_events->data[0][3] = html_print_image('images/module_unknown.png', true, array('title' => __('Unknown events'))); $table_events->data[0][3] .= "   " . "". format_numeric($data['unknown']).""; } if (!defined('METACONSOLE')) { $event_view = '
' . __('Events by criticity') . '' . html_print_table($table_events, true) . '
'; } else{ $table_events->class="tactical_view"; $table_events->styleTable="text-align:center;"; $table_events->size[0]="10%"; $table_events->size[1]="10%"; $table_events->size[2]="10%"; $table_events->size[3]="10%"; $event_view = '
' . __('Important Events by Criticity') . '' . html_print_table($table_events, true) . '
'; } return $event_view; } function reporting_get_last_activity() { global $config; // Show last activity from this user $table->width = '100%'; $table->data = array (); $table->size = array (); $table->size[2] = '150px'; $table->size[3] = '130px'; $table->size[5] = '200px'; $table->head = array (); $table->head[0] = __('User'); $table->head[1] = ''; $table->head[2] = __('Action'); $table->head[3] = __('Date'); $table->head[4] = __('Source IP'); $table->head[5] = __('Comments'); $table->title = '' . __('Last activity in Pandora FMS console') . ''; switch ($config["dbtype"]) { case "mysql": $sql = sprintf ("SELECT id_usuario,accion,fecha,ip_origen,descripcion,utimestamp FROM tsesion WHERE (`utimestamp` > UNIX_TIMESTAMP(NOW()) - " . SECONDS_1WEEK . ") AND `id_usuario` = '%s' ORDER BY `utimestamp` DESC LIMIT 5", $config["id_user"]); break; case "postgresql": $sql = sprintf ("SELECT \"id_usuario\", accion, fecha, \"ip_origen\", descripcion, utimestamp FROM tsesion WHERE (\"utimestamp\" > ceil(date_part('epoch', CURRENT_TIMESTAMP)) - " . SECONDS_1WEEK . ") AND \"id_usuario\" = '%s' ORDER BY \"utimestamp\" DESC LIMIT 5", $config["id_user"]); break; case "oracle": $sql = sprintf ("SELECT id_usuario, accion, fecha, ip_origen, descripcion, utimestamp FROM tsesion WHERE ((utimestamp > ceil((sysdate - to_date('19700101000000','YYYYMMDDHH24MISS')) * (" . SECONDS_1DAY . ")) - " . SECONDS_1WEEK . ") AND id_usuario = '%s') AND rownum <= 10 ORDER BY utimestamp DESC", $config["id_user"]); break; } $sessions = db_get_all_rows_sql ($sql); if ($sessions === false) $sessions = array (); foreach ($sessions as $session) { $data = array (); switch ($config["dbtype"]) { case "mysql": case "oracle": $session_id_usuario = $session['id_usuario']; $session_ip_origen = $session['ip_origen']; break; case "postgresql": $session_id_usuario = $session['id_usuario']; $session_ip_origen = $session['ip_origen']; break; } $data[0] = '' . $session_id_usuario . ''; $data[1] = ui_print_session_action_icon ($session['accion'], true); $data[2] = $session['accion']; $data[3] = ui_print_help_tip($session['fecha'], true) . human_time_comparation($session['utimestamp'], 'tiny'); $data[4] = $session_ip_origen; $data[5] = io_safe_output ($session['descripcion']); array_push ($table->data, $data); } if(defined("METACONSOLE")) $table->class="databox_tactical"; return html_print_table ($table, true); } function reporting_get_event_histogram ($events) { global $config; include_once ('../../include/graphs/functions_gd.php'); $max_value = count($events); if (defined("METACONSOLE")) $max_value = SECONDS_1HOUR; $ttl = 1; $urlImage = ui_get_full_url(false, true, false, false); $colors = array( EVENT_CRIT_MAINTENANCE => COL_MAINTENANCE, EVENT_CRIT_INFORMATIONAL => COL_INFORMATIONAL, EVENT_CRIT_NORMAL => COL_MINOR, EVENT_CRIT_MINOR => COL_NORMAL, EVENT_CRIT_WARNING => COL_WARNING, EVENT_CRIT_MAJOR => COL_MAJOR, EVENT_CRIT_CRITICAL => COL_CRITICAL ); if (defined("METACONSOLE")) { $full_legend = array(); $cont = 0; } foreach ($events as $data) { switch ($data['criticity']) { case 0: $color = EVENT_CRIT_MAINTENANCE; break; case 1: $color = EVENT_CRIT_INFORMATIONAL; break; case 2: $color = EVENT_CRIT_NORMAL; break; case 3: $color = EVENT_CRIT_WARNING; break; case 4: $color = EVENT_CRIT_CRITICAL; break; case 5: $color = EVENT_CRIT_MINOR; break; case 6: $color = EVENT_CRIT_MAJOR; break; case 20: $color = EVENT_CRIT_NOT_NORMAL; break; case 34: $color = EVENT_CRIT_WARNING_OR_CRITICAL; break; } if (defined("METACONSOLE")) { $full_legend[$cont] = $data['timestamp']; $graph_data[] = array( 'data' => $color, 'utimestamp' => $data['utimestamp'] - get_system_time () ); $cont++; } else { $graph_data[] = array( 'data' => $color, 'utimestamp' => 1 ); } } $table->width = '100%'; $table->data = array (); $table->size = array (); $table->head = array (); $table->title = '' . __('Events info (1hr.)') . ''; $table->data[0][0] = "" ; if (!empty($graph_data)) { if (defined("METACONSOLE")) $slicebar = flot_slicesbar_graph($graph_data, $max_value, "100%", 35, $full_legend, $colors, $config['fontpath'], $config['round_corner'], $url); else $slicebar = slicesbar_graph($graph_data, $max_value, 700, 25, $colors, $config['fontpath'], $config['round_corner'], $urlImage, $ttl); $table->data[0][0] = $slicebar; } else { $table->data[0][0] = __('No events'); } if (!defined('METACONSOLE')) { $event_graph = '
' . __('Events info (1hr)') . '' . html_print_table($table, true) . '
'; } else{ $table->class='tactical_view'; $event_graph = '
' . html_print_table($table, true) . '
'; } return $event_graph; } ?>