Added type to SNMP browser module creation

This commit is contained in:
Luis 2020-06-23 14:46:22 +02:00 committed by Daniel Rodriguez
parent 57df59448e
commit b40b98fc54
3 changed files with 71 additions and 3 deletions

View File

@ -13,6 +13,7 @@
// GNU General Public License for more details.
require_once $config['homedir'].'/include/functions_config.php';
require_once $config['homedir'].'/include/functions_snmp_browser.php';
require_once $config['homedir'].'/include/functions_snmp.php';
require_once $config['homedir'].'/include/functions_network_components.php';

View File

@ -455,3 +455,61 @@ function print_snmp_tags_active_filters($filter_resume=[])
ui_print_tags_view($title, $tags_set);
}
}
/**
* Retunr module type for snmp data type
*
* @param [type] $snmp_data_type
* @return void
*/
function snmp_module_get_type(string $snmp_data_type)
{
if (preg_match('/INTEGER/i', $snmp_data_type)) {
$type = 'remote_snmp';
} else if (preg_match('/Integer32/i', $snmp_data_type)) {
$type = 'remote_snmp';
} else if (preg_match('/octect string/i', $snmp_data_type)) {
$type = 'remote_snmp';
} else if (preg_match('/bits/i', $snmp_data_type)) {
$type = 'remote_snmp';
} else if (preg_match('/object identifier/i', $snmp_data_type)) {
$type = 'remote_snmp_string';
} else if (preg_match('/IpAddress/i', $snmp_data_type)) {
$type = 'remote_snmp_string';
} else if (preg_match('/Counter/i', $snmp_data_type)) {
$type = 'remote_snmp_inc';
} else if (preg_match('/Counter32/i', $snmp_data_type)) {
$type = 'remote_snmp_inc';
} else if (preg_match('/Gauge/i', $snmp_data_type)) {
$type = 'remote_snmp';
} else if (preg_match('/Gauge32/i', $snmp_data_type)) {
$type = 'remote_snmp';
} else if (preg_match('/Gauge64/i', $snmp_data_type)) {
$type = 'remote_snmp';
} else if (preg_match('/Unsigned32/i', $snmp_data_type)) {
$type = 'remote_snmp_inc';
} else if (preg_match('/TimeTicks/i', $snmp_data_type)) {
$type = 'remote_snmp';
} else if (preg_match('/Opaque/i', $snmp_data_type)) {
$type = 'remote_snmp_string';
} else if (preg_match('/Counter64/i', $snmp_data_type)) {
$type = 'remote_snmp_inc';
} else if (preg_match('/UInteger32/i', $snmp_data_type)) {
$type = 'remote_snmp';
} else if (preg_match('/BIT STRING/i', $snmp_data_type)) {
$type = 'remote_snmp_string';
} else if (preg_match('/STRING/i', $snmp_data_type)) {
$type = 'remote_snmp_string';
} else {
$type = 'remote_snmp_string';
}
if (!$type) {
$type = 'remote_snmp';
}
$type_id = modules_get_type_id($type);
return $type_id;
}

View File

@ -945,6 +945,12 @@ function snmp_browser_create_modules_snmp(string $module_target, array $snmp_val
$description = io_safe_input(preg_replace('/\s+/', ' ', $oid['description']));
}
if (!empty($oid['type'])) {
$module_type = snmp_module_get_type($oid['type']);
} else {
$module_type = 17;
}
if ($module_target == 'network_component') {
$name_check = db_get_value(
'name',
@ -956,7 +962,7 @@ function snmp_browser_create_modules_snmp(string $module_target, array $snmp_val
if (!$name_check) {
$id = network_components_create_network_component(
$oid['oid'],
17,
$module_type,
1,
[
'description' => $description,
@ -1009,12 +1015,13 @@ function snmp_browser_create_modules_snmp(string $module_target, array $snmp_val
'min_ff_event_critical' => 0,
'ff_type' => 0,
'each_ff' => 0,
'history_data' => 1,
]
);
}
} else if ($module_target == 'agent') {
$values = [
'id_tipo_modulo' => 17,
'id_tipo_modulo' => $module_type,
'descripcion' => $description,
'module_interval' => 300,
'max' => 0,
@ -1065,6 +1072,7 @@ function snmp_browser_create_modules_snmp(string $module_target, array $snmp_val
'ff_type' => 0,
'each_ff' => 0,
'ip_target' => $target_ip,
'history_data' => 1,
];
foreach ($id_target as $agent) {
$ids[] = modules_create_agent_module($agent, $oid['oid'], $values);
@ -1073,7 +1081,7 @@ function snmp_browser_create_modules_snmp(string $module_target, array $snmp_val
// Policies only in enterprise version.
if (enterprise_installed()) {
$values = [
'id_tipo_modulo' => 17,
'id_tipo_modulo' => $module_type,
'description' => $description,
'module_interval' => 300,
'max' => 0,
@ -1123,6 +1131,7 @@ function snmp_browser_create_modules_snmp(string $module_target, array $snmp_val
'each_ff' => 0,
'ip_target' => $target_ip,
'configuration_data' => '',
'history_data' => 1,
];
enterprise_include_once('include/functions_policies.php');