'.__('There was a problem loading agent').'';
return;
}
$is_extra = enterprise_hook('policies_is_agent_extra_policy', array($id_agente));
if($is_extra === ENTERPRISE_NOT_HOOK) {
$is_extra = false;
}
if (! check_acl ($config["id_user"], $agent["id_grupo"], "AR") && !$is_extra) {
db_pandora_audit("ACL Violation",
"Trying to access Agent General Information");
require_once ("general/noaccess.php");
return;
}
echo '
';
echo '
';
//Agent name
echo ''.__('Agent name').' | ';
if ($agent['disabled']) {
$cellName = "" . ui_print_agent_name ($agent["id_agente"], true, 500, "text-transform: uppercase;", true) . ui_print_help_tip(__('Disabled'), true) . "";
}
else {
$cellName = ui_print_agent_name ($agent["id_agente"], true, 500, "text-transform: uppercase;", true);
}
echo ''.$cellName.' | ';
//Addresses
echo '
'.__('IP Address').' | ';
echo '';
$ips = array();
$addresses = agents_get_addresses ($id_agente);
$address = agents_get_address($id_agente);
foreach($addresses as $k => $add) {
if($add == $address) {
unset($addresses[$k]);
}
}
echo $address;
if (!empty($addresses)) {
ui_print_help_tip(__('Other IP addresses').': '.implode(' ',$addresses));
}
echo ' |
';
// Agent Interval
echo ''.__('Interval').' | ';
echo ''.human_time_description_raw ($agent["intervalo"]).' |
';
// Comments
echo ''.__('Description').' | ';
echo ''.$agent["comentarios"].' |
';
// Agent version
echo ''.__('Agent Version'). ' | ';
echo ''.$agent["agent_version"].' |
';
// Position Information
if ($config['activate_gis']) {
$dataPositionAgent = gis_get_data_last_position_agent($agent['id_agente']);
echo ''.__('Position (Long, Lat)'). ' | ';
echo '';
if ($dataPositionAgent === false) {
echo __('There is no GIS data.');
}
else {
echo '';
if ($dataPositionAgent['description'] != "")
echo $dataPositionAgent['description'];
else
echo $dataPositionAgent['stored_longitude'].', '.$dataPositionAgent['stored_latitude'];
echo "";
}
echo ' |
';
}
// If the url description is setted
if ($agent['url_address'] != ''){
echo ''.__('Url address').' | ';
echo '' . $agent["url_address"] . ' |
';
}
// Last contact
echo ''.__('Last contact')." / ".__('Remote').' | ';
ui_print_timestamp ($agent["ultimo_contacto"]);
echo " / ";
if ($agent["ultimo_contacto_remoto"] == "01-01-1970 00:00:00") {
echo __('Never');
} else {
echo $agent["ultimo_contacto_remoto"];
}
echo ' |
';
// Timezone Offset
if ($agent['timezone_offset'] != 0) {
echo ''.__('Timezone Offset'). ' | ';
echo ''.$agent["timezone_offset"].' |
';
}
// Next contact (agent)
$progress = agents_get_next_contact($id_agente);
echo ''.__('Next agent contact').' | ';
echo '' . progress_bar($progress, 200, 20) . ' |
';
// Custom fields
$fields = db_get_all_rows_filter('tagent_custom_fields', array('display_on_front' => 1));
if ($fields === false) {
$fields = array ();
}
if ($fields)
foreach($fields as $field) {
echo ''.$field['name'] . ui_print_help_tip (__('Custom field'), true).' | ';
$custom_value = db_get_value_filter('description', 'tagent_custom_data', array('id_field' => $field['id_field'], 'id_agent' => $id_agente));
if($custom_value === false || $custom_value == '') {
$custom_value = '-'.__('empty').'-';
}
echo ''.$custom_value.' |
';
}
//End of table
echo '
';
// Blank space below title, DONT remove this, this
// Breaks the layout when Flash charts are enabled :-o
echo '
';
//Floating div
echo '';
if ($config["agentaccess"]){
echo ''.__('Agent access rate (24h)').'
';
graphic_agentaccess($id_agente, 280, 110, 86400);
}
echo '
';
graph_graphic_agentevents ($id_agente, 290, 15, 86400, '');
echo '
';
echo '';
return;
}
require_once ('include/functions_reporting.php');
require_once ('include/functions_users.php');
require_once ('include/functions_servers.php');
global $config;
$enterpriseEnable = false;
if (enterprise_include_once('include/functions_policies.php') !== ENTERPRISE_NOT_HOOK) {
$enterpriseEnable = true;
require_once ('enterprise/include/functions_policies.php');
}
$type = get_parameter('type');
$id = get_parameter('id');
$id_father = get_parameter('id_father');
$statusSel = get_parameter('status');
$search_free = get_parameter('search_free', '');
$printTable = get_parameter('printTable', 0);
if ($printTable) {
$id_agente = get_parameter('id_agente');
printTable($id_agente);
}
/*
* It's a binary for branch (0 show - 1 hide)
* and there are 2 position
* 0 0 - show 2 branch
* 0 1 - hide the 2º branch
* 1 0 - hide the 1º branch
* 1 1 - hide 2 branch
*/
$lessBranchs = get_parameter('less_branchs');
switch ($type) {
case 'group':
case 'os':
case 'module_group':
case 'policies':
case 'module':
$avariableGroups = users_get_groups();
$avariableGroupsIds = array_keys($avariableGroups);
$countRows = 0;
if (!empty($avariableGroupsIds)) {
$extra_sql = '';
if($extra_sql != '') {
$extra_sql .= ' OR';
}
$groups_sql = implode(', ', $avariableGroupsIds);
if ($search_free != '') {
$search_sql = " AND nombre COLLATE utf8_general_ci LIKE '%$search_free%'";
} else {
$search_sql = '';
}
//Extract all rows of data for each type
switch ($type) {
case 'group':
//Skip agents which only have not init modules
$search_sql .= " AND id_agente NOT IN (SELECT tagente_estado.id_agente FROM
tagente_estado GROUP BY id_agente HAVING SUM(utimestamp) = 0)";
$sql = agents_get_agents(array (
'order' => 'nombre COLLATE utf8_general_ci ASC',
'id_grupo' => $id,
'disabled' => 0,
'status' => $statusSel,
'search' => $search_sql),
array ('*'),
'AR',
false,
true);
break;
case 'os':
//Skip agents which only have not init modules
$search_sql .= " AND id_agente NOT IN (SELECT tagente_estado.id_agente FROM
tagente_estado GROUP BY id_agente HAVING SUM(utimestamp) = 0)";
$sql = agents_get_agents(array (
'order' => 'nombre COLLATE utf8_general_ci ASC',
'id_os' => $id,
'disabled' => 0,
'status' => $statusSel,
'search' => $search_sql),
array ('*'),
'AR',
false,
true);
break;
case 'module_group':
//Skip agents which only have not init modules
$search_sql .= " AND id_agente NOT IN (SELECT tagente_estado.id_agente FROM tagente_estado
WHERE id_agente_modulo IN
(SELECT id_agente_modulo FROM tagente_modulo
WHERE id_module_group = $id)
GROUP BY id_agente HAVING SUM(utimestamp) = 0)";
$sql = agents_get_agents(array (
'order' => 'nombre COLLATE utf8_general_ci ASC',
'disabled' => 0,
'status' => $statusSel,
'search' => $search_sql),
array ('*'),
'AR',
false,
true);
// Skip agents without modules
$sql .= ' AND id_agente IN
(SELECT tagente.id_agente
FROM tagente, tagente_modulo
WHERE tagente.id_agente = tagente_modulo.id_agente
AND id_module_group = ' . $id . ' AND tagente.disabled = 0
AND tagente_modulo.disabled = 0
group by tagente.id_agente
having COUNT(*) > 0)';
break;
case 'policies':
$sql = agents_get_agents(array (
'order' => 'nombre COLLATE utf8_general_ci ASC',
'disabled' => 0,
'search' => $search_sql),
array ('*'),
'AR',
false,
true);
if ($id != 0) {
// Skip agents without modules
$sql .= ' AND tagente.id_agente IN
(SELECT tagente.id_agente
FROM tagente, tagente_modulo, tagente_estado, tpolicy_modules
WHERE tagente.id_agente = tagente_modulo.id_agente
AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo
AND tagente_modulo.id_policy_module = tpolicy_modules.id
AND tagente.disabled = 0
AND tagente_modulo.disabled = 0
AND tagente_estado.utimestamp != 0
AND tagente_modulo.id_policy_module != 0
AND tpolicy_modules.id_policy = ' . $id . '
group by tagente.id_agente
having COUNT(*) > 0)';
}
else if ($statusSel == 0) {
// If status filter is NORMAL add void agents
$sql .= " UNION SELECT * FROM tagente
WHERE tagente.disabled = 0
AND tagente.id_agente NOT IN (SELECT tagente_estado.id_agente
FROM tagente_estado)";
}
break;
case 'module':
//Replace separator token "articapandora_32_pandoraartica_" for " "
//example:
// "Load_articapandora_32_pandoraartica_Average"
//result -> "Load Average"
$name = str_replace(array('_articapandora_'.ord(' ').'_pandoraartica_', '_articapandora_'.ord('#').'_pandoraartica_','_articapandora_'.ord('/').'_pandoraartica_'),array(' ','#','/'),$id);
$name = io_safe_input($name);
$sql = agents_get_agents(array (
'order' => 'nombre COLLATE utf8_general_ci ASC',
'disabled' => 0,
'status' => $statusSel,
'search' => $search_sql),
array ('*'),
'AR',
false,
true);
$sql .= sprintf('AND id_agente IN (
SELECT id_agente
FROM tagente_modulo
WHERE nombre = \'%s\' AND disabled = 0
)
', $name);
break;
}
$sql .= ' AND tagente.disabled = 0'. $search_sql;
$countRows = db_get_num_rows($sql);
}
if ($countRows === 0) {
echo "\n";
echo "- ";
if ($lessBranchs == 1)
echo html_print_image ("operation/tree/no_branch.png", true, array ("style" => 'vertical-align: middle;'));
else
echo html_print_image ("operation/tree/branch.png", true, array ("style" => 'vertical-align: middle;'));
echo "" . __("Empty") . "";
echo "
";
echo "
";
return;
}
$new = true;
$count = 0;
echo "\n";
while($row = db_get_all_row_by_steps_sql($new, $result, $sql)) {
$new = false;
$count++;
switch ($type) {
case 'group':
case 'os':
$agent_info["monitor_alertsfired"] = agents_get_alerts_fired ($row["id_agente"], array("disabled" => 0));
$agent_info["monitor_critical"] = agents_monitor_critical ($row["id_agente"]);
$agent_info["monitor_warning"] = agents_monitor_warning ($row["id_agente"]);
$agent_info["monitor_unknown"] = agents_monitor_unknown ($row["id_agente"]);
$agent_info["monitor_normal"] = agents_monitor_ok ($row["id_agente"]);
$agent_info["alert_img"] = agents_tree_view_alert_img ($agent_info["monitor_alertsfired"]);
$agent_info["status_img"] = agetns_tree_view_status_img ($agent_info["monitor_critical"],
$agent_info["monitor_warning"],
$agent_info["monitor_unknown"]);
//Count all modules
$agent_info["modules"] = $agent_info["monitor_critical"] + $agent_info["monitor_warning"] + $agent_info["monitor_unknown"] + $agent_info["monitor_normal"];
break;
case 'policies':
$filter = "tagente_modulo.id_policy_module = 0";
if ($id) {
$filter = "tagente_modulo.id_policy_module = " . $id . " ";
}
$filter .= " AND tagente_modulo.disabled = 0 ";
$agent_info["monitor_alertsfired"] = agents_get_alerts_fired ($row["id_agente"], $filter);
$agent_info["monitor_critical"] = agents_monitor_critical ($row["id_agente"], $filter);
$agent_info["monitor_warning"] = agents_monitor_warning ($row["id_agente"], $filter);
$agent_info["monitor_unknown"] = agents_monitor_unknown ($row["id_agente"], $filter);
$agent_info["monitor_normal"] = agents_monitor_ok ($row["id_agente"], $filter);
$agent_info["alert_img"] = agents_tree_view_alert_img ($agent_info["monitor_alertsfired"]);
$agent_info["status_img"] = agetns_tree_view_status_img ($agent_info["monitor_critical"],
$agent_info["monitor_warning"],
$agent_info["monitor_unknown"]);
//Count all modules
$agent_info["modules"] = $agent_info["monitor_critical"] + $agent_info["monitor_warning"] + $agent_info["monitor_unknown"] + $agent_info["monitor_normal"];
break;
case 'module_group':
$agent_info["monitor_alertsfired"] = agents_get_alerts_fired ($row["id_agente"], "id_module_group = $id AND disabled = 0");
$agent_info["monitor_critical"] = agents_monitor_critical($row["id_agente"], "tagente_modulo.id_module_group = $id");
$agent_info["monitor_warning"] = agents_monitor_warning ($row["id_agente"], "tagente_modulo.id_module_group = $id");
$agent_info["monitor_unknown"] = agents_monitor_unknown ($row["id_agente"], "tagente_modulo.id_module_group = $id");
$agent_info["monitor_normal"] = agents_monitor_ok ($row["id_agente"], "tagente_modulo.id_module_group = $id");
$agent_info["alert_img"] = agents_tree_view_alert_img ($agent_info["monitor_alertsfired"]);
$agent_info["status_img"] = agetns_tree_view_status_img ($agent_info["monitor_critical"],
$agent_info["monitor_warning"],
$agent_info["monitor_unknown"]);
//Count all modules
$agent_info["modules"] = $agent_info["monitor_critical"] + $agent_info["monitor_warning"] + $agent_info["monitor_unknown"] + $agent_info["monitor_normal"];
break;
case 'module':
switch ($config["dbtype"]) {
case "mysql":
$agent_info["monitor_alertsfired"] = agents_get_alerts_fired ($row["id_agente"], ' tagente_modulo.nombre COLLATE utf8_general_ci = "' . $name . '" AND disabled = 0');
$agent_info["monitor_critical"] = agents_monitor_critical($row["id_agente"], ' tagente_modulo.nombre COLLATE utf8_general_ci = "' . $name . '"');
$agent_info["monitor_warning"] = agents_monitor_warning ($row["id_agente"], ' tagente_modulo.nombre COLLATE utf8_general_ci = "' . $name . '"');
$agent_info["monitor_unknown"] = agents_monitor_unknown ($row["id_agente"], ' tagente_modulo.nombre COLLATE utf8_general_ci = "' . $name . '"');
$agent_info["monitor_normal"] = agents_monitor_ok ($row["id_agente"], ' tagente_modulo.nombre COLLATE utf8_general_ci = "' . $name . '"');
$agent_info["alert_img"] = agents_tree_view_alert_img ($agent_info["monitor_alertsfired"]);
$agent_info["status_img"] = agetns_tree_view_status_img ($agent_info["monitor_critical"],
$agent_info["monitor_warning"],
$agent_info["monitor_unknown"]);
//Count all modules
$agent_info["modules"] = $agent_info["monitor_critical"] + $agent_info["monitor_warning"] + $agent_info["monitor_unknown"] + $agent_info["monitor_normal"];
break;
case "postgresql":
case "oracle":
//TODO REVIEW ORACLE AND POSTGRESQL
$agent_info["monitor_alertsfired"] = agents_get_alerts_fired ($row["id_agente"], ' tagente_modulo.nombre = \'' . $name . '\' AND disabled = 0');
$agent_info["monitor_critical"] = agents_monitor_critical($row["id_agente"], ' tagente_modulo.nombre = \'' . $name . '\'');
$agent_info["monitor_warning"] = agents_monitor_warning ($row["id_agente"], ' tagente_modulo.nombre = \'' . $name . '\'');
$agent_info["monitor_unknown"] = agents_monitor_unknown ($row["id_agente"], ' tagente_modulo.nombre = \'' . $name . '\'');
$agent_info["monitor_normal"] = agents_monitor_ok ($row["id_agente"], ' tagente_modulo.nombre = \'' . $name . '\'');
$agent_info["alert_img"] = agents_tree_view_alert_img ($agent_info["monitor_alertsfired"]);
$agent_info["status_img"] = agetns_tree_view_status_img ($agent_info["monitor_critical"],
$agent_info["monitor_warning"],
$agent_info["monitor_unknown"]);
//Count all modules
$agent_info["modules"] = $agent_info["monitor_critical"] + $agent_info["monitor_warning"] + $agent_info["monitor_unknown"] + $agent_info["monitor_normal"];
break;
}
break;
}
// Filter by status (only in policy view)
if ($type == 'policies') {
if ($statusSel == NORMAL) {
if (strpos($agent_info["status_img"], 'ok') === false)
continue;
}
else if ($statusSel == WARNING) {
if (strpos($agent_info["status_img"], 'warning') === false)
continue;
}
else if ($statusSel == CRITICAL) {
if (strpos($agent_info["status_img"], 'critical') === false)
continue;
}
else if ($statusSel == UNKNOWN) {
if (strpos($agent_info["status_img"], 'down') === false)
continue;
}
}
$less = $lessBranchs;
if ($count != $countRows)
$img = html_print_image ("operation/tree/closed.png", true, array ("style" => 'vertical-align: middle;', "id" => "tree_image" . $id . "_agent_" . $type . "_" . $row["id_agente"], "pos_tree" => "2"));
else {
$less = $less + 2; // $less = $less or 0b10
$img = html_print_image ("operation/tree/last_closed.png", true, array ("style" => 'vertical-align: middle;', "id" => "tree_image" . $id . "_agent_" . $row["id_agente"], "pos_tree" => "3"));
}
echo "- ";
echo "";
if ($lessBranchs == 1)
html_print_image ("operation/tree/no_branch.png", false, array ("style" => 'vertical-align: middle;'));
else
html_print_image ("operation/tree/branch.png", false, array ("style" => 'vertical-align: middle;'));
echo $img;
echo "";
echo " ";
echo str_replace('.png' ,'_ball.png',
str_replace('img', 'img style="vertical-align: middle;"', $agent_info["status_img"])
);
echo " ";
echo str_replace('.png' ,'_ball.png',
str_replace('img', 'img style="vertical-align: middle;"', $agent_info["alert_img"])
);
echo "";
echo " ";
echo $row["nombre"];
echo " (";
echo '';
echo $agent_info["modules"];
echo '';
if ($agent_info["monitor_alertsfired"] > 0)
echo ' : '.$agent_info["monitor_alertsfired"].'';
if ($agent_info["monitor_critical"] > 0)
echo ' : '.$agent_info["monitor_critical"].'';
if ($agent_info["monitor_warning"] > 0)
echo ' : '.$agent_info["monitor_warning"].'';
if ($agent_info["monitor_unknown"] > 0)
echo ' : '.$agent_info["monitor_unknown"].'';
if ($agent_info["monitor_normal"] > 0)
echo ' : '.$agent_info["monitor_normal"].'';
echo ")";
if ($agent_info["last_contact"]!='') {
echo " (";
ui_print_timestamp ($agent_info["last_contact"]);
echo ")";
}
echo "";
echo "";
echo "
";
}
echo "
\n";
break;
//also aknolegment as second subtree/branch
case 'agent_group':
case 'agent_module_group':
case 'agent_os':
case 'agent_policies':
case 'agent_module':
$fatherType = str_replace('agent_', '', $type);
switch ($fatherType) {
case 'group':
$sql = 'SELECT *
FROM tagente_modulo AS t1
INNER JOIN tagente_estado AS t2 ON t1.id_agente_modulo = t2.id_agente_modulo
WHERE t1.id_agente = ' . $id;
break;
case 'os':
$sql = 'SELECT *
FROM tagente_modulo AS t1
INNER JOIN tagente_estado AS t2 ON t1.id_agente_modulo = t2.id_agente_modulo
WHERE t1.id_agente = ' . $id;
break;
case 'module_group':
$sql = 'SELECT *
FROM tagente_modulo AS t1
INNER JOIN tagente_estado AS t2 ON t1.id_agente_modulo = t2.id_agente_modulo
WHERE t1.id_agente = ' . $id . ' AND id_module_group = ' . $id_father;
break;
case 'policies':
$whereQuery = '';
if ($id_father != 0)
$whereQuery = ' AND t1.id_policy_module IN
(SELECT id FROM tpolicy_modules WHERE id_policy = ' . $id_father . ')';
else
$whereQuery = ' AND t1.id_policy_module = 0 ';
$sql = 'SELECT *
FROM tagente_modulo AS t1
INNER JOIN tagente_estado AS t2 ON t1.id_agente_modulo = t2.id_agente_modulo
WHERE t1.id_agente = ' . $id . $whereQuery;
break;
case 'module':
$name = str_replace(array('_articapandora_'.ord(' ').'_pandoraartica_', '_articapandora_'.ord('#').'_pandoraartica_','_articapandora_'.ord('/').'_pandoraartica_'),array(' ','#','/'),$id_father);
switch ($config["dbtype"]) {
case "mysql":
$sql = 'SELECT *
FROM tagente_modulo AS t1
INNER JOIN tagente_estado AS t2 ON t1.id_agente_modulo = t2.id_agente_modulo
WHERE t1.id_agente = ' . $id . ' AND nombre = \'' . io_safe_input($name) . '\'';
break;
case "postgresql":
case "oracle":
$sql = 'SELECT *
FROM tagente_modulo AS t1
INNER JOIN tagente_estado AS t2 ON t1.id_agente_modulo = t2.id_agente_modulo
WHERE t1.id_agente = ' . $id . ' AND nombre = \'' . io_safe_input($name) . '\'';
break;
}
break;
}
// This line checks for initializated modules or (non-initialized) asyncronous modules
$sql .= ' AND disabled = 0 AND (utimestamp > 0 OR id_tipo_modulo IN (21,22,23))';
$countRows = db_get_num_rows($sql);
if ($countRows === 0) {
echo "\n";
echo "- ";
switch ($lessBranchs) {
case 0:
html_print_image ("operation/tree/branch.png", false, array ("style" => 'vertical-align: middle;'));
html_print_image ("operation/tree/branch.png", false, array ("style" => 'vertical-align: middle;'));
break;
case 1:
html_print_image ("operation/tree/no_branch.png", false, array ("style" => 'vertical-align: middle;'));
html_print_image ("operation/tree/branch.png", false, array ("style" => 'vertical-align: middle;'));
break;
case 2:
html_print_image ("operation/tree/branch.png", false, array ("style" => 'vertical-align: middle;'));
html_print_image ("operation/tree/no_branch.png", false, array ("style" => 'vertical-align: middle;'));
break;
case 3:
html_print_image ("operation/tree/no_branch.png", false, array ("style" => 'vertical-align: middle;'));
html_print_image ("operation/tree/no_branch.png", false, array ("style" => 'vertical-align: middle;'));
break;
}
echo "" . __("Empty") . "";
echo "
";
echo "
";
return;
}
$new = true;
$count = 0;
echo "\n";
while($row = db_get_all_row_by_steps_sql($new, $result, $sql)) {
$new = false;
$count++;
echo "- ";
switch ($lessBranchs) {
case 0:
html_print_image ("operation/tree/branch.png", false, array ("style" => 'vertical-align: middle;'));
html_print_image ("operation/tree/branch.png", false, array ("style" => 'vertical-align: middle;'));
break;
case 1:
html_print_image ("operation/tree/no_branch.png", false, array ("style" => 'vertical-align: middle;'));
html_print_image ("operation/tree/branch.png", false, array ("style" => 'vertical-align: middle;'));
break;
case 2:
html_print_image ("operation/tree/branch.png", false, array ("style" => 'vertical-align: middle;'));
html_print_image ("operation/tree/no_branch.png", false, array ("style" => 'vertical-align: middle;'));
break;
case 3:
html_print_image ("operation/tree/no_branch.png", false, array ("style" => 'vertical-align: middle;'));
html_print_image ("operation/tree/no_branch.png", false, array ("style" => 'vertical-align: middle;'));
break;
}
if ($countRows != $count)
html_print_image ("operation/tree/leaf.png", false, array ("style" => 'vertical-align: middle;', "id" => "tree_image_os_" . $row["id_agente"], "pos_tree" => "1" ));
else
html_print_image ("operation/tree/last_leaf.png", false, array ("style" => 'vertical-align: middle;', "id" => "tree_image_os_" . $row["id_agente"], "pos_tree" => "2" ));
// This line checks for (non-initialized) asyncronous modules
if ($row["estado"] == 0 AND $row["utimestamp"] == 0 AND ($row["id_tipo_modulo"] >= 21 AND $row["id_tipo_modulo"] <= 23)){
$status = STATUS_MODULE_NO_DATA;
$title = __('UNKNOWN');
} // Else checks module status
elseif ($row["estado"] == 1) {
$status = STATUS_MODULE_CRITICAL;
$title = __('CRITICAL');
}
elseif ($row["estado"] == 2) {
$status = STATUS_MODULE_WARNING;
$title = __('WARNING');
}
elseif ($row["estado"] == 3) {
$status = STATUS_MODULE_NO_DATA;
$title = __('UNKNOWN');
}
else {
$status = STATUS_MODULE_OK;
$title = __('NORMAL');
}
if (is_numeric($row["datos"])) {
$title .= " : " . format_for_graph($row["datos"]);
}
else {
$title .= " : " . substr(io_safe_output($row["datos"]),0,42);
}
echo str_replace('.png' ,'_ball.png',
str_replace('img', 'img style="vertical-align: middle;"', ui_print_status_image($status, $title,true))
);
echo " ";
echo str_replace('img', 'img style="vertical-align: middle;"', servers_show_type ($row['id_modulo']));
echo " ";
$graph_type = return_graphtype ($row["id_tipo_modulo"]);
$win_handle=dechex(crc32($row["id_agente_modulo"] . $row["nombre"]));
$link ="winopeng('operation/agentes/stat_win.php?type=$graph_type&period=86400&id=".$row["id_agente_modulo"]."&label=".base64_encode($row["nombre"])."&refresh=600','day_".$win_handle."')";
echo '' . html_print_image ("images/chart_curve.png", true, array ("style" => 'vertical-align: middle;', "border" => "0" )) . '';
echo " ";
echo "" . html_print_image ("images/binary.png", true, array ("style" => 'vertical-align: middle;', "border" => "0" )) . "";
echo " ";
echo io_safe_output($row['nombre']);
if (is_numeric($row["datos"]))
$data = format_numeric($row["datos"]);
else
$data = "".substr(io_safe_output($row["datos"]),0,12)."";
echo "";
echo $data;
if ($row['unit'] != '') {
echo " ";
echo '('.$row['unit'].')';
}
if ($row['utimestamp'] != '') {
echo " ";
ui_print_help_tip ($row["timestamp"], '', 'images/clock2.png');
}
echo "
";
}
echo "
\n";
break;
}
return;
}
include_once($config['homedir'] . "/include/functions_groups.php");
include_once($config['homedir'] . "/include/functions_os.php");
include_once($config['homedir'] . "/include/functions_modules.php");
include_once($config['homedir'] . "/include/functions_servers.php");
include_once($config['homedir'] . "/include/functions_reporting.php");
include_once($config['homedir'] . "/include/functions_ui.php");
function printTree_($type) {
global $config;
$search_free = get_parameter('search_free', '');
$select_status = get_parameter('status', -1);
echo '';
echo '';
//Get all groups
$avariableGroups = users_get_groups (); //db_get_all_rows_in_table('tgrupo', 'nombre');
//Get all groups with agents
$full_groups = db_get_all_rows_sql("SELECT DISTINCT tagente.id_grupo FROM tagente, tagente_estado WHERE
tagente.id_agente = tagente_estado.id_agente AND tagente_estado.utimestamp != 0
UNION SELECT tagente.id_grupo FROM tagente
WHERE disabled = 0
AND id_agente NOT IN (SELECT tagente.id_agente
FROM tagente, tagente_modulo
WHERE tagente.id_agente = tagente_modulo.id_agente
AND tagente.disabled = 0
AND tagente_modulo.disabled = 0
group by tagente.id_agente
having COUNT(*) > 0)");
$fgroups = array();
foreach ($full_groups as $fg) {
$fgroups[$fg['id_grupo']] = "";
}
// We only want groups with agents, so we need the intesect of both arrays.
// Not for policies, we need all groups
if ($type != 'policies')
$avariableGroups = array_intersect_key($avariableGroups, $fgroups);
$avariableGroupsIds = implode(',',array_keys($avariableGroups));
if($avariableGroupsIds == ''){
$avariableGroupsIds == -1;
}
if ($type !== 'policies') {
// Filter groups by agent status
switch ($select_status) {
case NORMAL:
foreach ($avariableGroups as $group_name) {
$id_group = db_get_value_sql('SELECT id_grupo FROM tgrupo where nombre ="' . $group_name . '"');
$num_ok = groups_agent_ok($id_group);
if ($num_ok <= 0)
unset($avariableGroups[$id_group]);
}
break;
case WARNING:
foreach ($avariableGroups as $group_name) {
$id_group = db_get_value_sql('SELECT id_grupo FROM tgrupo where nombre ="' . $group_name . '"');
$num_warning = groups_agent_warning($id_group);
if ($num_warning <= 0)
unset($avariableGroups[$id_group]);
}
break;
case CRITICAL:
foreach ($avariableGroups as $group_name) {
$id_group = db_get_value_sql('SELECT id_grupo FROM tgrupo where nombre ="' . $group_name . '"');
$num_critical = groups_agent_critical($id_group);
if ($num_critical <= 0)
unset($avariableGroups[$id_group]);
}
break;
case UNKNOWN:
foreach ($avariableGroups as $group_name) {
$id_group = db_get_value_sql('SELECT id_grupo FROM tgrupo where nombre ="' . $group_name . '"');
$num_unknown = groups_agent_unknown($id_group);
if ($num_unknown <= 0)
unset($avariableGroups[$id_group]);
}
break;
}
// If there are not groups display error and return
if (empty($avariableGroups)) {
ui_print_error_message("There aren't agents in this agrupation");
echo ' |
';
echo '
';
return;
}
}
if ($search_free != '') {
$sql_search = " AND id_grupo IN (SELECT id_grupo FROM tagente
WHERE nombre COLLATE utf8_general_ci LIKE '%$search_free%')";
} else {
$sql_search ='';
}
switch ($type) {
default:
case 'os':
//Skip agent with all modules in not init status
$sql_search .= " AND id_agente NOT IN (SELECT tagente_estado.id_agente FROM
tagente_estado GROUP BY id_agente HAVING SUM(utimestamp) = 0)";
$sql = agents_get_agents(array (
'order' => 'nombre COLLATE utf8_general_ci ASC',
'disabled' => 0,
'status' => $select_status,
'search' => $sql_search),
array ('tagente.id_os'),
'AR',
false,
true);
$sql_os = sprintf("SELECT * FROM tconfig_os WHERE id_os IN (%s)", $sql);
$list = db_get_all_rows_sql($sql_os);
break;
case 'group':
$stringAvariableGroups = (
implode(', ',
array_map(
create_function('&$itemA', '{ return "\'" . $itemA . "\'"; }'), $avariableGroups
)
)
);
switch ($config["dbtype"]) {
case "mysql":
case "postgresql":
$list = db_get_all_rows_sql("SELECT * FROM tgrupo WHERE nombre IN (" . $stringAvariableGroups . ") $sql_search");
break;
case "oracle":
$list = db_get_all_rows_sql("SELECT * FROM tgrupo WHERE dbms_lob.substr(nombre,4000,1) IN (" . $stringAvariableGroups . ")");
break;
}
break;
case 'module_group':
//Skip agents which only have not init modules
$sql_search .= " AND id_agente NOT IN (SELECT tagente_estado.id_agente FROM
tagente_estado GROUP BY id_agente HAVING SUM(utimestamp) = 0)";
$sql = agents_get_agents(array (
'order' => 'nombre COLLATE utf8_general_ci ASC',
'disabled' => 0,
'status' => $select_status,
'search' => $sql_search),
array ('id_agente'),
'AR',
false,
true);
// Skip agents without modules
$sql .= ' AND id_agente IN
(SELECT tagente.id_agente
FROM tagente, tagente_modulo
WHERE tagente.id_agente = tagente_modulo.id_agente
AND tagente.disabled = 0
AND tagente_modulo.disabled = 0
group by tagente.id_agente
having COUNT(*) > 0)';
$sql_module_groups = sprintf("SELECT * FROM tmodule_group
WHERE id_mg IN (SELECT id_module_group FROM tagente_modulo WHERE id_agente IN (%s))", $sql);
$list = db_get_all_rows_sql($sql_module_groups);
if ($list == false) {
$list = array();
}
array_push($list, array('id_mg' => 0, 'name' => 'Not assigned'));
break;
case 'policies':
$avariableGroups = users_get_groups ();
$groups_id = array_keys($avariableGroups);
$groups = implode(',',$groups_id);
if ($search_free != '') {
$sql = "SELECT DISTINCT tpolicies.id, tpolicies.name FROM tpolicies, tpolicy_modules, tagente_estado, tagente, tagente_modulo WHERE
tagente.id_agente = tagente_estado.id_agente AND tagente_modulo.id_agente = tagente_estado.id_agente AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo AND
tagente_estado.utimestamp != 0 AND tagente_modulo.id_policy_module != 0 AND tpolicy_modules.id = tagente_modulo.id_policy_module AND tpolicies.id = tpolicy_modules.id_policy AND
tagente.id_grupo IN ($groups) AND tagente.nombre LIKE '%$search_free%' AND tagente.disabled = 0 AND tagente_modulo.disabled = 0";
$list = db_get_all_rows_sql($sql);
if ($list === false)
$list = array();
$element = 0;
switch ($select_status) {
case NORMAL:
foreach ($list as $policy_element) {
$policy_agents_ok = policies_agents_ok($policy_element['id']);
if ($policy_agents_ok <= 0)
unset($list[$element]);
$element++;
}
break;
case CRITICAL:
foreach ($list as $policy_element) {
$policy_agents_critical = policies_agents_critical($policy_element['id']);
if ($policy_agents_critical <= 0)
unset($list[$element]);
$element++;
}
break;
case WARNING:
foreach ($list as $policy_element) {
$policy_agents_warning = policies_agents_warning($policy_element['id']);
if ($policy_agents_warning <= 0)
unset($list[$element]);
$element++;
}
break;
case UNKNOWN:
foreach ($list as $policy_element) {
$policy_agents_unknown = policies_agents_unknown($policy_element['id']);
if ($policy_agents_unknown <= 0)
unset($list[$element]);
$element++;
}
break;
}
if ($list === false)
$list = array();
array_push($list, array('id' => 0, 'name' => 'No policy'));
} else {
$list = db_get_all_rows_sql("SELECT DISTINCT tpolicies.id, tpolicies.name FROM tpolicies, tpolicy_modules, tagente_estado, tagente, tagente_modulo WHERE
tagente.id_agente = tagente_estado.id_agente AND tagente_modulo.id_agente = tagente_estado.id_agente AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo AND
tagente_estado.utimestamp != 0 AND tagente_modulo.id_policy_module != 0 AND tpolicy_modules.id = tagente_modulo.id_policy_module AND tpolicies.id = tpolicy_modules.id_policy AND
tagente.id_grupo IN ($groups) AND tagente.disabled = 0 AND tagente_modulo.disabled = 0");
$element = 0;
switch ($select_status) {
case NORMAL:
foreach ($list as $policy_element) {
$policy_agents_ok = policies_agents_ok($policy_element['id']);
if ($policy_agents_ok <= 0)
unset($list[$element]);
$element++;
}
break;
case CRITICAL:
foreach ($list as $policy_element) {
$policy_agents_critical = policies_agents_critical($policy_element['id']);
if ($policy_agents_critical <= 0)
unset($list[$element]);
$element++;
}
break;
case WARNING:
foreach ($list as $policy_element) {
$policy_agents_warning = policies_agents_warning($policy_element['id']);
if ($policy_agents_warning <= 0)
unset($list[$element]);
$element++;
}
break;
case UNKNOWN:
foreach ($list as $policy_element) {
$policy_agents_unknown = policies_agents_unknown($policy_element['id']);
if ($policy_agents_unknown <= 0)
unset($list[$element]);
$element++;
}
break;
}
if ($list === false)
$list = array();
array_push($list, array('id' => 0, 'name' => 'No policy'));
}
break;
case 'module':
$avariableGroupsIds = implode(',',array_keys($avariableGroups));
if($avariableGroupsIds == ''){
$avariableGroupsIds == -1;
}
if ($search_free != '') {
$sql_search = " AND t1.id_agente IN (SELECT id_agente FROM tagente
WHERE nombre COLLATE utf8_general_ci LIKE '%$search_free%')";
} else {
$sql_search = '';
}
if ($select_status != -1)
$sql_search .= " AND estado = " . $select_status . " ";
switch ($config["dbtype"]) {
case "mysql":
case "postgresql":
$list = db_get_all_rows_sql('SELECT t1.nombre
FROM tagente_modulo t1, tagente t2, tagente_estado t3
WHERE t1.id_agente = t2.id_agente AND t1.id_agente_modulo = t3.id_agente_modulo
AND t2.disabled = 0 AND t1.disabled = 0
AND t3.utimestamp !=0 AND t2.id_grupo in (' . $avariableGroupsIds . ')' .$sql_search.'
GROUP BY t1.nombre ORDER BY t1.nombre');
break;
case "oracle":
$list = db_get_all_rows_sql('SELECT dbms_lob.substr(t1.nombre,4000,1) as nombre
FROM tagente_modulo t1, tagente t2, tagente_estado t3
WHERE t1.id_agente = t2.id_agente AND t2.id_grupo in (' . $avariableGroupsIds . ') AND t1.id_agente_modulo = t3.id_agente_modulo
AND t2.disabled = 0 AND t1.disabled = 0 AND t3.utimestamp !=0 GROUP BY dbms_lob.substr(t1.nombre,4000,1) ORDER BY dbms_lob.substr(t1.nombre,4000,1) ASC');
break;
}
break;
}
if ($list === false) {
ui_print_error_message("There aren't agents in this agrupation");
echo '';
echo '';
}
else {
echo "\n";
$first = true;
foreach ($list as $item) {
$iconImg = '';
switch ($type) {
default:
case 'os':
$id = $item['id_os'];
$name = $item['name'];
$iconImg = html_print_image(str_replace('.png' ,'_small.png', ui_print_os_icon ($item['id_os'], false, true, false)) . " ", true);
$num_ok = os_agents_ok($id);
$num_critical = os_agents_critical($id);
$num_warning = os_agents_warning($id);
$num_unknown = os_agents_unknown($id);
break;
case 'group':
$id = $item['id_grupo'];
$name = $item['nombre'];
$iconImg = html_print_image ("images/groups_small/" . groups_get_icon($item['id_grupo']).".png", true, array ("style" => 'vertical-align: middle; width: 16px; height: 16px;'));
$num_ok = groups_agent_ok($id);
$num_critical = groups_agent_critical($id);
$num_warning = groups_agent_warning($id);
$num_unknown = groups_agent_unknown ($id);
break;
case 'module_group':
$id = $item['id_mg'];
$name = $item['name'];
$num_ok = modules_group_agent_ok($id);
$num_critical = modules_group_agent_critical ($id);
$num_warning = modules_group_agent_warning($id);
$num_unknown = modules_group_agent_unknown($id);
break;
case 'policies':
$id = $item['id'];
$name = $item['name'];
$num_ok = policies_agents_ok($id);
$num_critical = policies_agents_critical($id);
$num_warning = policies_agents_warning($id);
$num_unknown = policies_agents_unknown($id);
break;
case 'module':
$id = str_replace(array(' ','#','/'), array('_articapandora_'.ord(' ').'_pandoraartica_', '_articapandora_'.ord('#').'_pandoraartica_', '_articapandora_'.ord('/').'_pandoraartica_'),io_safe_output($item['nombre']));
$name = io_safe_output($item['nombre']);
$module_name = $item['nombre'];
$num_ok = modules_agents_ok($module_name);
$num_critical = modules_agents_critical($module_name);
$num_warning = modules_agents_warning($module_name);
$num_unknown = modules_agents_unknown($module_name);
break;
}
$lessBranchs = 0;
if ($first) {
if ($item != end($list)) {
$img = html_print_image ("operation/tree/first_closed.png", true, array ("style" => 'vertical-align: middle;', "id" => "tree_image_" . $type . "_" . $id, "pos_tree" => "0"));
$first = false;
}
else {
$lessBranchs = 1;
$img = html_print_image ("operation/tree/one_closed.png", true, array ("style" => 'vertical-align: middle;', "id" => "tree_image_" . $type . "_" . $id, "pos_tree" => "1"));
}
}
else {
if ($item != end($list))
$img = html_print_image ("operation/tree/closed.png", true, array ("style" => 'vertical-align: middle;', "id" => "tree_image_" . $type . "_" . $id, "pos_tree" => "2"));
else
{
$lessBranchs = 1;
$img = html_print_image ("operation/tree/last_closed.png", true, array ("style" => 'vertical-align: middle;', "id" => "tree_image_" . $type . "_" . $id, "pos_tree" => "3"));
}
}
echo "-
" .
$img . $iconImg ." " . __($name) . ' ('.
''.''.$num_ok.''.''.
' : '.$num_critical.'' .
' : '.$num_warning.''.
' : '.$num_unknown.''.') '. "";
echo "";
echo "
\n";
}
echo "
\n";
echo '';
echo '';
echo ' ';
echo ' ';
echo' ';
echo ' | ';
echo '';
}
}
global $config;
$enterpriseEnable = false;
if (enterprise_include_once('include/functions_policies.php') !== ENTERPRISE_NOT_HOOK) {
$enterpriseEnable = true;
}
///////// INI MENU AND TABS /////////////
$img_style = array ("class" => "top", "width" => 16);
$activeTab = get_parameter('sort_by','group');
$os_tab = array('text' => ""
. html_print_image ("images/computer.png", true, array ("title" => __('OS'))) . "", 'active' => $activeTab == "os");
$group_tab = array('text' => ""
. html_print_image ("images/group.png", true, array ("title" => __('Groups'))) . "", 'active' => $activeTab == "group");
$module_group_tab = array('text' => ""
. html_print_image ("images/agents_group.png", true, array ("title" => __('Module groups'))) . "", 'active' => $activeTab == "module_group");
if ($enterpriseEnable) {
$policies_tab = array('text' => ""
. html_print_image ("images/policies.png", true, array ("title" => __('Policies'))) . "", 'active' => $activeTab == "policies");
} else {
$policies_tab = '';
}
$module_tab = array('text' => ""
. html_print_image ("images/brick.png", true, array ("title" => __('Modules'))) . "", 'active' => $activeTab == "module");
$onheader = array('os' => $os_tab, 'group' => $group_tab, 'module_group' => $module_group_tab, 'policies' => $policies_tab, 'module' => $module_tab);
switch ($activeTab) {
case 'group':
$order = __('groups');
break;
case 'module_group':
$order = __('module groups');
break;
case 'policies':
$order = __('policies');
break;
case 'module':
$order = __('modules');
break;
case 'os':
$order = __('OS');
break;
}
ui_print_page_header (__('Tree view')." - ".__('Sort the agents by ') .$order, "images/extensions.png", false, "", false, $onheader);
echo "
";
echo '";
echo "";
echo "";
echo "";
///////// END MENU AND TABS /////////////
printTree_($activeTab);
?>