implement demo data load

This commit is contained in:
alejandro.campos@artica.es 2023-11-24 12:56:21 +01:00
parent c7770ec4f1
commit a1916dc4b9
6 changed files with 118 additions and 85 deletions

View File

@ -496,6 +496,9 @@ if ($access_console_node === true) {
$sub2['godmode/setup/setup&section=welcome_tips']['text'] = __('Welcome Tips'); $sub2['godmode/setup/setup&section=welcome_tips']['text'] = __('Welcome Tips');
$sub2['godmode/setup/setup&section=welcome_tips']['refr'] = 0; $sub2['godmode/setup/setup&section=welcome_tips']['refr'] = 0;
$sub2['godmode/setup/setup&section=demo_data']['text'] = __('Demo data');
$sub2['godmode/setup/setup&section=demo_data']['refr'] = 0;
if ((bool) $config['activate_gis'] === true) { if ((bool) $config['activate_gis'] === true) {
$sub2['godmode/setup/setup&section=gis']['text'] = __('Map conections GIS'); $sub2['godmode/setup/setup&section=gis']['text'] = __('Map conections GIS');
} }
@ -506,12 +509,7 @@ if ($access_console_node === true) {
enterprise_hook('skins_submenu'); enterprise_hook('skins_submenu');
$sub['godmode/setup/demo']['text'] = __('Demo data');
$sub['godmode/setup/demo']['id'] = 'demo';
$menu_godmode['gsetup']['sub'] = $sub; $menu_godmode['gsetup']['sub'] = $sub;
} }
} }

View File

@ -131,9 +131,8 @@ if ($display_loading === true || $running_create === true || $running_delete) {
DEMO_DASHBOARD => 'dashboards', DEMO_DASHBOARD => 'dashboards',
]; ];
if ($adv_options_is_enabled === true) { if ((bool) $adv_options_is_enabled === true) {
$enabled_keys = array_keys(array_filter($enabled_items)); $enabled_keys = array_keys(array_filter($enabled_items));
$items_ids_text_map = array_filter( $items_ids_text_map = array_filter(
$items_ids_text_map, $items_ids_text_map,
function ($k) use ($dir_item_id_map, $enabled_keys) { function ($k) use ($dir_item_id_map, $enabled_keys) {
@ -141,10 +140,13 @@ if ($display_loading === true || $running_create === true || $running_delete) {
}, },
ARRAY_FILTER_USE_KEY ARRAY_FILTER_USE_KEY
); );
array_merge([DEMO_AGENT => 'agents'], $items_ids_text_map);
} }
if (enterprise_installed() === false) {
unset($items_ids_text_map[DEMO_SERVICE]);
}
$items_ids_text_map = ([DEMO_AGENT => 'agents'] + $items_ids_text_map);
$list_mkup = '<ul id="load-info">'; $list_mkup = '<ul id="load-info">';
foreach ($items_ids_text_map as $item_id => $item_text) { foreach ($items_ids_text_map as $item_id => $item_text) {
$list_mkup .= '<li data-item-id="'.$item_id.'">'; $list_mkup .= '<li data-item-id="'.$item_id.'">';
@ -240,7 +242,7 @@ if ($display_loading === true || $running_create === true || $running_delete) {
'agents_num', 'agents_num',
$agents_num, $agents_num,
'', '',
'30', '',
30, 30,
true, true,
false, false,
@ -271,8 +273,26 @@ if ($display_loading === true || $running_create === true || $running_delete) {
$table_adv->size[0] = '50%'; $table_adv->size[0] = '50%';
$table_adv->size[1] = '50%'; $table_adv->size[1] = '50%';
$interval_select = html_print_extended_select_for_time(
'interval',
$interval,
'',
'',
'0',
10,
true,
false,
true,
'w20p'
);
$table_adv->data['row0'][] = html_print_label_input_block( $table_adv->data['row0'][] = html_print_label_input_block(
__('Generate historical data for all agents (15 days by default)'), __('Agents interval'),
$interval_select
);
$table_adv->data['row1'][] = html_print_label_input_block(
__('Generate historical data for all agents'),
html_print_checkbox_switch( html_print_checkbox_switch(
'enable_history', 'enable_history',
1, 1,
@ -281,7 +301,7 @@ if ($display_loading === true || $running_create === true || $running_delete) {
) )
); );
$table_adv->data['row1'][] = html_print_label_input_block( $table_adv->data['row2'][] = html_print_label_input_block(
__('Days of historical data to insert in the agent data'), __('Days of historical data to insert in the agent data'),
html_print_input_text( html_print_input_text(
'days_hist_data', 'days_hist_data',
@ -297,33 +317,17 @@ if ($display_loading === true || $running_create === true || $running_delete) {
) )
); );
$table_adv->data['row2'][] = html_print_label_input_block( if (enterprise_installed() === true) {
__('Create custom graphs'), $table_adv->data['row3'][] = html_print_label_input_block(
html_print_checkbox_switch( __('Create services'),
'enable_cg', html_print_checkbox_switch(
1, 'enable_services',
$enabled_items['graphs'], 1,
true $enabled_items['services'],
) true
); )
);
$interval_select = html_print_extended_select_for_time( }
'interval',
$interval,
'',
'',
'0',
10,
true,
false,
true,
'w20p'
);
$table_adv->data['row3'][] = html_print_label_input_block(
__('Interval'),
$interval_select
);
$table_adv->data['row4'][] = html_print_label_input_block( $table_adv->data['row4'][] = html_print_label_input_block(
__('Create network maps'), __('Create network maps'),
@ -336,11 +340,11 @@ if ($display_loading === true || $running_create === true || $running_delete) {
); );
$table_adv->data['row5'][] = html_print_label_input_block( $table_adv->data['row5'][] = html_print_label_input_block(
__('Create services'), __('Create custom graphs'),
html_print_checkbox_switch( html_print_checkbox_switch(
'enable_services', 'enable_cg',
1, 1,
$enabled_items['services'], $enabled_items['graphs'],
true true
) )
); );
@ -356,17 +360,6 @@ if ($display_loading === true || $running_create === true || $running_delete) {
); );
$table_adv->data['row7'][] = html_print_label_input_block( $table_adv->data['row7'][] = html_print_label_input_block(
__('Create dashboards'),
html_print_checkbox_switch(
'enable_dashboards',
1,
$enabled_items['dashboards'],
true
)
);
$table_adv->data['row8'][] = html_print_label_input_block(
__('Create visual consoles'), __('Create visual consoles'),
html_print_checkbox_switch( html_print_checkbox_switch(
'enable_vc', 'enable_vc',
@ -376,6 +369,16 @@ if ($display_loading === true || $running_create === true || $running_delete) {
) )
); );
$table_adv->data['row8'][] = html_print_label_input_block(
__('Create dashboards'),
html_print_checkbox_switch(
'enable_dashboards',
1,
$enabled_items['dashboards'],
true
)
);
echo '<form class="max_floating_element_size" id="form_setup" method="post">'; echo '<form class="max_floating_element_size" id="form_setup" method="post">';
echo '<fieldset>'; echo '<fieldset>';
echo '<legend>'.__('Configure demo data').'</legend>'; echo '<legend>'.__('Configure demo data').'</legend>';
@ -432,20 +435,32 @@ if ($display_loading === true || $running_create === true || $running_delete) {
$table_summary->size[0] = '50%'; $table_summary->size[0] = '50%';
$table_summary->size[1] = '50%'; $table_summary->size[1] = '50%';
$table_summary->data['row0'][0] = __('Agents'); $i = 0;
$table_summary->data['row0'][1] = ($demo_agents_count > 0) ? $demo_agents_count : '-'; $table_summary->data[$i][0] = __('Agents');
$table_summary->data['row1'][0] = __('Services'); $table_summary->data[$i][1] = ($demo_agents_count > 0) ? $demo_agents_count : '-';
$table_summary->data['row1'][1] = ($demo_services_count > 0) ? $demo_services_count : '-'; $i++;
$table_summary->data['row2'][0] = __('Network maps');
$table_summary->data['row2'][1] = ($demo_nm_count > 0) ? $demo_nm_count : '-'; if (enterprise_installed() === true) {
$table_summary->data['row3'][0] = __('Custom graphs'); $table_summary->data[$i][0] = __('Services');
$table_summary->data['row3'][1] = ($demo_cg_count > 0) ? $demo_cg_count : '-'; $table_summary->data[$i][1] = ($demo_services_count > 0) ? $demo_services_count : '-';
$table_summary->data['row4'][0] = __('Custom reports'); $i++;
$table_summary->data['row4'][1] = ($demo_rep_count > 0) ? $demo_rep_count : '-'; }
$table_summary->data['row5'][0] = __('Visual consoles');
$table_summary->data['row5'][1] = ($demo_vc_count > 0) ? $demo_vc_count : '-'; $i++;
$table_summary->data['row6'][0] = __('Dashboards'); $table_summary->data[$i][0] = __('Network maps');
$table_summary->data['row6'][1] = ($demo_dashboards_count > 0) ? $demo_dashboards_count : '-'; $table_summary->data[$i][1] = ($demo_nm_count > 0) ? $demo_nm_count : '-';
$i++;
$table_summary->data[$i][0] = __('Custom graphs');
$table_summary->data[$i][1] = ($demo_cg_count > 0) ? $demo_cg_count : '-';
$i++;
$table_summary->data[$i][0] = __('Custom reports');
$table_summary->data[$i][1] = ($demo_rep_count > 0) ? $demo_rep_count : '-';
$i++;
$table_summary->data[$i][0] = __('Visual consoles');
$table_summary->data[$i][1] = ($demo_vc_count > 0) ? $demo_vc_count : '-';
$i++;
$table_summary->data[$i][0] = __('Dashboards');
$table_summary->data[$i][1] = ($demo_dashboards_count > 0) ? $demo_dashboards_count : '-';
echo '<form class="max_floating_element_size" method="post">'; echo '<form class="max_floating_element_size" method="post">';
echo '<fieldset>'; echo '<fieldset>';
@ -504,16 +519,16 @@ if ($display_loading === true || $running_create === true || $running_delete) {
} }
}); });
$('#table-adv-row1').hide(); $('#table-adv-row2').hide();
if ($('#checkbox-enable_history').is(':checked') === true) { if ($('#checkbox-enable_history').is(':checked') === true) {
$('#table-adv-row1').show(); $('#table-adv-row2').show();
} }
$('#checkbox-enable_history').change(function() { $('#checkbox-enable_history').change(function() {
if ($(this).is(':checked') === true) { if ($(this).is(':checked') === true) {
$('#table-adv-row1').show(); $('#table-adv-row2').show();
} else { } else {
$('#table-adv-row1').hide(); $('#table-adv-row2').hide();
} }
}); });

View File

@ -243,6 +243,11 @@ $buttons['welcome_tips'] = [
'text' => '<a href="'.ui_get_full_url('index.php?sec=gsetup&sec2=godmode/setup/setup&section=welcome_tips').'">'.html_print_image('images/inventory.png', true, ['title' => __('Welcome tips'), 'class' => 'invert_filter']).'</a>', 'text' => '<a href="'.ui_get_full_url('index.php?sec=gsetup&sec2=godmode/setup/setup&section=welcome_tips').'">'.html_print_image('images/inventory.png', true, ['title' => __('Welcome tips'), 'class' => 'invert_filter']).'</a>',
]; ];
$buttons['demo_data'] = [
'active' => false,
'text' => '<a href="'.ui_get_full_url('index.php?sec=gsetup&sec2=godmode/setup/setup&section=demo_data').'">'.html_print_image('images/demo_data.png', true, ['title' => __('Demo data'), 'class' => 'invert_filter']).'</a>',
];
if ($config['activate_gis']) { if ($config['activate_gis']) {
$buttons['gis'] = [ $buttons['gis'] = [
'active' => false, 'active' => false,
@ -351,6 +356,12 @@ switch ($section) {
$help_header = ''; $help_header = '';
break; break;
case 'demo_data':
$buttons['demo_data']['active'] = true;
$subpage = __('Demo data');
$help_header = '';
break;
case 'enterprise': case 'enterprise':
$buttons['enterprise']['active'] = true; $buttons['enterprise']['active'] = true;
$subpage = __('Enterprise'); $subpage = __('Enterprise');
@ -466,6 +477,10 @@ switch ($section) {
include_once $config['homedir'].'/godmode/setup/welcome_tips.php'; include_once $config['homedir'].'/godmode/setup/welcome_tips.php';
break; break;
case 'demo_data':
include_once $config['homedir'].'/godmode/setup/demo.php';
break;
default: default:
enterprise_hook('setup_enterprise_select_tab', [$section]); enterprise_hook('setup_enterprise_select_tab', [$section]);
break; break;

Binary file not shown.

After

Width:  |  Height:  |  Size: 655 B

View File

@ -75,6 +75,10 @@ if ($action === 'create_demo_data') {
$enabled_directories = $directories; $enabled_directories = $directories;
} }
if (enterprise_installed() === false) {
unset($enabled_directories['services']);
}
foreach ($enabled_directories as $directory) { foreach ($enabled_directories as $directory) {
$directory_path = $demodata_directory.$directory; $directory_path = $demodata_directory.$directory;
if (is_dir($directory_path)) { if (is_dir($directory_path)) {
@ -89,6 +93,10 @@ if ($action === 'create_demo_data') {
} }
} }
if (enterprise_installed() === false) {
unset($parsed_ini['services']);
}
$total_agents_to_create = (int) get_parameter('agents_num', 0); $total_agents_to_create = (int) get_parameter('agents_num', 0);
$total_items_count = count($parsed_ini); $total_items_count = count($parsed_ini);
@ -152,7 +160,6 @@ if ($action === 'create_demo_data') {
// Total agents limit specified by user has been reached. // Total agents limit specified by user has been reached.
break; break;
} else { } else {
///hd($total_agents_to_create." - (".$agent_created_total." + ".$iter_agents_to_create." + ".$iter_agents_created.")", true);
// Calculate max number of agents that can be created in this iteration until max number specified by user is reached. // Calculate max number of agents that can be created in this iteration until max number specified by user is reached.
$max_agents_to_limit = ($total_agents_to_create - ($agent_created_total + $iter_agents_to_create/* + $iter_agents_created*/)); $max_agents_to_limit = ($total_agents_to_create - ($agent_created_total + $iter_agents_to_create/* + $iter_agents_created*/));
} }
@ -236,7 +243,9 @@ if ($action === 'create_demo_data') {
} }
$values = [ $values = [
'server_name' => $server_name 'server_name' => $server_name,
'id_os' => $id_os,
'os_version' => $os_version,
]; ];
$create_alias = $agent_data['agent_alias'].'-'.($agents_created_count[$agent_data['agent_name']] + 1); $create_alias = $agent_data['agent_alias'].'-'.($agents_created_count[$agent_data['agent_name']] + 1);
@ -247,9 +256,7 @@ if ($action === 'create_demo_data') {
$agent_interval, $agent_interval,
$next_ip_address, $next_ip_address,
$values, $values,
true, true
$id_os,
$os_version
); );
if ($created_agent_id > 0) { if ($created_agent_id > 0) {
@ -775,7 +782,7 @@ if ($action === 'create_demo_data') {
} }
} }
$services_count = count($parsed_ini['services']); $services_count = count($parsed_ini['services'] ?? []);
if ($services_count > 0) { if ($services_count > 0) {
// Create services. // Create services.
foreach ($parsed_ini['services'] as $ini_service_data) { foreach ($parsed_ini['services'] as $ini_service_data) {
@ -1021,7 +1028,7 @@ if ($action === 'create_demo_data') {
register_error(DEMO_SERVICE, __('No configuration files found or failed to parse files')); register_error(DEMO_SERVICE, __('No configuration files found or failed to parse files'));
} }
$nm_count = count($parsed_ini['network_maps']); $nm_count = count($parsed_ini['network_maps'] ?? []);
if ($nm_count > 0) { if ($nm_count > 0) {
// Create network maps. // Create network maps.
foreach ($parsed_ini['network_maps'] as $ini_nm_data) { foreach ($parsed_ini['network_maps'] as $ini_nm_data) {
@ -1203,7 +1210,7 @@ if ($action === 'create_demo_data') {
register_error(DEMO_NETWORK_MAP, __('No configuration files found or failed to parse files')); register_error(DEMO_NETWORK_MAP, __('No configuration files found or failed to parse files'));
} }
$cg_count = count($parsed_ini['graphs']); $cg_count = count($parsed_ini['graphs'] ?? []);
if ($cg_count > 0) { if ($cg_count > 0) {
// Create graphs. // Create graphs.
foreach ($parsed_ini['graphs'] as $ini_graph_data) { foreach ($parsed_ini['graphs'] as $ini_graph_data) {
@ -1375,7 +1382,7 @@ if ($action === 'create_demo_data') {
register_error(DEMO_CUSTOM_GRAPH, __('No configuration files found or failed to parse files')); register_error(DEMO_CUSTOM_GRAPH, __('No configuration files found or failed to parse files'));
} }
$rep_count = count($parsed_ini['reports']); $rep_count = count($parsed_ini['reports'] ?? []);
if ($rep_count > 0) { if ($rep_count > 0) {
// Create reports. // Create reports.
foreach ($parsed_ini['reports'] as $ini_report_data) { foreach ($parsed_ini['reports'] as $ini_report_data) {
@ -1570,7 +1577,7 @@ if ($action === 'create_demo_data') {
register_error(DEMO_REPORT, __('No configuration files found or failed to parse files')); register_error(DEMO_REPORT, __('No configuration files found or failed to parse files'));
} }
$vc_count = count($parsed_ini['visual_consoles']); $vc_count = count($parsed_ini['visual_consoles'] ?? []);
if ($vc_count > 0) { if ($vc_count > 0) {
// Create visual consoles. // Create visual consoles.
foreach ($parsed_ini['visual_consoles'] as $ini_data) { foreach ($parsed_ini['visual_consoles'] as $ini_data) {
@ -1899,7 +1906,7 @@ if ($action === 'create_demo_data') {
register_error(DEMO_VISUAL_CONSOLE, __('No configuration files found or failed to parse files')); register_error(DEMO_VISUAL_CONSOLE, __('No configuration files found or failed to parse files'));
} }
$dashboards_count = count($parsed_ini['dashboards']); $dashboards_count = count($parsed_ini['dashboards'] ?? []);
if ($dashboards_count > 0) { if ($dashboards_count > 0) {
// Create dashboards. // Create dashboards.
foreach ($parsed_ini['dashboards'] as $ini_data) { foreach ($parsed_ini['dashboards'] as $ini_data) {

View File

@ -218,9 +218,7 @@ function agents_create_agent(
$interval, $interval,
$ip_address, $ip_address,
$values=false, $values=false,
$alias_as_name=false, $alias_as_name=false
$os=false,
$os_version=false
) { ) {
global $config; global $config;