This commit is contained in:
m-lopez-f 2015-04-27 13:35:52 +02:00
commit 25e5a476f0
40 changed files with 764 additions and 641 deletions

View File

@ -1,5 +1,5 @@
package: pandorafms-agent-unix package: pandorafms-agent-unix
Version: 6.0dev-150424 Version: 6.0dev-150427
Architecture: all Architecture: all
Priority: optional Priority: optional
Section: admin Section: admin

View File

@ -14,7 +14,7 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
pandora_version="6.0dev-150424" pandora_version="6.0dev-150427"
echo "Test if you has the tools for to make the packages." echo "Test if you has the tools for to make the packages."
whereis dpkg-deb | cut -d":" -f2 | grep dpkg-deb > /dev/null whereis dpkg-deb | cut -d":" -f2 | grep dpkg-deb > /dev/null

View File

@ -41,7 +41,7 @@ my $Sem = undef;
my $ThreadSem = undef; my $ThreadSem = undef;
use constant AGENT_VERSION => '6.0dev'; use constant AGENT_VERSION => '6.0dev';
use constant AGENT_BUILD => '150424'; use constant AGENT_BUILD => '150427';
# Commands to retrieve total memory information in kB # Commands to retrieve total memory information in kB
use constant TOTALMEMORY_CMDS => { use constant TOTALMEMORY_CMDS => {

View File

@ -3,7 +3,7 @@
# #
%define name pandorafms_agent_unix %define name pandorafms_agent_unix
%define version 6.0dev %define version 6.0dev
%define release 150424 %define release 150427
Summary: Pandora FMS Linux agent, PERL version Summary: Pandora FMS Linux agent, PERL version
Name: %{name} Name: %{name}

View File

@ -3,7 +3,7 @@
# #
%define name pandorafms_agent_unix %define name pandorafms_agent_unix
%define version 6.0dev %define version 6.0dev
%define release 150424 %define release 150427
Summary: Pandora FMS Linux agent, PERL version Summary: Pandora FMS Linux agent, PERL version
Name: %{name} Name: %{name}

View File

@ -186,7 +186,7 @@ UpgradeApplicationID
{} {}
Version Version
{150424} {150427}
ViewReadme ViewReadme
{Yes} {Yes}

View File

@ -30,7 +30,7 @@ using namespace Pandora;
using namespace Pandora_Strutils; using namespace Pandora_Strutils;
#define PATH_SIZE _MAX_PATH+1 #define PATH_SIZE _MAX_PATH+1
#define PANDORA_VERSION ("6.0dev(Build 150424)") #define PANDORA_VERSION ("6.0dev(Build 150427)")
string pandora_path; string pandora_path;
string pandora_dir; string pandora_dir;

View File

@ -11,7 +11,7 @@ BEGIN
VALUE "LegalCopyright", "Artica ST" VALUE "LegalCopyright", "Artica ST"
VALUE "OriginalFilename", "PandoraAgent.exe" VALUE "OriginalFilename", "PandoraAgent.exe"
VALUE "ProductName", "Pandora FMS Windows Agent" VALUE "ProductName", "Pandora FMS Windows Agent"
VALUE "ProductVersion", "(6.0dev(Build 150424))" VALUE "ProductVersion", "(6.0dev(Build 150427))"
VALUE "FileVersion", "1.0.0.0" VALUE "FileVersion", "1.0.0.0"
END END
END END

View File

@ -1,5 +1,5 @@
package: pandorafms-console package: pandorafms-console
Version: 6.0dev-150424 Version: 6.0dev-150427
Architecture: all Architecture: all
Priority: optional Priority: optional
Section: admin Section: admin

View File

@ -14,7 +14,7 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
pandora_version="6.0dev-150424" pandora_version="6.0dev-150427"
package_pear=0 package_pear=0
package_pandora=1 package_pandora=1

View File

@ -340,11 +340,9 @@ foreach ($layoutDatas as $layoutData) {
$params['javascript_ajax_page'] = '../../ajax.php'; $params['javascript_ajax_page'] = '../../ajax.php';
$params['disabled_javascript_on_blur_function'] = true; $params['disabled_javascript_on_blur_function'] = true;
$params['print_input_server'] = true; $params['print_input_id_server'] = true;
$params['input_server_id'] = $params['input_id_server_id'] = $params['input_id_server_name'] = 'id_server_id_' . $idLayoutData;
$params['input_server_name'] = 'id_server_name_' . $idLayoutData; $params['input_id_server_value'] = $layoutData['id_metaconsole'];
$params['input_server_value'] =
db_get_value('server_name', 'tmetaconsole_setup', 'id', $layoutData['id_metaconsole']);
$params['metaconsole_enabled'] = true; $params['metaconsole_enabled'] = true;
$params['print_hidden_input_idagent'] = true; $params['print_hidden_input_idagent'] = true;
$params['hidden_input_idagent_name'] = 'id_agent_' . $idLayoutData; $params['hidden_input_idagent_name'] = 'id_agent_' . $idLayoutData;

View File

@ -281,11 +281,8 @@ switch ($activeTab) {
} }
$agentName = get_parameter('agent_' . $id, ''); $agentName = get_parameter('agent_' . $id, '');
if (defined('METACONSOLE')) { if (defined('METACONSOLE')) {
$values['id_metaconsole'] = db_get_value('id', $values['id_metaconsole'] = (int) get_parameter('id_server_id_' . $id, '');
'tmetaconsole_setup', 'server_name', $values['id_agent'] = (int) get_parameter('id_agent_' . $id, 0);
get_parameter('id_server_name_' . $id, ''));
$values['id_agent'] =
(int)get_parameter('id_agent_' . $id, 0);
} }
else { else {
$values['id_agent'] = agents_get_agent_id($agentName); $values['id_agent'] = agents_get_agent_id($agentName);

View File

@ -183,7 +183,7 @@ if (defined('METACONSOLE')) {
$table->rowstyle["all_2"] = 'display: none;'; $table->rowstyle["all_2"] = 'display: none;';
$table->data["all_2"][0] = __('Servers'); $table->data["all_2"][0] = __('Servers');
$table->data["all_2"][1] = html_meta_print_select_servers(false, $table->data["all_2"][1] = html_meta_print_select_servers(false,
false, 'servers', '', '', '', 0, true); false, 'servers', '', 'metaconsole_init();', '', 0, true);
} }
@ -210,8 +210,12 @@ $table->data["all_one_item_per_agent"][1] .= html_print_input_hidden(
$table->rowstyle["all_4"] = 'display: none;'; $table->rowstyle["all_4"] = 'display: none;';
$table->data["all_4"][0] = __('Agents'); $table->data["all_4"][0] = __('Agents');
$table->data["all_4"][1] = html_print_select(
agents_get_group_agents(0, false, "none", false, true), $agents_list = array();
if (!defined('METACONSOLE'))
$agents_list = agents_get_group_agents(0, false, "none", false, true);
$table->data["all_4"][1] = html_print_select($agents_list,
'id_agents[]', 0, false, '', '', true, true); 'id_agents[]', 0, false, '', '', true, true);
$table->data["all_4"][2] = ' <span style="vertical-align: top;">' . $table->data["all_4"][2] = ' <span style="vertical-align: top;">' .
__('Modules') . '</span>'; __('Modules') . '</span>';
@ -296,16 +300,14 @@ echo '<span id="none_text" style="display: none;">' . __('None') . '</span>';
echo '<span id="loading_text" style="display: none;">' . __('Loading...') . '</span>'; echo '<span id="loading_text" style="display: none;">' . __('Loading...') . '</span>';
?> ?>
<script type="text/javascript"> <script type="text/javascript">
var show_only_enabled_modules = true;
<?php var metaconsole_enabled = <?php echo json_encode(defined('METACONSOLE')); ?>;
if (defined('METACONSOLE')) { var show_only_enabled_modules = true;
echo 'var url_ajax = "../../ajax.php";'; var url_ajax = "ajax.php";
if (metaconsole_enabled) {
url_ajax = "../../ajax.php";
} }
else {
echo 'var url_ajax = "ajax.php";';
}
?>
$(document).ready (function () { $(document).ready (function () {
hidden_rows(); hidden_rows();
@ -314,37 +316,39 @@ $(document).ready (function () {
selected = $("#process_value").val(); selected = $("#process_value").val();
if (selected == <?php echo PROCESS_VALUE_NONE; ?>) { if (selected == <?php echo PROCESS_VALUE_NONE; ?>) {
$("tr", "#wizard_table").filter(function () {return /^.*modulegraph_simplevalue.*/.test(this.id); }).hide(); $("tr", "#wizard_table").filter(function () {
return /^.*modulegraph_simplevalue.*/.test(this.id);
}).hide();
} }
else { else {
$("tr", "#wizard_table").filter(function () {return /^.*modulegraph_simplevalue.*/.test(this.id); }).show(); $("tr", "#wizard_table").filter(function () {
return /^.*modulegraph_simplevalue.*/.test(this.id);
}).show();
} }
}); });
$("#groups").change (function () { $("#groups").change (function () {
$('#id_agents').attr('disabled', true); $('#id_agents')
$('#id_agents').empty (); .attr('disabled', true)
$('#id_agents').append ($('<option></option>').html($("#loading_text").html())); .empty ()
$('#id_agents').css ("width", "auto"); .css ("width", "auto")
$('#id_agents').css ("max-width", ""); .css ("max-width", "")
.append ($('<option></option>').html($("#loading_text").html()));
var data_params = {"page": "include/ajax/agent", var data_params = {
"get_agents_group": 1, page: "include/ajax/agent",
"id_group": $("#groups").val(), get_agents_group: 1,
<?php id_group: $("#groups").val(),
if (defined('METACONSOLE')) { mode: "json"
echo '"id_server": $("#servers").val(),' . "\n";
}
?>
"mode": "json"
}; };
if (metaconsole_enabled)
data_params.id_server = $("#servers").val();
jQuery.ajax ({ jQuery.ajax ({
data: data_params, data: data_params,
async: false,
type: 'POST', type: 'POST',
url: url_ajax, url: url_ajax,
timeout: 10000,
dataType: 'json', dataType: 'json',
success: function (data) { success: function (data) {
$('#id_agents').empty(); $('#id_agents').empty();
@ -361,35 +365,32 @@ $(document).ready (function () {
}); });
} }
$('#id_agents').css ("width", "auto");
$('#id_agents').css ("max-width", "");
$('#id_agents').removeAttr('disabled'); $('#id_agents').removeAttr('disabled');
return;
} }
}); });
return;
}); });
$("#id_agents").change ( function() { $("#id_agents").change ( function() {
if ($("#hidden-item_per_agent_test").val() == 0) if ($("#hidden-item_per_agent_test").val() == 0) {
agent_changed_by_multiple_agents( var options = {};
<?php
if (defined('METACONSOLE')) { if (metaconsole_enabled) {
echo "{'data': {'id_server': 'servers', 'metaconsole': 1, 'homedir': '../../'}}"; options = {
'data': {
'id_server': 'servers',
'metaconsole': 1,
'homedir': '../../'
}
};
}
agent_changed_by_multiple_agents(options);
} }
?>
);
}); });
<?php if (metaconsole_enabled) {
if (defined('METACONSOLE')) { metaconsole_init();
echo "metaconsole_init();";
} }
?>
$("select[name='kind_relationship']").change(function() { $("select[name='kind_relationship']").change(function() {
@ -500,7 +501,7 @@ function item_per_agent_change(itemPerAgent) {
} }
function metaconsole_init() { function metaconsole_init() {
$("#groups").trigger('change'); $("#groups").change();
} }
</script> </script>
<style type="text/css"> <style type="text/css">

View File

@ -36,34 +36,12 @@ if ($get_agents_group) {
$return = array(); $return = array();
if ($id_group != -1) { if ($id_group != -1) {
if (defined('METACONSOLE')) { $filter = array();
if ($id_server == 0) { if (defined('METACONSOLE'))
$servers = $servers = db_get_all_rows_sql ("SELECT * $filter['id_server'] = $id_server;
FROM tmetaconsole_setup
WHERE disabled = 0");
}
else {
$servers = db_get_all_rows_sql ("SELECT *
FROM tmetaconsole_setup
WHERE id = " . $id_server . "
AND disabled = 0");
}
foreach ($servers as $server) { $return = agents_get_group_agents($id_group, $filter, "none");
if (metaconsole_load_external_db ($server) != NOERR) {
continue;
}
$return = agents_get_group_agents($id_group);
//Restore db connection
metaconsole_restore_db();
}
}
else {
$return = agents_get_group_agents($id_group);
}
} }
switch ($mode) { switch ($mode) {
@ -185,12 +163,6 @@ if ($search_agents && ((!defined('METACONSOLE')) || $force_local)) {
return; return;
} }
elseif ($search_agents && ($config['metaconsole'] == 1) && defined('METACONSOLE')) { elseif ($search_agents && ($config['metaconsole'] == 1) && defined('METACONSOLE')) {
$servers = db_get_all_rows_sql ("SELECT *
FROM tmetaconsole_setup
WHERE disabled = 0");
if (!isset($servers)) {
return;
}
$id_agent = (int) get_parameter ('id_agent'); $id_agent = (int) get_parameter ('id_agent');
$string = (string) get_parameter ('q'); /* q is what autocomplete plugin gives */ $string = (string) get_parameter ('q'); /* q is what autocomplete plugin gives */
@ -217,91 +189,64 @@ elseif ($search_agents && ($config['metaconsole'] == 1) && defined('METACONSOLE'
} }
} }
$data = array(); if (!empty($id_agent)) {
foreach ($servers as $server) { $filter['id_agente'] = $id_agent;
if (metaconsole_load_external_db ($server) != NOERR) {
continue;
} }
if (!empty($string)) {
$search_filters = array();
//Get agents for only the name. //Get agents for only the name.
$filter_agents = $filter;
switch ($config['dbtype']) { switch ($config['dbtype']) {
case "mysql": case "mysql":
$filter_agents[] = '(nombre COLLATE utf8_general_ci LIKE "%'.$string.'%")'; //Get agents for only the name.
break; $search_filters[] = "(nombre COLLATE utf8_general_ci LIKE '%$string%')";
case "postgresql":
$filter_agents[] = '(nombre LIKE \'%'.$string.'%\')';
break;
case "oracle":
$filter_agents[] = '(UPPER(nombre) LIKE UPPER(\'%'.$string.'%\')';
break;
}
$agents = agents_get_agents($filter_agents, array ('id_agente', 'nombre', 'direccion'));
if ($agents !== false) {
foreach ($agents as $agent) {
$data[] = array('id' => $agent['id_agente'],
'name' => io_safe_output($agent['nombre']),
'ip' => io_safe_output($agent['direccion']),
'filter' => 'agent',
'id_server' => $server['id']);
}
}
//Get agents for only the address //Get agents for only the address
$filter_address = $filter; $search_filters[] = "(direccion LIKE '%$string%')";
switch ($config['dbtype']) { //Get agents for only the description
case "mysql": $search_filters[] = "(comentarios LIKE '%$string%')";
$filter_address[] = '(nombre COLLATE utf8_general_ci NOT LIKE "%'.$string.'%" AND direccion LIKE "%'.$string.'%")';
break; break;
case "postgresql": case "postgresql":
$filter_address[] = '(nombre NOT LIKE \'%'.$string.'%\' AND direccion LIKE \'%'.$string.'%\')'; //Get agents for only the name.
$search_filters[] = "(nombre LIKE '%$string%')";
//Get agents for only the address
$search_filters[] = "(direccion LIKE '%$string%')";
//Get agents for only the description
$search_filters[] = "(comentarios LIKE '%$string%')";
break; break;
case "oracle": case "oracle":
$filter_address[] = '(UPPER(nombre) NOT LIKE UPPER(\'%'.$string.'%\') AND UPPER(direccion) LIKE UPPER(\'%'.$string.'%\'))'; //Get agents for only the name.
$search_filters[] = "(UPPER(nombre) LIKE UPPER('%$string%')";
//Get agents for only the address
$search_filters[] = "(UPPER(direccion) LIKE UPPER('%$string%'))";
//Get agents for only the description
$search_filters[] = "(UPPER(comentarios) LIKE UPPER('%$string%'))";
break; break;
} }
$agents = agents_get_agents($filter_address, array ('id_agente', 'nombre', 'direccion'));
if ($agents !== false) {
foreach ($agents as $agent) {
$data[] = array('id' => $agent['id_agente'],
'name' => io_safe_output($agent['nombre']),
'ip' => io_safe_output($agent['direccion']),
'filter' => 'address',
'id_server' => $server['id']);
}
}
//Get agents for only the description $search_filters_str = implode($search_filters, ' OR ');
$filter_description = $filter;
switch ($config['dbtype']) { if (!empty($search_filters_str))
case "mysql": $filter[] = "($search_filters_str)";
$filter_description[] =
'(nombre COLLATE utf8_general_ci NOT LIKE "%'.$string.'%" AND direccion NOT LIKE "%'.$string.'%" AND comentarios LIKE "%'.$string.'%")';
break;
case "postgresql":
$filter_description[] =
'(nombre NOT LIKE \'%'.$string.'%\' AND direccion NOT LIKE \'%'.$string.'%\' AND comentarios LIKE \'%'.$string.'%\')';
break;
case "oracle":
$filter_description[] =
'(UPPER(nombre) NOT LIKE UPPER(\'%'.$string.'%\') AND UPPER(direccion) NOT LIKE UPPER(\'%'.$string.'%\') AND UPPER(comentarios) LIKE UPPER(\'%'.$string.'%\'))';
break;
} }
$agents = agents_get_agents($filter_description,
array ('id_agente', 'nombre', 'direccion')); $fields = array(
'id_tagente AS id_agente', 'nombre',
'direccion', 'id_tmetaconsole_setup AS id_server'
);
$agents = db_get_all_rows_filter('tmetaconsole_agent', $filter, $fields);
$data = array();
if ($agents !== false) { if ($agents !== false) {
foreach ($agents as $agent) { foreach ($agents as $agent) {
$data[] = array('id' => $agent['id_agente'], $data[] = array('id' => $agent['id_agente'],
'name' => io_safe_output($agent['nombre']), 'name' => io_safe_output($agent['nombre']),
'ip' => io_safe_output($agent['direccion']), 'ip' => io_safe_output($agent['direccion']),
'filter' => 'description', 'filter' => 'description',
'id_server' => $server['id']); 'id_server' => $agent['id_server']);
} }
} }
//Restore db connection
metaconsole_restore_db();
}
echo json_encode($data); echo json_encode($data);
return; return;

View File

@ -352,9 +352,10 @@ class Tree {
if ($this->strictACL) if ($this->strictACL)
return false; return false;
$columns = 'tg.id_grupo AS id, tg.nombre AS name, tg.parent, tg.icon, COUNT(DISTINCT(ta.id_agente)) AS total_count'; $columns = 'tg.id_grupo AS id, tg.nombre AS name, tg.parent, tg.icon';
$order_fields = 'tg.nombre ASC, tg.id_grupo ASC'; $order_fields = 'tg.nombre ASC, tg.id_grupo ASC';
if (! defined('METACONSOLE')) {
// Add the agent counters to the columns // Add the agent counters to the columns
$agent_table = "SELECT COUNT(DISTINCT(ta.id_agente)) $agent_table = "SELECT COUNT(DISTINCT(ta.id_agente))
FROM tagente AS ta FROM tagente AS ta
@ -367,8 +368,7 @@ class Tree {
AND ta.id_grupo = tg.id_grupo AND ta.id_grupo = tg.id_grupo
$group_acl $group_acl
$agent_search_filter $agent_search_filter
$agent_status_filter $agent_status_filter";
$module_search_filter";
$counter_columns = $this->getAgentCounterColumnsSql($agent_table); $counter_columns = $this->getAgentCounterColumnsSql($agent_table);
if (!empty($counter_columns)) if (!empty($counter_columns))
$columns .= ", $counter_columns"; $columns .= ", $counter_columns";
@ -386,11 +386,37 @@ class Tree {
$group_acl $group_acl
$agent_search_filter $agent_search_filter
$agent_status_filter $agent_status_filter
$module_search_filter
GROUP BY tg.id_grupo GROUP BY tg.id_grupo
ORDER BY $order_fields"; ORDER BY $order_fields";
} }
// Metaconsole
else { else {
// Add the agent counters to the columns
$agent_table = "SELECT COUNT(DISTINCT(ta.id_agente))
FROM tmetaconsole_agent AS ta
WHERE ta.disabled = 0
AND ta.id_grupo = tg.id_grupo
$group_acl
$agent_search_filter
$agent_status_filter";
$counter_columns = $this->getAgentCounterColumnsSql($agent_table);
if (!empty($counter_columns))
$columns .= ", $counter_columns";
$sql = "SELECT $columns
FROM tgrupo AS tg
LEFT JOIN tagente AS ta
ON ta.disabled = 0
AND tg.id_grupo = ta.id_grupo
$group_acl
$agent_search_filter
$agent_status_filter
GROUP BY tg.id_grupo
ORDER BY $order_fields";
}
}
else {
if (! defined('METACONSOLE') || $this->strictACL) {
$columns = 'ta.id_agente AS id, ta.nombre AS name, $columns = 'ta.id_agente AS id, ta.nombre AS name,
ta.fired_count, ta.normal_count, ta.warning_count, ta.fired_count, ta.normal_count, ta.warning_count,
ta.critical_count, ta.unknown_count, ta.notinit_count, ta.critical_count, ta.unknown_count, ta.notinit_count,
@ -409,10 +435,27 @@ class Tree {
$group_acl $group_acl
$agent_search_filter $agent_search_filter
$agent_status_filter $agent_status_filter
$module_search_filter
GROUP BY ta.id_agente GROUP BY ta.id_agente
ORDER BY $order_fields"; ORDER BY $order_fields";
} }
else {
$columns = 'ta.id_tagente AS id, ta.nombre AS name,
ta.fired_count, ta.normal_count, ta.warning_count,
ta.critical_count, ta.unknown_count, ta.notinit_count,
ta.total_count, ta.quiet, id_tmetaconsole_setup AS server_id';
$order_fields = 'ta.nombre ASC, ta.id_tagente ASC';
$sql = "SELECT $columns
FROM tmetaconsole_agent AS ta
WHERE ta.disabled = 0
AND ta.id_grupo = $rootID
$group_acl
$agent_search_filter
$agent_status_filter
GROUP BY ta.id_tagente
ORDER BY $order_fields";
}
}
break; break;
// Get the modules of an agent // Get the modules of an agent
case 'agent': case 'agent':
@ -1387,8 +1430,12 @@ class Tree {
$agent['rootID'] = $this->rootID; $agent['rootID'] = $this->rootID;
$agent['rootType'] = $this->rootType; $agent['rootType'] = $this->rootType;
if (defined("METACONSOLE") && !empty($server)) if (defined("METACONSOLE")) {
if (isset($agent['server_id']))
$agent['serverID'] = $agent['server_id'];
else if (!empty($server))
$agent['serverID'] = $server['id']; $agent['serverID'] = $server['id'];
}
// Realtime counters for Strict ACL // Realtime counters for Strict ACL
if ($this->strictACL) { if ($this->strictACL) {
@ -1535,37 +1582,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($agent['id']); $agent['counters']['unknown'] = (int) 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($agent['id']); $agent['counters']['critical'] = (int) 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($agent['id']); $agent['counters']['warning'] = (int) 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($agent['id']); $agent['counters']['not_init'] = (int) 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($agent['id']); $agent['counters']['ok'] = (int) 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($agent['id']); $agent['counters']['total'] = (int) 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($agent['id']); $agent['counters']['alerts'] = (int) agents_get_alerts_fired($agent['id']);
} }
// Status image // Status image
@ -1643,25 +1690,25 @@ class Tree {
} }
} }
private static function extractItemWithID ($items, $item_id, $item_type = "group") { private static function extractItemWithID ($items, $item_id, $item_type = "group", $strictACL = false) {
foreach ($items as $item) { foreach ($items as $item) {
if ($item["type"] != $item_type) if ($item["type"] != $item_type)
continue; continue;
// Item found // Item found
if (! defined("METACONSOLE")) { if ($strictACL && defined("METACONSOLE")) {
if ($item["id"] == $item_id)
return $item;
}
else {
foreach ($item["id"] as $server_id => $id) { foreach ($item["id"] as $server_id => $id) {
if ($id == $item_id) if ($id == $item_id)
return $item; return $item;
} }
} }
else {
if ($item["id"] == $item_id)
return $item;
}
if ($item["type"] == "group" && !empty($item["children"])) { if ($item["type"] == "group" && !empty($item["children"])) {
$result = self::extractItemWithID($item["children"], $item_id, $item_type); $result = self::extractItemWithID($item["children"], $item_id, $item_type, $strictACL);
// Item found on children // Item found on children
if ($result !== false) if ($result !== false)
@ -1675,7 +1722,7 @@ class Tree {
public function getData() { public function getData() {
if (! $this->strictACL) { if (! defined('METACONSOLE')) {
switch ($this->type) { switch ($this->type) {
case 'os': case 'os':
$this->getDataOS(); $this->getDataOS();
@ -1699,7 +1746,7 @@ class Tree {
$this->getDataExtended(); $this->getDataExtended();
} }
} }
else { else if ($this->strictACL) {
switch ($this->type) { switch ($this->type) {
case 'group': case 'group':
case 'tag': case 'tag':
@ -1710,6 +1757,14 @@ class Tree {
break; break;
} }
} }
else {
if ($this->type == 'agent') {
$this->getDataAgent();
}
else {
$this->getDataGroup();
}
}
} }
protected function getDataExtended () { protected function getDataExtended () {
@ -1737,19 +1792,13 @@ class Tree {
$server = metaconsole_get_servers($this->serverID); $server = metaconsole_get_servers($this->serverID);
if (metaconsole_connect($server) == NOERR) { if (metaconsole_connect($server) == NOERR) {
db_clean_cache(); $items = $this->getItems();
$this->processModules($items, $server);
$newItems = $this->getItems();
$this->processModules($newItems, $server);
$items = array_merge($items, $newItems);
metaconsole_restore_db(); metaconsole_restore_db();
} }
} }
if (!empty($items))
usort($items, array("Tree", "cmpSortNames"));
$processed_items = $items; $processed_items = $items;
} }
} }
@ -1897,7 +1946,7 @@ class Tree {
// Groups // Groups
if ($this->id == -1) { if ($this->id == -1) {
if (! defined ('METACONSOLE')) {
$items = $this->getItems(); $items = $this->getItems();
// Build the group hierarchy // Build the group hierarchy
@ -1915,38 +1964,9 @@ class Tree {
$processed_items[] = $processed_item; $processed_items[] = $processed_item;
} }
} }
}
else {
$servers = metaconsole_get_servers();
$item_list = array();
foreach ($servers as $server) {
if (metaconsole_connect($server) != NOERR)
continue;
db_clean_cache();
$items = $this->getItems();
// Build the group hierarchy
$processed_items = array();
foreach ($items as $key => $item) {
if (empty($item['parent'])) {
unset($items[$key]);
$processed_items[] = $this->getProcessedItem($item, $server, $items);
}
}
$item_list = array_merge($item_list, $processed_items);
metaconsole_restore_db();
}
$processed_items = $this->getMergedItems($item_list);
}
// groupID filter. To access the view from tactical views f.e. // groupID filter. To access the view from tactical views f.e.
if (!empty($processed_items) && !empty($this->filter['groupID'])) { if (!empty($processed_items) && !empty($this->filter['groupID'])) {
$result = self::extractItemWithID($processed_items, $this->filter['groupID'], "group"); $result = self::extractItemWithID($processed_items, $this->filter['groupID'], "group", $this->strictACL);
if ($result === false) if ($result === false)
$processed_items = array(); $processed_items = array();
@ -1956,36 +1976,10 @@ class Tree {
} }
// Agents // Agents
else { else {
if (! defined ('METACONSOLE')) {
$items = $this->getItems(); $items = $this->getItems();
$this->processAgents($items); $this->processAgents($items);
$processed_items = $items; $processed_items = $items;
} }
else {
$rootIDs = $this->rootID;
$items = array();
foreach ($rootIDs as $serverID => $rootID) {
$server = metaconsole_get_servers($serverID);
if (metaconsole_connect($server) != NOERR)
continue;
db_clean_cache();
$this->rootID = $rootID;
$newItems = $this->getItems();
$this->processAgents($newItems, $server);
$items = array_merge($items, $newItems);
metaconsole_restore_db();
}
$this->rootID = $rootIDs;
if (!empty($items))
usort($items, array("Tree", "cmpSortNames"));
$processed_items = $items;
}
}
$this->tree = $processed_items; $this->tree = $processed_items;
} }

View File

@ -22,7 +22,7 @@
/** /**
* Pandora build version and version * Pandora build version and version
*/ */
$build_version = 'PC150424'; $build_version = 'PC150427';
$pandora_version = 'v6.0dev'; $pandora_version = 'v6.0dev';
// Do not overwrite default timezone set if defined. // Do not overwrite default timezone set if defined.

View File

@ -19,8 +19,10 @@
* @subpackage Agents * @subpackage Agents
*/ */
require_once($config['homedir'] . '/include/functions.php');
require_once($config['homedir'] . "/include/functions_modules.php"); require_once($config['homedir'] . "/include/functions_modules.php");
require_once($config['homedir'] . '/include/functions_users.php'); require_once($config['homedir'] . '/include/functions_users.php');
enterprise_include_once('/include/functions_agents.php');
/** /**
* Check the agent exists in the DB. * Check the agent exists in the DB.
@ -755,13 +757,14 @@ function agents_common_modules ($id_agent, $filter = false, $indexed = true, $ge
* @param string $case Which case to return the agentname as (lower, upper, none) * @param string $case Which case to return the agentname as (lower, upper, none)
* @param boolean $noACL jump the ACL test. * @param boolean $noACL jump the ACL test.
* @param boolean $childGroups The flag to get agents in the child group of group parent passed. By default false. * @param boolean $childGroups The flag to get agents in the child group of group parent passed. By default false.
* @param boolean $extra_access The flag to get agents of extra access policies.
* *
* @return array An array with all agents in the group or an empty array * @return array An array with all agents in the group or an empty array
*/ */
function agents_get_group_agents ($id_group = 0, $search = false, $case = "lower", $noACL = false, $childGroups = false, $extra_access = true) { function agents_get_group_agents ($id_group = 0, $search = false, $case = "lower", $noACL = false, $childGroups = false) {
global $config; global $config;
$filter = array();
if (!$noACL) { if (!$noACL) {
$id_group = groups_safe_acl($config["id_user"], $id_group, "AR"); $id_group = groups_safe_acl($config["id_user"], $id_group, "AR");
@ -783,43 +786,30 @@ function agents_get_group_agents ($id_group = 0, $search = false, $case = "lower
$id_group = array_keys(users_get_groups(false, "AR", true, false, (array)$id_group)); $id_group = array_keys(users_get_groups(false, "AR", true, false, (array)$id_group));
} }
if (is_array($id_group)) { if (!empty($id_group)) {
$all_groups = false; $filter['id_grupo'] = $id_group;
$search_group_sql = sprintf ('id_grupo IN (%s)', implode (",", $id_group));
} }
else if ($id_group == 0) { //All group
$all_groups = true;
$search_group_sql = '1 = 1';
}
else {
$all_groups = false;
$search_group_sql = sprintf ('id_grupo = %d', $id_group);
}
$search_sql = '1 = 1';
if ($search === true) { if ($search === true) {
//No added search. Show both disabled and non-disabled //No added search. Show both disabled and non-disabled
} }
else if (is_array ($search)) { else if (is_array ($search)) {
$filter['disabled'] = 0;
if (isset ($search["disabled"])) { if (isset ($search["disabled"])) {
$search_sql .= ' AND disabled = '.($search["disabled"] ? 1 : 0); //Bool, no cleanup necessary $filter['disabled'] = (int) $search["disabled"];
}
else {
$search_sql .= ' AND disabled = 0';
}
unset ($search["disabled"]); unset ($search["disabled"]);
}
if (isset ($search["string"])) { if (isset ($search["string"])) {
$string = io_safe_input ($search["string"]); $string = io_safe_input ($search["string"]);
switch ($config["dbtype"]) { switch ($config["dbtype"]) {
case "mysql": case "mysql":
$search_sql .= ' AND (nombre COLLATE utf8_general_ci LIKE "%'.$string.'%" OR direccion LIKE "%'.$string.'%")';
break;
case "postgresql": case "postgresql":
$search_sql .= ' AND (nombre COLLATE utf8_general_ci LIKE \'%'.$string.'%\' OR direccion LIKE \'%'.$string.'%\')'; $filter[] = "(nombre COLLATE utf8_general_ci LIKE '%$string%' OR direccion LIKE '%$string%')";
break; break;
case "oracle": case "oracle":
$search_sql .= ' AND (UPPER(nombre) LIKE UPPER(\'%'.$string.'%\') OR direccion LIKE upper(\'%'.$string.'%\'))'; $filter[] = "(UPPER(nombre) LIKE UPPER('%$string%') OR direccion LIKE upper('%$string%'))";
break; break;
} }
@ -830,13 +820,11 @@ function agents_get_group_agents ($id_group = 0, $search = false, $case = "lower
$name = io_safe_input ($search["name"]); $name = io_safe_input ($search["name"]);
switch ($config["dbtype"]) { switch ($config["dbtype"]) {
case "mysql": case "mysql":
$search_sql .= ' AND nombre COLLATE utf8_general_ci LIKE "' . $name . '" ';
break;
case "postgresql": case "postgresql":
$search_sql .= ' AND nombre COLLATE utf8_general_ci LIKE \'' . $name . '\' '; $filter[] = "nombre COLLATE utf8_general_ci LIKE '$name'";
break; break;
case "oracle": case "oracle":
$search_sql .= ' AND UPPER(nombre) LIKE UPPER(\'' . $name . '\') '; $filter[] = "UPPER(nombre) LIKE UPPER('$name')";
break; break;
} }
@ -846,65 +834,60 @@ function agents_get_group_agents ($id_group = 0, $search = false, $case = "lower
if (isset($search['status'])) { if (isset($search['status'])) {
switch ($search['status']) { switch ($search['status']) {
case AGENT_STATUS_NORMAL: case AGENT_STATUS_NORMAL:
$search_sql .= $filter[] = "normal_count = total_count";
" AND normal_count = total_count";
break; break;
case AGENT_STATUS_WARNING: case AGENT_STATUS_WARNING:
$search_sql .= $filter[] = "(critical_count = 0 AND warning_count > 0)";
" AND critical_count = 0 AND warning_count > 0";
break; break;
case AGENT_STATUS_CRITICAL: case AGENT_STATUS_CRITICAL:
$search_sql .= $filter[] = "critical_count > 0";
" AND critical_count > 0";
break; break;
case AGENT_STATUS_UNKNOWN: case AGENT_STATUS_UNKNOWN:
$search_sql .= $filter[] = "(critical_count = 0 AND warning_count = 0 AND unknown_count > 0)";
" AND critical_count = 0 AND warning_count = 0
AND unknown_count > 0";
break; break;
case AGENT_STATUS_NOT_NORMAL: case AGENT_STATUS_NOT_NORMAL:
$search_sql .= " AND normal_count <> total_count"; $filter[] = "normal_count <> total_count";
break; break;
case AGENT_STATUS_NOT_INIT: case AGENT_STATUS_NOT_INIT:
$search_sql .= " AND notinit_count = total_count"; $filter[] = "notinit_count = total_count";
break; break;
} }
unset($search['status']); unset($search['status']);
} }
if (defined('METACONSOLE') && isset($search['id_server'])) {
$filter['id_tmetaconsole_setup'] = $search['id_server'];
if (! empty ($search)) { unset ($search["id_server"]);
$search_sql .= ' AND '.db_format_array_where_clause_sql ($search); }
// Add the rest of the filter from the search array
foreach ($search as $key => $value) {
$filter[] = $value;
} }
} }
else { else {
$search_sql .= ' AND disabled = 0'; $filter['disabled'] = 0;
} }
enterprise_include_once ('include/functions_policies.php'); $filter['order'] = 'nombre';
// TODO: CLEAN extra_sql if (defined('METACONSOLE')) {
$extra_sql = ''; $table_name = 'tmetaconsole_agent';
switch ($config["dbtype"]) { $fields = array(
case "mysql": 'id_tagente AS id_agente', 'nombre'
case "postgresql": );
$sql = sprintf ("SELECT id_agente, nombre }
FROM tagente else {
WHERE (%s %s) AND (%s) $table_name = 'tagente';
ORDER BY nombre",
$extra_sql, $search_group_sql, $search_sql); $fields = array(
break; 'id_agente', 'nombre'
case "oracle": );
$sql = sprintf ("SELECT id_agente, nombre
FROM tagente
WHERE (%s %s) AND (%s)
ORDER BY dbms_lob.substr(nombre,4000,1)",
$extra_sql, $search_group_sql, $search_sql);
break;
} }
$result = db_get_all_rows_sql ($sql); $result = db_get_all_rows_filter($table_name, $filter, $fields);
if ($result === false) if ($result === false)
return array (); //Return an empty array return array (); //Return an empty array
@ -1831,6 +1814,8 @@ function agents_delete_agent ($id_agents, $disableACL = false) {
db_pandora_audit( "Agent management", db_pandora_audit( "Agent management",
"Deleted agent '$agent_name'"); "Deleted agent '$agent_name'");
// Delete the agent from the metaconsole cache
enterprise_hook('agent_delete_from_cache', array($id_agent));
/* Break the loop on error */ /* Break the loop on error */
if ($error) if ($error)

View File

@ -204,6 +204,11 @@ function config_update_config () {
if ((int)get_parameter('event_replication') == 1) { if ((int)get_parameter('event_replication') == 1) {
if (!config_update_value ('replication_interval', (int)get_parameter('replication_interval'))) if (!config_update_value ('replication_interval', (int)get_parameter('replication_interval')))
$error_update[] = __('Replication interval'); $error_update[] = __('Replication interval');
if (!config_update_value ('replication_mode', (string)get_parameter('replication_mode')))
$error_update[] = __('Replication mode');
if (!config_update_value ('show_events_in_local', (string)get_parameter('show_events_in_local')))
$error_update[] = __('Show events list in local console (read only)');
}
if (!config_update_value ('replication_dbhost', (string)get_parameter('replication_dbhost'))) if (!config_update_value ('replication_dbhost', (string)get_parameter('replication_dbhost')))
$error_update[] = __('Replication DB host'); $error_update[] = __('Replication DB host');
if (!config_update_value ('replication_dbname', (string)get_parameter('replication_dbname'))) if (!config_update_value ('replication_dbname', (string)get_parameter('replication_dbname')))
@ -214,11 +219,8 @@ function config_update_config () {
$error_update[] = __('Replication DB password'); $error_update[] = __('Replication DB password');
if (!config_update_value ('replication_dbport', (string)get_parameter('replication_dbport'))) if (!config_update_value ('replication_dbport', (string)get_parameter('replication_dbport')))
$error_update[] = __('Replication DB port'); $error_update[] = __('Replication DB port');
if (!config_update_value ('replication_mode', (string)get_parameter('replication_mode'))) if (!config_update_value ('metaconsole_agent_cache', (int)get_parameter('metaconsole_agent_cache')))
$error_update[] = __('Replication mode'); $error_update[] = __('Metaconsole agent cache');
if (!config_update_value ('show_events_in_local', (string)get_parameter('show_events_in_local')))
$error_update[] = __('Show events list in local console (read only)');
}
if (!config_update_value ('log_collector', (bool)get_parameter('log_collector'))) if (!config_update_value ('log_collector', (bool)get_parameter('log_collector')))
$error_update[] = __('Activate Log Collector'); $error_update[] = __('Activate Log Collector');
@ -798,6 +800,10 @@ function config_process_config () {
config_update_value ('replication_mode', "only_validated"); config_update_value ('replication_mode', "only_validated");
} }
if (!isset ($config["metaconsole_agent_cache"])) {
config_update_value ('metaconsole_agent_cache', 0);
}
if (!isset ($config["show_events_in_local"])) { if (!isset ($config["show_events_in_local"])) {
config_update_value ('show_events_in_local', 0); config_update_value ('show_events_in_local', 0);
} }

View File

@ -2341,10 +2341,251 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu
else { else {
$i = 0; $i = 0;
} }
/*
* Agent cache for metaconsole.
* Retrieve the statistic data from the cache table.
*/
if (!$user_strict && defined('METACONSOLE') && !empty($list_groups)) {
$cache_table = 'tmetaconsole_agent';
$sql_stats = "SELECT id_grupo, COUNT(id_agente) AS agents_total,
SUM(total_count) AS monitors_total,
SUM(normal_count) AS monitors_ok,
SUM(warning_count) AS monitors_warning,
SUM(critical_count) AS monitors_critical,
SUM(unknown_count) AS monitors_unknown,
SUM(notinit_count) AS monitors_not_init,
SUM(fired_count) AS alerts_fired
FROM $cache_table
WHERE disabled = 0
AND id_grupo IN ($user_groups_ids)
GROUP BY id_grupo";
$data_stats = db_get_all_rows_sql($sql_stats);
$sql_stats_unknown = "SELECT id_grupo, COUNT(id_agente) AS agents_unknown
FROM $cache_table
WHERE disabled = 0
AND id_grupo IN ($user_groups_ids)
AND critical_count = 0
AND warning_count = 0
AND unknown_count > 0
GROUP BY id_grupo";
$data_stats_unknown = db_get_all_rows_sql($sql_stats_unknown);
$sql_stats_not_init = "SELECT id_grupo, COUNT(id_agente) AS agents_not_init
FROM $cache_table
WHERE disabled = 0
AND id_grupo IN ($user_groups_ids)
AND (total_count = 0 OR total_count = notinit_count)
GROUP BY id_grupo";
$data_stats_not_init = db_get_all_rows_sql($sql_stats_not_init);
if ($mode == 'tactical' || $mode == 'tree') {
$sql_stats_ok = "SELECT id_grupo, COUNT(id_agente) AS agents_ok
FROM $cache_table
WHERE disabled = 0
AND id_grupo IN ($user_groups_ids)
AND critical_count = 0
AND warning_count = 0
AND unknown_count = 0
AND normal_count > 0
GROUP BY id_grupo";
$data_stats_ok = db_get_all_rows_sql($sql_stats_ok);
$sql_stats_warning = "SELECT id_grupo, COUNT(id_agente) AS agents_warning
FROM $cache_table
WHERE disabled = 0
AND id_grupo IN ($user_groups_ids)
AND critical_count = 0
AND warning_count > 0
GROUP BY id_grupo";
$data_stats_warning = db_get_all_rows_sql($sql_stats_warning);
$sql_stats_critical = "SELECT id_grupo, COUNT(id_agente) AS agents_critical
FROM $cache_table
WHERE disabled = 0
AND id_grupo IN ($user_groups_ids)
AND critical_count = 0
AND warning_count > 0
GROUP BY id_grupo";
$data_stats_critical = db_get_all_rows_sql($sql_stats_critical);
}
$stats_by_group = array();
if (!empty($data_stats)) {
foreach ($data_stats as $value) {
$group_id = (int) $value['id_grupo'];
$stats = array();
$stats['agents_total'] = (int) $value['agents_total'];
$stats['monitors_total'] = (int) $value['monitors_total'];
$stats['monitors_ok'] = (int) $value['monitors_ok'];
$stats['monitors_warning'] = (int) $value['monitors_warning'];
$stats['monitors_critical'] = (int) $value['monitors_critical'];
$stats['monitors_unknown'] = (int) $value['monitors_unknown'];
$stats['monitors_not_init'] = (int) $value['monitors_not_init'];
$stats['alerts_fired'] = (int) $value['alerts_fired'];
$stats_by_group[$group_id] = $stats;
}
if (!empty($stats_by_group)) {
if (!empty($data_stats_unknown)) {
foreach ($data_stats_unknown as $value) {
$group_id = (int) $value['id_grupo'];
if (isset($stats_by_group[$group_id])) {
$stats_by_group[$group_id]['agents_unknown'] = (int) $value['agents_unknown'];
}
}
}
if (!empty($data_stats_not_init)) {
foreach ($data_stats_not_init as $value) {
$group_id = (int) $value['id_grupo'];
if (isset($stats_by_group[$group_id])) {
$stats_by_group[$group_id]['agents_not_init'] = (int) $value['agents_not_init'];
}
}
}
if (!empty($data_stats_ok)) {
foreach ($data_stats_ok as $value) {
$group_id = (int) $value['id_grupo'];
if (isset($stats_by_group[$group_id])) {
$stats_by_group[$group_id]['agents_ok'] = (int) $value['agents_ok'];
}
}
}
if (!empty($data_stats_warning)) {
foreach ($data_stats_warning as $value) {
$group_id = (int) $value['id_grupo'];
if (isset($stats_by_group[$group_id])) {
$stats_by_group[$group_id]['agents_warning'] = (int) $value['agents_warning'];
}
}
}
if (!empty($data_stats_critical)) {
foreach ($data_stats_critical as $value) {
$group_id = (int) $value['id_grupo'];
if (isset($stats_by_group[$group_id])) {
$stats_by_group[$group_id]['agents_critical'] = (int) $value['agents_critical'];
}
}
}
}
}
}
foreach ($list_groups as $key => $item) { foreach ($list_groups as $key => $item) {
$id = $item['id_grupo']; $id = $item['id_grupo'];
if (($config["realtimestats"] == 0) && !$user_strict) { if (!$user_strict && defined('METACONSOLE')) { // Agent cache
$group_stat = array();
if (isset($stats_by_group[$id]))
$group_stat = $stats_by_group[$id];
$list[$i]['_id_'] = $id;
$list[$i]['_name_'] = $item['nombre'];
$list[$i]['_iconImg_'] = html_print_image ("images/groups_small/" . groups_get_icon($item['id_grupo']).".png", true, array ("style" => 'vertical-align: middle;'));
if ($mode == 'tree' && !empty($item['parent']))
$list[$i]['_parent_id_'] = $item['parent'];
$list[$i]['_agents_unknown_'] = isset($group_stat['agents_unknown']) ? $group_stat['agents_unknown'] : 0;
$list[$i]['_monitors_alerts_fired_'] = isset($group_stat['alerts_fired']) ? $group_stat['alerts_fired'] : 0;
$list[$i]['_total_agents_'] = isset($group_stat['agents_total']) ? $group_stat['agents_total'] : 0;
// This fields are not in database
$list[$i]['_monitors_ok_'] = isset($group_stat['monitors_ok']) ? $group_stat['monitors_ok'] : 0;
$list[$i]['_monitors_critical_'] = isset($group_stat['monitors_critical']) ? $group_stat['monitors_critical'] : 0;
$list[$i]['_monitors_warning_'] = isset($group_stat['monitors_warning']) ? $group_stat['monitors_warning'] : 0;
$list[$i]['_monitors_unknown_'] = isset($group_stat['monitors_unknown']) ? $group_stat['monitors_unknown'] : 0;
$list[$i]['_monitors_not_init_'] = isset($group_stat['monitors_not_init']) ? $group_stat['monitors_not_init'] : 0;
$list[$i]['_agents_not_init_'] = isset($group_stat['agents_not_init']) ? $group_stat['agents_not_init'] : 0;
if ($mode == 'tactical' || $mode == 'tree') {
$list[$i]['_agents_ok_'] = isset($group_stat['agents_ok']) ? $group_stat['agents_ok'] : 0;
$list[$i]['_agents_warning_'] = isset($group_stat['agents_warning']) ? $group_stat['agents_warning'] : 0;
$list[$i]['_agents_critical_'] = isset($group_stat['agents_critical']) ? $group_stat['agents_critical'] : 0;
$list[$i]['_monitors_alerts_'] = isset($group_stat['alerts']) ? $group_stat['alerts'] : 0;;
$list[$i]["_monitor_alerts_fire_count_"] = $group_stat[0]["alerts_fired"];
$list[$i]["_total_checks_"] = $group_stat[0]["modules"];
$list[$i]["_total_alerts_"] = $group_stat[0]["alerts"];
}
if ($mode == 'tactical') {
// Get total count of monitors for this group, except disabled.
$list[$i]["_monitor_checks_"] = $list[$i]["_monitors_not_init_"] + $list[$i]["_monitors_unknown_"] + $list[$i]["_monitors_warning_"] + $list[$i]["_monitors_critical_"] + $list[$i]["_monitors_ok_"];
// Calculate not_normal monitors
$list[$i]["_monitor_not_normal_"] = $list[$i]["_monitor_checks_"] - $list[$i]["_monitors_ok_"];
if ($list[$i]["_monitor_not_normal_"] > 0 && $list[$i]["_monitor_checks_"] > 0) {
$list[$i]["_monitor_health_"] = format_numeric (100 - ($list[$i]["_monitor_not_normal_"] / ($list[$i]["_monitor_checks_"] / 100)), 1);
}
else {
$list[$i]["_monitor_health_"] = 100;
}
if ($list[$i]["_monitors_not_init_"] > 0 && $list[$i]["_monitor_checks_"] > 0) {
$list[$i]["_module_sanity_"] = format_numeric (100 - ($list[$i]["_monitors_not_init_"] / ($list[$i]["_monitor_checks_"] / 100)), 1);
}
else {
$list[$i]["_module_sanity_"] = 100;
}
if (isset($list[$i]["_alerts_"])) {
if ($list[$i]["_monitors_alerts_fired_"] > 0 && $list[$i]["_alerts_"] > 0) {
$list[$i]["_alert_level_"] = format_numeric (100 - ($list[$i]["_monitors_alerts_fired_"] / ($list[$i]["_alerts_"] / 100)), 1);
}
else {
$list[$i]["_alert_level_"] = 100;
}
}
else {
$list[$i]["_alert_level_"] = 100;
$list[$i]["_alerts_"] = 0;
}
$list[$i]["_monitor_bad_"] = $list[$i]["_monitors_critical_"] + $list[$i]["_monitors_warning_"];
if ($list[$i]["_monitor_bad_"] > 0 && $list[$i]["_monitor_checks_"] > 0) {
$list[$i]["_global_health_"] = format_numeric (100 - ($list[$i]["_monitor_bad_"] / ($list[$i]["_monitor_checks_"] / 100)), 1);
}
else {
$list[$i]["_global_health_"] = 100;
}
$list[$i]["_server_sanity_"] = format_numeric (100 - $list[$i]["_module_sanity_"], 1);
}
if ($returnAllGroup) {
$list[0]['_agents_unknown_'] += $list[$i]['_agents_unknown_'];
$list[0]['_monitors_alerts_fired_'] += $list[$i]['_monitors_alerts_fired_'];
$list[0]['_total_agents_'] += $list[$i]['_total_agents_'];
$list[0]['_monitors_ok_'] += $list[$i]['_monitors_ok_'];
$list[0]['_monitors_critical_'] += $list[$i]['_monitors_critical_'];
$list[0]['_monitors_warning_'] += $list[$i]['_monitors_warning_'];
$list[0]['_monitors_unknown_'] += $list[$i]['_monitors_unknown_'];
$list[0]['_monitors_not_init_'] += $list[$i]['_monitors_not_init_'];
$list[0]['_agents_not_init_'] += $list[$i]['_agents_not_init_'];
if ($mode == 'tactical' || $mode == 'tree') {
$list[0]['_agents_ok_'] += $list[$i]['_agents_ok_'];
$list[0]['_agents_warning_'] += $list[$i]['_agents_warning_'];
$list[0]['_agents_critical_'] += $list[$i]['_agents_critical_'];
$list[0]['_monitors_alerts_'] += $list[$i]['_monitors_alerts_'];
}
}
if ($mode == 'group') {
if (($list[$i]['_agents_unknown_'] == 0) && ($list[$i]['_monitors_alerts_fired_'] == 0)
&& ($list[$i]['_total_agents_'] == 0) && ($list[$i]['_monitors_ok_'] == 0)
&& ($list[$i]['_monitors_critical_'] == 0) && ($list[$i]['_monitors_warning_'] == 0)) {
unset($list[$i]);
}
}
}
else if (($config["realtimestats"] == 0) && !$user_strict) {
$group_stat = db_get_all_rows_sql ("SELECT * $group_stat = db_get_all_rows_sql ("SELECT *
FROM tgroup_stat, tgrupo FROM tgroup_stat, tgrupo
WHERE tgrupo.id_grupo = tgroup_stat.id_group WHERE tgrupo.id_grupo = tgroup_stat.id_group
@ -2684,7 +2925,7 @@ function group_get_groups_list($id_user = false, $user_strict = false, $access =
$acltags = tags_get_user_module_and_tags ($id_user, $access, $user_strict); $acltags = tags_get_user_module_and_tags ($id_user, $access, $user_strict);
if (! defined ('METACONSOLE')) { if (! $user_strict) {
$result_list = group_get_data ($id_user, $user_strict, $acltags, $result_list = group_get_data ($id_user, $user_strict, $acltags,
$returnAllGroup, $mode); $returnAllGroup, $mode);

View File

@ -1853,12 +1853,16 @@ function reporting_get_stats_alerts($data, $links = false) {
__('Defined and fired alerts') . __('Defined and fired alerts') .
'</legend>' . '</legend>' .
html_print_table($table_al, true) . '</fieldset>'; html_print_table($table_al, true) . '</fieldset>';
}else{ }
else {
// Remove the defined alerts cause with the new cache table is difficult to retrieve them
unset($table_al->data[0][0], $table_al->data[0][1]);
$table_al->class = "tactical_view"; $table_al->class = "tactical_view";
$table_al->style = array(); $table_al->style = array();
$output = '<fieldset class="tactical_set"> $output = '<fieldset class="tactical_set">
<legend>' . <legend>' .
__('Defined and fired alerts') . __('Fired alerts') .
'</legend>' . '</legend>' .
html_print_table($table_al, true) . '</fieldset>'; html_print_table($table_al, true) . '</fieldset>';
} }

View File

@ -3157,7 +3157,6 @@ function ui_print_agent_autocomplete_input($parameters) {
jQuery.ajax ({ jQuery.ajax ({
data: data_params, data: data_params,
async: false,
type: "POST", type: "POST",
url: action="' . $javascript_ajax_page . '", url: action="' . $javascript_ajax_page . '",
timeout: 10000, timeout: 10000,
@ -3371,15 +3370,12 @@ function ui_print_agent_autocomplete_input($parameters) {
jQuery.ajax ({ jQuery.ajax ({
data: data_params, data: data_params,
async: false,
type: "POST", type: "POST",
url: action="' . $javascript_ajax_page . '", url: action="' . $javascript_ajax_page . '",
timeout: 10000, timeout: 10000,
dataType: "json", dataType: "json",
success: function (data) { success: function (data) {
if (data.length == 0) { if (data.length == 0) {
alert("' . __('Does not exist agent with this name.') . '");
//Set icon //Set icon
$("#' . $input_id . '") $("#' . $input_id . '")
.css("background", .css("background",

View File

@ -159,7 +159,6 @@ function show_response_dialog(event_id, response_id, response) {
data: params.join ("&"), data: params.join ("&"),
type: 'POST', type: 'POST',
url: action=ajax_file, url: action=ajax_file,
async: false,
timeout: 10000, timeout: 10000,
dataType: 'html', dataType: 'html',
success: function (data) { success: function (data) {

View File

@ -63,7 +63,7 @@
<div style='height: 10px'> <div style='height: 10px'>
<?php <?php
$version = '6.0dev'; $version = '6.0dev';
$build = '150424'; $build = '150427';
$banner = "v$version Build $build"; $banner = "v$version Build $build";
error_reporting(0); error_reporting(0);

View File

@ -423,6 +423,9 @@ if (is_ajax ()) {
($filter != '' ? $filter : false), $indexed); ($filter != '' ? $filter : false), $indexed);
} }
if (empty($agent_modules))
$agent_modules = array();
foreach ($agent_modules as $key => $module) { foreach ($agent_modules as $key => $module) {
$agent_modules[$key]['nombre'] = io_safe_output($module['nombre']); $agent_modules[$key]['nombre'] = io_safe_output($module['nombre']);
} }
@ -443,23 +446,19 @@ if (is_ajax ()) {
$server = null; $server = null;
if ($metaconsole) { if ($metaconsole) {
$strict_user = (bool) db_get_value('strict_acl', 'tusuario', 'id_user', $config['id_user']); $filter = array();
$server = db_get_row('tmetaconsole_setup', 'id', $id_server); if (!empty($id_agent))
$filter['id_tagente'] = $id_agent;
if (!empty($id_server))
$filter['id_tmetaconsole_setup'] = $id_server;
if (metaconsole_connect($server) != NOERR) { $agent = db_get_row_filter('tmetaconsole_agent', $filter);
return;
}
$agent = db_get_row ('tagente', 'id_agente', $id_agent);
metaconsole_restore_db();
} }
else { else {
$agent = db_get_row ('tagente', 'id_agente', $id_agent); $agent = db_get_row ('tagente', 'id_agente', $id_agent);
} }
if ($agent === false) { return; }
echo '<h3>'.$agent['nombre'].'</h3>'; echo '<h3>'.$agent['nombre'].'</h3>';
echo '<strong>'.__('Main IP').':</strong> '.$agent['direccion'].'<br />'; echo '<strong>'.__('Main IP').':</strong> '.$agent['direccion'].'<br />';
@ -475,6 +474,7 @@ if (is_ajax ()) {
echo '<strong>'.__('Last contact').':</strong> '.human_time_comparation($agent['ultimo_contacto']).'<br />'; echo '<strong>'.__('Last contact').':</strong> '.human_time_comparation($agent['ultimo_contacto']).'<br />';
echo '<strong>'.__('Last remote contact').':</strong> '.human_time_comparation($agent['ultimo_contacto_remoto']).'<br />'; echo '<strong>'.__('Last remote contact').':</strong> '.human_time_comparation($agent['ultimo_contacto_remoto']).'<br />';
if (!$metaconsole) {
# Fix : Only show agents with module with tags of user profile # Fix : Only show agents with module with tags of user profile
$_user_tags = tags_get_user_tags($config['id_user'], 'RR'); $_user_tags = tags_get_user_tags($config['id_user'], 'RR');
@ -497,43 +497,21 @@ if (is_ajax ()) {
$sql .= $_sql_post; $sql .= $_sql_post;
if ($metaconsole) {
if (metaconsole_connect($server) != NOERR) {
return;
}
$bad_modules = db_get_all_rows_sql ($sql); $bad_modules = db_get_all_rows_sql ($sql);
metaconsole_restore_db();
}
else {
$bad_modules = db_get_all_rows_sql ($sql);
}
$sql = sprintf ('SELECT COUNT(*) $sql = sprintf ('SELECT COUNT(*)
FROM tagente_modulo FROM tagente_modulo
WHERE id_agente = %d WHERE id_agente = %d
AND disabled = 0', $id_agent); AND disabled = 0', $id_agent);
if ($metaconsole) {
if (metaconsole_connect($server) != NOERR) {
return;
}
$total_modules = db_get_sql ($sql); $total_modules = db_get_sql ($sql);
metaconsole_restore_db();
}
else {
$total_modules = db_get_sql ($sql);
}
if ($bad_modules === false) if ($bad_modules === false)
$size_bad_modules = 0; $size_bad_modules = 0;
else else
$size_bad_modules = sizeof ($bad_modules); $size_bad_modules = sizeof ($bad_modules);
// Modules down // Modules down
if ($size_bad_modules > 0 && (!$metaconsole || !$strict_user)) { if ($size_bad_modules > 0) {
echo '<strong>'.__('Monitors down').':</strong> '.$size_bad_modules.' / '.$total_modules; echo '<strong>'.__('Monitors down').':</strong> '.$size_bad_modules.' / '.$total_modules;
echo '<ul>'; echo '<ul>';
foreach ($bad_modules as $module) { foreach ($bad_modules as $module) {
@ -554,20 +532,10 @@ if (is_ajax ()) {
AND tagente_modulo.id_agente_modulo = talert_template_modules.id_agent_module AND tagente_modulo.id_agente_modulo = talert_template_modules.id_agent_module
AND talert_template_modules.times_fired > 0 ', AND talert_template_modules.times_fired > 0 ',
$id_agent); $id_agent);
if ($metaconsole) {
if (metaconsole_connect($server) != NOERR) {
return;
}
$alert_modules = db_get_sql ($sql); $alert_modules = (int) db_get_sql ($sql);
metaconsole_restore_db(); if ($alert_modules > 0) {
}
else {
$alert_modules = db_get_sql ($sql);
}
if ($alert_modules > 0 && (!$metaconsole || !$strict_user)) {
$sql = sprintf ('SELECT tagente_modulo.nombre, talert_template_modules.last_fired $sql = sprintf ('SELECT tagente_modulo.nombre, talert_template_modules.last_fired
FROM talert_template_modules, tagente_modulo, tagente FROM talert_template_modules, tagente_modulo, tagente
WHERE tagente.id_agente = %d WHERE tagente.id_agente = %d
@ -577,18 +545,9 @@ if (is_ajax ()) {
AND tagente_modulo.id_agente_modulo = talert_template_modules.id_agent_module AND tagente_modulo.id_agente_modulo = talert_template_modules.id_agent_module
AND talert_template_modules.times_fired > 0 ', AND talert_template_modules.times_fired > 0 ',
$id_agent); $id_agent);
if ($metaconsole) {
if (metaconsole_connect($server) != NOERR) {
return;
}
$alerts = db_get_all_rows_sql ($sql); $alerts = db_get_all_rows_sql ($sql);
metaconsole_restore_db();
}
else {
$alerts = db_get_all_rows_sql ($sql);
}
echo '<strong>'.__('Alerts fired').':</strong>'; echo '<strong>'.__('Alerts fired').':</strong>';
echo "<ul>"; echo "<ul>";
foreach ($alerts as $alert_item) { foreach ($alerts as $alert_item) {
@ -599,6 +558,7 @@ if (is_ajax ()) {
} }
echo '</ul>'; echo '</ul>';
} }
}
return; return;
} }

View File

@ -223,7 +223,7 @@ $date_from = (string)get_parameter('date_from', '');
$date_to = (string)get_parameter('date_to', ''); $date_to = (string)get_parameter('date_to', '');
$server_id = (int)get_parameter('server_id', 0); $server_id = (int)get_parameter('server_id', 0);
$text_agent = (string) get_parameter("text_agent", __("All")); $text_agent = (string) get_parameter("text_agent");
$id_agent = get_parameter('id_agent', 0); $id_agent = get_parameter('id_agent', 0);
if ($id_agent != 0) { if ($id_agent != 0) {
$text_agent = db_get_value('nombre', 'tagente', 'id_agente', $id_agent); $text_agent = db_get_value('nombre', 'tagente', 'id_agente', $id_agent);

View File

@ -17,15 +17,14 @@
// Load global vars // Load global vars
global $config; global $config;
require_once ($config['homedir'] . "/include/functions.php");
require_once ($config['homedir'] . "/include/functions_events.php"); //Event processing functions require_once ($config['homedir'] . "/include/functions_events.php"); //Event processing functions
require_once ($config['homedir'] . "/include/functions_alerts.php"); //Alerts processing functions require_once ($config['homedir'] . "/include/functions_alerts.php"); //Alerts processing functions
require_once ($config['homedir']. "/include/functions.php");
require_once ($config['homedir'] . "/include/functions_agents.php"); //Agents funtions require_once ($config['homedir'] . "/include/functions_agents.php"); //Agents funtions
require_once ($config['homedir'] . "/include/functions_users.php"); //Users functions require_once ($config['homedir'] . "/include/functions_users.php"); //Users functions
require_once ($config['homedir'] . '/include/functions_groups.php'); require_once ($config['homedir'] . "/include/functions_groups.php");
require_once ($config["homedir"] . "/include/functions_graph.php");
require_once ($config["homedir"] . '/include/functions_graph.php'); require_once ($config["homedir"] . "/include/functions_tags.php");
require_once ($config["homedir"] . '/include/functions_tags.php');
check_login (); check_login ();
@ -36,8 +35,6 @@ if (! check_acl ($config["id_user"], 0, "ER")) {
return; return;
} }
$strict_user = db_get_value('strict_acl', 'tusuario', 'id_user', $config['id_user']);
if(defined('METACONSOLE')){ if(defined('METACONSOLE')){
$jump = '&nbsp;&nbsp;'; $jump = '&nbsp;&nbsp;';
} }

View File

@ -108,13 +108,7 @@ switch ($tab) {
break; break;
} }
if (defined('METACONSOLE')) { if (!defined('METACONSOLE')) {
if ($strict_acl)
$header_sub_title = '';
ui_meta_print_header($header_title, $header_sub_title, $tabs);
}
else{
if (!$strict_acl) if (!$strict_acl)
$header_title = $header_title ." - ". $header_sub_title; $header_title = $header_title ." - ". $header_sub_title;
@ -154,6 +148,7 @@ $table->rowspan[][count($row)-1] = 2;
$table->data[] = $row; $table->data[] = $row;
if (!defined('METACONSOLE')) {
// Module filter // Module filter
$module_status_arr = array(); $module_status_arr = array();
$module_status_arr[-1] = __('All'); //default $module_status_arr[-1] = __('All'); //default
@ -167,12 +162,10 @@ $row = array();
$row[] = __('Module status'); $row[] = __('Module status');
$row[] = html_print_select($module_status_arr, "status_module", $status_module, '', '', 0, true); $row[] = html_print_select($module_status_arr, "status_module", $status_module, '', '', 0, true);
$row[] = __('Search module'); $row[] = __('Search module');
if (defined('METACONSOLE'))
$row[] = html_print_input_text("search_module", $search_module, '', 70, 30, true);
else
$row[] = html_print_input_text("search_module", $search_module, '', 40, 30, true); $row[] = html_print_input_text("search_module", $search_module, '', 40, 30, true);
$table->data[] = $row; $table->data[] = $row;
}
if (defined('METACONSOLE')) { if (defined('METACONSOLE')) {
$table->width = "96%"; $table->width = "96%";

View File

@ -3,7 +3,7 @@
# #
%define name pandorafms_console %define name pandorafms_console
%define version 6.0dev %define version 6.0dev
%define release 150424 %define release 150427
# User and Group under which Apache is running # User and Group under which Apache is running
%define httpd_name httpd %define httpd_name httpd

View File

@ -3,7 +3,7 @@
# #
%define name pandorafms_console %define name pandorafms_console
%define version 6.0dev %define version 6.0dev
%define release 150424 %define release 150427
%define httpd_name httpd %define httpd_name httpd
# User and Group under which Apache is running # User and Group under which Apache is running
%define httpd_name apache2 %define httpd_name apache2

View File

@ -38,7 +38,7 @@ INSERT INTO `tconfig` (`token`, `value`) VALUES
('graph_res','5'), ('graph_res','5'),
('step_compact','1'), ('step_compact','1'),
('db_scheme_version','6.0dev'), ('db_scheme_version','6.0dev'),
('db_scheme_build','PD150424'), ('db_scheme_build','PD150427'),
('show_unknown','0'), ('show_unknown','0'),
('show_lastalerts','1'), ('show_lastalerts','1'),
('style','pandora'), ('style','pandora'),

View File

@ -1,5 +1,5 @@
package: pandorafms-server package: pandorafms-server
Version: 6.0dev-150424 Version: 6.0dev-150427
Architecture: all Architecture: all
Priority: optional Priority: optional
Section: admin Section: admin

View File

@ -14,7 +14,7 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
pandora_version="6.0dev-150424" pandora_version="6.0dev-150427"
package_cpan=0 package_cpan=0
package_pandora=1 package_pandora=1

View File

@ -101,6 +101,9 @@ sub pandora_startup () {
# Generate the encryption key after reading the passphrase. # Generate the encryption key after reading the passphrase.
$Config{"encryption_key"} = enterprise_hook('pandora_get_encryption_key', [\%Config, $Config{"encryption_passphrase"}]); $Config{"encryption_key"} = enterprise_hook('pandora_get_encryption_key', [\%Config, $Config{"encryption_passphrase"}]);
# Update the agent cache.
enterprise_hook('update_agent_cache', [\%Config, $DBH]) if ($Config{'metaconsole_agent_cache'} == 1);
pandora_audit (\%Config, 'Pandora FMS Server Daemon starting', 'SYSTEM', 'System', $DBH); pandora_audit (\%Config, 'Pandora FMS Server Daemon starting', 'SYSTEM', 'System', $DBH);
# Load servers # Load servers
@ -297,7 +300,7 @@ sub pandora_server_tasks ($) {
logger ($pa_config, "Updating module status and fired alert counts for agent " . $agent->{'nombre'}, 10); logger ($pa_config, "Updating module status and fired alert counts for agent " . $agent->{'nombre'}, 10);
if ($agent->{'update_module_count'} == 1) { if ($agent->{'update_module_count'} == 1) {
pandora_update_agent_module_count ($dbh, $agent->{'id_agente'}); pandora_update_agent_module_count ($pa_config, $dbh, $agent->{'id_agente'});
} }
if ($agent->{'update_alert_count'} == 1) { if ($agent->{'update_alert_count'} == 1) {

View File

@ -43,7 +43,7 @@ our @EXPORT = qw(
# version: Defines actual version of Pandora Server for this module only # version: Defines actual version of Pandora Server for this module only
my $pandora_version = "6.0dev"; my $pandora_version = "6.0dev";
my $pandora_build = "150424"; my $pandora_build = "150427";
our $VERSION = $pandora_version." ".$pandora_build; our $VERSION = $pandora_version." ".$pandora_build;
# Setup hash # Setup hash
@ -159,6 +159,9 @@ sub pandora_get_sharedconfig ($$) {
# Pandora FMS Console's attachment directory # Pandora FMS Console's attachment directory
$pa_config->{"attachment_dir"} = pandora_get_tconfig_token ($dbh, 'attachment_store', '/var/www/pandora_console/attachment'); $pa_config->{"attachment_dir"} = pandora_get_tconfig_token ($dbh, 'attachment_store', '/var/www/pandora_console/attachment');
# Metaconsole agent cache.
$pa_config->{"metaconsole_agent_cache"} = pandora_get_tconfig_token ($dbh, 'metaconsole_agent_cache', 0);
} }
########################################################################## ##########################################################################

View File

@ -2608,7 +2608,7 @@ sub pandora_create_module_from_hash ($$$) {
sub pandora_update_module_from_hash ($$$$$) { sub pandora_update_module_from_hash ($$$$$) {
my ($pa_config, $parameters, $where_column, $where_value, $dbh) = @_; my ($pa_config, $parameters, $where_column, $where_value, $dbh) = @_;
my $module_id = db_process_update($dbh, 'tagente_modulo', $parameters, $where_column, $where_value); my $module_id = db_process_update($dbh, 'tagente_modulo', $parameters, {$where_column => $where_value});
return $module_id; return $module_id;
} }
@ -2618,7 +2618,7 @@ sub pandora_update_module_from_hash ($$$$$) {
sub pandora_update_table_from_hash ($$$$$$) { sub pandora_update_table_from_hash ($$$$$$) {
my ($pa_config, $parameters, $where_column, $where_value, $table, $dbh) = @_; my ($pa_config, $parameters, $where_column, $where_value, $table, $dbh) = @_;
my $module_id = db_process_update($dbh, $table, $parameters, $where_column, $where_value); my $module_id = db_process_update($dbh, $table, $parameters, {$where_column => $where_value});
return $module_id; return $module_id;
} }
@ -4663,24 +4663,8 @@ sub pandora_set_event_storm_protection ($) {
########################################################################## ##########################################################################
# Update the module status count of an agent. # Update the module status count of an agent.
########################################################################## ##########################################################################
sub pandora_update_agent_count ($$) { sub pandora_update_agent_module_count ($$$) {
my ($dbh, $agent_id) = @_; my ($pa_config, $dbh, $agent_id) = @_;
db_do ($dbh, 'UPDATE tagente SET update_module_count=0,
normal_count=(SELECT COUNT(*) FROM tagente_modulo, tagente_estado WHERE tagente_modulo.id_agente_modulo=tagente_estado.id_agente_modulo AND tagente_modulo.id_agente=' . $agent_id . ' AND estado=0),
critical_count=(SELECT COUNT(*) FROM tagente_modulo, tagente_estado WHERE tagente_modulo.id_agente_modulo=tagente_estado.id_agente_modulo AND tagente_modulo.id_agente=' . $agent_id . ' AND estado=1),
warning_count=(SELECT COUNT(*) FROM tagente_modulo, tagente_estado WHERE tagente_modulo.id_agente_modulo=tagente_estado.id_agente_modulo AND tagente_modulo.id_agente=' . $agent_id . ' AND estado=2),
unknown_count=(SELECT COUNT(*) FROM tagente_modulo, tagente_estado WHERE tagente_modulo.id_agente_modulo=tagente_estado.id_agente_modulo AND tagente_modulo.id_agente=' . $agent_id . ' AND estado=3),
notinit_count=(SELECT COUNT(*) FROM tagente_modulo, tagente_estado WHERE tagente_modulo.id_agente_modulo=tagente_estado.id_agente_modulo AND tagente_modulo.id_agente=' . $agent_id . ' AND estado=4),
total_count=(SELECT COUNT(*) FROM tagente_modulo, tagente_estado WHERE tagente_modulo.id_agente_modulo=tagente_estado.id_agente_modulo AND tagente_modulo.id_agente=' . $agent_id .
') WHERE id_agente = ' . $agent_id);
}
##########################################################################
# Update the module status count of an agent.
##########################################################################
sub pandora_update_agent_module_count ($$) {
my ($dbh, $agent_id) = @_;
db_do ($dbh, 'UPDATE tagente SET update_module_count=0, db_do ($dbh, 'UPDATE tagente SET update_module_count=0,
normal_count=(SELECT COUNT(*) FROM tagente_modulo, tagente_estado WHERE tagente_modulo.disabled=0 AND tagente_modulo.id_agente_modulo=tagente_estado.id_agente_modulo AND tagente_modulo.id_agente=' . $agent_id . ' AND estado=0), normal_count=(SELECT COUNT(*) FROM tagente_modulo, tagente_estado WHERE tagente_modulo.disabled=0 AND tagente_modulo.id_agente_modulo=tagente_estado.id_agente_modulo AND tagente_modulo.id_agente=' . $agent_id . ' AND estado=0),
@ -4690,6 +4674,9 @@ sub pandora_update_agent_module_count ($$) {
notinit_count=(SELECT COUNT(*) FROM tagente_modulo, tagente_estado WHERE tagente_modulo.disabled=0 AND tagente_modulo.id_agente_modulo=tagente_estado.id_agente_modulo AND tagente_modulo.id_agente=' . $agent_id . ' AND estado=4), notinit_count=(SELECT COUNT(*) FROM tagente_modulo, tagente_estado WHERE tagente_modulo.disabled=0 AND tagente_modulo.id_agente_modulo=tagente_estado.id_agente_modulo AND tagente_modulo.id_agente=' . $agent_id . ' AND estado=4),
total_count=(SELECT COUNT(*) FROM tagente_modulo, tagente_estado WHERE tagente_modulo.disabled=0 AND tagente_modulo.id_agente_modulo=tagente_estado.id_agente_modulo AND tagente_modulo.id_agente=' . $agent_id . total_count=(SELECT COUNT(*) FROM tagente_modulo, tagente_estado WHERE tagente_modulo.disabled=0 AND tagente_modulo.id_agente_modulo=tagente_estado.id_agente_modulo AND tagente_modulo.id_agente=' . $agent_id .
') WHERE id_agente = ' . $agent_id); ') WHERE id_agente = ' . $agent_id);
# Sync the agent cache every time the module count is updated.
enterprise_hook('update_agent_cache', [$pa_config, $dbh, $agent_id]) if ($pa_config->{'metaconsole_agent_cache'} == 1);
} }
########################################################################## ##########################################################################

View File

@ -765,17 +765,20 @@ sub db_process_insert($$$$;@) {
######################################################################## ########################################################################
## SQL update. ## SQL update.
######################################################################## ########################################################################
sub db_process_update($$$$$;@) { sub db_process_update($$$$) {
my ($dbh, $table, $parameters, $where_column, $where_value, @values) = @_; my ($dbh, $table, $parameters, $conditions) = @_;
my @columns_array = keys %$parameters; my @columns_array = keys %$parameters;
my @values_array = values %$parameters; my @values_array = values %$parameters;
my @where_columns = keys %$conditions;
my @where_values = values %$conditions;
if (!defined($table) || $#columns_array == -1) { if (!defined($table) || $#columns_array == -1 || $#where_columns == -1) {
return -1; return -1;
exit; exit;
} }
# VALUES...
my $fields = ''; my $fields = '';
for (my $i = 0; $i <= $#values_array; $i++) { for (my $i = 0; $i <= $#values_array; $i++) {
if (!defined($values_array[$i])) { if (!defined($values_array[$i])) {
@ -788,11 +791,22 @@ sub db_process_update($$$$$;@) {
" " . $RDBMS_QUOTE . "$columns_array[$i]" . $RDBMS_QUOTE . " = ?"; " " . $RDBMS_QUOTE . "$columns_array[$i]" . $RDBMS_QUOTE . " = ?";
} }
push(@values_array, $where_value); # WHERE...
my $where = '';
for (my $i = 0; $i <= $#where_columns; $i++) {
if (!defined($where_values[$i])) {
$where_values[$i] = '';
}
if ($i > 0 && $i <= $#where_values) {
$where = $where.' AND ';
}
$where = $where .
" " . $RDBMS_QUOTE . "$where_columns[$i]" . $RDBMS_QUOTE . " = ?";
}
my $res = db_update ($dbh, "UPDATE $table my $res = db_update ($dbh, "UPDATE $table
SET $fields SET $fields
WHERE $where_column = ?", @values_array); WHERE $where", @values_array, @where_values);
return $res; return $res;
} }

View File

@ -3,7 +3,7 @@
# #
%define name pandorafms_server %define name pandorafms_server
%define version 6.0dev %define version 6.0dev
%define release 150424 %define release 150427
Summary: Pandora FMS Server Summary: Pandora FMS Server
Name: %{name} Name: %{name}

View File

@ -3,7 +3,7 @@
# #
%define name pandorafms_server %define name pandorafms_server
%define version 6.0dev %define version 6.0dev
%define release 150424 %define release 150427
Summary: Pandora FMS Server Summary: Pandora FMS Server
Name: %{name} Name: %{name}

View File

@ -33,7 +33,7 @@ use PandoraFMS::Tools;
use PandoraFMS::DB; use PandoraFMS::DB;
# version: define current version # version: define current version
my $version = "6.0dev PS150424"; my $version = "6.0dev PS150427";
# Pandora server configuration # Pandora server configuration
my %conf; my %conf;

View File

@ -35,7 +35,7 @@ use Encode::Locale;
Encode::Locale::decode_argv; Encode::Locale::decode_argv;
# version: define current version # version: define current version
my $version = "6.0dev PS150424"; my $version = "6.0dev PS150427";
# save program name for logging # save program name for logging
my $progname = basename($0); my $progname = basename($0);
@ -538,7 +538,7 @@ sub pandora_validate_event_id ($$$) {
sub pandora_update_user_from_hash ($$$$) { sub pandora_update_user_from_hash ($$$$) {
my ($parameters, $where_column, $where_value, $dbh) = @_; my ($parameters, $where_column, $where_value, $dbh) = @_;
my $user_id = db_process_update($dbh, 'tusuario', $parameters, $where_column, $where_value); my $user_id = db_process_update($dbh, 'tusuario', $parameters, {$where_column => $where_value});
return $user_id; return $user_id;
} }
@ -548,7 +548,7 @@ sub pandora_update_user_from_hash ($$$$) {
sub pandora_update_alert_template_from_hash ($$$$) { sub pandora_update_alert_template_from_hash ($$$$) {
my ($parameters, $where_column, $where_value, $dbh) = @_; my ($parameters, $where_column, $where_value, $dbh) = @_;
my $template_id = db_process_update($dbh, 'talert_templates', $parameters, $where_column, $where_value); my $template_id = db_process_update($dbh, 'talert_templates', $parameters, {$where_column => $where_value});
return $template_id; return $template_id;
} }
@ -662,7 +662,7 @@ sub pandora_create_special_day_from_hash ($$$) {
sub pandora_update_special_day_from_hash ($$$$) { sub pandora_update_special_day_from_hash ($$$$) {
my ($parameters, $where_column, $where_value, $dbh) = @_; my ($parameters, $where_column, $where_value, $dbh) = @_;
my $special_day_id = db_process_update($dbh, 'talert_special_days', $parameters, $where_column, $where_value); my $special_day_id = db_process_update($dbh, 'talert_special_days', $parameters, {$where_column => $where_value});
return $special_day_id; return $special_day_id;
} }
@ -3521,7 +3521,7 @@ sub cli_stop_downtime () {
my $parameters->{'date_to'} = time; my $parameters->{'date_to'} = time;
db_process_update($dbh, 'tplanned_downtime', $parameters, 'id', $downtime_id); db_process_update($dbh, 'tplanned_downtime', $parameters, {'id' => $downtime_id});
} }
############################################################################### ###############################################################################
@ -3634,7 +3634,7 @@ sub pandora_get_event_name($$) {
sub pandora_update_event_from_hash ($$$$) { sub pandora_update_event_from_hash ($$$$) {
my ($parameters, $where_column, $where_value, $dbh) = @_; my ($parameters, $where_column, $where_value, $dbh) = @_;
my $event_id = db_process_update($dbh, 'tevento', $parameters, $where_column, $where_value); my $event_id = db_process_update($dbh, 'tevento', $parameters, {$where_column => $where_value});
return $event_id; return $event_id;
} }