';
$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[] = "
'; 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); } } function reporting_html_custom_graph(&$table, $item) { $table->colspan['chart']['cell'] = 3; $table->cellstyle['chart']['cell'] = 'text-align: center;'; $table->data['chart']['cell'] = $item['chart']; } function reporting_html_simple_graph(&$table, $item) { $table->colspan['chart']['cell'] = 3; $table->cellstyle['chart']['cell'] = 'text-align: center;'; $table->data['chart']['cell'] = $item['chart']; } /** * 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 ($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 time intervals where an agentmodule is affected by the planned downtimes. * * @param int Agent module to calculate planned downtimes intervals. * @param int Start date in utimestamp. * @param int End date in utimestamp. * @param bool Whether ot not to get the planned downtimes that affect the service associated with the agentmodule. * * @return Array with time intervals. */ function reporting_get_planned_downtimes_intervals ($id_agent_module, $start_date, $end_date, $check_services = false) { global $config; if (empty($id_agent_module)) return false; require_once ($config['homedir'] . '/include/functions_planned_downtimes.php'); $malformed_planned_downtimes = planned_downtimes_get_malformed(); if (empty($malformed_planned_downtimes)) $malformed_planned_downtimes = array(); $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 = $id_agent_module UNION ALL SELECT tpd.* FROM tplanned_downtime tpd, tplanned_downtime_modules tpdm WHERE tpd.id = tpdm.id_downtime AND tpdm.id_agent_module = $id_agent_module ) tpdr ORDER BY tpdr.id"; $downtimes = db_get_all_rows_sql($sql_downtime); if ($downtimes == false) { $downtimes = array(); } $downtime_dates = array(); foreach ($downtimes as $downtime) { $downtime_id = $downtime['id']; $downtime_type = $downtime['type_execution']; $downtime_periodicity = $downtime['type_periodicity']; if ($downtime_type == 'once') { $dates = array(); $dates['date_from'] = $downtime['date_from']; $dates['date_to'] = $downtime['date_to']; $downtime_dates[] = $dates; } else if ($downtime_type == 'periodically') { // If a planned downtime have malformed dates, its intervals aren't taken account $downtime_malformed = false; foreach ($malformed_planned_downtimes as $malformed_planned_downtime) { if ($downtime_id == $malformed_planned_downtime['id']) { $downtime_malformed = true; break; } } if ($downtime_malformed == true) { continue; } // If a planned downtime have malformed dates, its intervals aren't taken account $downtime_time_from = $downtime['periodically_time_from']; $downtime_time_to = $downtime['periodically_time_to']; $downtime_hour_from = date("H", strtotime($downtime_time_from)); $downtime_minute_from = date("i", strtotime($downtime_time_from)); $downtime_second_from = date("s", strtotime($downtime_time_from)); $downtime_hour_to = date("H", strtotime($downtime_time_to)); $downtime_minute_to = date("i", strtotime($downtime_time_to)); $downtime_second_to = date("s", strtotime($downtime_time_to)); if ($downtime_periodicity == "monthly") { $downtime_day_from = $downtime['periodically_day_from']; $downtime_day_to = $downtime['periodically_day_to']; $date_aux = strtotime(date("Y-m-01", $start_date)); $year_aux = date("Y", $date_aux); $month_aux = date("m", $date_aux); $end_year = date("Y", $end_date); $end_month = date("m", $end_date); while ($year_aux < $end_year || ($year_aux == $end_year && $month_aux <= $end_month)) { if ($downtime_day_from > $downtime_day_to) { $dates = array(); $dates['date_from'] = strtotime("$year_aux-$month_aux-$downtime_day_from $downtime_hour_from:$downtime_minute_from:$downtime_second_from"); $dates['date_to'] = strtotime(date("Y-m-t H:i:s", strtotime("$year_aux-$month_aux-28 23:59:59"))); $downtime_dates[] = $dates; $dates = array(); if ($month_aux + 1 <= 12) { $dates['date_from'] = strtotime("$year_aux-".($month_aux + 1)."-01 00:00:00"); $dates['date_to'] = strtotime("$year_aux-".($month_aux + 1)."-$downtime_day_to $downtime_hour_to:$downtime_minute_to:$downtime_second_to"); } else { $dates['date_from'] = strtotime(($year_aux + 1)."-01-01 00:00:00"); $dates['date_to'] = strtotime(($year_aux + 1)."-01-$downtime_day_to $downtime_hour_to:$downtime_minute_to:$downtime_second_to"); } $downtime_dates[] = $dates; } else { if ($downtime_day_from == $downtime_day_to && strtotime($downtime_time_from) > strtotime($downtime_time_to)) { $date_aux_from = strtotime("$year_aux-$month_aux-$downtime_day_from $downtime_hour_from:$downtime_minute_from:$downtime_second_from"); $max_day_num = date('t', $date_aux); $dates = array(); $dates['date_from'] = strtotime("$year_aux-$month_aux-$downtime_day_from $downtime_hour_from:$downtime_minute_from:$downtime_second_from"); $dates['date_to'] = strtotime("$year_aux-$month_aux-$downtime_day_from 23:59:59"); $downtime_dates[] = $dates; if ($downtime_day_to + 1 > $max_day_num) { $dates = array(); if ($month_aux + 1 <= 12) { $dates['date_from'] = strtotime("$year_aux-".($month_aux + 1)."-01 00:00:00"); $dates['date_to'] = strtotime("$year_aux-".($month_aux + 1)."-01 $downtime_hour_to:$downtime_minute_to:$downtime_second_to"); } else { $dates['date_from'] = strtotime(($year_aux + 1)."-01-01 00:00:00"); $dates['date_to'] = strtotime(($year_aux + 1)."-01-01 $downtime_hour_to:$downtime_minute_to:$downtime_second_to"); } $downtime_dates[] = $dates; } else { $dates = array(); $dates['date_from'] = strtotime("$year_aux-$month_aux-".($downtime_day_to + 1)." 00:00:00"); $dates['date_to'] = strtotime("$year_aux-$month_aux-".($downtime_day_to + 1)." $downtime_hour_to:$downtime_minute_to:$downtime_second_to"); $downtime_dates[] = $dates; } } else { $dates = array(); $dates['date_from'] = strtotime("$year_aux-$month_aux-$downtime_day_from $downtime_hour_from:$downtime_minute_from:$downtime_second_from"); $dates['date_to'] = strtotime("$year_aux-$month_aux-$downtime_day_to $downtime_hour_to:$downtime_minute_to:$downtime_second_to"); $downtime_dates[] = $dates; } } $month_aux++; if ($month_aux > 12) { $month_aux = 1; $year_aux++; } } } else if ($downtime_periodicity == "weekly") { $date_aux = $start_date; $active_days = array(); $active_days[0] = ($downtime['sunday'] == 1) ? true : false; $active_days[1] = ($downtime['monday'] == 1) ? true : false; $active_days[2] = ($downtime['tuesday'] == 1) ? true : false; $active_days[3] = ($downtime['wednesday'] == 1) ? true : false; $active_days[4] = ($downtime['thursday'] == 1) ? true : false; $active_days[5] = ($downtime['friday'] == 1) ? true : false; $active_days[6] = ($downtime['saturday'] == 1) ? true : false; while ($date_aux <= $end_date) { $weekday_num = date('w', $date_aux); if ($active_days[$weekday_num]) { $day_num = date('d', $date_aux); $month_num = date('m', $date_aux); $year_num = date('Y', $date_aux); $max_day_num = date('t', $date_aux); if (strtotime($downtime_time_from) > strtotime($downtime_time_to)) { $dates = array(); $dates['date_from'] = strtotime("$year_num-$month_num-$day_num $downtime_hour_from:$downtime_minute_from:$downtime_second_from"); $dates['date_to'] = strtotime("$year_num-$month_num-$day_num 23:59:59"); $downtime_dates[] = $dates; $dates = array(); if ($day_num + 1 > $max_day_num) { if ($month_num + 1 > 12) { $dates['date_from'] = strtotime(($year_num + 1)."-01-01 00:00:00"); $dates['date_to'] = strtotime(($year_num + 1)."-01-01 $downtime_hour_to:$downtime_minute_to:$downtime_second_to"); } else { $dates['date_from'] = strtotime("$year_num-".($month_num + 1)."-01 00:00:00"); $dates['date_to'] = strtotime("$year_num-".($month_num + 1)."-01 $downtime_hour_to:$downtime_minute_to:$downtime_second_to"); } } else { $dates['date_from'] = strtotime("$year_num-$month_num-".($day_num + 1)." 00:00:00"); $dates['date_to'] = strtotime("$year_num-$month_num-".($day_num + 1)." $downtime_hour_to:$downtime_minute_to:$downtime_second_to"); } $downtime_dates[] = $dates; } else { $dates = array(); $dates['date_from'] = strtotime("$year_num-$month_num-$day_num $downtime_hour_from:$downtime_minute_from:$downtime_second_from"); $dates['date_to'] = strtotime("$year_num-$month_num-$day_num $downtime_hour_to:$downtime_minute_to:$downtime_second_to"); $downtime_dates[] = $dates; } } $date_aux += SECONDS_1DAY; } } } } if ($check_services) { enterprise_include_once("include/functions_services.php"); if (function_exists("services_get_planned_downtimes_intervals")) { services_get_planned_downtimes_intervals($downtime_dates, $start_date, $end_date, false, $id_agent_module); } } return $downtime_dates; } /** * 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] = ''; $data[0] .= html_print_image("images/module_ok.png", true) . ' ' . __('OK') . ': ' . $monitor_value.' %
'; if ($monitor_value !== __('Unknown')) { $monitor_value = format_numeric (100 - $monitor_value, 2) ; } $data[1] = ''; $data[1] .= html_print_image("images/module_critical.png", true) . ' ' .__('Not OK') . ': ' .$monitor_value.' % ' . '
'; array_push ($table->data, $data); break; case 'agent_detailed_event': case 'event_report_agent': if (empty($item_title)) { $item_title = __('Agent detailed event'); } reporting_header_content($mini, $content, $report, $table, $item_title, ui_print_truncate_text(agents_get_name($content['id_agent']), 'agent_medium', false)); $style = json_decode(io_safe_output($content['style']), true); $filter_event_no_validated = $style['filter_event_no_validated']; $filter_event_validated = $style['filter_event_validated']; $filter_event_critical = $style['filter_event_critical']; $filter_event_warning = $style['filter_event_warning']; $event_graph_by_agent = $style['event_graph_by_agent']; $event_graph_by_user_validator = $style['event_graph_by_user_validator']; $event_graph_by_criticity = $style['event_graph_by_criticity']; $event_graph_validated_vs_unvalidated = $style['event_graph_validated_vs_unvalidated']; $next_row = 1; // Put description at the end of the module (if exists) if ($content["description"] != "") { $data_desc = array(); $data_desc[0] = $content["description"]; array_push ($table->data, $data_desc); $table->colspan[$next_row][0] = 3; $next_row++; } $data = array (); $table->colspan[$next_row][0] = 3; $next_row++; $data[0] = reporting_get_agents_detailed_event( $content['id_agent'], $content['period'], $report["datetime"], true, $filter_event_validated, $filter_event_critical, $filter_event_warning, $filter_event_no_validated); if(!empty($data[0])) { array_push ($table->data, $data); $table->colspan[$next_row][0] = 3; $next_row++; } if ($event_graph_by_user_validator) { $data_graph = reporting_get_count_events_validated_by_user( array('id_agent' => $content['id_agent']), $content['period'], $report["datetime"], $filter_event_validated, $filter_event_critical, $filter_event_warning, $filter_event_no_validated); $table_event_graph = null; $table_event_graph->width = '100%'; $table_event_graph->style[0] = 'text-align: center;'; $table_event_graph->head[0] = __('Events validated by user'); $table_event_graph->data[0][0] = pie3d_graph( false, $data_graph, 500, 150, __("other"), "", ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", $config['fontpath'], $config['font_size']); $data[0] = html_print_table($table_event_graph, true); $table->colspan[$next_row][0] = 3; $next_row++; array_push ($table->data, $data); } if ($event_graph_by_criticity) { $data_graph = reporting_get_count_events_by_criticity( array('id_agent' => $content['id_agent']), $content['period'], $report["datetime"], $filter_event_validated, $filter_event_critical, $filter_event_warning, $filter_event_no_validated); $colors = get_criticity_pie_colors($data_graph); $table_event_graph = null; $table_event_graph->width = '100%'; $table_event_graph->style[0] = 'text-align: center;'; $table_event_graph->head[0] = __('Events by criticity'); $table_event_graph->data[0][0] = pie3d_graph( false, $data_graph, 500, 150, __("other"), "", ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", $config['fontpath'], $config['font_size'], 1, false, $colors); $data[0] = html_print_table($table_event_graph, true); $table->colspan[$next_row][0] = 3; $next_row++; array_push ($table->data, $data); } if ($event_graph_validated_vs_unvalidated) { $data_graph = reporting_get_count_events_validated( array('id_agent' => $content['id_agent']), $content['period'], $report["datetime"], $filter_event_validated, $filter_event_critical, $filter_event_warning, $filter_event_no_validated); $table_event_graph = null; $table_event_graph->width = '100%'; $table_event_graph->style[0] = 'text-align: center;'; $table_event_graph->head[0] = __('Amount events validated'); $table_event_graph->data[0][0] = pie3d_graph( false, $data_graph, 500, 150, __("other"), "", ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", $config['fontpath'], $config['font_size']); $data[0] = html_print_table($table_event_graph, true); $table->colspan[$next_row][0] = 3; $next_row++; array_push ($table->data, $data); } break; case 'sql_graph_vbar': case 'sql_graph_hbar': case 'sql_graph_pie': $sizgraph_h = 300; if ($content['type'] == 'sql_graph_vbar') { $sizgraph_h = 400; } if ($config['metaconsole'] == 1 && defined('METACONSOLE')) metaconsole_restore_db(); if (empty($item_title)) { $item_title = __('User defined graph') . " (".__($content["type"]) .")"; } reporting_header_content($mini, $content, $report, $table, $item_title, "", ""); // Put description at the end of the module (if exists) $next_row = 1; if ($content["description"] != "") { $data_desc = array(); $data_desc[0] = $content["description"]; array_push ($table->data, $data_desc); $table->colspan[$next_row][0] = 3; $next_row++; } $table->colspan[$next_row][0] = 3; $table2->class = 'databox'; $table2->width = '100%'; //Create the head $table2->head = array(); if ($content['header_definition'] != '') { $table2->head = explode('|', $content['header_definition']); } $data = array (); $data[0] = graph_custom_sql_graph( $content["id_rc"], $sizgraph_w, $sizgraph_h, $content["type"], true, ui_get_full_url(false, false, false, false)); array_push($table->data, $data); break; case 'event_report_group': if (empty($item_title)) { $item_title = __('Group detailed event'); } reporting_header_content($mini, $content, $report, $table, $item_title, ui_print_truncate_text(groups_get_name($content['id_group'], true), 60, false)); $next_row = 1; // Put description at the end of the module (if exists) if ($content["description"] != "") { $data_desc = array(); $data_desc[0] = $content["description"]; array_push ($table->data, $data_desc); $table->colspan[$next_row][0] = 3; $next_row++; } $data = array (); $style = json_decode(io_safe_output($content['style']), true); $filter_event_no_validated = $style['filter_event_no_validated']; $filter_event_validated = $style['filter_event_validated']; $filter_event_critical = $style['filter_event_critical']; $filter_event_warning = $style['filter_event_warning']; $event_graph_by_agent = $style['event_graph_by_agent']; $event_graph_by_user_validator = $style['event_graph_by_user_validator']; $event_graph_by_criticity = $style['event_graph_by_criticity']; $event_graph_validated_vs_unvalidated = $style['event_graph_validated_vs_unvalidated']; $data[0] = reporting_get_group_detailed_event( $content['id_group'], $content['period'], $report["datetime"], true, true, $filter_event_validated, $filter_event_critical, $filter_event_warning, $filter_event_no_validated); if(!empty($data[0])) { array_push ($table->data, $data); $table->colspan[$next_row][0] = 3; $next_row++; } if ($event_graph_by_agent) { $data_graph = reporting_get_count_events_by_agent( $content['id_group'], $content['period'], $report["datetime"], $filter_event_validated, $filter_event_critical, $filter_event_warning, $filter_event_no_validated); $table_event_graph = null; $table_event_graph->width = '100%'; $table_event_graph->style[0] = 'text-align: center;'; $table_event_graph->head[0] = __('Events by agent'); $table_event_graph->data[0][0] = pie3d_graph( false, $data_graph, 500, 150, __("other"), "", ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", $config['fontpath'], $config['font_size']); $data[0] = html_print_table($table_event_graph, true); $table->colspan[$next_row][0] = 3; $next_row++; array_push ($table->data, $data); } if ($event_graph_by_user_validator) { $data_graph = reporting_get_count_events_validated_by_user( array('id_group' => $content['id_group']), $content['period'], $report["datetime"], $filter_event_validated, $filter_event_critical, $filter_event_warning, $filter_event_no_validated); $table_event_graph = null; $table_event_graph->head[0] = __('Events validated by user'); $table_event_graph->width = '100%'; $table_event_graph->style[0] = 'text-align: center;'; $table_event_graph->data[0][0] = pie3d_graph( false, $data_graph, 500, 150, __("other"), "", ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", $config['fontpath'], $config['font_size']); $data[0] = html_print_table($table_event_graph, true); $table->colspan[$next_row][0] = 3; $next_row++; array_push ($table->data, $data); } if ($event_graph_by_criticity) { $data_graph = reporting_get_count_events_by_criticity( array('id_group' => $content['id_group']), $content['period'], $report["datetime"], $filter_event_validated, $filter_event_critical, $filter_event_warning, $filter_event_no_validated); $colors = get_criticity_pie_colors($data_graph); $table_event_graph = null; $table_event_graph->head[0] = __('Events by criticity'); $table_event_graph->width = '100%'; $table_event_graph->style[0] = 'text-align: center;'; $table_event_graph->data[0][0] = pie3d_graph( false, $data_graph, 500, 150, __("other"), "", ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", $config['fontpath'], $config['font_size'], 1, false, $colors); $data[0] = html_print_table($table_event_graph, true); $table->colspan[$next_row][0] = 3; $next_row++; array_push ($table->data, $data); } if ($event_graph_validated_vs_unvalidated) { $data_graph = reporting_get_count_events_validated( array('id_group' => $content['id_group']), $content['period'], $report["datetime"], $filter_event_validated, $filter_event_critical, $filter_event_warning, $filter_event_no_validated); $table_event_graph = null; $table_event_graph->head[0] = __('Amount events validated'); $table_event_graph->width = '100%'; $table_event_graph->style[0] = 'text-align: center;'; $table_event_graph->data[0][0] = pie3d_graph( false, $data_graph, 500, 150, __("other"), "", ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", $config['fontpath'], $config['font_size']); $data[0] = html_print_table($table_event_graph, true); $table->colspan[$next_row][0] = 3; $next_row++; array_push ($table->data, $data); } break; case 'event_report_module': if (empty($item_title)) { $item_title = __('Module detailed event'); } reporting_header_content($mini, $content, $report, $table, $item_title, ui_print_truncate_text($agent_name, 'agent_medium', false) . '" .
__('Total') . " |
" .
__('Unknown') . " |
|||||
" .
__('Agents') . " |
" .
$group_stats['total_agents'] . " |
" .
$group_stats['agents_unknown'] . " |
||||
" .
__('Total') . " |
" .
__('Normal') . " |
" .
__('Critical') . " |
" .
__('Warning') . " |
" .
__('Unknown') . " |
" .
__('Not init') . " |
|
" .
__('Monitors') . " |
" .
$group_stats['monitor_checks'] . " |
" .
$group_stats['monitor_ok'] ." |
" .
$group_stats['monitor_critical'] . " |
" .
$group_stats['monitor_warning'] . " |
" .
$group_stats['monitor_unknown'] . " |
" .
$group_stats['monitor_not_init'] . " |
" .
__('Defined') . " |
" .
__('Fired') . " |
|||||
" .
__('Alerts') . " |
" .
$group_stats['monitor_alerts'] . " |
" .
$group_stats['monitor_alerts_fired'] . " |
||||
" .
__('Last 8 hours') . " |
||||||
" .
__('Events') . " |
" .
count($events)." |
".__("Agents")." / ".__("Modules")." | "; $nmodules = 0; foreach ($modules_by_name as $module) { $nmodules++; $file_name = string2image(ui_print_truncate_text($module['name'], 'module_small', false, true, false, '...'), false, false, 6, 270, '#B1B1B1', 'FFF', 4, 0); $table_data .= '' . html_print_image($file_name, true, array('title' => $module['name']))." | "; } // Dont use pagination /*if ($block < $nmodules) { $table_data .= "... | "; }*/ $filter_agents = false; if ($id_group > 0) { $filter_agents = array('id_grupo' => $id_group); } // Prepare pagination ui_pagination ((int)count(agents_get_agents ($filter_agents))); $table_data .= "
---|---|---|
".html_print_image($file_name, true, array('title' => $agent['nombre']))." | "; $agent_modules = agents_get_modules($agent['id_agente']); $nmodules = 0; foreach ($modules_by_name as $module) { $nmodules++; // Don't use pagination /*if ($nmodules > $block) { continue; }*/ $match = false; foreach($module['id'] as $module_id){ if (!$match && array_key_exists($module_id,$agent_modules)) { $status = modules_get_agentmodule_status($module_id); $table_data .= ""; $win_handle = dechex(crc32($module_id.$module["name"])); $graph_type = return_graphtype (modules_get_agentmodule_type($module_id)); switch ($status) { case 0: $table_data .= ui_print_status_image ('module_ok.png', $module['name']." in ".$agent['nombre'].": ".__('NORMAL'), true, array('width' => '20px', 'height' => '20px')); break; case 1: $table_data .= ui_print_status_image ('module_critical.png', $module['name']." in ".$agent['nombre'].": ".__('CRITICAL'), true, array('width' => '20px', 'height' => '20px')); break; case 2: $table_data .= ui_print_status_image ('module_warning.png', $module['name']." in ".$agent['nombre'].": ".__('WARNING'), true, array('width' => '20px', 'height' => '20px')); break; case 3: $table_data .= ui_print_status_image ('module_unknown.png', $module['name']." in ".$agent['nombre'].": ".__('UNKNOWN'), true, array('width' => '20px', 'height' => '20px')); break; case 4: $table_data .= ui_print_status_image ('module_alertsfired.png', $module['name']." in ".$agent['nombre'].": ".__('ALERTS FIRED'), true, array('width' => '20px', 'height' => '20px')); break; } $table_data .= " | "; $match = true; } } if (!$match) { $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") . " |