mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-28 08:14:38 +02:00
Lot of work on the data retrieving and processing
This commit is contained in:
parent
39486ea9fc
commit
2e9b861d7c
@ -68,10 +68,8 @@ class Tree {
|
|||||||
html_debug_print($list_os);
|
html_debug_print($list_os);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getRecursiveGroup($parent, $limit = null) {
|
private function getGroupsRecursive($parent, $limit = null, $get_agents = true) {
|
||||||
$filter = array();
|
$filter = array();
|
||||||
|
|
||||||
|
|
||||||
$filter['parent'] = $parent;
|
$filter['parent'] = $parent;
|
||||||
|
|
||||||
if (!empty($this->filter['search'])) {
|
if (!empty($this->filter['search'])) {
|
||||||
@ -79,39 +77,34 @@ class Tree {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// First filter by name and father
|
// First filter by name and father
|
||||||
$groups = db_get_all_rows_filter('tgrupo',
|
$groups = db_get_all_rows_filter('tgrupo', $filter, array('id_grupo', 'nombre'));
|
||||||
$filter,
|
|
||||||
array('id_grupo', 'nombre'));
|
|
||||||
if (empty($groups))
|
if (empty($groups))
|
||||||
$groups = array();
|
$groups = array();
|
||||||
|
|
||||||
|
|
||||||
// Filter by status
|
// Filter by status
|
||||||
$filter_status = AGENT_STATUS_ALL;
|
$filter_status = AGENT_STATUS_ALL;
|
||||||
if (!empty($this->filter['status'])) {
|
if (!empty($this->filter['status'])) {
|
||||||
$filter_status = $this->filter['status'];
|
$filter_status = $this->filter['status'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
foreach ($groups as $iterator => $group) {
|
foreach ($groups as $iterator => $group) {
|
||||||
$data = reporting_get_group_stats($group['id_grupo']);
|
// Counters
|
||||||
|
$group_stats = reporting_get_group_stats($group['id_grupo']);
|
||||||
$groups[$iterator]['icon'] = groups_get_icon($group['id_grupo']) . '.png';
|
|
||||||
|
|
||||||
$groups[$iterator]['counters'] = array();
|
$groups[$iterator]['counters'] = array();
|
||||||
|
if (!empty($group_stats)) {
|
||||||
|
$groups[$iterator]['counters']['unknown'] = $group_stats['agents_unknown'];
|
||||||
|
$groups[$iterator]['counters']['critical'] = $group_stats['agent_critical'];
|
||||||
|
$groups[$iterator]['counters']['warning'] = $group_stats['agent_warning'];
|
||||||
|
$groups[$iterator]['counters']['not_init'] = $group_stats['agent_not_init'];
|
||||||
|
$groups[$iterator]['counters']['ok'] = $group_stats['agent_ok'];
|
||||||
|
$groups[$iterator]['counters']['total'] = $group_stats['total_agents'];
|
||||||
|
}
|
||||||
|
|
||||||
$groups[$iterator]['counters']['unknown'] = $data['agents_unknown'];
|
$groups[$iterator]['status'] = $group_stats['status'];
|
||||||
$groups[$iterator]['counters']['critical'] = $data['agent_critical'];
|
$groups[$iterator]['icon'] = groups_get_icon($group['id_grupo']) . '.png';
|
||||||
$groups[$iterator]['counters']['warning'] = $data['agent_warning'];
|
|
||||||
$groups[$iterator]['counters']['not_init'] = $data['agent_not_init'];
|
|
||||||
$groups[$iterator]['counters']['ok'] = $data['agent_ok'];
|
|
||||||
$groups[$iterator]['counters']['total'] = $data['total_agents'];
|
|
||||||
$groups[$iterator]['status'] = $data['status'];
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Filter by status
|
||||||
if ($filter_status != AGENT_STATUS_ALL) {
|
if ($filter_status != AGENT_STATUS_ALL) {
|
||||||
$remove_group = true;
|
$remove_group = true;
|
||||||
switch ($filter_status) {
|
switch ($filter_status) {
|
||||||
@ -145,134 +138,134 @@ class Tree {
|
|||||||
|
|
||||||
if (is_null($limit)) {
|
if (is_null($limit)) {
|
||||||
$groups[$iterator]['children'] =
|
$groups[$iterator]['children'] =
|
||||||
$this->getRecursiveGroup($group['id_grupo']);
|
$this->getGroupsRecursive($group['id_grupo']);
|
||||||
}
|
}
|
||||||
else if ($limit >= 1) {
|
else if ($limit >= 1) {
|
||||||
$groups[$iterator]['children'] =
|
$groups[$iterator]['children'] =
|
||||||
$this->getRecursiveGroup(
|
$this->getGroupsRecursive(
|
||||||
$group['id_grupo'],
|
$group['id_grupo'],
|
||||||
($limit - 1));
|
($limit - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch ($this->countAgentStatusMethod) {
|
||||||
|
case 'on_demand':
|
||||||
|
$groups[$iterator]['searchCounters'] = 1;
|
||||||
|
break;
|
||||||
|
case 'live':
|
||||||
|
$groups[$iterator]['searchCounters'] = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
switch ($this->childrenMethod) {
|
||||||
|
case 'on_demand':
|
||||||
|
// if (!empty($groups[$iterator]['children'])) {
|
||||||
|
// $groups[$iterator]['searchChildren'] = 1;
|
||||||
|
// }
|
||||||
|
// else {
|
||||||
|
// $groups[$iterator]['searchChildren'] = 0;
|
||||||
|
// }
|
||||||
|
$groups[$iterator]['searchChildren'] = 0;
|
||||||
|
break;
|
||||||
|
case 'live':
|
||||||
|
$groups[$iterator]['searchChildren'] = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
$groups[$iterator]['type'] = 'group';
|
$groups[$iterator]['type'] = 'group';
|
||||||
$groups[$iterator]['name'] = $groups[$iterator]['nombre'];
|
$groups[$iterator]['name'] = $groups[$iterator]['nombre'];
|
||||||
$groups[$iterator]['id'] = $groups[$iterator]['id_grupo'];
|
$groups[$iterator]['id'] = $groups[$iterator]['id_grupo'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($parent == 0) {
|
if (!empty($parent) && $get_agents) {
|
||||||
$agents = array();
|
$agents = $this->getAgents($parent, 'group');
|
||||||
}
|
|
||||||
else {
|
if (!empty($agents))
|
||||||
$agents = $this->getDataAgents('group', $parent);
|
$groups = array_merge($groups, $agents);
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = array_merge($groups, $agents);
|
return $groups;
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDataGroup() {
|
public function getDataGroup() {
|
||||||
|
// Get the parent
|
||||||
if (!empty($this->root)) {
|
if (empty($this->root))
|
||||||
$parent = $this->root;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$parent = 0;
|
$parent = 0;
|
||||||
}
|
else
|
||||||
|
$parent = $this->root;
|
||||||
|
|
||||||
$data = $this->getRecursiveGroup($parent, 1);
|
$groups = $this->getGroupsRecursive($parent);
|
||||||
|
|
||||||
// Make the data
|
if (empty($groups))
|
||||||
$this->tree = array();
|
$groups = array();
|
||||||
foreach ($data as $item) {
|
|
||||||
$temp = array();
|
$this->tree = $groups;
|
||||||
$temp['id'] = $item['id'];
|
}
|
||||||
$temp['type'] = $item['type'];
|
|
||||||
$temp['name'] = $item['name'];
|
public function getModules ($parent = 0) {
|
||||||
$temp['icon'] = $item['icon'];
|
$modules = array();
|
||||||
$temp['status'] = $item['status'];
|
|
||||||
switch ($this->countAgentStatusMethod) {
|
$modules_aux = agents_get_modules($parent, array('nombre', 'id_tipo_modulo'));
|
||||||
case 'on_demand':
|
|
||||||
$temp['searchCounters'] = 1;
|
if (empty($modules_aux))
|
||||||
|
$modules_aux = array();
|
||||||
|
|
||||||
|
// Process the modules
|
||||||
|
foreach ($modules_aux as $id => $module) {
|
||||||
|
$module['type'] = 'module';
|
||||||
|
$module['id'] = $id;
|
||||||
|
$module['name'] = $module['nombre'];
|
||||||
|
$module['icon'] = modules_get_type_icon($module['id_tipo_modulo']);
|
||||||
|
$module['value'] = modules_get_last_value($id);
|
||||||
|
|
||||||
|
// Status
|
||||||
|
switch (modules_get_status($id)) {
|
||||||
|
case AGENT_MODULE_STATUS_CRITICAL_BAD:
|
||||||
|
case AGENT_MODULE_STATUS_CRITICAL_ALERT:
|
||||||
|
$module['status'] = "critical";
|
||||||
break;
|
break;
|
||||||
case 'live':
|
case AGENT_MODULE_STATUS_WARNING:
|
||||||
$temp['searchCounters'] = 0;
|
case AGENT_MODULE_STATUS_WARNING_ALERT:
|
||||||
$temp['counters'] = $item['counters'];
|
$module['status'] = "warning";
|
||||||
break;
|
break;
|
||||||
}
|
case AGENT_MODULE_STATUS_UNKNOWN:
|
||||||
switch ($this->childrenMethod) {
|
$module['status'] = "unknown";
|
||||||
case 'on_demand':
|
|
||||||
if (!empty($item['children'])) {
|
|
||||||
$temp['searchChildren'] = 1;
|
|
||||||
// I hate myself
|
|
||||||
// No add children
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$temp['searchChildren'] = 0;
|
|
||||||
// I hate myself
|
|
||||||
// No add children
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 'live':
|
case AGENT_MODULE_STATUS_NO_DATA:
|
||||||
$temp['searchChildren'] = 0;
|
case AGENT_MODULE_STATUS_NOT_INIT:
|
||||||
$temp['children'] = $item['children'];
|
$module['status'] = "not_init";
|
||||||
|
break;
|
||||||
|
case AGENT_MODULE_STATUS_NORMAL:
|
||||||
|
case AGENT_MODULE_STATUS_NORMAL_ALERT:
|
||||||
|
default:
|
||||||
|
$module['status'] = "ok";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->tree[] = $temp;
|
$modules[] = $module;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $modules;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDataModules() {
|
public function getDataModules() {
|
||||||
$modules =
|
// Get the parent
|
||||||
agents_get_modules($this->root, array('nombre', 'id_tipo_modulo'));
|
if (empty($this->root))
|
||||||
|
$parent = 0;
|
||||||
|
else
|
||||||
|
$parent = $this->root;
|
||||||
|
|
||||||
|
//$modules = $this->getModules($parent);
|
||||||
|
|
||||||
if (empty($modules))
|
if (empty($modules))
|
||||||
$modules = array();
|
$modules = array();
|
||||||
|
|
||||||
$this->tree = array();
|
$this->tree = $modules;
|
||||||
foreach ($modules as $id => $module) {
|
|
||||||
$temp = array();
|
|
||||||
|
|
||||||
$temp['type'] = 'module';
|
|
||||||
$temp['id'] = $id;
|
|
||||||
$temp['name'] = $module['nombre'];
|
|
||||||
$temp['icon'] = modules_get_type_icon(
|
|
||||||
$module['id_tipo_modulo']);
|
|
||||||
$temp['value'] = modules_get_last_value($id);
|
|
||||||
switch (modules_get_status($id)) {
|
|
||||||
case AGENT_MODULE_STATUS_CRITICAL_BAD:
|
|
||||||
case AGENT_MODULE_STATUS_CRITICAL_ALERT:
|
|
||||||
$temp['status'] = "critical";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
case AGENT_MODULE_STATUS_NORMAL:
|
|
||||||
case AGENT_MODULE_STATUS_NORMAL_ALERT:
|
|
||||||
$temp['status'] = "ok";
|
|
||||||
break;
|
|
||||||
case AGENT_MODULE_STATUS_WARNING:
|
|
||||||
case AGENT_MODULE_STATUS_WARNING_ALERT:
|
|
||||||
$temp['status'] = "warning";
|
|
||||||
break;
|
|
||||||
case AGENT_MODULE_STATUS_UNKNOWN:
|
|
||||||
$temp['status'] = "unknown";
|
|
||||||
break;
|
|
||||||
case AGENT_MODULE_STATUS_NO_DATA:
|
|
||||||
case AGENT_MODULE_STATUS_NOT_INIT:
|
|
||||||
$temp['status'] = "not_init";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
$temp['children'] = array();
|
|
||||||
|
|
||||||
$this->tree[] = $temp;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDataAgents($type, $id) {
|
public function getAgents ($parent = 0, $parentType = '') {
|
||||||
switch ($type) {
|
switch ($parentType) {
|
||||||
case 'group':
|
case 'group':
|
||||||
$filter = array(
|
$filter = array(
|
||||||
'id_grupo' => $id,
|
'id_grupo' => $parent,
|
||||||
'status' => $this->filter['status'],
|
'status' => $this->filter['status'],
|
||||||
'nombre' => "%" . $this->filter['search'] . "%"
|
'nombre' => "%" . $this->filter['search'] . "%"
|
||||||
);
|
);
|
||||||
@ -282,17 +275,19 @@ class Tree {
|
|||||||
$agents = array();
|
$agents = array();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
return array();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($agents as $iterator => $agent) {
|
foreach ($agents as $iterator => $agent) {
|
||||||
$agents[$iterator]['type'] = 'agent';
|
$agents[$iterator]['type'] = 'agent';
|
||||||
$agents[$iterator]['id'] = $agents[$iterator]['id_agente'];
|
$agents[$iterator]['id'] = $agents[$iterator]['id_agente'];
|
||||||
$agents[$iterator]['name'] = $agents[$iterator]['nombre'];
|
$agents[$iterator]['name'] = $agents[$iterator]['nombre'];
|
||||||
$agents[$iterator]['icon'] =
|
$agents[$iterator]['icon'] = ui_print_os_icon( $agents[$iterator]["id_os"],
|
||||||
ui_print_os_icon(
|
false, true, true, false, true, true);
|
||||||
$agents[$iterator]["id_os"], false, true, true,
|
|
||||||
false, true, true);
|
|
||||||
|
|
||||||
|
// Counters
|
||||||
$agents[$iterator]['counters'] = array();
|
$agents[$iterator]['counters'] = array();
|
||||||
$agents[$iterator]['counters']['unknown'] =
|
$agents[$iterator]['counters']['unknown'] =
|
||||||
agents_monitor_unknown($agents[$iterator]['id']);
|
agents_monitor_unknown($agents[$iterator]['id']);
|
||||||
@ -308,6 +303,8 @@ class Tree {
|
|||||||
agents_monitor_total($agents[$iterator]['id']);
|
agents_monitor_total($agents[$iterator]['id']);
|
||||||
$agents[$iterator]['counters']['alerts'] =
|
$agents[$iterator]['counters']['alerts'] =
|
||||||
agents_get_alerts_fired($agents[$iterator]['id']);
|
agents_get_alerts_fired($agents[$iterator]['id']);
|
||||||
|
|
||||||
|
// Status
|
||||||
switch (agents_get_status($agents[$iterator]['id'])) {
|
switch (agents_get_status($agents[$iterator]['id'])) {
|
||||||
case AGENT_STATUS_NORMAL:
|
case AGENT_STATUS_NORMAL:
|
||||||
$agents[$iterator]['status'] = "ok";
|
$agents[$iterator]['status'] = "ok";
|
||||||
@ -329,19 +326,26 @@ class Tree {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Children
|
||||||
$agents[$iterator]['children'] = array();
|
$agents[$iterator]['children'] = array();
|
||||||
if ($agents[$iterator]['counters']['total'] > 0) {
|
if ($agents[$iterator]['counters']['total'] > 0) {
|
||||||
|
|
||||||
|
|
||||||
switch ($this->childrenMethod) {
|
switch ($this->childrenMethod) {
|
||||||
case 'on_demand':
|
case 'on_demand':
|
||||||
$agents[$iterator]['children'] = 1;
|
$agents[$iterator]['searchChildren'] = 1;
|
||||||
break;
|
break;
|
||||||
case 'live':
|
case 'live':
|
||||||
$modules =
|
$agents[$iterator]['searchChildren'] = 0;
|
||||||
agents_get_modules($agents[$iterator]['id_agente']);
|
$agents[$iterator]['children'] = $this->getModules($agents[$iterator]['id']);
|
||||||
// TO DO
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
switch ($this->childrenMethod) {
|
||||||
|
case 'on_demand':
|
||||||
|
$agents[$iterator]['searchChildren'] = 0;
|
||||||
|
break;
|
||||||
|
case 'live':
|
||||||
|
$agents[$iterator]['searchChildren'] = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -351,6 +355,10 @@ class Tree {
|
|||||||
return $agents;
|
return $agents;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getDataAgents($type, $id) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public function getDataModuleGroup() {
|
public function getDataModuleGroup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user