Error fixes related with the data retrieving for the tree views on the metaconsole
This commit is contained in:
parent
c755d7a326
commit
1127737f83
|
@ -34,6 +34,7 @@ if (is_ajax ()) {
|
||||||
$rootType = get_parameter('rootType', '');
|
$rootType = get_parameter('rootType', '');
|
||||||
$id = get_parameter('id', -1);
|
$id = get_parameter('id', -1);
|
||||||
$rootID = get_parameter('rootID', -1);
|
$rootID = get_parameter('rootID', -1);
|
||||||
|
$serverID = get_parameter('serverID', false);
|
||||||
$childrenMethod = get_parameter('childrenMethod', 'on_demand');
|
$childrenMethod = get_parameter('childrenMethod', 'on_demand');
|
||||||
|
|
||||||
$default_filters = array(
|
$default_filters = array(
|
||||||
|
@ -45,10 +46,10 @@ if (is_ajax ()) {
|
||||||
$filter = get_parameter('filter', $default_filters);
|
$filter = get_parameter('filter', $default_filters);
|
||||||
|
|
||||||
if (class_exists('TreeEnterprise')) {
|
if (class_exists('TreeEnterprise')) {
|
||||||
$tree = new TreeEnterprise($type, $rootType, $id, $rootID, $childrenMethod);
|
$tree = new TreeEnterprise($type, $rootType, $id, $rootID, $serverID, $childrenMethod);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$tree = new Tree($type, $rootType, $id, $rootID, $childrenMethod);
|
$tree = new Tree($type, $rootType, $id, $rootID, $serverID, $childrenMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
$tree->setFilter($filter);
|
$tree->setFilter($filter);
|
||||||
|
@ -56,32 +57,6 @@ if (is_ajax ()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($getGroupStatus) {
|
|
||||||
$id = (int)get_parameter('id', 0);
|
|
||||||
$type = get_parameter('type', 'group');
|
|
||||||
$id = 0;
|
|
||||||
|
|
||||||
$status = array();
|
|
||||||
|
|
||||||
switch ($type) {
|
|
||||||
case 'group':
|
|
||||||
$data = reporting_get_group_stats($id);
|
|
||||||
|
|
||||||
$status['unknown'] = $data['agents_unknown'];
|
|
||||||
$status['critical'] = $data['agent_critical'];
|
|
||||||
$status['warning'] = $data['agent_warning'];
|
|
||||||
$status['not_init'] = $data['agent_not_init'];
|
|
||||||
$status['ok'] = $data['agent_ok'];
|
|
||||||
$status['total'] = $data['total_agents'];
|
|
||||||
$status['status'] = $data['status'];
|
|
||||||
$status['alert_fired'] = $data['alert_fired'];
|
|
||||||
|
|
||||||
echo json_encode($status);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($getDetail) {
|
if ($getDetail) {
|
||||||
require_once($config['homedir']."/include/functions_treeview.php");
|
require_once($config['homedir']."/include/functions_treeview.php");
|
||||||
|
|
||||||
|
@ -92,7 +67,9 @@ if (is_ajax ()) {
|
||||||
if (defined ('METACONSOLE')) {
|
if (defined ('METACONSOLE')) {
|
||||||
$server_id = (int) get_parameter('serverID');
|
$server_id = (int) get_parameter('serverID');
|
||||||
$server = metaconsole_get_servers($server_id);
|
$server = metaconsole_get_servers($server_id);
|
||||||
metaconsole_connect($server);
|
|
||||||
|
if (metaconsole_connect($server) != NOERR)
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ob_clean();
|
ob_clean();
|
||||||
|
|
|
@ -18,6 +18,7 @@ class Tree {
|
||||||
protected $rootType = null;
|
protected $rootType = null;
|
||||||
protected $id = -1;
|
protected $id = -1;
|
||||||
protected $rootID = -1;
|
protected $rootID = -1;
|
||||||
|
protected $serverID = false;
|
||||||
protected $tree = array();
|
protected $tree = array();
|
||||||
protected $filter = array();
|
protected $filter = array();
|
||||||
protected $childrenMethod = "on_demand";
|
protected $childrenMethod = "on_demand";
|
||||||
|
@ -27,12 +28,13 @@ class Tree {
|
||||||
protected $strictACL = false;
|
protected $strictACL = false;
|
||||||
protected $acltags = false;
|
protected $acltags = false;
|
||||||
|
|
||||||
public function __construct($type, $rootType = '', $id = -1, $rootID = -1, $childrenMethod = "on_demand") {
|
public function __construct($type, $rootType = '', $id = -1, $rootID = -1, $serverID = false, $childrenMethod = "on_demand") {
|
||||||
|
|
||||||
$this->type = $type;
|
$this->type = $type;
|
||||||
$this->rootType = !empty($rootType) ? $rootType : $type;
|
$this->rootType = !empty($rootType) ? $rootType : $type;
|
||||||
$this->id = $id;
|
$this->id = $id;
|
||||||
$this->rootID = !empty($rootID) ? $rootID : $id;
|
$this->rootID = !empty($rootID) ? $rootID : $id;
|
||||||
|
$this->serverID = $serverID;
|
||||||
$this->childrenMethod = $childrenMethod;
|
$this->childrenMethod = $childrenMethod;
|
||||||
|
|
||||||
$userGroups = users_get_groups();
|
$userGroups = users_get_groups();
|
||||||
|
@ -216,6 +218,9 @@ class Tree {
|
||||||
// Get the root id
|
// Get the root id
|
||||||
$rootID = $this->rootID;
|
$rootID = $this->rootID;
|
||||||
|
|
||||||
|
// Get the server id
|
||||||
|
$serverID = $this->serverID;
|
||||||
|
|
||||||
// Agent name filter
|
// Agent name filter
|
||||||
$agent_search_filter = "";
|
$agent_search_filter = "";
|
||||||
if (!empty($this->filter['searchAgent'])) {
|
if (!empty($this->filter['searchAgent'])) {
|
||||||
|
@ -889,10 +894,9 @@ class Tree {
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$sql = $this->getSqlExtended($item_for_count, $type, $rootType, $parent, $rootID,
|
$sql = $this->getSqlExtended($item_for_count, $type, $rootType, $parent, $rootID,
|
||||||
$agent_search_filter, $agent_status_filter,
|
$serverID, $agent_search_filter, $agent_status_filter,
|
||||||
$agents_join, $module_search_filter,
|
$agents_join, $module_search_filter, $module_status_filter,
|
||||||
$module_status_filter, $modules_join,
|
$modules_join, $module_status_join);
|
||||||
$module_status_join);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $sql;
|
return $sql;
|
||||||
|
@ -900,10 +904,9 @@ class Tree {
|
||||||
|
|
||||||
// Override this method
|
// Override this method
|
||||||
protected function getSqlExtended ($item_for_count, $type, $rootType, $parent, $rootID,
|
protected function getSqlExtended ($item_for_count, $type, $rootType, $parent, $rootID,
|
||||||
$agent_search_filter, $agent_status_filter,
|
$serverID, $agent_search_filter, $agent_status_filter,
|
||||||
$agents_join, $module_search_filter,
|
$agents_join, $module_search_filter, $module_status_filter,
|
||||||
$module_status_filter, $modules_join,
|
$modules_join, $module_status_join) {
|
||||||
$module_status_join) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -980,7 +983,7 @@ class Tree {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (defined("METACONSOLE") && !empty($server)) {
|
if (defined("METACONSOLE") && !empty($server)) {
|
||||||
$processed_item['server_id'] = $server['id'];
|
$processed_item['serverID'] = $server['id'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$counters = array();
|
$counters = array();
|
||||||
|
@ -1037,9 +1040,11 @@ class Tree {
|
||||||
|
|
||||||
// The 'id' parameter will be stored as 'server_id' => 'id'
|
// The 'id' parameter will be stored as 'server_id' => 'id'
|
||||||
$resultItem['id'] = array();
|
$resultItem['id'] = array();
|
||||||
$resultItem['id'][$item['server_id']] = $item['id'];
|
$resultItem['id'][$item['serverID']] = $item['id'];
|
||||||
$resultItem['rootID'] = array();
|
$resultItem['rootID'] = array();
|
||||||
$resultItem['rootID'][$item['server_id']] = $item['rootID'];
|
$resultItem['rootID'][$item['serverID']] = $item['rootID'];
|
||||||
|
$resultItem['serverID'] = array();
|
||||||
|
$resultItem['serverID'][$item['serverID']] = $item['rootID'];
|
||||||
|
|
||||||
// Initialize counters if any of it don't exist
|
// Initialize counters if any of it don't exist
|
||||||
if (!isset($resultItem['counters']))
|
if (!isset($resultItem['counters']))
|
||||||
|
@ -1074,8 +1079,12 @@ class Tree {
|
||||||
// Match with the name and type
|
// Match with the name and type
|
||||||
if ($item['name'] == $item2['name'] && $item['type'] == $item2['type']) {
|
if ($item['name'] == $item2['name'] && $item['type'] == $item2['type']) {
|
||||||
// Add the matched ids
|
// Add the matched ids
|
||||||
$resultItem['id'][$item2['server_id']] = $item2['id'];
|
$resultItem['id'] = array();
|
||||||
$resultItem['rootID'][$item2['server_id']] = $item2['rootID'];
|
$resultItem['id'][$item2['serverID']] = $item2['id'];
|
||||||
|
$resultItem['rootID'] = array();
|
||||||
|
$resultItem['rootID'][$item2['serverID']] = $item2['rootID'];
|
||||||
|
$resultItem['serverID'] = array();
|
||||||
|
$resultItem['serverID'][$item2['serverID']] = $item2['rootID'];
|
||||||
|
|
||||||
// Add the matched counters
|
// Add the matched counters
|
||||||
if (isset($item2['counters']) && !empty($item2['counters'])) {
|
if (isset($item2['counters']) && !empty($item2['counters'])) {
|
||||||
|
@ -1128,8 +1137,8 @@ class Tree {
|
||||||
$module['value'] = $module['datos'];
|
$module['value'] = $module['datos'];
|
||||||
|
|
||||||
if (defined("METACONSOLE") && !empty($server)) {
|
if (defined("METACONSOLE") && !empty($server)) {
|
||||||
$module['server_id'] = $server['id'];
|
$module['serverID'] = $server['id'];
|
||||||
$module['server_name'] = $server['server_name'];
|
$module['serverName'] = $server['server_name'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($module['value']))
|
if (!isset($module['value']))
|
||||||
|
@ -1235,11 +1244,8 @@ class Tree {
|
||||||
$agent['rootID'] = $this->rootID;
|
$agent['rootID'] = $this->rootID;
|
||||||
$agent['rootType'] = $this->rootType;
|
$agent['rootType'] = $this->rootType;
|
||||||
|
|
||||||
$id = $agent['id'];
|
if (defined("METACONSOLE") && !empty($server))
|
||||||
if (defined("METACONSOLE") && !empty($server)) {
|
$agent['serverID'] = $server['id'];
|
||||||
$agent['id'] = array();
|
|
||||||
$agent['id'][$server['id']] = $id;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Counters
|
// Counters
|
||||||
if (empty($agent['counters'])) {
|
if (empty($agent['counters'])) {
|
||||||
|
@ -1248,37 +1254,37 @@ class Tree {
|
||||||
if (isset($agent['unknown_count']))
|
if (isset($agent['unknown_count']))
|
||||||
$agent['counters']['unknown'] = $agent['unknown_count'];
|
$agent['counters']['unknown'] = $agent['unknown_count'];
|
||||||
else
|
else
|
||||||
$agent['counters']['unknown'] = agents_monitor_unknown($id);
|
$agent['counters']['unknown'] = agents_monitor_unknown($agent['id']);
|
||||||
|
|
||||||
if (isset($agent['critical_count']))
|
if (isset($agent['critical_count']))
|
||||||
$agent['counters']['critical'] = $agent['critical_count'];
|
$agent['counters']['critical'] = $agent['critical_count'];
|
||||||
else
|
else
|
||||||
$agent['counters']['critical'] = agents_monitor_critical($id);
|
$agent['counters']['critical'] = agents_monitor_critical($agent['id']);
|
||||||
|
|
||||||
if (isset($agent['warning_count']))
|
if (isset($agent['warning_count']))
|
||||||
$agent['counters']['warning'] = $agent['warning_count'];
|
$agent['counters']['warning'] = $agent['warning_count'];
|
||||||
else
|
else
|
||||||
$agent['counters']['warning'] = agents_monitor_warning($id);
|
$agent['counters']['warning'] = agents_monitor_warning($agent['id']);
|
||||||
|
|
||||||
if (isset($agent['notinit_count']))
|
if (isset($agent['notinit_count']))
|
||||||
$agent['counters']['not_init'] = $agent['notinit_count'];
|
$agent['counters']['not_init'] = $agent['notinit_count'];
|
||||||
else
|
else
|
||||||
$agent['counters']['not_init'] = agents_monitor_notinit($id);
|
$agent['counters']['not_init'] = agents_monitor_notinit($agent['id']);
|
||||||
|
|
||||||
if (isset($agent['normal_count']))
|
if (isset($agent['normal_count']))
|
||||||
$agent['counters']['ok'] = $agent['normal_count'];
|
$agent['counters']['ok'] = $agent['normal_count'];
|
||||||
else
|
else
|
||||||
$agent['counters']['ok'] = agents_monitor_ok($id);
|
$agent['counters']['ok'] = agents_monitor_ok($agent['id']);
|
||||||
|
|
||||||
if (isset($agent['total_count']))
|
if (isset($agent['total_count']))
|
||||||
$agent['counters']['total'] = $agent['total_count'];
|
$agent['counters']['total'] = $agent['total_count'];
|
||||||
else
|
else
|
||||||
$agent['counters']['total'] = agents_monitor_total($id);
|
$agent['counters']['total'] = agents_monitor_total($agent['id']);
|
||||||
|
|
||||||
if (isset($agent['fired_count']))
|
if (isset($agent['fired_count']))
|
||||||
$agent['counters']['alerts'] = $agent['fired_count'];
|
$agent['counters']['alerts'] = $agent['fired_count'];
|
||||||
else
|
else
|
||||||
$agent['counters']['alerts'] = agents_get_alerts_fired($id);
|
$agent['counters']['alerts'] = agents_get_alerts_fired($agent['id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Status image
|
// Status image
|
||||||
|
@ -1297,7 +1303,7 @@ class Tree {
|
||||||
$agent['quietImageHTML'] = html_print_image("/images/dot_green.disabled.png", true, array("title" => __('Quiet')));
|
$agent['quietImageHTML'] = html_print_image("/images/dot_green.disabled.png", true, array("title" => __('Quiet')));
|
||||||
|
|
||||||
// Status
|
// Status
|
||||||
$agent['statusRaw'] = agents_get_status($id);
|
$agent['statusRaw'] = agents_get_status($agent['id']);
|
||||||
switch ($agent['statusRaw']) {
|
switch ($agent['statusRaw']) {
|
||||||
case AGENT_STATUS_NORMAL:
|
case AGENT_STATUS_NORMAL:
|
||||||
$agent['status'] = "ok";
|
$agent['status'] = "ok";
|
||||||
|
@ -1331,7 +1337,7 @@ class Tree {
|
||||||
$agent['searchChildren'] = 0;
|
$agent['searchChildren'] = 0;
|
||||||
|
|
||||||
// if ($searchChildren)
|
// if ($searchChildren)
|
||||||
// $agent['children'] = $this->getModules($id, $modulesFilter);
|
// $agent['children'] = $this->getModules($agent['id'], $modulesFilter);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1414,23 +1420,21 @@ class Tree {
|
||||||
$processed_items = $items;
|
$processed_items = $items;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$ids = $this->id;
|
|
||||||
|
|
||||||
$items = array();
|
$items = array();
|
||||||
foreach ($ids as $serverID => $id) {
|
|
||||||
$server = metaconsole_get_servers($serverID);
|
|
||||||
if (metaconsole_connect($server) != NOERR)
|
|
||||||
continue;
|
|
||||||
db_clean_cache();
|
|
||||||
|
|
||||||
$this->id = $id;
|
if ($this->serverID !== false) {
|
||||||
$newItems = $this->getItems();
|
|
||||||
$this->processModules($newItems, $server);
|
|
||||||
$items = array_merge($items, $newItems);
|
|
||||||
|
|
||||||
metaconsole_restore_db();
|
$server = metaconsole_get_servers($this->serverID);
|
||||||
|
if (metaconsole_connect($server) == NOERR) {
|
||||||
|
db_clean_cache();
|
||||||
|
|
||||||
|
$newItems = $this->getItems();
|
||||||
|
$this->processModules($newItems, $server);
|
||||||
|
$items = array_merge($items, $newItems);
|
||||||
|
|
||||||
|
metaconsole_restore_db();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$this->id = $ids;
|
|
||||||
|
|
||||||
if (!empty($items))
|
if (!empty($items))
|
||||||
usort($items, array("Tree", "cmpSortNames"));
|
usort($items, array("Tree", "cmpSortNames"));
|
||||||
|
|
|
@ -385,12 +385,12 @@ TreeController = {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var serverName = element.server_name.length > 0 ? element.server_name : '';console.log(serverName);
|
var serverName = element.serverName.length > 0 ? element.serverName : '';
|
||||||
if ($("#module_details_window").length > 0)
|
if ($("#module_details_window").length > 0)
|
||||||
show_module_detail_dialog(element.id, '', serverName, 0, 86400);
|
show_module_detail_dialog(element.id, '', serverName, 0, 86400);
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
console.log(error);
|
// console.log(error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -434,6 +434,7 @@ TreeController = {
|
||||||
recipient: controller.detailRecipient,
|
recipient: controller.detailRecipient,
|
||||||
type: element.type,
|
type: element.type,
|
||||||
id: element.id,
|
id: element.id,
|
||||||
|
serverID: element.serverID,
|
||||||
baseURL: controller.baseURL,
|
baseURL: controller.baseURL,
|
||||||
ajaxURL: controller.ajaxURL,
|
ajaxURL: controller.ajaxURL,
|
||||||
ajaxPage: controller.ajaxPage
|
ajaxPage: controller.ajaxPage
|
||||||
|
@ -506,6 +507,7 @@ TreeController = {
|
||||||
id: element.id,
|
id: element.id,
|
||||||
type: element.type,
|
type: element.type,
|
||||||
rootID: element.rootID,
|
rootID: element.rootID,
|
||||||
|
serverID: element.serverID,
|
||||||
rootType: element.rootType,
|
rootType: element.rootType,
|
||||||
filter: controller.filter
|
filter: controller.filter
|
||||||
},
|
},
|
||||||
|
@ -661,8 +663,8 @@ TreeNodeDetailController = {
|
||||||
},
|
},
|
||||||
removeControllers: function () {
|
removeControllers: function () {
|
||||||
try {
|
try {
|
||||||
$.each(TreeNodeDetailController.controllers, function(type, elements) {console.log(elements);console.log(type);
|
$.each(TreeNodeDetailController.controllers, function(type, elements) {
|
||||||
$.each(elements, function(id, element) {console.log(element);console.log(id);
|
$.each(elements, function(id, element) {
|
||||||
element.remove();
|
element.remove();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -676,6 +678,7 @@ TreeNodeDetailController = {
|
||||||
recipient: '',
|
recipient: '',
|
||||||
type: 'none',
|
type: 'none',
|
||||||
id: -1,
|
id: -1,
|
||||||
|
serverID: -1,
|
||||||
emptyMessage: "Empty",
|
emptyMessage: "Empty",
|
||||||
errorMessage: "Error",
|
errorMessage: "Error",
|
||||||
baseURL: "",
|
baseURL: "",
|
||||||
|
@ -716,7 +719,8 @@ TreeNodeDetailController = {
|
||||||
page: this.ajaxPage,
|
page: this.ajaxPage,
|
||||||
getDetail: 1,
|
getDetail: 1,
|
||||||
type: this.type,
|
type: this.type,
|
||||||
id: this.id
|
id: this.id,
|
||||||
|
serverID: this.serverID
|
||||||
},
|
},
|
||||||
complete: function(xhr, textStatus) {
|
complete: function(xhr, textStatus) {
|
||||||
$label.removeClass('tree-element-detail-loading');
|
$label.removeClass('tree-element-detail-loading');
|
||||||
|
@ -794,6 +798,9 @@ TreeNodeDetailController = {
|
||||||
else {
|
else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (typeof data.serverID != 'undefined' && (data.serverID.length > 0 || !isNaN(data.serverID))) {
|
||||||
|
this.serverID = data.serverID;
|
||||||
|
}
|
||||||
if (typeof data.emptyMessage != 'undefined' && data.emptyMessage.length > 0) {
|
if (typeof data.emptyMessage != 'undefined' && data.emptyMessage.length > 0) {
|
||||||
this.emptyMessage = data.emptyMessage;
|
this.emptyMessage = data.emptyMessage;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue