Rever some changes from the previous merge.

This commit is contained in:
mdtrooper 2015-03-30 11:33:26 +02:00
parent f8e544b89e
commit aabec6784e
1 changed files with 0 additions and 855 deletions

View File

@ -2136,859 +2136,4 @@ function reporting_get_agentmodule_ttr ($id_agent_module, $period = 0, $date = 0
return $critical_period; return $critical_period;
} }
/**
* 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;
}
/**
* Gets a detailed reporting of groups's events.
*
* @param unknown_type $id_group Id of the group.
* @param unknown_type $period Time period of the report.
* @param unknown_type $date Date of the report.
* @param unknown_type $return Whether to return or not.
* @param unknown_type $html Whether to return HTML code or not.
*
* @return string Report of groups's events
*/
function reporting_get_count_events_by_agent ($id_group, $period = 0,
$date = 0,
$filter_event_validated = false, $filter_event_critical = false,
$filter_event_warning = false, $filter_event_no_validated = false) {
if (!is_numeric ($date)) {
$date = strtotime ($date);
}
if (empty ($date)) {
$date = get_system_time ();
}
return events_get_count_events_by_agent($id_group, $period, $date,
$filter_event_validated, $filter_event_critical,
$filter_event_warning, $filter_event_no_validated);
}
/**
* Gets a detailed reporting of groups's events.
*
* @param unknown_type $filter.
* @param unknown_type $period Time period of the report.
* @param unknown_type $date Date of the report.
* @param unknown_type $return Whether to return or not.
* @param unknown_type $html Whether to return HTML code or not.
*
* @return string Report of groups's events
*/
function reporting_get_count_events_validated_by_user ($filter, $period = 0,
$date = 0,
$filter_event_validated = false, $filter_event_critical = false,
$filter_event_warning = false, $filter_event_no_validated = false) {
if (!is_numeric ($date)) {
$date = strtotime ($date);
}
if (empty ($date)) {
$date = get_system_time ();
}
return events_get_count_events_validated_by_user($filter, $period, $date,
$filter_event_validated, $filter_event_critical,
$filter_event_warning, $filter_event_no_validated);
}
/**
* Gets a detailed reporting of groups's events.
*
* @param unknown_type $id_group Id of the group.
* @param unknown_type $period Time period of the report.
* @param unknown_type $date Date of the report.
* @param unknown_type $return Whether to return or not.
* @param unknown_type $html Whether to return HTML code or not.
*
* @return string Report of groups's events
*/
function reporting_get_count_events_by_criticity ($filter, $period = 0,
$date = 0,
$filter_event_validated = false, $filter_event_critical = false,
$filter_event_warning = false, $filter_event_no_validated = false) {
if (!is_numeric ($date)) {
$date = strtotime ($date);
}
if (empty ($date)) {
$date = get_system_time ();
}
return events_get_count_events_by_criticity($filter, $period, $date,
$filter_event_validated, $filter_event_critical,
$filter_event_warning, $filter_event_no_validated);
}
/**
* Gets a detailed reporting of groups's events.
*
* @param unknown_type $id_group Id of the group.
* @param unknown_type $period Time period of the report.
* @param unknown_type $date Date of the report.
* @param unknown_type $return Whether to return or not.
* @param unknown_type $html Whether to return HTML code or not.
*
* @return string Report of groups's events
*/
function reporting_get_count_events_validated ($filter, $period = 0,
$date = 0,
$filter_event_validated = false, $filter_event_critical = false,
$filter_event_warning = false, $filter_event_no_validated = false) {
if (!is_numeric ($date)) {
$date = strtotime ($date);
}
if (empty ($date)) {
$date = get_system_time ();
}
return events_get_count_events_validated($filter, $period, $date,
$filter_event_validated, $filter_event_critical,
$filter_event_warning, $filter_event_no_validated);
}
/**
* Print tiny statistics of the status of one agent, group, etc.
*
* @param mixed Array with the counts of the total modules, normal modules, critical modules, warning modules, unknown modules and fired alerts
* @param bool return or echo flag
*
* @return string html formatted tiny stats of modules/alerts of an agent
*/
function reporting_tiny_stats ($counts_info, $return = false, $type = 'agent', $separator = ':', $strict_user = false) {
global $config;
$out = '';
// Depend the type of object, the stats will refer agents, modules...
switch ($type) {
case 'modules':
$template_title['total_count'] = __('%d Total modules');
$template_title['normal_count'] = __('%d Normal modules');
$template_title['critical_count'] = __('%d Critical modules');
$template_title['warning_count'] = __('%d Warning modules');
$template_title['unknown_count'] = __('%d Unknown modules');
break;
case 'agent':
$template_title['total_count'] = __('%d Total modules');
$template_title['normal_count'] = __('%d Normal modules');
$template_title['critical_count'] = __('%d Critical modules');
$template_title['warning_count'] = __('%d Warning modules');
$template_title['unknown_count'] = __('%d Unknown modules');
$template_title['fired_count'] = __('%d Fired alerts');
break;
default:
$template_title['total_count'] = __('%d Total agents');
$template_title['normal_count'] = __('%d Normal agents');
$template_title['critical_count'] = __('%d Critical agents');
$template_title['warning_count'] = __('%d Warning agents');
$template_title['unknown_count'] = __('%d Unknown agents');
$template_title['not_init_count'] = __('%d not init agents');
$template_title['fired_count'] = __('%d Fired alerts');
break;
}
if ($strict_user && $type == 'agent') {
$acltags = tags_get_user_module_and_tags ($config['id_user'],'AR', $strict_user);
$filter['disabled'] = 0;
$id_agent = $counts_info['id_agente'];
$counts_info = array();
$counts_info['normal_count'] = count(tags_get_agent_modules ($id_agent, $acltags, false, $filter, false, AGENT_MODULE_STATUS_NORMAL));
$counts_info['warning_count'] = count(tags_get_agent_modules ($id_agent, $acltags, false, $filter, false, AGENT_MODULE_STATUS_WARNING));
$counts_info['critical_count'] = count(tags_get_agent_modules ($id_agent, $acltags, false, $filter, false, AGENT_MODULE_STATUS_CRITICAL_BAD));
$counts_info['notinit_count'] = count(tags_get_agent_modules ($id_agent, $acltags, false, $filter, false, AGENT_MODULE_STATUS_NOT_INIT));
$counts_info['unknown_count'] = count(tags_get_agent_modules ($id_agent, $acltags, false, $filter, false, AGENT_MODULE_STATUS_UNKNOWN));
$counts_info['total_count'] = $counts_info['normal_count'] + $counts_info['warning_count'] + $counts_info['critical_count'] + $counts_info['unknown_count'] + $counts_info['notinit_count'];
$all_agent_modules = tags_get_agent_modules ($id_agent, $acltags, false, $filter);
if (!empty($all_agent_modules)) {
$mod_clause = "(".implode(',', array_keys($all_agent_modules)).")";
$counts_info['fired_count'] = (int) db_get_sql ("SELECT COUNT(times_fired)
FROM talert_template_modules
WHERE times_fired != 0 AND id_agent_module IN ".$mod_clause);
}
else {
$counts_info['fired_count'] = 0;
}
}
// Store the counts in a data structure to print hidden divs with titles
$stats = array();
if (isset($counts_info['total_count'])) {
$not_init = isset($counts_info['notinit_count']) ? $counts_info['notinit_count'] : 0;
$total_count = $counts_info['total_count'] - $not_init;
$stats[] = array('name' => 'total_count', 'count' => $total_count, 'title' => sprintf($template_title['total_count'], $total_count));
}
if (isset($counts_info['normal_count'])) {
$normal_count = $counts_info['normal_count'];
$stats[] = array('name' => 'normal_count', 'count' => $normal_count, 'title' => sprintf($template_title['normal_count'], $normal_count));
}
if (isset($counts_info['critical_count'])) {
$critical_count = $counts_info['critical_count'];
$stats[] = array('name' => 'critical_count', 'count' => $critical_count, 'title' => sprintf($template_title['critical_count'], $critical_count));
}
if (isset($counts_info['warning_count'])) {
$warning_count = $counts_info['warning_count'];
$stats[] = array('name' => 'warning_count', 'count' => $warning_count, 'title' => sprintf($template_title['warning_count'], $warning_count));
}
if (isset($counts_info['unknown_count'])) {
$unknown_count = $counts_info['unknown_count'];
$stats[] = array('name' => 'unknown_count', 'count' => $unknown_count, 'title' => sprintf($template_title['unknown_count'], $unknown_count));
}
if (isset($counts_info['not_init_count'])) {
$not_init_count = $counts_info['not_init_count'];
$stats[] = array('name' => 'not_init_count',
'count' => $not_init_count,
'title' => sprintf($template_title['not_init_count'], $not_init_count));
}
if (isset($template_title['fired_count'])) {
if (isset($counts_info['fired_count'])) {
$fired_count = $counts_info['fired_count'];
$stats[] = array('name' => 'fired_count', 'count' => $fired_count, 'title' => sprintf($template_title['fired_count'], $fired_count));
}
}
$uniq_id = uniqid();
foreach ($stats as $stat) {
$params = array('id' => 'forced_title_' . $stat['name'] . '_' . $uniq_id,
'class' => 'forced_title_layer',
'content' => $stat['title'],
'hidden' => true);
$out .= html_print_div($params, true);
}
// If total count is less than 0, is an error. Never show negative numbers
if ($total_count < 0) {
$total_count = 0;
}
$out .= '<b>' . '<span id="total_count_' . $uniq_id . '" class="forced_title" style="font-size: 7pt">' . $total_count . '</span>';
if (isset($fired_count) && $fired_count > 0)
$out .= ' ' . $separator . ' <span class="orange forced_title" id="fired_count_' . $uniq_id . '" style="font-size: 7pt">' . $fired_count . '</span>';
if (isset($critical_count) && $critical_count > 0)
$out .= ' ' . $separator . ' <span class="red forced_title" id="critical_count_' . $uniq_id . '" style="font-size: 7pt">' . $critical_count . '</span>';
if (isset($warning_count) && $warning_count > 0)
$out .= ' ' . $separator . ' <span class="yellow forced_title" id="warning_count_' . $uniq_id . '" style="font-size: 7pt">' . $warning_count . '</span>';
if (isset($unknown_count) && $unknown_count > 0)
$out .= ' ' . $separator . ' <span class="grey forced_title" id="unknown_count_' . $uniq_id . '" style="font-size: 7pt">' . $unknown_count . '</span>';
if (isset($not_init_count) && $not_init_count > 0)
$out .= ' ' . $separator . ' <span class="blue forced_title" id="not_init_count_' . $uniq_id . '" style="font-size: 7pt">' . $not_init_count . '</span>';
if (isset($normal_count) && $normal_count > 0)
$out .= ' ' . $separator . ' <span class="green forced_title" id="normal_count_' . $uniq_id . '" style="font-size: 7pt">' . $normal_count . '</span>';
$out .= '</b>';
if ($return) {
return $out;
}
else {
echo $out;
}
}
function reporting_network_interfaces_table ($content, $report, $mini, $item_title = "", &$table = null, &$pdf = null) {
global $config;
include_once($config['homedir'] . "/include/functions_custom_graphs.php");
if (empty($item_title)) {
$group_name = groups_get_name($content['id_group']);
$item_title = __('Network interfaces') . " - " . sprintf(__('Group "%s"'), $group_name);
}
$is_html = $table !== null;
$is_pdf = $pdf !== null;
$ttl = $is_pdf ? 2 : 1;
$graph_width = 900;
$graph_height = 200;
$datetime = $report['datetime'];
$period = $content['period'];
if ($is_pdf) {
$graph_width = 800;
$graph_height = 200;
pdf_header_content($pdf, $content, $report, $item_title, false, $content["description"]);
}
else if ($is_html) {
reporting_header_content($mini, $content, $report, $table, $item_title);
//RUNNING
$table->style[1] = 'text-align: right';
// Put description at the end of the module (if exists)
$table->colspan[0][1] = 2;
$next_row = 1;
if ($content["description"] != "") {
$table->colspan[$next_row][0] = 3;
$next_row++;
$data_desc = array();
$data_desc[0] = $content["description"];
array_push ($table->data, $data_desc);
}
}
$filter = array(
'id_grupo' => $content['id_group'],
'disabled' => 0
);
$network_interfaces_by_agents = agents_get_network_interfaces(false, $filter);
if (empty($network_interfaces_by_agents)) {
if ($is_pdf) {
$pdf->addHTML(__('The group has no agents or none of the agents has any network interface'));
}
else if ($is_html) {
$data = array();
$data[0] = __('The group has no agents or none of the agents has any network interface');
$table->colspan[$next_row][0] = 3;
array_push ($table->data, $data);
}
return;
}
else {
foreach ($network_interfaces_by_agents as $agent_id => $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';
if ($is_pdf) {
$table_agent->class = 'table_sla table_beauty';
$table_agent->headstyle[0] = 'background: #373737; color: #FFF; display: table-cell; font-size: 16px; border: 1px solid grey';
}
$table_agent->data['interfaces'] = "";
foreach ($agent['interfaces'] as $interface_name => $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';
if ($is_pdf) {
$table_interface->class = 'table_sla table_beauty';
$table_interface->titlestyle = 'background: #373737; color: #FFF; display: table-cell; font-size: 12px; border: 1px solid grey';
$table_interface->headstyle['ip'] = 'text-align: left; background: #666; color: #FFF; display: table-cell; font-size: 11px; border: 1px solid grey';
$table_interface->headstyle['mac'] = 'text-align: left; background: #666; color: #FFF; display: table-cell; font-size: 11px; border: 1px solid grey';
$table_interface->headstyle['status'] = 'background: #666; color: #FFF; display: table-cell; font-size: 11px; border: 1px solid grey';
$table_interface->style['ip'] = 'text-align: left; display: table-cell; font-size: 10px;';
$table_interface->style['mac'] = 'text-align: left; display: table-cell; font-size: 10px;';
$table_interface->style['status'] = 'text-align: center; display: table-cell; font-size: 10px;';
}
$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['traffic'])) {
$only_image = !(bool)$config['flash_charts'] || $is_pdf ? true : false;
$graph = custom_graphs_print(0,
$graph_height,
$graph_width,
$period,
null,
true,
$date,
$only_image,
'white',
array_values($interface['traffic']),
$config['homeurl'],
array_keys($interface['traffic']),
array_fill(0, count($interface['traffic']),"bytes/s"),
false,
true,
true,
true,
$ttl);
$table_interface->data['graph'] = $graph;
$table_interface->colspan['graph'][0] = count($table_interface->head);
$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;
}
if ($is_html) {
$table->data[$agent_id] = html_print_table($table_agent, true);
$table->colspan[$agent_id][0] = 3;
}
else if ($is_pdf) {
$html = html_print_table($table_agent, true);
$pdf->addHTML($html);
}
}
}
}
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] = "<a style='color: #FC4444;' href='" . $links['agents_critical'] . "'><b><span style='font-size: 12pt; font-weight: bold; color: #FC4444;'>";
$agent_data[1] .= format_numeric($data["agent_critical"]) <= 0 ? '-' : format_numeric($data['agent_critical']);
$agent_data[1] .= "</span></b></a>";
$agent_data[2] = html_print_image('images/agent_warning.png', true, array('title' => __('Agents warning')));
$agent_data[3] = "<a style='color: #FAD403;' href='" . $links['agents_warning'] . "'><b><span style='font-size: 12pt; font-weight: bold; color: #FAD403;'>";
$agent_data[3] .= $data["agent_warning"] <= 0 ? '-' : format_numeric($data['agent_warning']);
$agent_data[3] .= "</span></b></a>";
$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] = "<a style='color: #80BA27;' href='" . $links['agents_ok'] . "'><b><span style='font-size: 12pt; font-weight: bold; color: #80BA27;'>";
$agent_data[1] .= $data["agent_ok"] <= 0 ? '-' : format_numeric($data['agent_ok']);
$agent_data[1] .= "</span></b></a>";
$agent_data[2] = html_print_image('images/agent_unknown.png', true, array('title' => __('Agents unknown')));
$agent_data[3] = "<a style='color: #B2B2B2;' href='" . $links['agents_unknown'] . "'><b><span style='font-size: 12pt; font-weight: bold; color: #B2B2B2;'>";
$agent_data[3] .= $data["agent_unknown"] <= 0 ? '-' : format_numeric($data['agent_unknown']);
$agent_data[3] .= "</span></b></a>";
$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] = "<a style='color: #5BB6E5;' href='" . $links['agents_not_init'] . "'><b><span style='font-size: 12pt; font-weight: bold; color: #5BB6E5;'>";
$agent_data[1] .= $data["agent_not_init"] <= 0 ? '-' : format_numeric($data['agent_not_init']);
$agent_data[1] .= "</span></b></a>";
$agent_data[2] = "";
$agent_data[3] = "";
$table_agent->data[] = $agent_data;
if (!defined('METACONSOLE')) {
$agents_data = '<fieldset class="databox tactical_set">
<legend>' .
__('Agents by status') .
'</legend>' .
html_print_table($table_agent, true) . '</fieldset>';
}
else{
$table_agent->style=array();
$table_agent->class = "tactical_view";
$agents_data = '<fieldset class="tactical_set">
<legend>' .
__('Agents by status') .
'</legend>' .
html_print_table($table_agent, true) . '</fieldset>';
}
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 = '<fieldset class="databox tactical_set">
<legend>' .
__('Total agents and monitors') .
'</legend>' .
html_print_table($table_total, true) . '</fieldset>';
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] = "<b><span style='font-size: 12pt; font-weight: bold; color: black;'>";
$node_data[1] .= $num_servers <= 0 ? '-' : format_numeric($num_servers);
$node_data[1] .= "</span></b>";
$table_node->data[] = $node_data;
if (!defined('METACONSOLE')){
$node_overview = '<fieldset class="databox tactical_set">
<legend>' .
__('Node overview') .
'</legend>' .
html_print_table($table_node, true) . '</fieldset>';
}else{
$table_node->style = array();
$table_node->class = "tactical_view";
$node_overview = '<fieldset class="tactical_set">
<legend>' .
__('Node overview') .
'</legend>' .
html_print_table($table_node, true) . '</fieldset>';
}
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] .= "&nbsp;&nbsp;&nbsp;" .
"<a style='color:#FFF; font-size: 12pt; font-weight: bold;" . $style . "' href='" . $links['critical'] . "'>";
$table_events->data[0][0] .= format_numeric($data['critical']) <= 0 ? ' -' : format_numeric($data['critical']);
$table_events->data[0][0] .= "</a>";
$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] .= "&nbsp;&nbsp;&nbsp;" .
"<a style='color:#FFF; font-size: 12pt; font-weight: bold;" . $style . "' href='" . $links['warning'] . "'>";
$table_events->data[0][1] .= format_numeric($data['warning']) <= 0 ? ' -' : format_numeric($data['warning']);
$table_events->data[0][1] .= "</a>";
$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] .= "&nbsp;&nbsp;&nbsp;" .
"<a style='color:#FFF; font-size: 12pt; font-weight: bold;" . $style . "' href='" . $links['normal'] . "'>";
$table_events->data[0][2] .= format_numeric($data['normal']) <= 0 ? ' -' : format_numeric($data['normal']);
$table_events->data[0][2] .= "</a>";
$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] .= "&nbsp;&nbsp;&nbsp;" .
"<a style='color:#FFF; font-size: 12pt; font-weight: bold;" . $style . "' href='" . $links['unknown'] . "'>";
$table_events->data[0][3] .=format_numeric($data['unknown']) <= 0 ? ' -' : format_numeric($data['unknown']);
$table_events->data[0][3] .="</a>";
}
else{
$table_events->data[0][0] = html_print_image('images/module_critical.png', true, array('title' => __('Critical events')));
$table_events->data[0][0] .= "&nbsp;&nbsp;&nbsp;" .
"<a style='color: #FC4444;" . $style . "' href='" . $links['critical'] . "'><b><span style='font-size: 12pt; font-weight: bold; color: #FC4444;'>".
format_numeric($data['critical'])."</span></b></a>";
$table_events->data[0][1] = html_print_image('images/module_warning.png', true, array('title' => __('Warning events')));
$table_events->data[0][1] .= "&nbsp;&nbsp;&nbsp;" .
"<a style='color: #FAD403;" . $style . "' href='" . $links['warning'] . "'><b><span style='font-size: 12pt; font-weight: bold; color: #FAD403;'>".
format_numeric($data['warning'])."</span></b></a>";
$table_events->data[0][2] = html_print_image('images/module_ok.png', true, array('title' => __('OK events')));
$table_events->data[0][2] .= "&nbsp;&nbsp;&nbsp;" .
"<a style='color: #80BA27;" . $style . "' href='" . $links['normal'] . "'><b style='font-size: 12pt; font-weight: bold; color: #80BA27;'>".
format_numeric($data['normal'])."</b></a>";
$table_events->data[0][3] = html_print_image('images/module_unknown.png', true, array('title' => __('Unknown events')));
$table_events->data[0][3] .= "&nbsp;&nbsp;&nbsp;" .
"<a style='color: #B2B2B2;" . $style . "' href='" . $links['unknown'] . "'><b><span style='font-size: 12pt; font-weight: bold; color: #B2B2B2;'>".
format_numeric($data['unknown'])."</span></b></a>";
}
if (!defined('METACONSOLE')) {
$event_view = '<fieldset class="databox tactical_set">
<legend>' .
__('Events by criticity') .
'</legend>' .
html_print_table($table_events, true) . '</fieldset>';
}
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 = '<fieldset class="tactical_set">
<legend>' .
__('Important Events by Criticity') .
'</legend>' .
html_print_table($table_events, true) . '</fieldset>';
}
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 = '<span>' . __('Last activity in Pandora FMS console') . '</span>';
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] = '<strong>' . $session_id_usuario . '</strong>';
$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_NORMAL,
EVENT_CRIT_MINOR => COL_MINOR,
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 = '<span>' . __('Events info (1hr.)') . '</span>';
$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'], $urlImage);
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 = '<fieldset class="databox tactical_set">
<legend>' .
__('Events info (1hr)') .
'</legend>' .
html_print_table($table, true) . '</fieldset>';
}
else{
$table->class='tactical_view';
$event_graph = '<fieldset id="event_tactical" class="tactical_set">' .
html_print_table($table, true) . '</fieldset>';
}
return $event_graph;
}
?> ?>