Merge branch 'ent-8558-inventario-pasa-de-enterprise-open' into 'develop'

Move inventory to open

See merge request artica/pandorafms!5105
This commit is contained in:
Daniel Rodriguez 2023-01-16 13:43:19 +00:00
commit a165eec2a1
32 changed files with 3853 additions and 30 deletions

View File

@ -207,6 +207,6 @@ module_end
module_plugin grep_log /var/log/auth.log Syslog sshd
# Plugin for inventory on the agent (Only Enterprise)
# Plugin for inventory on the agent.
# module_plugin inventory 1 cpu ram video nic hd cdrom software

View File

@ -269,7 +269,7 @@ module_plugin grep_log /var/log/syslog Syslog ssh
#module_description Used memory in KB postprocessed to be in MB
#module_end
# Plugin for inventory on the agent (Only Enterprise)
# Plugin for inventory on the agent.
# module_plugin inventory 1 cpu ram video nic hd cdrom software init_services filesystem users process ip route

View File

@ -164,5 +164,5 @@ module_end
module_plugin grep_log /var/log/syslog Syslog ssh
# Plugin for inventory on the agent (Only Enterprise)
# Plugin for inventory on the agent.
# module_plugin inventory 1 cpu ram video nic hd cdrom software

View File

@ -379,6 +379,6 @@ module_end
#module_plugin grep_log /var/log/syslog Syslog ssh
# Plugin for inventory on the agent (Only Enterprise)
# Plugin for inventory on the agent.
# module_plugin inventory 1 cpu ram video nic hd cdrom software

View File

@ -272,7 +272,7 @@ module_plugin pandora_df_free
module_plugin grep_log /var/log/auth.log Syslog sshd
# Plugin for inventory on the agent (Only Enterprise)
# Plugin for inventory on the agent.
# module_plugin inventory 1 cpu ram video nic hd cdrom software init_services filesystem users route
# Log collection modules. Only for enterprise version, this will collect log files for forensic analysis.

View File

@ -269,7 +269,7 @@ module_plugin pandora_netusage
# Service autodiscovery plugin
module_plugin autodiscover --default
# Plugin for inventory on the agent (Only Enterprise)
# Plugin for inventory on the agent.
#module_plugin inventory 1 cpu ram video nic hd cdrom software init_services filesystem users route
# Log collection modules. Only for enterprise version, this will collect log files for forensic analysis.

View File

@ -232,6 +232,6 @@ module_end
module_plugin grep_log /var/log/auth.log Syslog sshd
# Plugin for inventory on the agent (Only Enterprise)
# Plugin for inventory on the agent.
# module_plugin inventory 1 cpu ram video nic hd cdrom software

View File

@ -1685,5 +1685,10 @@ enterprise/operation/agentes/manage_transmap.php
enterprise/operation/agentes/manage_transmap_creation.php
enterprise/operation/agentes/manage_transmap_creation_phases_data.php
enterprise/operation/agentes/transactional_map.php
enterprise/godmode/agentes/inventory_manager.php
enterprise/operation/agentes/agent_inventory.php
enterprise/godmode/modules/manage_inventory_modules.php
enterprise/godmode/modules/manage_inventory_modules_form.php
enterprise/operation/inventory/inventory.php
include/test.js
include/web2image.js

View File

@ -459,7 +459,20 @@ if ($id_agente) {
// Inventory.
$inventorytab = enterprise_hook('inventory_tab');
$inventorytab['text'] = '<a href="index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=inventory&id_agente='.$id_agente.'">'.html_print_image(
'images/page_white_text.png',
true,
[
'title' => __('Inventory'),
'class' => 'invert_filter',
]
).'</a>';
if ($tab == 'inventory') {
$inventorytab['active'] = true;
} else {
$inventorytab['active'] = false;
}
if ($inventorytab == -1) {
$inventorytab = '';
@ -2384,6 +2397,10 @@ switch ($tab) {
include 'agent_wizard.php';
break;
case 'inventory':
include 'inventory_manager.php';
break;
default:
if (enterprise_hook('switch_agent_tab', [$tab])) {
// This will make sure that blank pages will have at least some

View File

@ -0,0 +1,263 @@
<?php
// ______ __ _______ _______ _______
// | __ \.---.-.-----.--| |.-----.----.---.-. | ___| | | __|
// | __/| _ | | _ || _ | _| _ | | ___| |__ |
// |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
//
// ============================================================================
// Copyright (c) 2007-2021 Artica Soluciones Tecnologicas, http://www.artica.es
// This code is NOT free software. This code is NOT licenced under GPL2 licence
// You cannnot redistribute it without written permission of copyright holder.
// ============================================================================
// Load global variables
global $config;
// Check user credentials
check_login();
if (! check_acl($config['id_user'], 0, 'AW')) {
db_pandora_audit(
AUDIT_LOG_ACL_VIOLATION,
'Trying to access agent manager'
);
include $config['homedir'].'/general/noaccess.php';
return;
}
global $direccion_agente, $id_agente, $id_os;
// include_once ($config['homedir'].'/'.ENTERPRISE_DIR.'/include/functions_policies.php');
require_once $config['homedir'].'/include/functions_ui.php';
// Initialize data
$add_inventory_module = (boolean) get_parameter('add_inventory_module');
$update_inventory_module = (boolean) get_parameter('update_inventory_module');
$delete_inventory_module = (int) get_parameter('delete_inventory_module');
$load_inventory_module = (int) get_parameter('load_inventory_module');
$force_inventory_module = (int) get_parameter('force_inventory_module');
$id_agent_module_inventory = (int) get_parameter('id_agent_module_inventory');
$id_module_inventory = (int) get_parameter('id_module_inventory');
$target = (string) get_parameter('target', '');
$username = (string) get_parameter('username');
$password = io_input_password((string) get_parameter('password'));
$interval = (int) get_parameter('interval');
$custom_fields = array_map(
function ($field) {
$field['secure'] = (bool) $field['secure'];
if ($field['secure']) {
$field['value'] = io_input_password($field['value']);
}
return $field;
},
get_parameter('custom_fields', [])
);
$custom_fields_enabled = (bool) get_parameter('custom_fields_enabled');
// Add inventory module to agent
if ($add_inventory_module) {
$if_exists = db_get_value_filter(
'id_agent_module_inventory',
'tagent_module_inventory',
[
'id_agente' => $id_agente,
'id_module_inventory' => $id_module_inventory,
]
);
if (!$if_exists) {
$values = [
'id_agente' => $id_agente,
'id_module_inventory' => $id_module_inventory,
'target' => $target,
'interval' => $interval,
'username' => $username,
'password' => $password,
'custom_fields' => $custom_fields_enabled && !empty($custom_fields) ? base64_encode(json_encode($custom_fields)) : '',
];
$result = db_process_sql_insert('tagent_module_inventory', $values);
if ($result) {
ui_print_success_message(__('Successfully added inventory module'));
} else {
ui_print_error_message(__('Error adding inventory module'));
}
} else {
ui_print_error_message(__('The inventory of the module already exists'));
}
// Remove inventory module from agent
} else if ($delete_inventory_module) {
$result = db_process_sql_delete(
'tagent_module_inventory',
['id_agent_module_inventory' => $delete_inventory_module]
);
if ($result) {
ui_print_success_message(__('Successfully deleted inventory module'));
} else {
ui_print_error_message(__('Error deleting inventory module'));
}
// Update inventory module
} else if ($force_inventory_module) {
$result = db_process_sql_update('tagent_module_inventory', ['flag' => 1], ['id_agent_module_inventory' => $force_inventory_module]);
if ($result) {
ui_print_success_message(__('Successfully forced inventory module'));
} else {
ui_print_error_message(__('Error forcing inventory module'));
}
// Update inventory module
} else if ($update_inventory_module) {
$values = [
'target' => $target,
'interval' => $interval,
'username' => $username,
'password' => $password,
'custom_fields' => $custom_fields_enabled && !empty($custom_fields) ? base64_encode(json_encode($custom_fields)) : '',
];
$result = db_process_sql_update('tagent_module_inventory', $values, ['id_agent_module_inventory' => $id_agent_module_inventory, 'id_agente' => $id_agente]);
if ($result) {
ui_print_success_message(__('Successfully updated inventory module'));
} else {
ui_print_error_message(__('Error updating inventory module'));
}
}
// Load inventory module data for updating
if ($load_inventory_module) {
$sql = 'SELECT * FROM tagent_module_inventory WHERE id_module_inventory = '.$load_inventory_module;
$row = db_get_row_sql($sql);
if (!empty($row)) {
$id_agent_module_inventory = $row['id_agent_module_inventory'];
$id_module_inventory = $row['id_module_inventory'];
$target = $row['target'];
$interval = $row['interval'];
$username = $row['username'];
$password = io_output_password($row['password']);
$custom_fields = [];
if (!empty($row['custom_fields'])) {
try {
$custom_fields = array_map(
function ($field) {
if ($field['secure']) {
$field['value'] = io_output_password($field['value']);
}
return $field;
},
json_decode(base64_decode($row['custom_fields']), true)
);
$custom_fields_enabled = true;
} catch (Exception $e) {
}
}
} else {
ui_print_error_message(__('Inventory module error'));
include 'general/footer.php';
return;
}
} else {
$target = $direccion_agente;
$interval = (string) SECONDS_1HOUR;
$username = '';
$password = '';
$custom_fields_enabled = false;
$custom_fields = [];
}
// Inventory module configuration
$form_buttons = '';
if ($load_inventory_module) {
$form_buttons .= html_print_input_hidden('id_agent_module_inventory', $id_agent_module_inventory, true);
$form_buttons .= html_print_submit_button(__('Update'), 'update_inventory_module', false, 'class="sub next"', true);
} else {
$form_buttons .= html_print_submit_button(__('Add'), 'add_inventory_module', false, 'class="sub next"', true);
}
echo ui_get_inventory_module_add_form(
'index.php?sec=estado&sec2=godmode/agentes/configurar_agente&tab=inventory&id_agente='.$id_agente,
$form_buttons,
$load_inventory_module,
$id_os,
$target,
$interval,
$username,
$password,
$custom_fields_enabled,
$custom_fields
);
// Inventory module list
$sql = sprintf(
'SELECT *
FROM tmodule_inventory, tagent_module_inventory
WHERE tagent_module_inventory.id_agente = %d
AND tmodule_inventory.id_module_inventory = tagent_module_inventory.id_module_inventory
ORDER BY name',
$id_agente
);
$result = db_process_sql($sql);
if (db_get_num_rows($sql) == 0) {
echo '&nbsp;</td></tr><tr><td>';
} else {
$table = new stdClass();
$table->width = '100%';
$table->class = 'databox filters';
$table->data = [];
$table->head = [];
$table->styleTable = 'margin-top: 20px;';
$table->head[0] = "<span title='".__('Policy')."'>".__('P.').'</span>';
$table->head[1] = __('Name');
$table->head[2] = __('Description');
$table->head[3] = __('Target');
$table->head[4] = __('Interval');
$table->head[5] = __('Actions');
$table->align = [];
$table->align[5] = 'left';
foreach ($result as $row) {
$data = [];
$sql = sprintf('SELECT id_policy FROM tpolicy_modules_inventory WHERE id = %d', $row['id_policy_module_inventory']);
$id_policy = db_get_value_sql($sql);
if ($id_policy) {
$policy = policies_get_policy($id_policy);
$data[0] = '<a href="index.php?sec=gmodules&sec2='.ENTERPRISE_DIR.'/godmode/policies/policies&id='.$id_policy.'">';
$data[0] .= html_print_image('images/policies_mc.png', true, ['border' => '0', 'title' => $policy['name']]);
$data[0] .= '</a>';
} else {
$data[0] = '';
}
$data[1] = '<a href="index.php?sec=estado&sec2=godmode/agentes/configurar_agente&tab=inventory&id_agente='.$id_agente.'&load_inventory_module='.$row['id_module_inventory'].'">'.$row['name'].'</a>';
$data[2] = $row['description'];
$data[3] = $row['target'];
$data[4] = human_time_description_raw($row['interval']);
// Delete module
$data[5] = '<a href="index.php?sec=estado&sec2=godmode/agentes/configurar_agente&tab=inventory&id_agente='.$id_agente.'&delete_inventory_module='.$row['id_agent_module_inventory'].'" onClick="if (!confirm(\''.__('Are you sure?').'\')) return false;">';
$data[5] .= html_print_image('images/cross.png', true, ['border' => '0', 'title' => __('Delete'), 'class' => 'invert_filter']);
$data[5] .= '</b></a>&nbsp;&nbsp;';
// Update module
$data[5] .= '<a href="index.php?sec=estado&sec2=godmode/agentes/configurar_agente&tab=inventory&id_agente='.$id_agente.'&load_inventory_module='.$row['id_module_inventory'].'">';
$data[5] .= html_print_image('images/config.png', true, ['border' => '0', 'title' => __('Update'), 'class' => 'invert_filter']);
$data[5] .= '</b></a>&nbsp;&nbsp;';
// Force refresh module
$data[5] .= '<a href="index.php?sec=estado&sec2=godmode/agentes/configurar_agente&tab=inventory&id_agente='.$id_agente.'&force_inventory_module='.$row['id_agent_module_inventory'].'">';
$data[5] .= html_print_image('images/target.png', true, ['border' => '0', 'title' => __('Force'), 'class' => 'invert_filter']).'</b></a>';
array_push($table->data, $data);
}
html_print_table($table);
}

View File

@ -181,7 +181,9 @@ if ($access_console_node === true) {
$sub2['godmode/modules/manage_network_components']['id'] = 'Network components';
$sub['templates']['sub2'] = $sub2;
enterprise_hook('inventory_submenu');
$sub['godmode/modules/manage_inventory_modules']['text'] = __('Inventory modules');
$sub['godmode/modules/manage_inventory_modules']['id'] = 'Inventory modules';
enterprise_hook('autoconfiguration_menu');
enterprise_hook('agent_repository_menu');
}

View File

@ -0,0 +1,393 @@
<?php
// ______ __ _______ _______ _______
// | __ \.---.-.-----.--| |.-----.----.---.-. | ___| | | __|
// | __/| _ | | _ || _ | _| _ | | ___| |__ |
// |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
//
// ============================================================================
// Copyright (c) 2007-2021 Artica Soluciones Tecnologicas, http://www.artica.es
// This code is NOT free software. This code is NOT licenced under GPL2 licence
// You cannnot redistribute it without written permission of copyright holder.
// ============================================================================
// Load global variables
global $config;
// Check user credentials.
check_login();
if (! check_acl($config['id_user'], 0, 'PM') && ! check_acl($config['id_user'], 0, 'AW')) {
db_pandora_audit(
AUDIT_LOG_ACL_VIOLATION,
'Trying to access Inventory Module Management'
);
include 'general/noaccess.php';
return;
}
require_once $config['homedir'].'/include/functions_inventory.php';
enterprise_include_once('include/functions_metaconsole.php');
$management_allowed = is_management_allowed();
// Header.
if (is_metaconsole() === true) {
$sec = 'advanced';
enterprise_include_once('meta/include/functions_components_meta.php');
enterprise_hook('open_meta_frame');
components_meta_print_header();
if ($management_allowed === false) {
ui_print_warning_message(__('To manage inventory plugin you must activate centralized management'));
}
} else {
$sec = 'gmodules';
ui_print_page_header(
__('Module management').' &raquo; '.__('Inventory modules'),
'images/page_white_text.png',
false,
'',
true
);
if ($management_allowed === false) {
if (is_metaconsole() === false) {
$url = '<a target="_blank" href="'.ui_get_meta_url(
'index.php?sec=advanced&sec2=godmode/modules/manage_inventory_modules'
).'">'.__('metaconsole').'</a>';
} else {
$url = __('any node');
}
ui_print_warning_message(
__(
'This console is not manager of this environment, please manage this feature from centralized manager console. Go to %s to manage it.',
$url
)
);
}
}
$is_windows = strtoupper(substr(PHP_OS, 0, 3)) == 'WIN';
if ($is_windows) {
ui_print_error_message(__('Not supported in Windows systems'));
}
// Initialize variables.
$offset = (int) get_parameter('offset');
$create_module_inventory = (bool) get_parameter('create_module_inventory');
$update_module_inventory = (bool) get_parameter('update_module_inventory');
$delete_inventory_module = (int) get_parameter('delete_inventory_module');
$multiple_delete = (bool) get_parameter('multiple_delete', 0);
$id_module_inventory = (int) get_parameter('id_module_inventory');
$name = (string) get_parameter('name');
$description = (string) get_parameter('description');
$id_os = (int) get_parameter('id_os');
if ($id_os == 0) {
$id_os = 'NULL';
}
$interpreter = (string) get_parameter('interpreter');
$script_mode = (string) get_parameter('script_mode');
$code = (string) get_parameter('code');
$code = base64_encode(str_replace("\r", '', html_entity_decode($code, ENT_QUOTES)));
$format = (string) get_parameter('format');
$block_mode = (int) get_parameter('block_mode', 0);
$script_path = (string) get_parameter('script_path');
// Create inventory module.
if ($create_module_inventory === true) {
$values = [
'name' => $name,
'description' => $description,
'id_os' => $id_os,
'interpreter' => $interpreter,
'code' => $code,
'data_format' => $format,
'block_mode' => $block_mode,
'script_mode' => $script_mode,
'script_path' => $script_path,
];
$result = (bool) inventory_create_inventory_module($values);
$auditMessage = ((bool) $result === true) ? sprintf('Create inventory module #%s', $result) : 'Fail try to create inventory module';
db_pandora_audit(
AUDIT_LOG_MODULE_MANAGEMENT,
$auditMessage
);
ui_print_result_message(
(bool) $result,
__('Successfully created inventory module'),
__('Error creating inventory module')
);
// Update inventory module.
} else if ($update_module_inventory === true) {
$values = [
'name' => $name,
'description' => $description,
'id_os' => $id_os,
'interpreter' => $interpreter,
'code' => $code,
'data_format' => $format,
'block_mode' => $block_mode,
'script_mode' => $script_mode,
'script_path' => $script_path,
];
$result = inventory_update_inventory_module($id_module_inventory, $values);
$auditMessage = ((bool) $result === true) ? 'Update inventory module' : 'Fail try to update inventory module';
db_pandora_audit(
AUDIT_LOG_MODULE_MANAGEMENT,
sprintf('%s #%s', $auditMessage, $id_module_inventory)
);
ui_print_result_message(
(bool) $result,
__('Successfully updated inventory module'),
__('Error updating inventory module')
);
// Delete inventory module.
} else if ((bool) $delete_inventory_module === true) {
$result = db_process_sql_delete(
'tmodule_inventory',
['id_module_inventory' => $delete_inventory_module]
);
$auditMessage = ((bool) $result === true) ? 'Delete inventory module' : 'Fail try to delete inventory module';
db_pandora_audit(
AUDIT_LOG_MODULE_MANAGEMENT,
sprintf('%s #%s', $auditMessage, $id_module_inventory)
);
ui_print_result_message(
(bool) $result,
__('Successfully deleted inventory module'),
__('Error deleting inventory module')
);
if (is_metaconsole() === true) {
$setups = db_get_all_rows_in_table('tmetaconsole_setup');
foreach ($setups as $key => $setup) {
if (metaconsole_connect($setup) == NOERR) {
$result = db_process_sql_delete(
'tmodule_inventory',
['id_module_inventory' => $delete_inventory_module]
);
$auditMessage = ((bool) $result === true) ? 'Delete inventory module' : 'Fail try to delete inventory module';
db_pandora_audit(
AUDIT_LOG_MODULE_MANAGEMENT,
sprintf('%s #%s', $auditMessage, $id_module_inventory)
);
ui_print_result_message(
(bool) $result,
$setup['server_name'].': '.__('Successfully deleted inventory module'),
$setup['server_name'].': '.__('Error deleting inventory module')
);
}
metaconsole_restore_db();
}
}
} else if ($multiple_delete) {
$ids = (array) get_parameter('delete_multiple', []);
foreach ($ids as $id) {
$result = db_process_sql_delete('tmodule_inventory', ['id_module_inventory' => $id]);
if ($result === false) {
break;
}
}
if ($result !== false) {
$result = true;
} else {
$result = false;
}
$str_ids = implode(',', $ids);
$auditMessage = ($result === true) ? 'Multiple delete inventory module' : 'Fail try to delete inventory module';
db_pandora_audit(
AUDIT_LOG_MODULE_MANAGEMENT,
sprintf('%s :%s', $auditMessage, $str_ids)
);
ui_print_result_message(
$result,
__('Successfully multiple deleted'),
__('Not deleted. Error deleting multiple data')
);
$id = 0;
if (is_metaconsole()) {
$setups = db_get_all_rows_in_table('tmetaconsole_setup');
foreach ($setups as $key => $setup) {
if (metaconsole_connect($setup) == NOERR) {
foreach ($ids as $id) {
$result_node = db_process_sql_delete('tmodule_inventory', ['id_module_inventory' => $id]);
if ($result_node === false) {
break;
}
}
if ($result_node !== false) {
$result_node = true;
} else {
$result_node = false;
}
$str_ids = implode(',', $ids);
$auditMessage = ($result_node === true) ? 'Multiple delete inventory module' : 'Fail try to delete inventory module';
db_pandora_audit(
AUDIT_LOG_MODULE_MANAGEMENT,
sprintf('%s :%s', $auditMessage, $str_ids)
);
ui_print_result_message(
$result_node,
$setup['server_name'].': '.__('Successfully multiple deleted'),
$setup['server_name'].': '.__('Not deleted. Error deleting multiple data')
);
}
metaconsole_restore_db();
}
}
}
$total_modules = db_get_sql('SELECT COUNT(*) FROM tmodule_inventory');
$table = new stdClass();
$table->width = '100%';
$table->class = 'info_table';
$table->size = [];
$table->size[0] = '140px';
$table->align = [];
$table->align[2] = 'left';
$table->align[4] = 'left';
$table->data = [];
$table->head = [];
$table->head[0] = __('Name');
$table->head[1] = __('Description');
$table->head[2] = __('OS');
$table->head[3] = __('Interpreter');
if ($management_allowed === true) {
$table->head[4] = __('Action').html_print_checkbox('all_delete', 0, false, true, false);
}
$result = inventory_get_modules_list($offset);
if ($result === false) {
ui_print_info_message(['no_close' => true, 'message' => __('No inventory modules defined') ]);
} else {
$status = '';
$begin = true;
while ($row = array_shift($result)) {
$data = [];
$begin = false;
if ($management_allowed === true) {
$data[0] = '<strong><a href="index.php?sec='.$sec.'&sec2=godmode/modules/manage_inventory_modules_form&id_module_inventory='.$row['id_module_inventory'].'">'.$row['name'].'</a></strong>';
} else {
$data[0] = '<strong>'.$row['name'].'</strong>';
}
$data[1] = $row['description'];
if ($row['os_name'] == null) {
$data[2] = html_print_image('images/agent.png', true, ['border' => '0', 'alt' => __('Agent'), 'title' => __('Agent'), 'height' => '18', 'class' => 'invert_filter']);
} else {
$data[2] = ui_print_os_icon($row['id_os'], false, true);
}
if ($row['interpreter'] == '') {
$data[3] = __('Local module');
} else {
$data[3] = __('Remote/Local');
}
if ($management_allowed === true) {
// Update module.
$data[4] = '<a href="index.php?sec='.$sec.'&sec2=godmode/modules/manage_inventory_modules_form&id_module_inventory='.$row['id_module_inventory'].'">';
$data[4] .= html_print_image('images/config.png', true, ['border' => '0', 'title' => __('Update'), 'class' => 'invert_filter']).'</b></a>';
// Delete module.
$data[4] .= '<a href="index.php?sec='.$sec.'&sec2=godmode/modules/manage_inventory_modules&delete_inventory_module='.$row['id_module_inventory'].'" onClick="if (!confirm(\''.__('Are you sure?').'\')) return false;">';
$data[4] .= html_print_image('images/cross.png', true, ['border' => '0', 'title' => __('Delete'), 'class' => 'invert_filter']);
$data[4] .= '</b></a>&nbsp;&nbsp;';
$data[4] .= html_print_checkbox_extended('delete_multiple[]', $row['id_module_inventory'], false, false, '', 'class="check_delete"', true);
}
array_push($table->data, $data);
}
echo "<form method='post' action='index.php?sec=".$sec."&sec2=godmode/modules/manage_inventory_modules'>";
html_print_input_hidden('multiple_delete', 1);
ui_pagination($total_modules, 'index.php?sec='.$sec.'&sec2=godmode/modules/manage_inventory_modules', $offset);
html_print_table($table);
ui_pagination($total_modules, 'index.php?sec='.$sec.'&sec2=godmode/modules/manage_inventory_modules', $offset, 0, false, 'offset', true, 'pagination-bottom');
echo "<div class='pdd_l_5px float-right'>";
if ($management_allowed === true) {
html_print_submit_button(__('Delete'), 'delete_btn', false, 'class="sub delete"');
}
echo '</div>';
echo '</form>';
}
if ($management_allowed === true) {
echo '<form method="post" action="index.php?sec='.$sec.'&sec2=godmode/modules/manage_inventory_modules_form">';
echo '<div class="float-right mrgn_btn_15px">';
html_print_input_hidden('create_module_inventory', 1);
html_print_submit_button(__('Create'), 'crt', false, 'class="sub next"');
echo '</div>';
echo '</form>';
}
if (is_metaconsole() === true) {
enterprise_hook('close_meta_frame');
echo '<div id="deploy_messages" class="invisible">';
echo '<span>'.__(
'The configurations of inventory modules from the nodes have been unified.
From this point on, changes to the inventory scripts must be made through this screen.'
).'</br></br>'.__('You can find more information at:')."<a href='https://pandorafms.com/manual'>https://pandorafms.com/manual</a>".'</span>';
echo '</div>';
}
?>
<script type="text/javascript">
$( document ).ready(function() {
$('[id^=checkbox-delete_multiple]').change(function(){
if($(this).parent().parent().hasClass('checkselected')){
$(this).parent().parent().removeClass('checkselected');
}
else{
$(this).parent().parent().addClass('checkselected');
}
});
$('[id^=checkbox-all_delete]').change(function() {
if ($("#checkbox-all_delete").prop("checked")) {
$('[id^=checkbox-delete_multiple]').parent().parent().addClass('checkselected');
$(".check_delete").prop("checked", true);
}
else {
$('[id^=checkbox-delete_multiple]').parent().parent().removeClass('checkselected');
$(".check_delete").prop("checked", false);
}
});
});
</script>

View File

@ -0,0 +1,206 @@
<?php
// ______ __ _______ _______ _______
// | __ \.---.-.-----.--| |.-----.----.---.-. | ___| | | __|
// | __/| _ | | _ || _ | _| _ | | ___| |__ |
// |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
//
// ============================================================================
// Copyright (c) 2007-2021 Artica Soluciones Tecnologicas, http://www.artica.es
// This code is NOT free software. This code is NOT licenced under GPL2 licence
// You cannnot redistribute it without written permission of copyright holder.
// ============================================================================
// Load global variables
global $config;
// Check user credentials
check_login();
if (! check_acl($config['id_user'], 0, 'PM') && ! check_acl($config['id_user'], 0, 'AW')) {
db_pandora_audit(
AUDIT_LOG_ACL_VIOLATION,
'Trying to access Inventory Module Management'
);
include 'general/noaccess.php';
return;
}
// Header
if (defined('METACONSOLE')) {
$sec = 'advanced';
enterprise_include_once('meta/include/functions_components_meta.php');
enterprise_hook('open_meta_frame');
components_meta_print_header();
} else {
$sec = 'gmodules';
ui_print_page_header(
__('Module management').' » '.__('Inventory modules'),
'images/op_inventory.png',
false,
'',
true
);
}
// Header
$is_windows = strtoupper(substr(PHP_OS, 0, 3)) == 'WIN';
if ($is_windows) {
ui_print_error_message(__('Not supported in Windows systems'));
}
// Initialize variables
$id_module_inventory = (int) get_parameter('id_module_inventory');
$script_mode = 1;
// Updating
if ($id_module_inventory) {
$row = db_get_row(
'tmodule_inventory',
'id_module_inventory',
$id_module_inventory
);
if (!empty($row)) {
$name = $row['name'];
$description = $row['description'];
$id_os = $row['id_os'];
$interpreter = $row['interpreter'];
$code = $row['code'];
$data_format = $row['data_format'];
$block_mode = $row['block_mode'];
$script_path = $row['script_path'];
$script_mode = $row['script_mode'];
} else {
ui_print_error_message(__('Inventory module error'));
include 'general/footer.php';
return;
}
// New module
} else {
$name = '';
$description = '';
$id_os = 1;
$interpreter = '';
$code = '';
$data_format = '';
$block_mode = 0;
}
if ($id_os == null) {
$disabled = true;
} else {
$disabled = false;
}
$table = new stdClass();
$table->width = '100%';
$table->class = 'databox filters';
$table->style = [];
$table->style[0] = 'font-weight: bold';
$table->data = [];
$table->data[0][0] = '<strong>'.__('Name').'</strong>';
$table->data[0][1] = html_print_input_text('name', $name, '', 45, 100, true, $disabled);
$table->data[1][0] = '<strong>'.__('Description').'</strong>';
$table->data[1][1] = html_print_input_text('description', $description, '', 60, 500, true);
$table->data[2][0] = '<strong>'.__('OS').'</strong>';
$table->data[2][1] = html_print_select_from_sql(
'SELECT id_os, name FROM tconfig_os ORDER BY name',
'id_os',
$id_os,
'',
'',
'',
$return = true
);
$table->data[3][0] = '<strong>'.__('Interpreter').'</strong>';
$table->data[3][1] = html_print_input_text('interpreter', $interpreter, '', 25, 100, true);
$table->data[3][1] .= ui_print_help_tip(__('Left blank for the LOCAL inventory modules'), true);
$table->data['block_mode'][0] = '<strong>'.__('Block Mode').'</strong>';
$table->data['block_mode'][1] = html_print_checkbox('block_mode', 1, $block_mode, true);
$table->data[4][0] = '<strong>'.__('Format').'</strong>';
$table->data[4][0] .= ui_print_help_tip(__('separate fields with ').SEPARATOR_COLUMN, true);
$table->data[4][1] = html_print_input_text('format', $data_format, '', 50, 100, true);
$table->data[5][0] = '<strong>'.__('Script mode').'</strong>';
$table->data[5][0] .= ui_print_help_tip(__(''), true);
$table->data[5][1] = __('Use script');
$table->data[5][1] .= html_print_radio_button(
'script_mode',
1,
'',
$script_mode,
true
).'&nbsp;&nbsp;';
$table->data[5][1] .= '&nbsp&nbsp&nbsp&nbsp'.__('Use inline code');
$table->data[5][1] .= html_print_radio_button(
'script_mode',
2,
'',
$script_mode,
true
).'&nbsp;&nbsp;';
$table->data[6][0] = '<strong>'.__('Script path').'</strong>';
$table->data[6][1] = html_print_input_text('script_path', $script_path, '', 50, 1000, true);
$table->data[7][0] = '<strong>'.__('Code').'</strong>';
$table->data[7][0] .= ui_print_help_tip(__("Here is placed the script for the REMOTE inventory modules Local inventory modules don't use this field").SEPARATOR_COLUMN, true);
$table->data[7][1] = html_print_textarea('code', 25, 80, base64_decode($code), '', true);
echo '<form name="inventorymodule" id="inventorymodule_form" method="post"
action="index.php?sec='.$sec.'&sec2=godmode/modules/manage_inventory_modules">';
html_print_table($table);
if ($id_module_inventory) {
html_print_input_hidden('update_module_inventory', 1);
html_print_input_hidden('id_module_inventory', $id_module_inventory);
} else {
html_print_input_hidden('create_module_inventory', 1);
}
echo '<div class="action-buttons" style="width: '.$table->width.'">';
if ($id_module_inventory) {
html_print_submit_button(__('Update'), 'submit', false, 'class="sub next"');
} else {
html_print_submit_button(__('Create'), 'submit', false, 'class="sub upd"');
}
echo '</div>';
echo '</form>';
if (defined('METACONSOLE')) {
enterprise_hook('close_meta_frame');
}
?>
<script type="text/javascript">
$(document).ready (function () {
var mode = <?php echo $script_mode; ?>;
if (mode == 1) {
$('#table1-6').show();
$('#table1-7').hide();
} else {
$('#table1-7').show();
$('#table1-6').hide();
}
$('input[type=radio][name=script_mode]').change(function() {
if (this.value == 1) {
$('#table1-6').show();
$('#table1-7').hide();
}
else if (this.value == 2) {
$('#table1-7').show();
$('#table1-6').hide();
}
});
});
</script>

View File

@ -350,6 +350,87 @@ $table->data[$i++][1] = html_print_textarea(
true
);
// Inventory changes blacklist.
$table->data[$i][0] = __('Inventory changes blacklist');
$inventory_changes_blacklist_id = get_parameter(
'inventory_changes_blacklist',
$config['inventory_changes_blacklist']
);
if (!is_array($inventory_changes_blacklist_id)) {
$inventory_changes_blacklist_id = explode(
',',
$inventory_changes_blacklist_id
);
}
$inventory_modules = db_get_all_rows_sql(
'SELECT mi.id_module_inventory, mi.name module_inventory_name, os.name os_name
FROM tmodule_inventory mi, tconfig_os os
WHERE os.id_os = mi.id_os'
);
$inventory_changes_blacklist = [];
$inventory_changes_blacklist_out = [];
foreach ($inventory_modules as $inventory_module) {
if (in_array($inventory_module['id_module_inventory'], $inventory_changes_blacklist_id)) {
$inventory_changes_blacklist[$inventory_module['id_module_inventory']] = $inventory_module['module_inventory_name'].' ('.$inventory_module['os_name'].')';
} else {
$inventory_changes_blacklist_out[$inventory_module['id_module_inventory']] = $inventory_module['module_inventory_name'].' ('.$inventory_module['os_name'].')';
}
}
$select_out = html_print_select(
$inventory_changes_blacklist_out,
'inventory_changes_blacklist_out[]',
'',
'',
'',
'',
true,
true,
true,
'',
false,
'width:200px'
);
$arrows = ' ';
$select_in = html_print_select(
$inventory_changes_blacklist,
'inventory_changes_blacklist[]',
'',
'',
'',
'',
true,
true,
true,
'',
false,
'width:200px'
);
$table_ichanges = '<table>
<tr>
<td>'.__('Out of black list').'</td>
<td></td>
<td>'.__('In black list').'</td>
</tr>
<tr>
<td>'.$select_out.'</td>
<td>
<a href="javascript:">'.html_print_image('images/darrowright.png', true, ['id' => 'right_iblacklist', 'alt' => __('Push selected modules into blacklist'), 'title' => __('Push selected modules into blacklist'), 'class' => 'invert_filter']).'</a>
<br><br>
<a href="javascript:">'.html_print_image('images/darrowleft.png', true, ['id' => 'left_iblacklist', 'alt' => __('Pop selected modules out of blacklist'), 'title' => __('Pop selected modules out of blacklist'), 'class' => 'invert_filter']).'</a>
</td>
<td>'.$select_in.'</td>
</tr>
</table>';
$table->data[$i++][1] = $table_ichanges;
$table->data[$i][0] = __('Referer security');
$table->data[$i++][1] = html_print_checkbox_switch(
'referer_security',
@ -815,5 +896,64 @@ $(document).ready (function () {
})
$('input#button-email_test').click(perform_email_test);
$("#right_iblacklist").click (function () {
jQuery.each($("select[name='inventory_changes_blacklist_out[]'] option:selected"), function (key, value) {
imodule_name = $(value).html();
if (imodule_name != <?php echo "'".__('None')."'"; ?>) {
id_imodule = $(value).attr('value');
$("select[name='inventory_changes_blacklist[]']")
.append(
$("<option></option>")
.val(id_imodule)
.html('<i>' + imodule_name + '</i>')
);
$("#inventory_changes_blacklist_out")
.find("option[value='" + id_imodule + "']").remove();
$("#inventory_changes_blacklist")
.find("option[value='']").remove();
if($("#inventory_changes_blacklist_out option").length == 0) {
$("select[name='inventory_changes_blacklist_out[]']")
.append(
$("<option></option>")
.val('')
.html('<i><?php echo __('None'); ?></i>')
);
}
}
});
});
$("#left_iblacklist").click (function () {
jQuery.each($("select[name='inventory_changes_blacklist[]'] option:selected"), function (key, value) {
imodule_name = $(value).html();
if (imodule_name != <?php echo "'".__('None')."'"; ?>) {
id_imodule = $(value).attr('value');
$("select[name='inventory_changes_blacklist_out[]']")
.append(
$("<option></option>")
.val(id_imodule)
.html('<i>' + imodule_name + '</i>')
);
$("#inventory_changes_blacklist")
.find("option[value='" + id_imodule + "']").remove();
$("#inventory_changes_blacklist_out")
.find("option[value='']").remove();
if($("#inventory_changes_blacklist option").length == 0) {
$("select[name='inventory_changes_blacklist[]']")
.append(
$("<option></option>")
.val('')
.html('<i><?php echo __('None'); ?></i>')
);
}
}
});
});
$("#submit-update_button").click(function () {
$('#inventory_changes_blacklist option').map(function(){
$(this).prop('selected', true);
});
});
});
</script>

View File

@ -395,6 +395,11 @@ function config_update_config()
if (config_update_value('email_password', io_input_password(get_parameter('email_password')), true) === false) {
$error_update[] = __('Email password');
}
$inventory_changes_blacklist = get_parameter('inventory_changes_blacklist', []);
if (config_update_value('inventory_changes_blacklist', implode(',', $inventory_changes_blacklist), true) === false) {
$error_update[] = __('Inventory changes blacklist');
}
break;
case 'enterprise':
@ -458,11 +463,6 @@ function config_update_config()
if (config_update_value('sap_license', get_parameter('sap_license'), true) === false) {
$error_update[] = __('SAP/R3 Plugin Licence');
}
$inventory_changes_blacklist = get_parameter('inventory_changes_blacklist', []);
if (config_update_value('inventory_changes_blacklist', implode(',', $inventory_changes_blacklist), true) === false) {
$error_update[] = __('Inventory changes blacklist');
}
}
break;

File diff suppressed because it is too large Load Diff

View File

@ -487,7 +487,7 @@ function menu_add_extras(&$menu)
$menu_extra['gusuarios']['sub']['godmode/users/configure_profile']['text'] = __('Configure profile');
$menu_extra['gmodules']['sub']['godmode/modules/manage_network_templates_form']['text'] = __('Module templates management');
$menu_extra['gmodules']['sub']['enterprise/godmode/modules/manage_inventory_modules_form']['text'] = __('Inventory modules management');
$menu_extra['gmodules']['sub']['godmode/modules/manage_inventory_modules_form']['text'] = __('Inventory modules management');
$menu_extra['gagente']['sub']['godmode/agentes/configurar_agente']['text'] = __('Agents management');

View File

@ -24,7 +24,8 @@ global $config;
* Include the usual functions
*/
require_once $config['homedir'].'/include/functions_ui.php';
// enterprise_include_once('include/functions_inventory.php');
function planned_downtimes_check_dates($type_execution='once', $type_periodicity='', $datetime_from=false, $datetime_to=false, $periodically_time_from=false, $periodically_time_to=false, $periodically_day_from=false, $periodically_day_to=false)
{
global $config;

View File

@ -38,6 +38,7 @@ require_once $config['homedir'].'/include/functions_alerts.php';
require_once $config['homedir'].'/include/functions_users.php';
enterprise_include_once('include/functions_metaconsole.php');
enterprise_include_once('include/functions_inventory.php');
require_once $config['homedir'].'/include/functions_inventory.php';
require_once $config['homedir'].'/include/functions_forecast.php';
require_once $config['homedir'].'/include/functions_ui.php';
require_once $config['homedir'].'/include/functions_netflow.php';

View File

@ -6828,3 +6828,259 @@ function ui_print_spinner(string $text='Loading', bool $return=false)
echo $output;
}
}
function ui_get_inventory_module_add_form(
$form_action,
$form_buttons='',
$inventory_module_id=0,
$os_id=false,
$target=false,
$interval=3600,
$username='',
$password='',
$custom_fields_enabled=false,
$custom_fields=[]
) {
$table = new stdClass();
$table->id = 'inventory-module-form';
$table->width = '100%';
$table->class = 'databox filters';
$table->style['module-title'] = 'font-weight: bold;';
$table->style['interval-title'] = 'font-weight: bold;';
$table->style['target-title'] = 'font-weight: bold;';
$table->style['chkbx-custom-fields-title'] = 'font-weight: bold;';
$table->style['username-title'] = 'font-weight: bold;';
$table->style['password-title'] = 'font-weight: bold;';
$table->rowstyle = [];
$table->rowstyle['hidden-custom-field-row'] = 'display: none;';
$table->colspan = [];
$table->colspan['custom-fields-row'] = [];
$table->colspan['custom-fields-row']['custom-fields-column'] = 4;
$table->data = [];
$row = [];
$row['module-title'] = __('Module');
if (empty($inventory_module_id)) {
if (empty($os_id)) {
$sql = 'SELECT mi.id_module_inventory AS id, mi.name AS name, co.name AS os
FROM tmodule_inventory mi, tconfig_os co
WHERE co.id_os = mi.id_os
ORDER BY co.name, mi.name';
$inventory_modules_raw = db_get_all_rows_sql($sql);
$inventory_modules = [];
foreach ($inventory_modules_raw as $im) {
$inventory_modules[$im['id']] = [
'name' => $im['name'],
'optgroup' => $im['os'],
];
}
} else {
$sql = sprintf(
'SELECT id_module_inventory AS id, name
FROM tmodule_inventory
WHERE id_os = %d
ORDER BY name',
$os_id
);
$inventory_modules_raw = db_get_all_rows_sql($sql);
$inventory_modules = [];
foreach ($inventory_modules_raw as $im) {
$inventory_modules[$im['id']] = $im['name'];
}
}
$row['module-input'] = html_print_select($inventory_modules, 'id_module_inventory', 0, '', __('Select inventory module'), 0, true, false, false);
} else {
$row['module-input'] = db_get_sql('SELECT name FROM tmodule_inventory WHERE id_module_inventory = '.$inventory_module_id);
}
$row['interval-title'] = __('Interval');
$row['interval-input'] = html_print_extended_select_for_time('interval', $interval, '', '', '', false, true);
$table->data['first-row'] = $row;
$row = [];
if ($target !== false) {
$row['target-title'] = __('Target');
$row['target-input'] = html_print_input_text('target', $target, '', 25, 40, true);
}
$row['chkbx-custom-fields-title'] = __('Use custom fields');
$row['chkbx-custom-fields-input'] = html_print_checkbox('custom_fields_enabled', 1, $custom_fields_enabled, true);
$table->data['second-row'] = $row;
$row = [];
$row['username-title'] = __('Username');
$row['username-input'] = html_print_input_text('username', $username, '', 25, 40, true);
$row['password-title'] = __('Password');
$row['password-input'] = html_print_input_password('password', $password, '', 25, 40, true);
$table->data['userpass-row'] = $row;
$row = [];
$row['hidden-title'] = '';
$row['hidden-input'] = html_print_input_hidden('hidden-custom-field-name', '', true);
$row['hidden-input'] .= html_print_input_hidden('hidden-custom-field-is-secure', 0, true);
$row['hidden-input'] .= html_print_input_text('hidden-custom-field-input', '', '', 25, 40, true);
$row['hidden-input'] .= '<span>&nbsp;</span>';
$row['hidden-input'] .= html_print_image(
'images/cross.png',
true,
[
'border' => '0',
'title' => __('Remove'),
'style' => 'cursor: pointer;',
'class' => 'remove-custom-field invert_filter',
]
);
$table->data['hidden-custom-field-row'] = $row;
if ($custom_fields_enabled) {
foreach ($custom_fields as $i => $field) {
$row = [];
$row['title'] = '<b>'.$field['name'].'</b>';
$row['input'] = html_print_input_hidden(
'custom_fields['.$i.'][name]',
$field['name'],
true
);
$row['input'] .= html_print_input_hidden(
'custom_fields['.$i.'][secure]',
$field['secure'],
true
);
if ($field['secure']) {
$row['input'] .= html_print_input_password(
'custom_fields['.$i.'][value]',
$field['value'],
'',
25,
40,
true
);
} else {
$row['input'] .= html_print_input_text(
'custom_fields['.$i.'][value]',
$field['value'],
'',
25,
40,
true
);
}
$row['input'] .= '<span>&nbsp;</span>';
$row['input'] .= html_print_image(
'images/cross.png',
true,
[
'border' => '0',
'title' => __('Remove'),
'style' => 'cursor: pointer;',
'class' => 'remove-custom-field invert_filter',
]
);
$table->data['custom-field-row-'.$i] = $row;
}
}
$row = [];
$row['custom-fields-column'] = '<b>'.__('Field name').'</b>'.'&nbsp;&nbsp;'.html_print_input_text('field-name', '', '', 25, 40, true).'&nbsp;&nbsp;&nbsp;'.html_print_checkbox('field-is-password', 1, false, true).__("It's a password").'&nbsp;&nbsp;&nbsp;'.html_print_button(__('Add field'), 'add-field', false, '', 'class="sub add"', true);
$table->data['custom-fields-row'] = $row;
ob_start();
echo '<form name="modulo" method="post" action="'.$form_action.'">';
echo html_print_table($table);
echo '<div class="action-buttons w100p">';
echo $form_buttons;
echo '</div>';
echo '</form>';
?>
<script type="text/javascript">
(function () {
function toggle_custom_fields () {
if ($("#checkbox-custom_fields_enabled").prop("checked")) {
$("#inventory-module-form-userpass-row").hide();
$("#inventory-module-form-custom-fields-row").show();
$("tr[id^=inventory-module-form-custom-field-row-]").show();
} else {
$("#inventory-module-form-userpass-row").show();
$("#inventory-module-form-custom-fields-row").hide();
$("tr[id^=inventory-module-form-custom-field-row-]").hide();
}
}
function add_row_for_custom_field (fieldName, isSecure) {
var custom_fields_num = $("tr[id^=inventory-module-form-custom-field-row-]").length;
$("#inventory-module-form-hidden-custom-field-row")
.clone()
.prop("id", "inventory-module-form-custom-field-row-" + custom_fields_num)
.children("#inventory-module-form-hidden-custom-field-row-hidden-title")
.prop("id", "inventory-module-form-custom-field-row-title-" + custom_fields_num)
.html("<b>" + fieldName + "</b>")
.parent()
.children("#inventory-module-form-hidden-custom-field-row-hidden-input")
.prop("id", "inventory-module-form-custom-field-row-input-" + custom_fields_num)
.prop("colspan", 2)
.children("input[name=hidden-custom-field-name]")
.prop("id", "custom-field-name-" + custom_fields_num)
.prop("name", "custom_fields[" + custom_fields_num + "][name]")
.val(fieldName)
.parent()
.children("input[name=hidden-custom-field-is-secure]")
.prop("id", "custom-field-is-secure-" + custom_fields_num)
.prop("name", "custom_fields[" + custom_fields_num + "][secure]")
.val(isSecure ? 1 : 0)
.parent()
.children("input[name=hidden-custom-field-input]")
.prop("id", "custom-field-input-" + custom_fields_num)
.prop("type", isSecure ? "password" : "text")
.prop("name", "custom_fields[" + custom_fields_num + "][value]")
.parent()
.children("img.remove-custom-field")
.click(remove_custom_field)
.parent()
.parent()
.insertBefore($("#inventory-module-form-custom-fields-row"))
.show();
}
function add_custom_field () {
var fieldName = $("#text-field-name").val();
var isSecure = $("#checkbox-field-is-password").prop("checked");
if (fieldName.length === 0) return;
add_row_for_custom_field(fieldName, isSecure);
// Clean the fields
$("#text-field-name").val("");
$("#checkbox-field-is-password").prop("checked", false);
}
function remove_custom_field (event) {
$(event.target).parents("tr[id^=inventory-module-form-custom-field-row-]").remove();
}
$("#checkbox-custom_fields_enabled").click(toggle_custom_fields);
$("#button-add-field").click(add_custom_field);
$("img.remove-custom-field").click(remove_custom_field);
toggle_custom_fields();
})();
</script>
<?php
return ob_get_clean();
}

View File

@ -0,0 +1,281 @@
<?php
// phpcs:disable Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
/**
* Agent Inventory view.
*
* @category Monitoring.
* @package Pandora FMS
* @subpackage Enterprise
* @version 1.0.0
* @license See below
*
* ______ ___ _______ _______ ________
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
*
* ============================================================================
* Copyright (c) 2005-2022 Artica Soluciones Tecnologicas
* Please see http://pandorafms.org for full contribution list
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation for version 2.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* ============================================================================
*/
// Begin.
require 'include/config.php';
// Check user credentials.
check_login();
if (! check_acl($config['id_user'], 0, 'AR') && ! check_acl($config['id_user'], 0, 'AW')) {
db_pandora_audit(
AUDIT_LOG_ACL_VIOLATION,
'Trying to access Agent Inventory view'
);
include 'general/noaccess.php';
return;
}
global $id_agente;
$diff_view = (bool) get_parameter('diff_view', 0);
if ($diff_view === true) {
// Show the diff.
include 'enterprise/operation/agentes/agent_inventory.diff_view.php';
return;
}
// Initialize data.
$module = (int) get_parameter('module_inventory_agent_view');
$utimestamp = (int) get_parameter('utimestamp', 0);
$search_string = (string) get_parameter('search_string');
$sqlGetData = sprintf(
'SELECT *
FROM tmodule_inventory, tagent_module_inventory
WHERE tmodule_inventory.id_module_inventory = tagent_module_inventory.id_module_inventory
AND id_agente = %d %s',
$id_agente,
($module !== 0) ? 'AND tagent_module_inventory.id_module_inventory = '.$module : ''
);
$rows = db_get_all_rows_sql($sqlGetData);
if ($rows === false) {
ui_print_empty_data(__('This agent has not modules inventory'));
return;
}
// Get Module Inventory.
$sqlModuleInventoryAgentView = sprintf(
'SELECT tmodule_inventory.id_module_inventory, tmodule_inventory.name
FROM tmodule_inventory, tagent_module_inventory
WHERE tmodule_inventory.id_module_inventory = tagent_module_inventory.id_module_inventory
AND id_agente = %s',
$id_agente
);
// Utimestamps.
$utimestamps = db_get_all_rows_sql(
sprintf(
'SELECT tagente_datos_inventory.utimestamp
FROM tmodule_inventory, tagent_module_inventory, tagente_datos_inventory
WHERE tmodule_inventory.id_module_inventory = tagent_module_inventory.id_module_inventory
AND tagente_datos_inventory.id_agent_module_inventory = tagent_module_inventory.id_agent_module_inventory
AND tagent_module_inventory.%s',
($module !== 0) ? 'id_module_inventory = '.$module : 'id_agente = '.$id_agente
)
);
$utimestamps = (empty($utimestamps) === true) ? [] : extract_column($utimestamps, 'utimestamp');
$utimestampSelectValues = array_reduce(
$utimestamps,
function ($acc, $utimestamp) use ($config) {
$acc[$utimestamp] = date($config['date_format'], $utimestamp);
return $acc;
},
[]
);
// Inventory module select.
$table = new stdClass();
$table->width = '100%';
$table->class = 'databox filters';
$table->size = [];
$table->data = [];
$table->data[0][0] = __('Module');
$table->data[0][1] = html_print_select_from_sql(
$sqlModuleInventoryAgentView,
'module_inventory_agent_view',
$module,
'javascript:this.form.submit();',
__('All'),
0,
true
);
$table->data[0][2] = __('Date');
$table->data[0][3] = html_print_select(
$utimestampSelectValues,
'utimestamp',
$utimestamp,
'javascript:this.form.submit();',
__('Now'),
0,
true
);
$table->data[0][4] = __('Search');
$table->data[0][5] = html_print_input_text('search_string', $search_string, '', 25, 0, true);
$table->data[0][6] = html_print_submit_button(__('Search'), 'search_button', false, 'class="sub wand"', true);
// Show filters table.
echo sprintf(
'<form method="post" action="index.php?sec=estado&sec2=operation/agentes/ver_agente&tab=inventory&id_agente=%s">%s</form>',
$id_agente,
html_print_table($table, true)
);
unset($table);
$idModuleInventory = null;
$rowTable = 1;
$printedTables = 0;
// Inventory module data.
foreach ($rows as $row) {
if ($utimestamp > 0) {
$data_row = db_get_row_sql(
"SELECT data, timestamp
FROM tagente_datos_inventory
WHERE utimestamp <= '".$utimestamp."'
AND id_agent_module_inventory = ".$row['id_agent_module_inventory'].'
ORDER BY utimestamp DESC'
);
if ($data_row !== false) {
$row['data'] = $data_row['data'];
$row['timestamp'] = $data_row['timestamp'];
}
}
if ($idModuleInventory != $row['id_module_inventory']) {
if (isset($table) === true && $rowTable > 1) {
html_print_table($table);
unset($table);
$rowTable = 1;
$printedTables++;
}
$table = new StdClass();
$table->width = '98%';
$table->align = [];
$table->cellpadding = 4;
$table->cellspacing = 4;
$table->class = 'databox filters';
$table->head = [];
$table->head[0] = $row['name'].' - ('.date($config['date_format'], $row['utimestamp']).')';
if ((bool) $row['block_mode'] === true) {
$table->head[0] .= '&nbsp;&nbsp;&nbsp;<a href="index.php?sec=estado&sec2=operation/agentes/ver_agente&tab=inventory&id_agente='.$id_agente.'&utimestamp='.$utimestamp.'&id_agent_module_inventory='.$row['id_agent_module_inventory'].'&diff_view=1">'.html_print_image(
'images/op_inventory.menu.png',
true,
[
'alt' => __('Diff view'),
'title' => __('Diff view'),
'style' => 'vertical-align: middle; opacity: 0.8;',
]
).'</a>';
}
$subHeadTitles = explode(';', io_safe_output($row['data_format']));
$table->head_colspan = [];
$table->head_colspan[0] = (1 + count($subHeadTitles));
$total_fields = count($subHeadTitles);
$table->rowspan = [];
$table->data = [];
$iterator = 0;
foreach ($subHeadTitles as $titleData) {
$table->data[0][$iterator] = $titleData;
$table->cellstyle[0][$iterator] = 'background: #373737; color: #FFF;';
$iterator++;
}
}
if ($row['block_mode']) {
$rowTable++;
$table->data[$rowTable][0] = '<pre>'.$row['data'].'</pre>';
} else {
$arrayDataRowsInventory = explode(SEPARATOR_ROW, io_safe_output($row['data']));
// SPLIT DATA IN ROWS
// Remove the empty item caused by a line ending with a new line.
$len = count($arrayDataRowsInventory);
if (end($arrayDataRowsInventory) == '') {
$len--;
unset($arrayDataRowsInventory[$len]);
}
$iterator1 = 0;
$numRowHasNameAgent = $rowTable;
$rowPair = true;
$iterator = 0;
foreach ($arrayDataRowsInventory as $dataRowInventory) {
$table->rowclass[$iterator] = ($rowPair === true) ? 'rowPair' : 'rowOdd';
$rowPair = !$rowPair;
$iterator++;
// Because SQL query extract all rows (row1;row2;row3...) and only I want the row has
// the search string.
if ($search_string && preg_match('/'.io_safe_output($search_string).'/i', io_safe_output($dataRowInventory)) == 0) {
continue;
}
if ($rowTable > $numRowHasNameAgent) {
$table->data[$rowTable][0] = '';
}
$arrayDataColumnInventory = explode(SEPARATOR_COLUMN, $dataRowInventory);
// SPLIT ROW IN COLUMNS.
$iterator2 = 0;
foreach ($arrayDataColumnInventory as $dataColumnInventory) {
$table->data[$rowTable][$iterator2] = $dataColumnInventory;
$iterator2++;
}
$iterator1++;
$rowTable++;
}
if ($iterator1 > 5) {
// PRINT COUNT TOTAL.
$table->data[$rowTable][0] = '<b>'.__('Total').': </b>'.$iterator1;
$rowTable++;
}
}
$idModuleInventory = $row['id_module_inventory'];
}
if (isset($table) === true && $rowTable > 1) {
html_print_table($table);
$printedTables++;
}
if ($printedTables === 0) {
echo "<div class='nf'>".__('No data found.').'</div>';
}

View File

@ -1455,8 +1455,20 @@ if ($tab === 'alert') {
// Inventory.
$inventoryCount = db_get_num_rows('SELECT id_agent_module_inventory FROM tagent_module_inventory WHERE id_agente = '.$agent['id_agente']);
$inventorytab = enterprise_hook('inventory_tab');
if ($inventorytab == -1 || $inventoryCount === 0) {
$inventorytab['text'] = '<a href="index.php?sec=estado&sec2=operation/agentes/ver_agente&tab=inventory&id_agente='.$id_agente.'">'.html_print_image(
'images/page_white_text.png',
true,
[
'class' => 'invert_filter',
'title' => __('Inventory'),
]
).'</a>';
if ($tab == 'inventory') {
$inventorytab['active'] = true;
} else {
$inventorytab['active'] = false;
}if ($inventorytab == -1 || $inventoryCount === 0) {
$inventorytab = '';
}
@ -1986,7 +1998,7 @@ switch ($tab) {
break;
case 'inventory':
enterprise_include('operation/agentes/agent_inventory.php');
include 'operation/agentes/agent_inventory.php';
break;
case 'collection':

View File

@ -0,0 +1,551 @@
<?php
/**
* Inventory view.
*
* @category Monitoring.
* @package Pandora FMS
* @subpackage Community
* @version 1.0.0
* @license See below
*
* ______ ___ _______ _______ ________
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
*
* ============================================================================
* Copyright (c) 2005-2022 Artica Soluciones Tecnologicas
* Please see http://pandorafms.org for full contribution list
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation for version 2.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* ============================================================================
*/
// Begin.
require_once $config['homedir'].'/include/functions_users.php';
require_once $config['homedir'].'/include/functions_inventory.php';
if (is_ajax() === true) {
$get_csv_url = (bool) get_parameter('get_csv_url');
if ($get_csv_url) {
// $inventory_module = get_parameter ('module_inventory_general_view', 'all');
$inventory_module = get_parameter('module', 'all');
$inventory_id_group = (int) get_parameter('id_group', 0);
// 0 is All groups
$inventory_search_string = (string) get_parameter('search_string');
$export = (string) get_parameter('export');
$utimestamp = (int) get_parameter('utimestamp', 0);
$inventory_agent = (string) get_parameter('agent', '');
$order_by_agent = (boolean) get_parameter('order_by_agent', 0);
// Agent select.
$agents = [];
$sql = 'SELECT id_agente, nombre FROM tagente';
if ($inventory_id_group > 0) {
$sql .= ' WHERE id_grupo = '.$inventory_id_group;
} else {
$user_groups = implode(',', array_keys(users_get_groups($config['id_user'])));
// Avoid errors if there are no groups.
if (empty($user_groups) === true) {
$user_groups = '"0"';
}
$sql .= ' WHERE id_grupo IN ('.$user_groups.')';
}
$result = db_get_all_rows_sql($sql);
if ($result !== false) {
foreach ($result as $row) {
$agents[$row['id_agente']] = $row['nombre'];
}
}
$agents_select = $agents;
if (strlen($inventory_agent) == 0) {
$inventory_id_agent = -1;
$inventory_agent = __('All');
} else if ($inventory_agent == __('All')) {
$inventory_id_agent = 0;
} else {
$sql = 'SELECT id_agente
FROM tagente
WHERE nombre LIKE "'.$inventory_agent.'"';
$result = db_get_all_rows_sql($sql);
$inventory_id_agent = $result[0]['id_agente'];
}
// Single agent selected.
if ($inventory_id_agent > 0 && isset($agents[$inventory_id_agent]) === true) {
$agents = [$inventory_id_agent => $agents[$inventory_id_agent]];
}
$agents_ids = array_keys($agents);
if (count($agents_ids) > 0) {
$inventory_data = inventory_get_data(
$agents_ids,
$inventory_module,
$utimestamp,
$inventory_search_string,
$export,
false,
$order_by_agent
);
if ((int) $inventory_data === ERR_NODATA) {
$inventory_data = '';
}
}
return;
}
return;
}
global $config;
check_login();
$is_metaconsole = is_metaconsole();
if ($is_metaconsole === true) {
open_meta_frame();
}
if (! check_acl($config['id_user'], 0, 'AR') && ! check_acl($config['id_user'], 0, 'AW')) {
db_pandora_audit(
AUDIT_LOG_ACL_VIOLATION,
'Trying to access Inventory'
);
include 'general/noaccess.php';
return;
}
require_once $config['homedir'].'/include/functions_users.php';
require_once $config['homedir'].'/include/functions_inventory.php';
// Header.
ui_print_standard_header(
__('Inventory'),
'images/op_inventory.png',
false,
'',
false,
[],
[
[
'link' => '',
'label' => __('Monitoring'),
],
]
);
$inventory_id_agent = (int) get_parameter('agent_id', -1);
$inventory_agent = (string) get_parameter('agent', '');
if (strlen($inventory_agent) == 0) {
$inventory_id_agent = -1;
$inventory_agent = __('All');
} else if ($inventory_agent == __('All')) {
$inventory_id_agent = 0;
}
$inventory_module = get_parameter('module_inventory_general_view');
$inventory_id_group = (int) get_parameter('id_group');
$inventory_search_string = (string) get_parameter('search_string');
$order_by_agent = (bool) get_parameter('order_by_agent');
$export = (string) get_parameter('export');
$utimestamp = (int) get_parameter('utimestamp');
$submit_filter = (bool) get_parameter('submit_filter');
$pagination_url_parameters = [
'inventory_id_agent' => $inventory_id_agent,
'inventory_agent' => $inventory_agent,
'inventory_id_group' => $inventory_id_group,
];
$noFilterSelected = false;
// Get variables.
if ($is_metaconsole === true) {
$nodes_connection = metaconsole_get_connections();
$id_server = (int) get_parameter('id_server', 0);
$pagination_url_parameters['id_server'] = $id_server;
if ($inventory_id_agent > 0) {
$inventory_id_server = (int) get_parameter('id_server_agent', -1);
$pagination_url_parameters['inventory_id_server'] = $inventory_id_server;
if ($inventory_id_server !== -1) {
$id_server = $inventory_id_server;
$pagination_url_parameters['id_server'] = $id_server;
}
}
// No filter selected.
$noFilterSelected = $inventory_id_agent === -1 && $inventory_id_group === 0 && $id_server === 0;
}
if ($is_metaconsole === true) {
if ($id_server > 0) {
$connection = metaconsole_get_connection_by_id($id_server);
$agents_node = metaconsole_get_agents_servers($connection['server_name'], $inventory_id_group);
$node = metaconsole_get_servers($id_server);
if (metaconsole_connect($connection) !== NOERR) {
ui_print_error_message(
__('There was a problem connecting with the node')
);
}
$sql = 'SELECT DISTINCT name as indexname, name
FROM tmodule_inventory, tagent_module_inventory
WHERE tmodule_inventory.id_module_inventory = tagent_module_inventory.id_module_inventory';
if ($inventory_id_agent > 0) {
$sql .= ' AND id_agente = '.$inventory_id_agent;
}
$result_module = db_get_all_rows_sql($sql);
if ($submit_filter === true) {
$inventory_data .= inventory_get_data(
array_keys($agents_node),
$inventory_module,
$utimestamp,
$inventory_search_string,
$export,
false,
$order_by_agent,
$node,
$pagination_url_parameters
);
}
// Restore db connection.
metaconsole_restore_db();
} else {
$result_module = [];
foreach ($nodes_connection as $key => $server) {
$agents_node = metaconsole_get_agents_servers($server['server_name'], $inventory_id_group);
$connection = metaconsole_get_connection($server['server_name']);
if (metaconsole_connect($connection) !== NOERR) {
continue;
}
$sql = 'SELECT DISTINCT name as indexname, name
FROM tmodule_inventory, tagent_module_inventory
WHERE tmodule_inventory.id_module_inventory = tagent_module_inventory.id_module_inventory';
if ($inventory_id_agent > 0) {
$sql .= ' AND id_agente = '.$inventory_id_agent;
}
$result = db_get_all_rows_sql($sql);
if ($result !== false) {
$result_module = array_merge($result_module, $result);
if ($submit_filter === true) {
// Get the data.
$result_data = inventory_get_data(
array_keys($agents_node),
$inventory_module,
$utimestamp,
$inventory_search_string,
$export,
false,
$order_by_agent,
$server,
$pagination_url_parameters
);
if ($result_data !== ERR_NODATA) {
$inventory_data .= $result_data;
}
}
}
// Restore db connection.
metaconsole_restore_db();
}
}
$fields = [];
foreach ($result_module as $row) {
$id = array_shift($row);
$value = array_shift($row);
$fields[$id] = $value;
}
}
$agent_a = (bool) check_acl($config['id_user'], 0, 'AR');
$agent_w = (bool) check_acl($config['id_user'], 0, 'AW');
$access = ($agent_a === true) ? 'AR' : (($agent_w === true) ? 'AW' : 'AR');
if (is_metaconsole() === true) {
$filteringFunction = 'active_inventory_submit()';
ui_print_info_message(['no_close' => true, 'message' => __('You must select at least one filter.'), 'force_class' => 'select_one_filter']);
?>
<script type="text/javascript">
function active_inventory_submit() {
if (
$("#id_group").val() == 0 &&
$("#id_server").val() == 0 &&
$("#module_inventory_general_view").val() == 0 &&
$("#text-search_string").val() === ''
) {
$("#submit-submit_filter").attr("disabled", true);
$(".select_one_filter").css("display", "table");
} else {
$("#submit-submit_filter").attr("disabled", false);
$(".select_one_filter").css("display", "none");
}
}
</script>
<?php
} else {
$filteringFunction = '';
}
echo '<form method="POST" action="index.php?sec=estado&sec2=operation/inventory/inventory" name="form_inventory">';
$table = new stdClass();
$table->width = '100%';
$table->class = 'databox filters';
$table->size = [];
$table->size[0] = '120px';
$table->cellpadding = 0;
$table->cellspacing = 0;
$table->data = [];
$table->rowspan[0][4] = 2;
if ($is_metaconsole === true) {
// Node select.
$nodes = [];
foreach ($nodes_connection as $row) {
$nodes[$row['id']] = $row['server_name'];
}
$table->data[-1][0] = '<strong>'.__('Server').'</strong>';
$table->data[-1][1] = html_print_select($nodes, 'id_server', $id_server, $filteringFunction, __('All'), 0, true, false, true, '', false, 'min-width: 250px; max-width: 300px;');
}
// Group select.
$table->data[0][0] = '<strong>'.__('Group').'</strong>';
$table->data[0][1] = '<div class="w250px">';
$table->data[0][1] .= html_print_select_groups(
$config['id_user'],
$access,
true,
'id_group',
$inventory_id_group,
$filteringFunction,
'',
'1',
true,
false,
true,
'',
false
);
$table->data[0][1] .= '</div>';
// Module selected.
$table->data[0][2] = '<strong>'.__('Module').'</strong>';
if ($is_metaconsole === true) {
$table->data[0][3] = html_print_select($fields, 'module_inventory_general_view', $inventory_module, $filteringFunction, __('All'), 0, true, false, true, '', false, 'min-width: 194px; max-width: 200px;');
} else {
$sql = 'SELECT name as indexname, name
FROM tmodule_inventory, tagent_module_inventory
WHERE tmodule_inventory.id_module_inventory = tagent_module_inventory.id_module_inventory';
if ($inventory_id_agent > 0) {
$sql .= ' AND id_agente = '.$inventory_id_agent;
}
$table->data[0][3] = html_print_select_from_sql($sql, 'module_inventory_general_view', $inventory_module, '', __('All'), 'all', true, false, false);
}
// Button of submit.
$table->data[0][4] = html_print_submit_button(__('Search'), 'submit_filter', $noFilterSelected, "class='sub search'", true);
// Agent select.
if ($is_metaconsole === false) {
$agents = [];
$sql = 'SELECT id_agente, nombre FROM tagente';
if ($inventory_id_group > 0) {
$sql .= ' WHERE id_grupo = '.$inventory_id_group;
} else {
$user_groups = implode(',', array_keys(users_get_groups($config['id_user'])));
// Avoid errors if there are no groups.
if (empty($user_groups) === true) {
$user_groups = '"0"';
}
$sql .= ' WHERE id_grupo IN ('.$user_groups.')';
}
$result = db_get_all_rows_sql($sql);
if ($result) {
foreach ($result as $row) {
$agents[$row['id_agente']] = $row['nombre'];
}
}
}
$table->data[1][0] = '<strong>'.__('Agent').'</strong>';
$params = [];
$params['return'] = true;
$params['show_helptip'] = true;
$params['input_name'] = 'agent';
$params['value'] = $inventory_agent;
$params['selectbox_id'] = 'module_inventory_general_view';
$params['javascript_is_function_select'] = true;
$params['javascript_function_action_after_select'] = 'this.form.submit';
$params['use_hidden_input_idagent'] = true;
$params['print_hidden_input_idagent'] = true;
$params['hidden_input_idagent_id'] = 'hidden-autocomplete_id_agent';
$params['hidden_input_idagent_name'] = 'agent_id';
$params['hidden_input_idagent_value'] = $inventory_id_agent;
if ($is_metaconsole === true) {
$params['print_input_id_server'] = true;
$params['input_id_server_id'] = 'hidden-autocomplete_id_server';
$params['input_id_server_name'] = 'id_server_agent';
$params['input_id_server_value'] = $inventory_id_server;
$params['metaconsole_enabled'] = true;
}
$table->data[1][1] = ui_print_agent_autocomplete_input($params);
// String search_string.
$table->data[1][2] = '<strong>'.__('Search').'</strong>';
$table->data[1][3] = html_print_input_text('search_string', $inventory_search_string, '', 25, 0, true, false, false, '', '', $filteringFunction, 'off', false, $filteringFunction);
// Date filter. In Metaconsole has not reason for show.
if (is_metaconsole() === false) {
$table->data[2][0] = '<strong>'.__('Date').'</strong>';
$dates = inventory_get_dates($inventory_module, $inventory_agent, $inventory_id_group);
$table->data[2][1] = html_print_select($dates, 'utimestamp', $utimestamp, '', __('Last'), 0, true);
}
// Order by agent filter.
$table->data[2][2] = '<strong>'.__('Order by agent').'</strong>';
$table->data[2][3] = html_print_checkbox('order_by_agent', 1, $order_by_agent, true, false, '');
html_print_table($table);
echo '</form>';
// No agent selected or no search performed.
if ($inventory_id_agent < 0 || $submit_filter === false) {
echo '&nbsp;</td></tr><tr><td>';
return;
}
if ($is_metaconsole === false) {
// Single agent selected.
if ($inventory_id_agent > 0 && isset($agents[$inventory_id_agent]) === true) {
$agents = [$inventory_id_agent => $agents[$inventory_id_agent]];
}
$agents_ids = array_keys($agents);
if (count($agents_ids) > 0) {
$inventory_data = inventory_get_data(
$agents_ids,
$inventory_module,
$utimestamp,
$inventory_search_string,
$export,
false,
$order_by_agent,
'',
$pagination_url_parameters
);
}
if (count($agents_ids) === 0 || (int) $inventory_data === ERR_NODATA) {
ui_print_info_message(['no_close' => true, 'message' => __('No data found.') ]);
echo '&nbsp;</td></tr><tr><td>';
return;
}
echo "<div id='url_csv' style='width: ".$table->width.";' class='inventory_table_buttons'>";
echo "<a href='javascript: get_csv_url(\"".$inventory_module.'",'.$inventory_id_group.','.'"'.$inventory_search_string.'",'.$utimestamp.','.'"'.$inventory_agent.'",'.$order_by_agent.")'><span>".__('Export this list to CSV').'</span>'.html_print_image('images/csv.png', true, ['title' => __('Export this list to CSV')]).'</a>';
echo '</div>';
echo "<div id='loading_url' style='display: none; width: ".$table->width."; text-align: right;'>".html_print_image('images/spinner.gif', true).'</div>';
?>
<script type="text/javascript">
function get_csv_url(module, id_group, search_string, utimestamp, agent, order_by_agent) {
$("#url_csv").hide();
$("#loading_url").show();
$.ajax ({
method:'GET',
url:'ajax.php',
datatype:'html',
data:{
"page" : "operation/inventory/inventory",
"get_csv_url" : 1,
"module" : module,
"id_group" : id_group,
"search_string" : search_string,
"utimestamp" : utimestamp,
"agent" : agent,
"export": true,
"order_by_agent": order_by_agent
},
success: function (data, status) {
$("#url_csv").html(data);
$("#loading_url").hide();
$("#url_csv").show();
}
});
}
</script>
<?php
echo $inventory_data;
} else {
if (empty($inventory_data) === true) {
ui_print_info_message(['no_close' => true, 'message' => __('No data found.') ]);
} else {
echo $inventory_data;
}
close_meta_frame();
}
ui_require_jquery_file('pandora.controls');
ui_require_jquery_file('ajaxqueue');
ui_require_jquery_file('bgiframe');
?>
<script type="text/javascript">
/* <![CDATA[ */
$(document).ready (function () {
<?php if (is_metaconsole() === true) : ?>
active_inventory_submit();
<?php endif; ?>
$("#id_group").click (
function () {
$(this).css ("width", "auto");
}
);
$("#id_group").blur (function () {
$(this).css ("width", "180px");
});
});
/* ]]> */
</script>

View File

@ -73,7 +73,11 @@ if ($access_console_node === true) {
$sub['view']['sub2'] = $sub2;
enterprise_hook('inventory_menu');
if (check_acl($config['id_user'], 0, 'AR') || check_acl($config['id_user'], 0, 'AW')) {
$sub['operation/inventory/inventory']['text'] = __('Inventory');
$sub['operation/inventory/inventory']['id'] = 'Inventory';
$sub['operation/inventory/inventory']['refr'] = 0;
}
if ($config['activate_netflow']) {
$sub['network_traffic'] = [

View File

@ -378,11 +378,11 @@ web_threads 1
# Uncomment to perform web checks with LWP instead of CURL.
#web_engine lwp
# Enable (1) or disable (0) Pandora FMS Inventory Server (PANDORA FMS ENTERPRISE ONLY).
# Enable (1) or disable (0) Pandora FMS Inventory Server.
inventoryserver 1
# Number of threads for the Web Server (PANDORA FMS ENTERPRISE ONLY).
# Number of threads for the Inventory Server.
inventory_threads 1

View File

@ -370,11 +370,11 @@ web_threads 1
# Uncomment to perform web checks with LWP instead of CURL.
#web_engine lwp
# Enable (1) or disable (0) Pandora FMS Inventory Server (PANDORA FMS ENTERPRISE ONLY).
# Enable (1) or disable (0) Pandora FMS Inventory Server.
inventoryserver 1
# Number of threads for the Web Server (PANDORA FMS ENTERPRISE ONLY).
# Number of threads for the Inventory Server.
inventory_threads 1

View File

@ -40,6 +40,7 @@ use PandoraFMS::WMIServer;
use PandoraFMS::PluginServer;
use PandoraFMS::PredictionServer;
use PandoraFMS::WebServer;
use PandoraFMS::InventoryServer;
# Constants for Win32 services.
use constant WIN32_SERVICE_STOPPED => 0x01;
@ -157,6 +158,8 @@ sub pandora_startup () {
push (@Servers, new PandoraFMS::PluginServer (\%Config, $DBH));
push (@Servers, new PandoraFMS::PredictionServer (\%Config, $DBH));
push (@Servers, new PandoraFMS::WebServer (\%Config, $DBH));
push (@Servers, new PandoraFMS::InventoryServer (\%Config, $DBH));
} else {
# Metaconsole service modules are run by the prediction server
push (@Servers, new PandoraFMS::PredictionServer (\%Config, $DBH));

View File

@ -457,11 +457,11 @@ web_timeout 60
# Uncomment to perform web checks with LWP instead of CURL.
#web_engine lwp
# Enable (1) or disable (0) Pandora FMS Inventory Server (PANDORA FMS ENTERPRISE ONLY).
# Enable (1) or disable (0) Pandora FMS Inventory Server.
inventoryserver 1
# Number of threads for the Web Server (PANDORA FMS ENTERPRISE ONLY).
# Number of threads for the Inventory Server.
inventory_threads 1

View File

@ -375,11 +375,11 @@ web_threads 1
# Uncomment to perform web checks with LWP instead of CURL.
#web_engine lwp
# Enable (1) or disable (0) Pandora FMS Inventory Server (PANDORA FMS ENTERPRISE ONLY).
# Enable (1) or disable (0) Pandora FMS Inventory Server.
inventoryserver 1
# Number of threads for the Web Server (PANDORA FMS ENTERPRISE ONLY).
# Number of threads for the Inventory Server.
inventory_threads 1

View File

@ -280,6 +280,8 @@ our @EXPORT = qw(
notification_set_targets
notification_get_users
notification_get_groups
process_inventory_data
process_inventory_module_diff
exec_cluster_aa_module
exec_cluster_ap_module
exec_cluster_status_module
@ -5068,6 +5070,7 @@ sub process_inc_abs_data ($$$$$$) {
return $diff;
}
sub log4x_get_severity_num($) {
my ($data_object) = @_;
my $data = $data_object->{'severity'};
@ -7190,6 +7193,278 @@ sub notification_get_groups {
return @results;
}
################################################################################
################################################################################
## Inventory XML data
################################################################################
################################################################################
################################################################################
# Process inventory data, creating the module if necessary.
################################################################################
sub process_inventory_data ($$$$$$$) {
my ($pa_config, $data, $server_id, $agent_name,
$interval, $timestamp, $dbh) = @_;
foreach my $inventory (@{$data->{'inventory'}}) {
# Process inventory modules
foreach my $module_data (@{$inventory->{'inventory_module'}}) {
my $module_name = get_tag_value ($module_data, 'name', '');
# Unnamed module
next if ($module_name eq '');
# Process inventory data
my $data_list = '';
foreach my $list (@{$module_data->{'datalist'}}) {
# Empty list
next unless defined ($list->{'data'});
foreach my $data (@{$list->{'data'}}) {
$data_list .= $data . "\n";
}
}
next if ($data_list eq '');
process_inventory_module_data ($pa_config, $data_list, $server_id, $agent_name, $module_name, $interval, $timestamp, $dbh);
}
}
}
################################################################################
# Process inventory module data, creating the module if necessary.
################################################################################
sub process_inventory_module_data ($$$$$$$$) {
my ($pa_config, $data, $server_id, $agent_name,
$module_name, $interval, $timestamp, $dbh) = @_;
logger ($pa_config, "Processing inventory module '$module_name' for agent '$agent_name'.", 10);
# Get agent data
my $agent = get_db_single_row ($dbh,
'SELECT * FROM tagente WHERE nombre = ?', safe_input($agent_name));
if (! defined ($agent)) {
logger ($pa_config, "Agent '$agent_name' not found for inventory module '$module_name'.", 3);
return;
}
# Parse the timestamp and process the module
if ($timestamp !~ /(\d+)\/(\d+)\/(\d+) +(\d+):(\d+):(\d+)/ &&
$timestamp !~ /(\d+)\-(\d+)\-(\d+) +(\d+):(\d+):(\d+)/) {
logger($pa_config, "Invalid timestamp '$timestamp' from module '$module_name' agent '$agent_name'.", 3);
return;
}
my $utimestamp;
eval {
$utimestamp = strftime("%s", $6, $5, $4, $3, $2 - 1, $1 - 1900);
};
if ($@) {
logger($pa_config, "Invalid timestamp '$timestamp' from module '$module_name' agent '$agent_name'.", 3);
return;
}
# Get module data or create it if it does not exist
my $inventory_module = get_db_single_row ($dbh,
'SELECT tagent_module_inventory.*, tmodule_inventory.name
FROM tagent_module_inventory, tmodule_inventory
WHERE tagent_module_inventory.id_module_inventory = tmodule_inventory.id_module_inventory
AND id_agente = ? AND name = ?',
$agent->{'id_agente'}, safe_input($module_name));
if (! defined ($inventory_module)) {
# Get the module
my $module_id = get_db_value ($dbh,
'SELECT id_module_inventory FROM tmodule_inventory WHERE name = ? AND id_os = ?',
safe_input($module_name), $agent->{'id_os'});
return unless defined ($module_id);
my $id_agent_module_inventory = 0;
# Update the module data
$id_agent_module_inventory = db_insert ($dbh, 'id_agent_module_inventory',
"INSERT INTO tagent_module_inventory (id_agente, id_module_inventory,
${RDBMS_QUOTE}interval${RDBMS_QUOTE}, data, timestamp, utimestamp, flag)
VALUES (?, ?, ?, ?, ?, ?, ?)",
$agent->{'id_agente'}, $module_id, $interval, safe_input($data), $timestamp, $utimestamp, 0);
return unless ($id_agent_module_inventory > 0);
db_do ($dbh,
'INSERT INTO tagente_datos_inventory (id_agent_module_inventory, data, timestamp, utimestamp)
VALUES (?, ?, ?, ?)',
$id_agent_module_inventory, safe_input($data), $timestamp, $utimestamp);
return;
}
process_inventory_module_diff($pa_config, safe_input($data),
$inventory_module, $timestamp, $utimestamp, $dbh, $interval);
}
################################################################################
# Searching differences between incoming module and stored module,
# creating/updating module and event
################################################################################
sub process_inventory_module_diff ($$$$$$;$) {
my ($pa_config, $incoming_data, $inventory_module, $timestamp, $utimestamp, $dbh, $interval) = @_;
my $stored_data = $inventory_module->{'data'};
my $agent_id = $inventory_module->{'id_agente'};
my $stored_utimestamp = $inventory_module->{'utimestamp'};
my $agent_module_inventory_id = $inventory_module->{'id_agent_module_inventory'};
my $module_inventory_id = $inventory_module->{'id_module_inventory'};
enterprise_hook('process_inventory_alerts', [$pa_config, $incoming_data,
$inventory_module, $timestamp, $utimestamp, $dbh, $interval]);
# If there were any changes generate an event and save the new data
if (decode('UTF-8', $stored_data) ne $incoming_data) {
my $inventory_db = $stored_data;
my $inventory_new = $incoming_data;
my @inventory = split('\n', $inventory_new);
my $diff_new = "";
my $diff_delete = "";
foreach my $inv (@inventory) {
my $inv_clean = quotemeta($inv);
if($inventory_db =~ m/$inv_clean/) {
$inventory_db =~ s/$inv_clean//g;
$inventory_new =~ s/$inv_clean//g;
}
else {
$diff_new .= "$inv\n";
}
}
# If any register is in the stored yet, we store as deleted
$inventory_db =~ s/\n\n*/\n/g;
$inventory_db =~ s/^\n//g;
$diff_delete = $inventory_db;
if($diff_new ne "") {
$diff_new = " NEW: '$diff_new' ";
}
if($diff_delete ne "") {
$diff_delete = " DELETED: '$diff_delete' ";
}
db_do ($dbh, 'INSERT INTO tagente_datos_inventory (id_agent_module_inventory, data, timestamp, utimestamp) VALUES (?, ?, ?, ?)',
$agent_module_inventory_id, $incoming_data, $timestamp, $utimestamp);
# Do not generate an event the first time the module runs
if ($stored_utimestamp != 0) {
my $inventory_changes_blacklist = pandora_get_config_value ($dbh, 'inventory_changes_blacklist');
my $inventory_module_blocked = 0;
if($inventory_changes_blacklist ne "") {
foreach my $inventory_id_excluded (split (',', $inventory_changes_blacklist)) {
# If the inventory_module_id is in the blacklist, the change will not be processed
if($inventory_module->{'id_module_inventory'} == $inventory_id_excluded) {
logger ($pa_config, "Inventory change omitted on inventory #$inventory_id_excluded due be on the changes blacklist", 10);
$inventory_module_blocked = 1;
}
}
}
# If the inventory_module_id is in the blacklist, the change will not be processed
if ($inventory_module_blocked == 0) {
my $inventory_module_name = get_db_value ($dbh, "SELECT name FROM tmodule_inventory WHERE id_module_inventory = ?", $module_inventory_id);
return unless defined ($inventory_module_name);
my $agent_name = get_agent_name ($dbh, $agent_id);
return unless defined ($agent_name);
my $agent_alias = get_agent_alias ($dbh, $agent_id);
return unless defined ($agent_alias);
my $group_id = get_agent_group ($dbh, $agent_id);
$stored_data =~ s/&amp;#x20;/ /g;
$incoming_data =~ s/&amp;#x20;/ /g;
my @values_stored = split('&#x0a;', $stored_data);
my @finalc_stored = ();
my @values_incoming = split('&#x0a;', $incoming_data);
my @finalc_incoming = ();
my @finalc_compare_added = ();
my @finalc_compare_deleted = ();
my @finalc_compare_updated = ();
my @finalc_compare_updated_del = ();
my @finalc_compare_updated_add = ();
my $temp_compare = ();
my $final_d = '';
my $final_a = '';
my $final_u = '';
foreach my $i (0 .. $#values_stored) {
$finalc_stored[$i] = $values_stored[$i];
if ( grep $_ eq $values_stored[$i], @values_incoming ) {
} else {
# Use 'safe_output' to avoid double encode the entities when creating the event with 'pandora_event'
$final_d .= "DELETED RECORD: ".safe_output($values_stored[$i])."\n";
}
}
foreach my $i (0 .. $#values_incoming) {
$finalc_incoming[$i] = $values_incoming[$i];
if ( grep $_ eq $values_incoming[$i], @values_stored ) {
} else {
# Use 'safe_output' to avoid double encode the entities when creating the event with 'pandora_event'
$final_a .= "NEW RECORD: ".safe_output($values_incoming[$i])."\n";
}
}
# foreach my $i (0 .. $#finalc_compare_deleted) {
# $finalc_compare_updated_del[$i] = split(';', $finalc_compare_deleted[$i]);
# $finalc_compare_updated_add[$i] = split(';', $finalc_compare_added[$i]);
# if($finalc_compare_updated_del[$i] ~~ @finalc_compare_updated_add){
# $finalc_compare_updated[$i] = $finalc_compare_updated_del[$i];
# }
# $finalc_compare_updated[$i] =~ s/DELETED RECORD:/UPDATED RECORD:/g;
# $finalc_compare_updated[$i] =~ s/NEW RECORD://g;
# }
pandora_event ($pa_config, "Configuration change:\n".$final_d.$final_a." for agent '" . safe_output($agent_alias) . "' module '" . safe_output($inventory_module_name) . "'.", $group_id, $agent_id, 0, 0, 0, "configuration_change", 0, $dbh);
}
}
}
# Update the module data
if (defined($interval)) {
db_do ($dbh, 'UPDATE tagent_module_inventory
SET'. $RDBMS_QUOTE . 'interval' .
$RDBMS_QUOTE . '=?, data=?, timestamp=?, utimestamp=?
WHERE id_agent_module_inventory=?',
$interval, $incoming_data, $timestamp,
$utimestamp, $agent_module_inventory_id);
}
else {
db_do ($dbh, 'UPDATE tagent_module_inventory
SET data = ?, timestamp = ?, utimestamp = ?
WHERE id_agent_module_inventory = ?',
$incoming_data, $timestamp, $utimestamp, $agent_module_inventory_id);
}
}
##########################################################################
=head2 C<< escalate_warning (I<$pa_config>, I<$agent>, I<$module>, I<$agent_status>, I<$new_status>, I<$known_status>) >>

View File

@ -681,8 +681,7 @@ sub process_xml_data ($$$$$) {
# Process inventory modules
enterprise_hook('process_inventory_data', [$pa_config, $data, $server_id, $agent_name,
$interval, $timestamp, $dbh]);
process_inventory_data($pa_config, $data, $server_id, $agent_name, $interval, $timestamp, $dbh);
# Process log modules
enterprise_hook('process_log_data', [$pa_config, $data, $server_id, $agent_name,

View File

@ -0,0 +1,267 @@
package PandoraFMS::InventoryServer;
##########################################################################
# Pandora FMS Inventory Server.
##########################################################################
# Copyright (c) 2007-2021 Artica Soluciones Tecnologicas S.L
# This code is not free or OpenSource. Please don't redistribute.
##########################################################################
use strict;
use warnings;
use threads;
use threads::shared;
use Thread::Semaphore;
use File::Temp qw(tempfile unlink0);
use POSIX qw(strftime);
use HTML::Entities;
use MIME::Base64;
use JSON;
# UTF-8 flags control with I/O for multibyte characters
use open ":utf8";
# Default lib dir for RPM and DEB packages
BEGIN { push @INC, '/usr/lib/perl5'; }
use PandoraFMS::Tools;
use PandoraFMS::DB;
use PandoraFMS::Core;
use PandoraFMS::ProducerConsumerServer;
# Inherits from PandoraFMS::ProducerConsumerServer
our @ISA = qw(PandoraFMS::ProducerConsumerServer);
# Global variables
my @TaskQueue :shared;
my %PendingTasks :shared;
my $Sem :shared;
my $TaskSem :shared;
########################################################################################
# Inventory Server class constructor.
########################################################################################
sub new ($$;$) {
my ($class, $config, $dbh) = @_;
return undef unless $config->{'inventoryserver'} == 1;
# Initialize semaphores and queues
@TaskQueue = ();
%PendingTasks = ();
$Sem = Thread::Semaphore->new;
$TaskSem = Thread::Semaphore->new (0);
# Call the constructor of the parent class
my $self = $class->SUPER::new($config, INVENTORYSERVER, \&PandoraFMS::InventoryServer::data_producer, \&PandoraFMS::InventoryServer::data_consumer, $dbh);
bless $self, $class;
return $self;
}
###############################################################################
# Run.
###############################################################################
sub run ($) {
my $self = shift;
my $pa_config = $self->getConfig ();
print_message ($pa_config, " [*] Starting " . $pa_config->{'rb_product_name'} . " Inventory Server.", 1);
$self->setNumThreads ($pa_config->{'inventory_threads'});
$self->SUPER::run (\@TaskQueue, \%PendingTasks, $Sem, $TaskSem);
}
###############################################################################
# Data producer.
###############################################################################
sub data_producer ($) {
my $self = shift;
my ($pa_config, $dbh) = ($self->getConfig (), $self->getDBH ());
my @tasks;
my @rows;
if (pandora_is_master($pa_config) == 0) {
if ($pa_config->{'dbengine'} ne 'oracle') {
@rows = get_db_rows ($dbh,
'SELECT tagent_module_inventory.id_agent_module_inventory, tagent_module_inventory.flag, tagent_module_inventory.timestamp
FROM tagente, tagent_module_inventory, tmodule_inventory
WHERE tagente.server_name = ?
AND tmodule_inventory.id_module_inventory = tagent_module_inventory.id_module_inventory
AND tmodule_inventory.id_os IS NOT NULL
AND tagente.id_agente = tagent_module_inventory.id_agente
AND tagent_module_inventory.target <> \'\'
AND tagente.disabled = 0
AND (tagent_module_inventory.timestamp = \'1970-01-01 00:00:00\'
OR UNIX_TIMESTAMP(tagent_module_inventory.timestamp) + tagent_module_inventory.interval < UNIX_TIMESTAMP()
OR tagent_module_inventory.flag = 1)
ORDER BY tagent_module_inventory.timestamp ASC',
$pa_config->{'servername'});
}
else {
@rows = get_db_rows ($dbh,
'SELECT tagent_module_inventory.id_agent_module_inventory, tagent_module_inventory.flag, tagent_module_inventory.timestamp
FROM tagente, tagent_module_inventory, tmodule_inventory
WHERE tagente.server_name = ?
AND tmodule_inventory.id_module_inventory = tagent_module_inventory.id_module_inventory
AND tmodule_inventory.id_os IS NOT NULL
AND tagente.id_agente = tagent_module_inventory.id_agente
AND tagent_module_inventory.target IS NOT NULL
AND tagente.disabled = 0
AND (tagent_module_inventory.timestamp = \'1970-01-01 00:00:00\'
OR UNIX_TIMESTAMP(tagent_module_inventory.timestamp) + tagent_module_inventory.' . ${RDBMS_QUOTE} . 'interval' . ${RDBMS_QUOTE} . '< UNIX_TIMESTAMP()
OR tagent_module_inventory.flag = 1)
ORDER BY tagent_module_inventory.timestamp ASC',
$pa_config->{'servername'});
}
}
else {
if ($pa_config->{'dbengine'} ne 'oracle') {
@rows = get_db_rows ($dbh,
'SELECT tagent_module_inventory.id_agent_module_inventory, tagent_module_inventory.flag, tagent_module_inventory.timestamp
FROM tagente, tagent_module_inventory, tmodule_inventory
WHERE (server_name = ? OR server_name = ANY(SELECT name FROM tserver WHERE status <> 1 AND server_type = ?))
AND tmodule_inventory.id_module_inventory = tagent_module_inventory.id_module_inventory
AND tmodule_inventory.id_os IS NOT NULL
AND tagente.id_agente = tagent_module_inventory.id_agente
AND tagent_module_inventory.target <> \'\'
AND tagente.disabled = 0
AND (tagent_module_inventory.timestamp = \'1970-01-01 00:00:00\'
OR UNIX_TIMESTAMP(tagent_module_inventory.timestamp) + tagent_module_inventory.interval < UNIX_TIMESTAMP()
OR tagent_module_inventory.flag = 1)
ORDER BY tagent_module_inventory.timestamp ASC',
$pa_config->{'servername'}, INVENTORYSERVER);
}
else {
@rows = get_db_rows ($dbh,
'SELECT tagent_module_inventory.id_agent_module_inventory, tagent_module_inventory.flag, tagent_module_inventory.timestamp
FROM tagente, tagent_module_inventory, tmodule_inventory
WHERE (server_name = ? OR server_name = ANY(SELECT name FROM tserver WHERE status <> 1 AND server_type = ?))
AND tmodule_inventory.id_module_inventory = tagent_module_inventory.id_module_inventory
AND tmodule_inventory.id_os IS NOT NULL
AND tagente.id_agente = tagent_module_inventory.id_agente
AND tagent_module_inventory.target IS NOT NULL
AND tagente.disabled = 0
AND (tagent_module_inventory.timestamp = \'1970-01-01 00:00:00\'
OR UNIX_TIMESTAMP(tagent_module_inventory.timestamp) + tagent_module_inventory.' . ${RDBMS_QUOTE} . 'interval' . ${RDBMS_QUOTE} . ' < UNIX_TIMESTAMP()
OR tagent_module_inventory.flag = 1)
ORDER BY tagent_module_inventory.timestamp ASC',
$pa_config->{'servername'}, INVENTORYSERVER);
}
}
foreach my $row (@rows) {
# Reset forced execution flag
if ($row->{'flag'} == 1) {
db_do ($dbh, 'UPDATE tagent_module_inventory SET flag = 0 WHERE id_agent_module_inventory = ?', $row->{'id_agent_module_inventory'});
}
push (@tasks, $row->{'id_agent_module_inventory'});
}
return @tasks;
}
###############################################################################
# Data consumer.
###############################################################################
sub data_consumer ($$) {
my ($self, $module_id) = @_;
my ($pa_config, $dbh) = ($self->getConfig (), $self->getDBH ());
my $timeout = $pa_config->{'inventory_timeout'};
# Get inventory module data
my $module = get_db_single_row ($dbh,
'SELECT * FROM tagent_module_inventory, tmodule_inventory
WHERE tagent_module_inventory.id_agent_module_inventory = ?
AND tagent_module_inventory.id_module_inventory = tmodule_inventory.id_module_inventory',
$module_id);
# No code to run
return if ($module->{'interpreter'} eq '');
# Save script in a temporary file
my ($fh, $temp_file) = tempfile();
$fh->print (decode_base64($module->{'code'}));
close ($fh);
set_file_permissions($pa_config, $temp_file, "0777");
# Run the script
my $command = $module->{'interpreter'} . ' ' . $temp_file . ' "' . $module->{'target'} . '"';
# Try to read the custom fields to use them as arguments into the command
if (defined($module->{'custom_fields'}) && $module->{'custom_fields'} ne '') {
my $decoded_cfields;
eval {
$decoded_cfields = decode_json (decode_base64 ($module->{'custom_fields'}));
};
if ($@) {
logger($pa_config, "Failed to encode received inventory data", 10);
}
if (!defined ($decoded_cfields)) {
logger ($pa_config, "Remote inventory module ".$module->{'name'}." has failed because the custom fields can't be read", 6);
unlink ($temp_file);
return;
}
foreach my $field (@{$decoded_cfields}) {
if ($field->{'secure'}) {
$command .= ' "' . pandora_output_password($pa_config, $field->{'value'}) . '"';
}
else {
$command .= ' "' . $field->{'value'} . '"';
}
}
}
# Add the default user/password arguments to the command
else {
# Initialize macros.
my %macros = (
'_agentcustomfield_\d+_' => undef,
);
my $wmi_user = safe_output(subst_column_macros($module->{"username"}, \%macros, $pa_config, $dbh, undef, $module));
my $wmi_pass = safe_output(pandora_output_password($pa_config, subst_column_macros($module->{"password"}, \%macros, $pa_config, $dbh, undef, $module)));
$command .= ' "' . $wmi_user . '" "' . $wmi_pass . '"';
}
logger ($pa_config, "Inventory execution command $command", 10);
my $data = `$command 2>$DEVNULL`;
# Check for errors
if ($? != 0) {
logger ($pa_config, "Remote inventory module ".$module->{'name'}." has failed with error level $?", 6);
unlink ($temp_file);
return;
}
unlink ($temp_file);
my $utimestamp = time ();
my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime ($utimestamp));
eval {
$data = encode_entities ($data, "'<>&");
};
if ($@) {
logger($pa_config, "Failed to encode received inventory data", 10);
return;
}
# Get previous data from the database
my $inventory_module = get_db_single_row ($dbh,
'SELECT * FROM tagent_module_inventory
WHERE id_agent_module_inventory = ?',
$module_id);
return unless defined ($inventory_module);
process_inventory_module_diff($pa_config, $data,
$inventory_module, $timestamp, $utimestamp, $dbh);
}
1;
__END__