diff --git a/pandora_console/extras/mr/32.sql b/pandora_console/extras/mr/32.sql index 18e31dfb38..2e50885f21 100644 --- a/pandora_console/extras/mr/32.sql +++ b/pandora_console/extras/mr/32.sql @@ -15,9 +15,30 @@ UPDATE `tlayout_data` SET `height` = 70 , `width` = 70 WHERE `height` = 0 && `wi (`type` = 10 && `image` IS NOT NULL && `image` != '' && `image` != 'none') || (`type` = 11 && `image` IS NOT NULL && `image` != '' && `image` != 'none' && `show_statistics` = 0)); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('integria_enabled', 0); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('integria_user', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('integria_pass', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('integria_hostname', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('integria_api_pass', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('integria_req_timeout', 5); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('default_group', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('default_criticity', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('default_creator', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('default_owner', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('incident_type', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('incident_status', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('incident_title', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('incident_content', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('cr_default_group', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('cr_default_criticity', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('cr_default_creator', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('cr_default_owner', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('cr_incident_type', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('cr_incident_status', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('cr_incident_title', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('cr_incident_content', ''); ALTER TABLE `treport_content` ADD COLUMN `uncompressed_module` TINYINT DEFAULT '0'; ALTER TABLE `treport_content_template` ADD COLUMN `uncompressed_module` TINYINT DEFAULT '0'; - COMMIT; diff --git a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql index a449004ce8..cac39dc56d 100644 --- a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql @@ -1256,10 +1256,30 @@ DELETE FROM `tconfig` WHERE `token` = 'current_package_enterprise'; INSERT INTO `tconfig` (`token`, `value`) VALUES ('current_package_enterprise', '737'); INSERT INTO `tconfig` (`token`, `value`) VALUES ('status_monitor_fields', 'policy,agent,data_type,module_name,server_type,interval,status,graph,warn,data,timestamp'); UPDATE `tconfig` SET `value` = 'mini_severity,evento,id_agente,estado,timestamp' WHERE `token` LIKE 'event_fields'; -DELETE FROM `tconfig` WHERE `token` LIKE 'integria_enabled'; DELETE FROM `tconfig` WHERE `token` LIKE 'integria_api_password'; DELETE FROM `tconfig` WHERE `token` LIKE 'integria_inventory'; DELETE FROM `tconfig` WHERE `token` LIKE 'integria_url'; +INSERT INTO `tconfig` (`token`, `value`) VALUES ('integria_user', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('integria_pass', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('integria_hostname', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('integria_api_pass', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('integria_req_timeout', 5); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('default_group', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('default_criticity', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('default_creator', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('default_owner', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('incident_type', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('incident_status', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('incident_title', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('incident_content', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('cr_default_group', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('cr_default_criticity', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('cr_default_creator', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('cr_default_owner', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('cr_incident_type', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('cr_incident_status', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('cr_incident_title', ''); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('cr_incident_content', ''); -- --------------------------------------------------------------------- -- Table `tconfig_os` diff --git a/pandora_console/godmode/menu.php b/pandora_console/godmode/menu.php index 000a105257..e57ee47409 100644 --- a/pandora_console/godmode/menu.php +++ b/pandora_console/godmode/menu.php @@ -295,6 +295,9 @@ if (check_acl($config['id_user'], 0, 'PM')) { $sub2['godmode/setup/setup&section=ehorus']['text'] = __('eHorus'); $sub2['godmode/setup/setup&section=ehorus']['refr'] = 0; + $sub2['godmode/setup/setup&section=integria']['text'] = __('Integria IMS'); + $sub2['godmode/setup/setup&section=integria']['refr'] = 0; + $sub2['godmode/setup/setup&section=notifications']['text'] = __('Notifications'); $sub2['godmode/setup/setup&section=notifications']['refr'] = 0; diff --git a/pandora_console/godmode/setup/setup.php b/pandora_console/godmode/setup/setup.php index c32f128ddd..a46d7bc832 100644 --- a/pandora_console/godmode/setup/setup.php +++ b/pandora_console/godmode/setup/setup.php @@ -117,6 +117,11 @@ if (check_acl($config['id_user'], 0, 'AW')) { } } +$buttons['integria'] = [ + 'active' => false, + 'text' => ''.html_print_image('images/integria.png', true, ['title' => __('Integria IMS')]).'', +]; + $buttons['ehorus'] = [ 'active' => false, 'text' => ''.html_print_image('images/ehorus/ehorus.png', true, ['title' => __('eHorus')]).'', @@ -167,6 +172,12 @@ switch ($section) { $help_header = 'setup_ehorus_tab'; break; + case 'integria': + $buttons['integria']['active'] = true; + $subpage = ' » '.__('Integria IMS'); + $help_header = 'setup_integria_tab'; + break; + case 'notifications': $buttons['notifications']['active'] = true; $subpage = ' » '.__('Notifications'); @@ -228,6 +239,10 @@ switch ($section) { include_once $config['homedir'].'/godmode/setup/setup_ehorus.php'; break; + case 'integria': + include_once $config['homedir'].'/godmode/setup/setup_integria.php'; + break; + case 'notifications': include_once $config['homedir'].'/godmode/setup/setup_notifications.php'; break; diff --git a/pandora_console/godmode/setup/setup_integria.php b/pandora_console/godmode/setup/setup_integria.php new file mode 100644 index 0000000000..95179f6add --- /dev/null +++ b/pandora_console/godmode/setup/setup_integria.php @@ -0,0 +1,702 @@ + 1]); + } else { + echo json_encode(['login' => 0]); + } + + return; +} + +$has_connection = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'get_login', []); + +if ($has_connection === false && $config['integria_enabled']) { + ui_print_error_message(__('Integria IMS API is not reachable')); +} + +if (get_parameter('update_config', 0) == 1) { + // Try to retrieve event response 'Create incident in IntegriaIMS from event' to check if it exists. + $event_response_exists = db_get_row_filter('tevent_response', ['name' => io_safe_input('Create ticket in IntegriaIMS from event')]); + + // Try to retrieve command 'Integia IMS Ticket' to check if it exists. + $command_exists = db_get_row_filter('talert_commands', ['name' => io_safe_input('Integria IMS Ticket')]); + + if ($config['integria_enabled'] == 1) { + if ($event_response_exists === false) { + // Create 'Create incident in IntegriaIMS from event' event response only when user enables IntegriaIMS integration and it does not exist in database. + db_process_sql_insert( + 'tevent_response', + [ + 'name' => io_safe_input('Create ticket in IntegriaIMS from event'), + 'description' => io_safe_input('Create a ticket in Integria IMS from an event'), + 'target' => io_safe_input('index.php?sec=incident&sec2=operation/incidents/configure_integriaims_incident&from_event=_event_id_'), + 'type' => 'url', + 'id_group' => '0', + 'modal_width' => '0', + 'modal_height' => '0', + 'new_window' => '1', + 'params' => '', + 'server_to_exec' => '0', + ] + ); + } + + if ($command_exists === false) { + // Create 'Integria IMS Ticket' command only when user enables IntegriaIMS integration and it does not exist in database. + $id_command_inserted = db_process_sql_insert( + 'talert_commands', + [ + 'name' => io_safe_input('Integria IMS Ticket'), + 'command' => io_safe_input('Internal type'), + 'internal' => 1, + 'description' => io_safe_input('Create a ticket in Integria IMS'), + 'fields_descriptions' => '["'.io_safe_input('Ticket title').'","'.io_safe_input('Ticket group ID').'","'.io_safe_input('Ticket priority').'","'.io_safe_input('Ticket owner').'","'.io_safe_input('Ticket type').'","'.io_safe_input('Ticket status').'","'.io_safe_input('Ticket description').'"]', + ] + ); + + // Create 'Create Integria IMS Ticket' action only when user enables IntegriaIMS integration and command exists in database. + $action_values = [ + 'field1' => io_safe_input($config['incident_title']), + 'field1_recovery' => io_safe_input($config['incident_title']), + 'field2' => io_safe_input($config['default_group']), + 'field2_recovery' => io_safe_input($config['default_group']), + 'field3' => io_safe_input($config['default_criticity']), + 'field3_recovery' => io_safe_input($config['default_criticity']), + 'field4' => io_safe_input($config['default_owner']), + 'field4_recovery' => io_safe_input($config['default_owner']), + 'field5' => io_safe_input($config['incident_type']), + 'field5_recovery' => io_safe_input($config['incident_type']), + 'field6' => io_safe_input($config['incident_status']), + 'field6_recovery' => io_safe_input($config['incident_status']), + 'field7' => io_safe_input($config['incident_content']), + 'field7_recovery' => io_safe_input($config['incident_content']), + 'id_group' => 0, + 'action_threshold' => 0, + ]; + + alerts_create_alert_action(io_safe_input('Create Integria IMS ticket'), $id_command_inserted, $action_values); + } else { + // Update 'Create Integria IMS Ticket' action when setup data is updated, user enables IntegriaIMS integration and command does exist in database. + db_process_sql_update( + 'talert_actions', + [ + 'field1' => io_safe_input($config['incident_title']), + 'field1_recovery' => io_safe_input($config['incident_title']), + 'field2' => io_safe_input($config['default_group']), + 'field2_recovery' => io_safe_input($config['default_group']), + 'field3' => io_safe_input($config['default_criticity']), + 'field3_recovery' => io_safe_input($config['default_criticity']), + 'field4' => io_safe_input($config['default_owner']), + 'field4_recovery' => io_safe_input($config['default_owner']), + 'field5' => io_safe_input($config['incident_type']), + 'field5_recovery' => io_safe_input($config['incident_type']), + 'field6' => io_safe_input($config['incident_status']), + 'field6_recovery' => io_safe_input($config['incident_status']), + 'field7' => io_safe_input($config['incident_content']), + 'field7_recovery' => io_safe_input($config['incident_content']), + ], + ['name' => io_safe_input('Create Integria IMS ticket')] + ); + } + } else { + if ($event_response_exists != false) { + // Delete 'Create incident in IntegriaIMS from event' event response if it does exist and IntegriaIMS integration is disabled. + db_process_sql_delete('tevent_response', ['name' => io_safe_input('Create ticket in IntegriaIMS from event')]); + } + + if ($command_exists != false) { + // Delete 'Integria IMS Ticket' command if it does exist and IntegriaIMS integration is disabled. + db_process_sql_delete('talert_commands', ['name' => io_safe_input('Integria IMS Ticket')]); + + // Delete 'Create Integria IMS Ticket' action if command exists and IntegriaIMS integration is disabled. + db_process_sql_delete('talert_actions', ['name' => io_safe_input('Create Integria IMS ticket')]); + } + } +} + +// Get parameters from Integria IMS API. +$integria_group_values = []; +$integria_criticity_values = []; +$integria_users_values = []; +$integria_types_values = []; +$integria_status_values = []; + +$integria_groups_csv = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'get_groups', []); + +get_array_from_csv_data_pair($integria_groups_csv, $integria_group_values); + +$integria_status_csv = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'get_incidents_status', []); + +get_array_from_csv_data_pair($integria_status_csv, $integria_status_values); + +$integria_criticity_levels_csv = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'get_incident_priorities', []); + +get_array_from_csv_data_pair($integria_criticity_levels_csv, $integria_criticity_values); + +$integria_users_csv = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'get_users', []); + +$csv_array = explode("\n", $integria_users_csv); + +foreach ($csv_array as $csv_line) { + if (!empty($csv_line)) { + $integria_users_values[$csv_line] = $csv_line; + } +} + +$integria_types_csv = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'get_types', []); + +get_array_from_csv_data_pair($integria_types_csv, $integria_types_values); + +// Enable table. +$table_enable = new StdClass(); +$table_enable->data = []; +$table_enable->width = '100%'; +$table_enable->id = 'integria-enable-setup'; +$table_enable->class = 'databox filters'; +$table_enable->size['name'] = '30%'; +$table_enable->style['name'] = 'font-weight: bold'; + +// Enable Integria. +$row = []; +$row['name'] = __('Enable Integria IMS'); +$row['control'] = html_print_checkbox_switch('integria_enabled', 1, $config['integria_enabled'], true); +$table_enable->data['integria_enabled'] = $row; + +// Remote config table. +$table_remote = new StdClass(); +$table_remote->data = []; +$table_remote->width = '100%'; +$table_remote->styleTable = 'margin-bottom: 10px;'; +$table_remote->id = 'integria-remote-setup'; +$table_remote->class = 'databox filters'; +$table_remote->size['name'] = '30%'; +$table_remote->style['name'] = 'font-weight: bold'; + +// Integria user. +$row = []; +$row['name'] = __('User'); +$row['control'] = html_print_input_text('integria_user', $config['integria_user'], '', 30, 100, true); +$table_remote->data['integria_user'] = $row; + +// Integria password. +$row = []; +$row['name'] = __('Password'); +$row['control'] = html_print_input_password('integria_pass', io_output_password($config['integria_pass']), '', 30, 100, true); +$table_remote->data['integria_pass'] = $row; + +// Integria hostname. +$row = []; +$row['name'] = __('API Hostname'); +$row['control'] = html_print_input_text('integria_hostname', $config['integria_hostname'], '', 30, 100, true); +$row['control'] .= ui_print_help_tip(__('Hostname of Integria IMS\' API (scheme must be specified. Example: http://192.168.0.0)'), true); +$table_remote->data['integria_hostname'] = $row; + +// API password. +$row = []; +$row['name'] = __('API Password'); +$row['control'] = html_print_input_password('integria_api_pass', io_output_password($config['integria_api_pass']), '', 30, 100, true); +$row['control'] .= ui_print_help_tip(__('Password of Integria IMS\' API'), true); +$table_remote->data['integria_api_pass'] = $row; + +// Request timeout. +$row = []; +$row['name'] = __('Request timeout'); +$row['control'] = html_print_input_text('integria_req_timeout', $config['integria_req_timeout'], '', 3, 10, true); +$row['control'] .= ui_print_help_tip(__('Time in seconds to set the maximum time of the requests to the Integria API').'. '.__('0 to disable'), true); +$table_remote->data['integria_req_timeout'] = $row; + +// Alert settings. +$table_alert_settings = new StdClass(); +$table_alert_settings->data = []; +$table_alert_settings->width = '100%'; +$table_alert_settings->styleTable = 'margin-bottom: 10px;'; +$table_alert_settings->id = 'integria-cr-settings-setup'; +$table_alert_settings->class = 'databox filters'; +$table_alert_settings->size['name'] = '30%'; +$table_alert_settings->style['name'] = 'font-weight: bold'; + +// Alert incident title. +$row = []; +$row['name'] = __('Title'); +$row['control'] = html_print_input_text( + 'incident_title', + $config['incident_title'], + __('Name'), + 50, + 100, + true, + false, + false +).ui_print_help_icon('alert_macros', true); +$table_alert_settings->data['custom_response_incident_title'] = $row; + +// Alert incident description. +$row = []; +$row['name'] = __('Description'); +$row['control'] = html_print_input_text( + 'incident_content', + $config['incident_content'], + '', + 50, + 100, + true, + false, + false +).ui_print_help_icon('alert_macros', true); +$table_alert_settings->data['custom_response_incident_content'] = $row; + +// Alert default group. +$row = []; +$row['name'] = __('Group'); +$row['control'] = html_print_select( + $integria_group_values, + 'default_group', + $config['default_group'], + '', + __('Select'), + 0, + true, + false, + true, + '', + false +); +$table_alert_settings->data['custom_response_def_group'] = $row; + +// Alert default criticity. +$row = []; +$row['name'] = __('Priority'); +$row['control'] = html_print_select( + $integria_criticity_values, + 'default_criticity', + $config['default_criticity'], + '', + __('Select'), + 0, + true, + false, + true, + '', + false +); +$table_alert_settings->data['custom_response_def_criticity'] = $row; + +// Alert default owner. +$row = []; +$row['name'] = __('Owner'); +$row['control'] = html_print_autocomplete_users_from_integria( + 'default_owner', + $config['default_owner'], + true +); + +$table_alert_settings->data['custom_response_def_owner'] = $row; + +// Alert default incident type. +$row = []; +$row['name'] = __('Type'); +$row['control'] = html_print_select( + $integria_types_values, + 'incident_type', + $config['incident_type'], + '', + __('Select'), + 0, + true, + false, + true, + '', + false +); +$table_alert_settings->data['custom_response_incident_type'] = $row; + +// Alert default incident status. +$row = []; +$row['name'] = __('Status'); +$row['control'] = html_print_select( + $integria_status_values, + 'incident_status', + $config['incident_status'], + '', + __('Select'), + 0, + true, + false, + true, + '', + false +); +$table_alert_settings->data['custom_response_incident_status'] = $row; + +// Custom response settings. +$table_cr_settings = new StdClass(); +$table_cr_settings->data = []; +$table_cr_settings->width = '100%'; +$table_cr_settings->styleTable = 'margin-bottom: 10px;'; +$table_cr_settings->id = 'integria-cr-settings-setup'; +$table_cr_settings->class = 'databox filters'; +$table_cr_settings->size['name'] = '30%'; +$table_cr_settings->style['name'] = 'font-weight: bold'; + +// Custom response incident title. +$row = []; +$row['name'] = __('Title'); +$row['control'] = html_print_input_text( + 'cr_incident_title', + $config['cr_incident_title'], + __('Name'), + 50, + 100, + true, + false, + false +).ui_print_help_icon('response_macros', true); +$table_cr_settings->data['custom_response_incident_title'] = $row; + +// Custom response incident description. +$row = []; +$row['name'] = __('Description'); +$row['control'] = html_print_input_text( + 'cr_incident_content', + $config['cr_incident_content'], + '', + 50, + 100, + true, + false, + false +).ui_print_help_icon('response_macros', true); +$table_cr_settings->data['custom_response_incident_content'] = $row; + +// Custom response default group. +$row = []; +$row['name'] = __('Group'); +$row['control'] = html_print_select( + $integria_group_values, + 'cr_default_group', + $config['cr_default_group'], + '', + __('Select'), + 0, + true, + false, + true, + '', + false +); +$table_cr_settings->data['custom_response_def_group'] = $row; + +// Custom response default criticity. +$row = []; +$row['name'] = __('Priority'); +$row['control'] = html_print_select( + $integria_criticity_values, + 'cr_default_criticity', + $config['cr_default_criticity'], + '', + __('Select'), + 0, + true, + false, + true, + '', + false +); +$table_cr_settings->data['custom_response_def_criticity'] = $row; + +// Custom response default owner. +$row = []; +$row['name'] = __('Owner'); +$row['control'] = html_print_autocomplete_users_from_integria( + 'cr_default_owner', + $config['cr_default_owner'], + true +); + +$table_cr_settings->data['custom_response_def_owner'] = $row; + +// Custom response default incident type. +$row = []; +$row['name'] = __('Type'); +$row['control'] = html_print_select( + $integria_types_values, + 'cr_incident_type', + $config['cr_incident_type'], + '', + __('Select'), + 0, + true, + false, + true, + '', + false +); +$table_cr_settings->data['custom_response_incident_type'] = $row; + +// Custom response default incident status. +$row = []; +$row['name'] = __('Status'); +$row['control'] = html_print_select( + $integria_status_values, + 'cr_incident_status', + $config['cr_incident_status'], + '', + __('Select'), + 0, + true, + false, + true, + '', + false +); +$table_cr_settings->data['custom_response_incident_status'] = $row; + +// Test. +$row = []; +$row['name'] = __('Test'); +$row['control'] = html_print_button(__('Start'), 'test-integria', false, '', 'class="sub next"', true); +$row['control'] .= ''; +$row['control'] .= ''; +$row['control'] .= ''; +$row['control'] .= ' '; +$table_remote->data['integria_test'] = $row; + +// Print. +echo '
'; +echo ''; +html_print_image('images/integria_logo.png'); +echo ''; +echo '
'; +echo '
'; +echo __('Integria IMS'); +echo '
'; +echo ''; +echo 'https://integriaims.com'; +echo ''; +echo '
'; + +echo "
"; +html_print_input_hidden('update_config', 1); + +// Form enable. +echo '
'; +html_print_table($table_enable); +echo '
'; + +// Form remote. +echo '
'; +echo '
'; +echo ''.__('Integria API settings').''; + +html_print_table($table_remote); + +echo '
'; +echo '
'; + +if ($has_connection != false) { + // Form alert default settings. + echo '
'; + echo '
'; + echo ''.__('Alert default values').''; + + html_print_table($table_alert_settings); + + echo '
'; + echo '
'; + + // Form custom response default settings. + echo '
'; + echo '
'; + echo ''.__('Event custom response default values').''; + + html_print_table($table_cr_settings); + + echo '
'; + echo '
'; + + echo '
'; + html_print_submit_button(__('Update'), 'update_button', false, 'class="sub upd"'); + echo '
'; +} else { + echo '
'; + html_print_submit_button(__('Update and continue'), 'update_button', false, 'class="sub next"'); + echo '
'; +} + + +echo '
'; + +?> + + diff --git a/pandora_console/images/integria.png b/pandora_console/images/integria.png new file mode 100644 index 0000000000..9dcad27e3b Binary files /dev/null and b/pandora_console/images/integria.png differ diff --git a/pandora_console/images/integria_logo.png b/pandora_console/images/integria_logo.png new file mode 100644 index 0000000000..f56ecfdab5 Binary files /dev/null and b/pandora_console/images/integria_logo.png differ diff --git a/pandora_console/images/integria_logo_gray.png b/pandora_console/images/integria_logo_gray.png new file mode 100644 index 0000000000..d901e72493 Binary files /dev/null and b/pandora_console/images/integria_logo_gray.png differ diff --git a/pandora_console/include/ajax/integria_incidents.ajax.php b/pandora_console/include/ajax/integria_incidents.ajax.php new file mode 100644 index 0000000000..3991ecf51c --- /dev/null +++ b/pandora_console/include/ajax/integria_incidents.ajax.php @@ -0,0 +1,60 @@ + 0, it's a metaconsole query. + * + * @param integer $event_id Event identifier. + * @param integer $value String value in which we want to apply macros. + * + * @return string The response text with the macros applied. + */ +function events_get_field_value_by_event_id( + int $event_id, + $value +) { + global $config; + + $meta = false; + $event = db_get_row('tevento', 'id_evento', $event_id); + + // Replace each macro. + if (strpos($value, '_agent_address_') !== false) { + if ($meta) { + $agente_table_name = 'tmetaconsole_agent'; + $filter = [ + 'id_tagente' => $event['id_agente'], + 'id_tmetaconsole_setup' => $server_id, + ]; + } else { + $agente_table_name = 'tagente'; + $filter = ['id_agente' => $event['id_agente']]; + } + + $ip = db_get_value_filter('direccion', $agente_table_name, $filter); + // If agent does not have an IP, display N/A. + if ($ip === false) { + $ip = __('N/A'); + } + + $value = str_replace('_agent_address_', $ip, $value); + } + + if (strpos($value, '_agent_id_') !== false) { + $value = str_replace('_agent_id_', $event['id_agente'], $value); + } + + if (strpos($value, '_module_address_') !== false) { + if ($event['id_agentmodule'] != 0) { + if ($meta) { + $server = metaconsole_get_connection_by_id($server_id); + metaconsole_connect($server); + } + + $module = db_get_row('tagente_modulo', 'id_agente_modulo', $event['id_agentmodule']); + if (empty($module['ip_target'])) { + $module['ip_target'] = __('N/A'); + } + + $value = str_replace('_module_address_', $module['ip_target'], $value); + if (empty($module['nombre'])) { + $module['nombre'] = __('N/A'); + } + + if ($meta) { + metaconsole_restore_db(); + } + } else { + $value = str_replace('_module_address_', __('N/A'), $value); + } + } + + if (strpos($value, '_module_name_') !== false) { + if ($event['id_agentmodule'] != 0) { + if ($meta) { + $server = metaconsole_get_connection_by_id($server_id); + metaconsole_connect($server); + } + + $module = db_get_row('tagente_modulo', 'id_agente_modulo', $event['id_agentmodule']); + if (empty($module['ip_target'])) { + $module['ip_target'] = __('N/A'); + } + + $value = str_replace( + '_module_name_', + io_safe_output($module['nombre']), + $value + ); + + if ($meta) { + metaconsole_restore_db(); + } + } else { + $value = str_replace('_module_name_', __('N/A'), $value); + } + } + + if (strpos($value, '_event_id_') !== false) { + $value = str_replace('_event_id_', $event['id_evento'], $value); + } + + if (strpos($value, '_user_id_') !== false) { + if (!empty($event['id_usuario'])) { + $value = str_replace('_user_id_', $event['id_usuario'], $value); + } else { + $value = str_replace('_user_id_', __('N/A'), $value); + } + } + + if (strpos($value, '_group_id_') !== false) { + $value = str_replace('_group_id_', $event['id_grupo'], $value); + } + + if (strpos($value, '_group_name_') !== false) { + $value = str_replace( + '_group_name_', + groups_get_name($event['id_grupo'], true), + $value + ); + } + + if (strpos($value, '_event_utimestamp_') !== false) { + $value = str_replace( + '_event_utimestamp_', + $event['utimestamp'], + $value + ); + } + + if (strpos($value, '_event_date_') !== false) { + $value = str_replace( + '_event_date_', + date($config['date_format'], $event['utimestamp']), + $value + ); + } + + if (strpos($value, '_event_text_') !== false) { + $value = str_replace( + '_event_text_', + events_display_name($event['evento']), + $value + ); + } + + if (strpos($value, '_event_type_') !== false) { + $value = str_replace( + '_event_type_', + events_print_type_description($event['event_type'], true), + $value + ); + } + + if (strpos($value, '_alert_id_') !== false) { + $value = str_replace( + '_alert_id_', + empty($event['is_alert_am']) ? __('N/A') : $event['is_alert_am'], + $value + ); + } + + if (strpos($value, '_event_severity_id_') !== false) { + $value = str_replace('_event_severity_id_', $event['criticity'], $value); + } + + if (strpos($value, '_event_severity_text_') !== false) { + $value = str_replace( + '_event_severity_text_', + get_priority_name($event['criticity']), + $value + ); + } + + if (strpos($value, '_module_id_') !== false) { + $value = str_replace('_module_id_', $event['id_agentmodule'], $value); + } + + if (strpos($value, '_event_tags_') !== false) { + $value = str_replace('_event_tags_', $event['tags'], $value); + } + + if (strpos($value, '_event_extra_id_') !== false) { + if (empty($event['id_extra'])) { + $value = str_replace('_event_extra_id_', __('N/A'), $value); + } else { + $value = str_replace('_event_extra_id_', $event['id_extra'], $value); + } + } + + if (strpos($value, '_event_source_') !== false) { + $value = str_replace('_event_source_', $event['source'], $value); + } + + if (strpos($value, '_event_instruction_') !== false) { + $value = str_replace( + '_event_instruction_', + events_display_instructions($event['event_type'], $event, false), + $value + ); + } + + if (strpos($value, '_owner_user_') !== false) { + if (empty($event['owner_user'])) { + $value = str_replace('_owner_user_', __('N/A'), $value); + } else { + $value = str_replace('_owner_user_', $event['owner_user'], $value); + } + } + + if (strpos($value, '_event_status_') !== false) { + $event_st = events_display_status($event['estado']); + $value = str_replace('_event_status_', $event_st['title'], $value); + } + + if (strpos($value, '_group_custom_id_') !== false) { + $group_custom_id = db_get_value_sql( + sprintf( + 'SELECT custom_id FROM tgrupo WHERE id_grupo=%s', + $event['id_grupo'] + ) + ); + $event_st = events_display_status($event['estado']); + $value = str_replace('_group_custom_id_', $group_custom_id, $value); + } + + // Parse the event custom data. + if (!empty($event['custom_data'])) { + $custom_data = json_decode(base64_decode($event['custom_data'])); + foreach ($custom_data as $key => $val) { + $value = str_replace('_customdata_'.$key.'_', $val, $value); + } + } + + // This will replace the macro with the current logged user. + if (strpos($value, '_current_user_') !== false) { + $value = str_replace('_current_user_', $config['id_user'], $value); + } + + return $value; + +} diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index 12d4aecc01..ab3aad9c7a 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -3383,3 +3383,116 @@ function html_print_input($data, $wrapper='div', $input_only=false) return $output; } + + +/** + * Print an autocomplete input filled out with Integria IMS users. + * + * @param string $name The name of ajax control, by default is "users". + * @param string $default The default value to show in the ajax control. + * @param boolean $return If it is true return a string with the output instead to echo the output. + * @param string $size Size. + * + * @return mixed If the $return is true, return the output as string. + */ +function html_print_autocomplete_users_from_integria( + $name='users', + $default='', + $return=false, + $size='30', + $disable=false, + $required=false +) { + global $config; + + ob_start(); + + $attrs = ['style' => 'background: url(images/user_green.png) no-repeat right;']; + + if ($required) { + $attrs['required'] = 'required'; + } + + html_print_input_text_extended( + $name, + $default, + 'text-'.$name, + '', + $size, + 100, + $disable, + '', + $attrs + ); + html_print_input_hidden($name.'_hidden', $id_agent_module); + + ui_print_help_tip(__('Type at least two characters to search the user.'), false); + + $javascript_ajax_page = ui_get_full_url('ajax.php', false, false, false, false); + ?> + + '.html_print_image('images/setup.png', true, ['title' => __('Configure Integria IMS')]).''; + $list_tab['text'] = ''.html_print_image('images/list.png', true, ['title' => __('Ticket list')]).''; + $create_tab['text'] = ''.html_print_image('images/pencil.png', true, ['title' => __('New ticket')]).''; + + switch ($active_tab) { + case 'setup_tab': + $setup_tab['active'] = true; + $list_tab['active'] = false; + $create_tab['active'] = false; + break; + + case 'list_tab': + $setup_tab['active'] = false; + $list_tab['active'] = true; + $create_tab['active'] = false; + break; + + case 'create_tab': + $setup_tab['active'] = false; + $list_tab['active'] = false; + $create_tab['active'] = true; + break; + + default: + $setup_tab['active'] = false; + $list_tab['active'] = false; + $create_tab['active'] = false; + break; + } + + if ($view) { + $create_tab['text'] = ''.html_print_image('images/pencil.png', true, ['title' => __('Edit ticket')]).''; + $view_tab['text'] = ''.html_print_image('images/operation.png', true, ['title' => __('View ticket')]).''; + // When the current page is the View page. + if (!$active_tab) { + $view_tab['active'] = true; + } + } + + $onheader = []; + + if (check_acl($config['id_user'], 0, 'IR') && $view) { + $onheader['view'] = $view_tab; + } + + if (check_acl($config['id_user'], 0, 'PM')) { + $onheader['configure'] = $setup_tab; + } + + if (check_acl($config['id_user'], 0, 'IR')) { + $onheader['list'] = $list_tab; + } + + if (check_acl($config['id_user'], 0, 'IW')) { + $onheader['create'] = $create_tab; + } + + return $onheader; +} + + +/** + * Gets all the details of Integria IMS API + * + * @param string $details Type of API call. + * @param number $detail_index Send index if you want return the text. + * + * @return string or array with result of API call. + */ +function integriaims_get_details($details, $detail_index=false) +{ + global $config; + + switch ($details) { + case 'status': + $operation = 'get_incidents_status'; + break; + + case 'group': + $operation = 'get_groups'; + break; + + case 'priority': + $operation = 'get_incident_priorities'; + break; + + case 'resolution': + $operation = 'get_incidents_resolutions'; + break; + + case 'type': + $operation = 'get_types'; + break; + + default: + // code... + break; + } + + $api_call = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], $operation); + $result = []; + get_array_from_csv_data_pair($api_call, $result); + + if ($detail_index !== false) { + if ($result[$detail_index] == '' || $result[$detail_index] === null) { + return __('None'); + } else { + return $result[$detail_index]; + } + } else { + return $result; + } +} + + +/** + * Perform an API call to Integria IMS. + * + * @param string API host URL. + * @param string User name. + * @param string User password. + * @param string API password. + * @param string API Operation. + * @param array Array with parameters required by the API function. + * + * @return boolean True if API request succeeded, false if API request failed. + */ +function integria_api_call($api_hostname, $user, $user_pass, $api_pass, $operation, $params_array=[], $show_credentials_error_msg=false) +{ + $params_string = implode(',', $params_array); + + $url_data = [ + 'user' => $user, + 'user_pass' => $user_pass, + 'pass' => $api_pass, + 'op' => $operation, + 'params' => html_entity_decode($params_string), + ]; + + // Build URL for API request. + $url = $api_hostname.'/integria/include/api.php'; + + // ob_start(); + // $out = fopen('php://output', 'w'); + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, $url_data); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_VERBOSE, true); + curl_setopt($ch, CURLOPT_STDERR, $out); + $result = curl_exec($ch); + + // fclose($out); + // $debug = ob_get_clean(); + $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE); + + $error = false; + + if ($result === false) { + $error = curl_error($ch); + } + + curl_close($ch); + + if ($error === true || $http_status !== 200) { + if ($show_credentials_error_msg === true) { + ui_print_error_message(__('API request failed. Please check Integria IMS\' access credentials in Pandora setup.')); + } + + return false; + } else { + return $result; + } +} + + +// Parse CSV consisting of one or more lines of the form key-value pair into an array. +function get_array_from_csv_data_pair($csv_data, &$array_values) +{ + $csv_array = explode("\n", $csv_data); + + foreach ($csv_array as $csv_value) { + if (empty($csv_value)) { + continue; + } + + $new_csv_value = str_getcsv($csv_value); + + $array_values[$new_csv_value[0]] = $new_csv_value[1]; + } +} + + +/** + * Parse CSV consisting of all lines into an array. + * + * @param string $csv_data Data returned of csv api call. + * @param string $array_values Returned array. + * @param array $index Array to create an associative index (opcional). + */ +function get_array_from_csv_data_all($csv_data, &$array_values, $index=false) +{ + $csv_array = explode("\n", $csv_data); + + foreach ($csv_array as $csv_value) { + if (empty($csv_value)) { + continue; + } + + $new_csv_value = str_getcsv($csv_value); + + if ($index !== false) { + foreach ($new_csv_value as $key => $value) { + $new_csv_value_index[$index[$key]] = str_replace(':::', ',', $value); + ; + } + + $array_values[$new_csv_value[0]] = $new_csv_value_index; + } else { + $new_csv_value_comma = array_map( + function ($item) { + return str_replace(':::', ',', $item); + }, + $new_csv_value + ); + $array_values[$new_csv_value[0]] = $new_csv_value_comma; + } + } +} + + +/** + * Print priority for Integria IMS with colors. + * + * @param string $priority value of priority in Integria IMS. + * @param string $priority_label text shown in color box. + * + * @return HTML code to print the color box. + */ +function ui_print_integria_incident_priority($priority, $priority_label) +{ + global $config; + + $output = ''; + switch ($priority) { + case 0: + $color = COL_UNKNOWN; + break; + + case 1: + $color = COL_NORMAL; + break; + + case 10: + $color = COL_NOTINIT; + break; + + case 2: + $color = COL_WARNING; + break; + + case 3: + $color = COL_ALERTFIRED; + break; + + case 4: + $color = COL_CRITICAL; + break; + } + + $output = '
'; + $output .= $priority_label; + $output .= '
'; + + return $output; +} + + +/** + * Get tickets from Integria IMS. + * + * @param array $tickets_filters Filters to send to API. + * + * @return array Tickets returned by API call. + */ +function get_tickets_integriaims($tickets_filters) +{ + global $config; + + // Filters. + $incident_text = $tickets_filters['incident_text']; + $incident_status = $tickets_filters['incident_status']; + $incident_group = $tickets_filters['incident_group']; + $incident_owner = $tickets_filters['incident_owner']; + $incident_creator = $tickets_filters['incident_creator']; + $incident_priority = $tickets_filters['incident_priority']; + $incident_resolution = $tickets_filters['incident_resolution']; + $created_from = $tickets_filters['created_from']; + $created_to = $tickets_filters['created_to']; + + // API call. + $result_api_call_list = integria_api_call( + $config['integria_hostname'], + $config['integria_user'], + $config['integria_pass'], + $config['integria_api_pass'], + 'get_incidents', + [ + $incident_text, + $incident_status, + $incident_group, + $incident_priority, + '0', + $incident_owner, + $incident_creator, + ] + ); + + // Return array of api call 'get_incidents'. + $array_get_incidents = []; + get_array_from_csv_data_all($result_api_call_list, $array_get_incidents); + + // Modify $array_get_incidents if filter for resolution exists. + $filter_resolution = []; + foreach ($array_get_incidents as $key => $value) { + if ($incident_resolution !== '' && ($array_get_incidents[$key][12] == $incident_resolution)) { + $filter_resolution[$key] = $array_get_incidents[$key]; + continue; + } + } + + if ($incident_resolution !== '') { + $array_get_incidents = $filter_resolution; + } + + // Modify $array_get_incidents if filter for date is selected. + if ($created_from !== '' && $created_to !== '') { + $date = []; + $date_utimestamp = []; + foreach ($array_get_incidents as $key => $value) { + // Change format date / to -. + $date[$key] = date('Y-m-d', strtotime($array_get_incidents[$key][9])); + // Covert date to utimestamp. + $date_utimestamp[$key] = strtotime($date[$key]); + } + + // Change format date / to -. + $created_from_date = date('Y-m-d', strtotime($created_from)); + $created_to_date = date('Y-m-d', strtotime($created_to)); + + // Covert date to utimestamp. + $created_from_timestamp = strtotime($created_from_date); + $created_to_timestamp = strtotime($created_to_date); + + // Dates within the selected period. + $selected_period = array_filter( + $date_utimestamp, + function ($value) use ($created_from_timestamp, $created_to_timestamp) { + return ($value >= $created_from_timestamp && $value <= $created_to_timestamp); + } + ); + + // Return incidents with the correct dates. + $filter_date = []; + foreach ($array_get_incidents as $key => $value) { + foreach ($selected_period as $index => $value) { + if ($array_get_incidents[$key][0] == $index) { + $filter_date[$key] = $array_get_incidents[$key]; + continue; + } + } + } + + $array_get_incidents = $filter_date; + } + + return $array_get_incidents; +} diff --git a/pandora_console/include/styles/integriaims.css b/pandora_console/include/styles/integriaims.css new file mode 100644 index 0000000000..0c8440e739 --- /dev/null +++ b/pandora_console/include/styles/integriaims.css @@ -0,0 +1,125 @@ +/* --- Integria IMS --- */ +div.priority { + width: 80px; + color: #fff; + text-align: center; + border-radius: 5px; + padding: 5px; + display: table-cell; + vertical-align: middle; +} + +/* Details view */ +div.integria_details { + display: grid; + grid-column-gap: 10px; + grid-template-columns: repeat(3, minmax(min-content, auto)); + grid-auto-rows: 1fr; +} + +div.integria_details div.box-shadow.white_table_graph { + box-shadow: none; +} + +div.integria_details div.priority { + display: inline-block; +} + +div.integriaims_details_row { + display: grid; + grid-gap: 10px; + text-align: center; + margin-top: 8px; + margin-bottom: 8px; +} + +div.integriaims_details_titles { + font-weight: bold; +} + +div.integria_details_row_five { + grid-template-columns: repeat(5, 1fr); +} + +div.integria_details_row_three { + grid-template-columns: repeat(3, 1fr); +} + +div.integria_details_description { + width: 100%; +} + +div.integria_details_description textarea { + width: 100%; + background-color: #fbfbfb; + resize: vertical; +} + +.integriaims_details_box { + display: grid; + grid-column-gap: 10px; + grid-row-gap: 5px; + align-items: center; + width: 100%; + text-align: center; +} + +.integriaims_details_box_five { + grid-template-rows: repeat(3, 1fr); + grid-template-columns: repeat(5, 1fr); +} + +.integriaims_details_box_three { + grid-template-rows: repeat(3, 1fr); + grid-template-columns: repeat(3, 1fr); +} + +/* ui_toggles */ +.integria_details_shadow { + background-color: #fff; + border-bottom: 1px solid #e2e2e2; + border-left: 1px solid #e2e2e2; + border-top-left-radius: 5px; + border-right: 1px solid #e2e2e2; + border-top-right-radius: 5px; +} + +.integria_details_shadow .white_table_graph_header { + border-left: none; + border-right: none; +} + +.integria_details_content { + border-bottom: none; + border-left: none; + border-right: none; +} + +/* Inputs type text shown as a black line */ +.integria_incidents_options input[type="text"] { + background-color: transparent; + border: none; + border-radius: 0; + border-bottom: 1px solid #ccc; + font-family: "lato-bolder", "Open Sans", sans-serif; + font-size: 10pt; + padding: 2px 5px; + box-sizing: border-box; + background-repeat: no-repeat; + background-position: left bottom 2px; + margin-bottom: 4px; +} + +.integria_incident_options input[readonly] { + color: #848484; +} + +.comment_title { + padding: 5px 10px 5px 20px; + background-color: rgba(130, 185, 46, 0.16); + border-radius: 3px; +} + +.comment_body { + padding: 15px 20px 15px 20px; +} diff --git a/pandora_console/operation/incidents/configure_integriaims_incident.php b/pandora_console/operation/incidents/configure_integriaims_incident.php new file mode 100644 index 0000000000..8cf70d7848 --- /dev/null +++ b/pandora_console/operation/incidents/configure_integriaims_incident.php @@ -0,0 +1,325 @@ +width = '100%'; +$table->id = 'add_alert_table'; +$table->class = 'databox filters integria_incidents_options'; +$table->head = []; + +$table->data = []; +$table->size = []; +$table->size = []; +$table->style[0] = 'width: 33%; padding-right: 50px; padding-left: 100px;'; +$table->style[1] = 'width: 33%; padding-right: 50px; padding-left: 50px;'; +$table->style[2] = 'width: 33%; padding-right: 100px; padding-left: 50px;'; +$table->colspan[0][0] = 2; +$table->colspan[3][0] = 3; + +$help_macros = isset($_GET['from_event']) ? ui_print_help_icon('response_macros', true) : ''; + +if (isset($_GET['from_event'])) { + if ($update) { + $input_value_title = $incident_details[3]; + $input_value_type = $incident_details[17]; + $input_value_status = $incident_details[6]; + $input_value_group = $incident_details[8]; + $input_value_criticity = $incident_details[7]; + $input_value_owner = $incident_details[5]; + $input_value_content = $incident_details[4]; + } else if (isset($_GET['from_event'])) { + $input_value_title = $config['cr_incident_title']; + $input_value_type = $config['cr_incident_type']; + $input_value_status = $config['cr_incident_status']; + $input_value_group = $config['cr_default_group']; + $input_value_criticity = $config['cr_default_criticity']; + $input_value_owner = $config['cr_default_owner']; + $input_value_content = $config['cr_incident_content']; + } else { + $input_value_title = ''; + $input_value_type = ''; + $input_value_status = ''; + $input_value_group = ''; + $input_value_criticity = ''; + $input_value_owner = ''; + $input_value_content = ''; + } +} + +$table->data[0][0] = '

'.__('Title').': '.$help_macros.'

'; +$table->data[0][0] .= '
'.html_print_input_text( + 'incident_title', + $input_value_title, + __('Name'), + 50, + 100, + true, + false, + true, + '', + 'w100p' +).'
'; + +$table->data[0][2] = html_print_image('images/integria_logo_gray.png', true, ['style' => 'width: 70%; float: right;'], false); + +$table->data[1][0] = '

'.__('Type').':

'; +$table->data[1][0] .= '
'.html_print_select( + $integria_types_values, + 'type', + $input_value_type, + '', + __('Select'), + 0, + true, + false, + true, + '', + false, + 'width: 100%;' +).'
'; + +$table->data[2][0] = '

'.__('Status').':

'; +$table->data[2][0] .= '
'.html_print_select( + $integria_status_values, + 'status', + $input_value_status, + '', + __('Select'), + 1, + true, + false, + true, + '', + false, + 'width: 100%;' +).'
'; + +$table->data[1][1] = '

'.__('Group').':

'; +$table->data[1][1] .= '
'.html_print_select( + $integria_group_values, + 'group', + $input_value_group, + '', + '', + 0, + true, + false, + true, + '', + false, + 'width: 100%;' +).'
'; + +$table->data[2][1] = '

'.__('Creator').':

'; +$table->data[2][1] .= '
'.html_print_input_text( + 'creator', + $config['integria_user'], + '', + '30', + 100, + true, + true, + false, + '', + 'w100p' +).ui_print_help_tip(__('This field corresponds to the Integria IMS user specified in Integria IMS setup'), true).'
'; + +$table->data[1][2] = '

'.__('Priority').':

'; +$table->data[1][2] .= '
'.html_print_select( + $integria_criticity_values, + 'criticity', + $input_value_criticity, + '', + __('Select'), + 0, + true, + false, + true, + '', + false, + 'width: 100%;' +).'
'; + +$table->data[2][2] = '

'.__('Owner').':

'; + +$table->data[2][2] .= '
'.html_print_autocomplete_users_from_integria( + 'owner', + $input_value_owner, + true +).'
'; + +$table->data[3][0] = '

'.__('Description').': '.$help_macros.'

'; +$table->data[3][0] .= '
'.html_print_textarea( + 'incident_content', + 3, + 20, + $input_value_content, + '', + true +).'
'; + +// Print forms and stuff. +echo '
'; +html_print_table($table); + +if (!$update) { + html_print_input_hidden('create_incident', 1); +} else { + html_print_input_hidden('update_incident', 1); +} + +echo '
'; + +echo '
'; +if ($update) { + html_print_submit_button(__('Update'), 'accion', false, 'form="create_integria_incident_form" class="sub wand"'); +} else { + html_print_submit_button(__('Create'), 'accion', false, 'form="create_integria_incident_form" class="sub wand"'); +} + +echo '
'; diff --git a/pandora_console/operation/incidents/dashboard_detail_integriaims_incident.php b/pandora_console/operation/incidents/dashboard_detail_integriaims_incident.php new file mode 100644 index 0000000000..aab95b4cd7 --- /dev/null +++ b/pandora_console/operation/incidents/dashboard_detail_integriaims_incident.php @@ -0,0 +1,488 @@ +width = '100%'; +$table_files_section->id = 'files_section_table'; +$table_files_section->class = 'databox filters'; +$table_files_section->head = []; + +$table_files_section->data = []; +$table_files_section->size = []; +$table_files_section->colspan[2][0] = 3; + +// Files list table. +$table_files = new stdClass(); +$table_files->width = '100%'; +$table_files->class = 'info_table'; +$table_files->head = []; + +$table_files->head[0] = __('Filename'); +$table_files->head[1] = __('Timestamp'); +$table_files->head[2] = __('Description'); +$table_files->head[3] = __('User'); +$table_files->head[4] = __('Size'); + +if (check_acl($config['id_user'], 0, 'IW')) { + $table_files->head[5] = __('Delete'); +} + +$table_files->data = []; + +// Upload file. +if ($upload_file && ($_FILES['userfile']['name'] != '')) { + $filedescription = get_parameter('file_description', __('No description available')); + + $filename = io_safe_input($_FILES['userfile']['name']); + $filesize = io_safe_input($_FILES['userfile']['size']); + + $extension = pathinfo($filename, PATHINFO_EXTENSION); + $invalid_extensions = '/^(bat|exe|cmd|sh|php|php1|php2|php3|php4|php5|pl|cgi|386|dll|com|torrent|js|app|jar|iso| + pif|vb|vbscript|wsf|asp|cer|csr|jsp|drv|sys|ade|adp|bas|chm|cpl|crt|csh|fxp|hlp|hta|inf|ins|isp|jse|htaccess| + htpasswd|ksh|lnk|mdb|mde|mdt|mdw|msc|msi|msp|mst|ops|pcd|prg|reg|scr|sct|shb|shs|url|vbe|vbs|wsc|wsf|wsh)$/i'; + + if (!preg_match($invalid_extensions, $extension)) { + // The following is if you have clamavlib installed. + // (php5-clamavlib) and enabled in php.ini + // http://www.howtoforge.com/scan_viruses_with_php_clamavlib + if (extension_loaded('clamav')) { + cl_setlimits(5, 1000, 200, 0, 10485760); + $malware = cl_scanfile($_FILES['file']['tmp_name']); + if ($malware) { + $error = 'Malware detected: '.$malware.'
ClamAV version: '.clam_get_version(); + die($error); + // On malware, we die because it's not good to handle it + } + } + + $filecontent = base64_encode(file_get_contents($_FILES['userfile']['tmp_name'])); + + $result_api_call = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'attach_file', [$incident_id, $filename, $filesize, $filedescription, $filecontent]); + + // API method returns '0' string if success. + $file_added = ($result_api_call === '0') ? true : false; + + ui_print_result_message( + $file_added, + __('File successfully added'), + __('File could not be added') + ); + } else { + ui_print_error_message(__('File has an invalid extension')); + } +} + +// Delete file. +if (isset($_GET['delete_file'])) { + $result_api_call = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'delete_file', [$delete_file_id]); + + $file_deleted = false; + + if ($result_api_call === '0') { + $file_deleted = true; + } + + ui_print_result_message( + $file_deleted, + __('File successfully deleted'), + __('File could not be deleted') + ); +} + +// Download file. +if (isset($_GET['download_file'])) { + $file_base64 = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'download_file', [$download_file_id]); + ob_end_clean(); + + $decoded = base64_decode($file_base64); + + file_put_contents($download_file_name, $decoded); + ob_end_clean(); + + if (file_exists($download_file_name)) { + header('Content-Description: File Transfer'); + header('Content-Type: application/octet-stream'); + header('Content-Disposition: attachment; filename="'.basename($download_file_name).'"'); + header('Expires: 0'); + header('Cache-Control: must-revalidate'); + header('Pragma: public'); + header('Content-Length: '.filesize($download_file_name)); + ob_end_clean(); + readfile($download_file_name); + unlink($download_file_name); + exit; + } + + header('Location: index.php?sec=incident&sec2=operation/incidents/dashboard_detail_integriaims_incident&incident_id='.$incident_id); +} + +// Retrieve files belonging to incident and create list table. +$result_api_call = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'get_incident_files', [$incident_id]); + +if ($result_api_call != false && strlen($result_api_call) > 0) { + $files = []; + $csv_array = explode("\n", $result_api_call); + + foreach ($csv_array as $csv_line) { + if (!empty($csv_line)) { + $files[] = explode(',', $csv_line); + } + } +} + +$i = 0; + +foreach ($files as $key => $value) { + $table_files->data[$i][0] = ''.$value[11].''; + $table_files->data[$i][1] = $value[14]; + $table_files->data[$i][2] = $value[12]; + $table_files->data[$i][3] = $value[8]; + $table_files->data[$i][4] = $value[13]; + if (check_acl($config['id_user'], 0, 'IW')) { + $table_files->data[$i][5] .= ''; + $table_files->data[$i][5] .= html_print_image('images/cross.png', true, ['title' => __('Delete')]); + } + + $table_files->data[$i][5] .= ''; + + $i++; +} + +$table_files_section->data[0][0] = '

'.__('File name').':

'; +$table_files_section->data[0][0] .= html_print_input_file('userfile', true); +$table_files_section->data[1][0] = '

'.__('Description').':

'; +$table_files_section->data[1][0] .= html_print_textarea( + 'file_description', + 3, + 20, + '', + '', + true +); + +$table_files_section->data[2][0] .= '
'.html_print_submit_button(__('Upload'), 'accion', false, 'class="sub wand"', true).'
'; + +$upload_file_form = '
'; + +if (check_acl($config['id_user'], 0, 'IW')) { + $upload_file_form .= '
'.'

'.__('Add attachment').'

'.html_print_table($table_files_section, true).html_print_input_hidden('upload_file', 1, true); +} + +$upload_file_form .= '

'.__('Attached files').'

'.html_print_table($table_files, true).'
'; + +// Incident comments management. +$upload_comment = get_parameter('upload_comment'); +$comment_description = get_parameter('comment_description'); + +// Comments section table. +$table_comments_section = new stdClass(); +$table_comments_section->width = '100%'; +$table_comments_section->id = 'files_section_table'; +$table_comments_section->class = 'databox filters'; +$table_comments_section->head = []; + +$table_comments_section->data = []; +$table_comments_section->size = []; + +// Comments list table. +$table_comments = new stdClass(); +$table_comments->width = '100%'; +$table_comments->class = 'info_table'; +$table_comments->head = []; + +$table_comments->head[0] = __('Filename'); +$table_comments->head[1] = __('Timestamp'); +$table_comments->head[2] = __('Description'); +$table_comments->head[3] = __('User'); +$table_comments->head[4] = __('Size'); +$table_comments->head[5] = __('Delete'); + +$table_comments->data = []; + +$comment_disabled = ($array_get_incidents[6] == 7); + +if ($comment_disabled === true) { + $attribute = 'disabled=disabled'; +} + +$table_comments_section->data[0][0] = '

'.__('Description').':

'; +$table_comments_section->data[0][0] .= html_print_textarea( + 'comment_description', + 3, + 20, + '', + $attribute, + true +); + +$table_comments_section->data[1][1] .= '
'.html_print_submit_button(__('Add'), 'accion', $comment_disabled, 'class="sub wand"', true).'
'; + +// Upload comment. If ticket is closed, this action cannot be performed. +if ($upload_comment && $array_get_incidents[6] != 7) { + $result_api_call = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'create_workunit', [$incident_id, $comment_description, '0.00', 0, 1, '0']); + + // API method returns id of new comment if success. + $comment_added = ($result_api_call >= '0') ? true : false; + + ui_print_result_message( + $comment_added, + __('Comment successfully added'), + __('Comment could not be added') + ); +} + +// Retrieve comments belonging to incident and create comments table. +$result_api_call = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'get_incident_workunits', [$incident_id]); + +if ($result_api_call != false && strlen($result_api_call) > 0) { + $comments = []; + $csv_array = explode("\n", $result_api_call); + + foreach ($csv_array as $csv_line) { + if (!empty($csv_line)) { + $comments[] = explode(',', $csv_line); + } + } +} + +$comment_table = ''; + +if (!empty($comments)) { + foreach ($comments as $key => $value) { + $comment_table .= '
'.$value[3].' said '.$value[1].''.$value[2].' Hours
'; + $comment_table .= '
'.$value[4].'
'; + } +} else { + $comment_table = __('No comments found'); +} + +$upload_comment_form = '
'; + +if (check_acl($config['id_user'], 0, 'IW')) { + $upload_comment_form .= '

'.__('Add comment').'

'.html_print_table($table_comments_section, true).html_print_input_hidden('upload_comment', 1, true).'
'; +} + +$upload_comment_form .= '

'.__('Comments').'

'.$comment_table.'
'; + +// Details box. +$details_box = '
'; +$details_box .= ' +
'.__('Status').'
+
'.__('Resolution').'
+
'.__('Group').'
+
'.__('Priority').'
+
'.__('Type').'
'; +$details_box .= ' +
'.html_print_image('images/heart.png', true).'
+
'.html_print_image('images/builder.png', true).'
+
'.html_print_image('images/user_green.png', true).'
+
'.ui_print_integria_incident_priority($priority, $priority_text).'
+
'.html_print_image('images/incidents.png', true).'
'; +$details_box .= ' +
'.$status_text.'
+
'.$resolution_text.'
+
'.$group_text.'
+
'.$priority_text.'
+
'.$type_text.'
'; +$details_box .= '
'; + + +// People box. +$people_box = '
'; +$people_box .= ' +
'.html_print_image('images/header_user_green.png', true, ['width' => '21']).'
+
'.html_print_image('images/header_user_green.png', true, ['width' => '21']).'
+
'.html_print_image('images/header_user_green.png', true, ['width' => '21']).'
'; +$people_box .= ' +
'.__('Created by').':
+
'.__('Owned by').':
+
'.__('Closed by').':
'; +$people_box .= ' +
'.$creator.'
+
'.$owner.'
+
'.$closed_by.'
'; +$people_box .= '
'; + + +// Dates box. +$dates_box = '
'; +$dates_box .= ' +
'.html_print_image('images/tick.png', true).'
+
'.html_print_image('images/update.png', true, ['width' => '21']).'
+
'.html_print_image('images/mul.png', true).'
'; +$dates_box .= ' +
'.__('Created at').':
+
'.__('Updated at').':
+
'.__('Closed at').':
'; +$dates_box .= ' +
'.$created_at.'
+
'.$updated_at.'
+
'.$closed_at.'
'; +$dates_box .= '
'; + + +// Show details, people and dates. +echo '
'; + ui_toggle($details_box, __('Details'), '', 'details_box', false, false, '', 'integria_details_content white-box-content', 'integria_details_shadow box-shadow white_table_graph'); + ui_toggle($people_box, __('People'), '', 'people_box', false, false, '', 'integria_details_content white-box-content', 'integria_details_shadow box-shadow white_table_graph'); + ui_toggle($dates_box, __('Dates'), '', 'dates_box', false, false, '', 'integria_details_content white-box-content', 'integria_details_shadow box-shadow white_table_graph'); +echo '
'; + + // Show description. +$description_box = '
'.html_print_textarea( + 'integria_details_description', + 3, + 0, + $description, + 'disabled="disabled"', + true +).'
'; +ui_toggle($description_box, __('Description'), '', '', false); + +echo '
'; +ui_toggle( + $upload_file_form, + __('Attached files'), + '', + '', + true, + false, + 'white_box white_box_opened', + 'no-border flex' +); +echo '
'; + +echo '
'; +ui_toggle( + $upload_comment_form, + __('Comments'), + '', + '', + true, + false, + 'white_box white_box_opened', + 'no-border flex' +); +echo '
'; + +?> + \ No newline at end of file diff --git a/pandora_console/operation/incidents/integriaims_export_csv.php b/pandora_console/operation/incidents/integriaims_export_csv.php new file mode 100644 index 0000000000..03a038e58a --- /dev/null +++ b/pandora_console/operation/incidents/integriaims_export_csv.php @@ -0,0 +1,129 @@ + $value) { + // Status. + if ($tickets_csv_array[$key][6] == 0) { + $tickets_csv_array[$key][6] = 'None'; + } else { + $tickets_csv_array[$key][6] = $status_incident[$tickets_csv_array[$key][6]]; + } + + // Priority. + $tickets_csv_array[$key][7] = $priority_incident[$tickets_csv_array[$key][7]]; + + // Group. + $tickets_csv_array[$key][8] = $group_incident[$tickets_csv_array[$key][8]]; + + // Resolution. + if ($tickets_csv_array[$key][12] == 0) { + $tickets_csv_array[$key][12] = 'None'; + } else { + $tickets_csv_array[$key][12] = $resolution_incident[$tickets_csv_array[$key][12]]; + } + + $tickets_csv_array_filter[$key] = [ + 'id_incidencia' => $tickets_csv_array[$key][0], + 'titulo' => $tickets_csv_array[$key][3], + 'id_grupo' => $tickets_csv_array[$key][8], + 'estado' => $tickets_csv_array[$key][6], + 'resolution' => $tickets_csv_array[$key][12], + 'prioridad' => $tickets_csv_array[$key][7], + 'actualizacion' => $tickets_csv_array[$key][9], + 'inicio' => $tickets_csv_array[$key][1], + 'id_creator' => $tickets_csv_array[$key][10], + 'owner' => $tickets_csv_array[$key][5], + ]; +} + +// Header for CSV file. +$header = [ + __('ID Ticket'), + __('Title'), + __('Group/Company'), + __('Status'), + __('Resolution'), + __('Priority'), + __('Updated'), + __('Started'), + __('Creator'), + __('Owner'), +]; + +$header_csv = ''; +foreach ($header as $key => $value) { + $header_csv .= $value.','; +} + +$header_csv = io_safe_output($header_csv).PHP_EOL; + + +// Join header and content. +$tickets_csv = ''; +foreach ($tickets_csv_array_filter as $key => $value) { + $tickets_csv .= implode(',', $tickets_csv_array_filter[$key]).PHP_EOL; +} + +$tickets_csv = $header_csv.$tickets_csv; + + +// Create csv file. +$filename = 'tickets_export-'.date('Ymd').'-'.date('His').'.csv'; + +ob_clean(); + +header('Content-Type: text/csv; charset=utf-8'); +header('Content-Disposition: attachment; filename='.$filename); + +// BOM. +echo pack('C*', 0xEF, 0xBB, 0xBF); + +// CSV file. +echo io_safe_output($tickets_csv); diff --git a/pandora_console/operation/incidents/list_integriaims_incidents.php b/pandora_console/operation/incidents/list_integriaims_incidents.php new file mode 100644 index 0000000000..d97276c15e --- /dev/null +++ b/pandora_console/operation/incidents/list_integriaims_incidents.php @@ -0,0 +1,335 @@ +width = '100%'; +$table->class = 'databox filters'; +$table->styleTable = 'margin-bottom:0px'; +$table->cellpadding = '0'; +$table->cellspacing = '0'; +$table->data = []; + +$table->data[0][0] = __('Text filter'); +$table->data[0][1] = html_print_input_text('incident_text', $incident_text, '', 30, 100, true); + +$table->data[0][2] = __('Status'); +$table->data[0][3] = html_print_select( + $status_incident, + 'incident_status', + $incident_status, + '', + __('All'), + 0, + true +); + +$table->data[0][4] = __('Group'); +$table->data[0][5] = html_print_select( + $group_incident, + 'incident_group', + $incident_group, + '', + __('All'), + 1, + true +); + +$table->data[1][0] = __('Owner'); +$table->data[1][1] = html_print_autocomplete_users_from_integria('incident_owner', $incident_owner, true); + +$table->data[1][2] = __('Creator'); +$table->data[1][3] = html_print_autocomplete_users_from_integria('incident_creator', $incident_creator, true); + +$table->data[1][4] = __('Priority'); +$table->data[1][5] = html_print_select( + $priority_incident, + 'incident_priority', + $incident_priority, + '', + __('All'), + -1, + true +); + +$table->data[2][0] = __('Resolution'); +$table->data[2][1] = html_print_select( + $resolution_incident, + 'incident_resolution', + $incident_resolution, + '', + __('All'), + '', + true +); + +// TODO: field type date. +$table->data[2][2] = __('Date'); +$table->data[2][3] = html_print_input_text_extended( + 'created_from', + $created_from, + 'created_from', + '', + 12, + 50, + false, + '', + 'placeholder="'.__('Created from').'"', + true +); +$table->data[2][3] .= html_print_input_text_extended( + 'created_to', + $created_to, + 'created_to', + '', + 12, + 50, + false, + '', + 'style="margin-left:5px;" placeholder="'.__('Created to').'"', + true +); + +// TODO: image of Integria IMS. +$table->data[2][4] = ''; +$table->data[2][5] = ''; + + +// Send filters to get_tickets_integriaims(). +$tickets_filters = [ + 'incident_text' => $incident_text, + 'incident_status' => $incident_status, + 'incident_group' => $incident_group, + 'incident_owner' => $incident_owner, + 'incident_creator' => $incident_creator, + 'incident_priority' => $incident_priority, + 'incident_resolution' => $incident_resolution, + 'created_from' => $created_from, + 'created_to' => $created_to, +]; + +// Data to export to csv file. +$decode_csv = base64_encode(json_encode($tickets_filters)); + + +// ---- PRINT TABLE FILTERS ---- +$integria_incidents_form = '
'; +$integria_incidents_form .= html_print_table($table, true); +$integria_incidents_form .= '
'; +$integria_incidents_form .= '
'.html_print_button( + __('Export to CSV'), + 'csv_export', + false, + "location.href='operation/incidents/integriaims_export_csv.php?tickets_filters=$decode_csv'", + 'class="sub next"', + true +).'
'; +$integria_incidents_form .= '
'.html_print_submit_button(__('Filter'), 'filter_button', false, 'class="sub filter"', true).'
'; +$integria_incidents_form .= '
'; +$integria_incidents_form .= '
'; + +ui_toggle($integria_incidents_form, __('Filter'), '', '', false); + +/* + * Order api call 'get_incidents'. + * + * resolution = $array_get_incidents[$key][12] + * id_incidencia = $array_get_incidents[$key][0] + * titulo = $array_get_incidents[$key][3] + * id_grupo = $array_get_incidents[$key][8] + * estado = $array_get_incidents[$key][6] + * prioridad = $array_get_incidents[$key][7] + * actualizacion = $array_get_incidents[$key][9] + * id_creator = $array_get_incidents[$key][10] + * + */ + +// ---- LIST OF INCIDENTS ---- +// Get list of incidents. +$array_get_incidents = get_tickets_integriaims($tickets_filters); + +// Prepare pagination. +$incidents_limit = $config['block_size']; +$incidents_paginated = array_slice($array_get_incidents, $offset, $incidents_limit, true); + +// TABLE INCIDENTS. +$table = new stdClass(); +$table->width = '100%'; +$table->class = 'info_table'; +$table->head = []; + +$table->head[0] = __('ID'); +$table->head[1] = __('Ticket'); +$table->head[2] = __('Group/Company'); +$table->head[3] = __('Status/Resolution'); +$table->head[4] = __('Prior'); +$table->head[5] = __('Updated/Started'); +$table->head[6] = __('Creator'); +$table->head[7] = __('Owner'); +if (check_acl($config['id_user'], 0, 'IW') || check_acl($config['id_user'], 0, 'IM')) { + $table->head[8] = ''; +} + +$table->data = []; +$i = 0; + +foreach ($incidents_paginated as $key => $value) { + if ($array_get_incidents[$key][6] == 0) { + $status_incident[$array_get_incidents[$key][6]] = __('None'); + } + + if ($array_get_incidents[$key][12] == 0) { + $resolution_incident[$array_get_incidents[$key][12]] = __('None'); + } + + $table->data[$i][0] = '#'.$array_get_incidents[$key][0]; + $table->data[$i][1] = ''; + $table->data[$i][1] .= $array_get_incidents[$key][3]; + $table->data[$i][1] .= ''; + $table->data[$i][2] = $group_incident[$array_get_incidents[$key][8]]; + $table->data[$i][3] = $status_incident[$array_get_incidents[$key][6]].' / '.$resolution_incident[$array_get_incidents[$key][12]]; + $table->data[$i][4] = ui_print_integria_incident_priority($array_get_incidents[$key][7], $priority_incident[$array_get_incidents[$key][7]]); + $table->data[$i][5] = $array_get_incidents[$key][9].' / '.$array_get_incidents[$key][1]; + $table->data[$i][6] = $array_get_incidents[$key][10]; + $table->data[$i][7] = $array_get_incidents[$key][5]; + $table->data[$i][8] = ''; + $table->cellclass[$i][8] = 'action_buttons'; + if (check_acl($config['id_user'], 0, 'IW')) { + $table->data[$i][8] .= ''; + $table->data[$i][8] .= html_print_image('images/config.png', true, ['title' => __('Edit')]); + $table->data[$i][8] .= ''; + } + + if (check_acl($config['id_user'], 0, 'IM')) { + $table->data[$i][8] .= ''; + $table->data[$i][8] .= html_print_image('images/cross.png', true, ['title' => __('Delete')]); + $table->data[$i][8] .= ''; + } + + $i++; +} + +// Show table incidents. +ui_pagination(count($array_get_incidents), $url, $offset); +if (empty($table->data) === true) { + ui_print_info_message(['no_close' => true, 'message' => __('No tickets to show').'.' ]); +} else { + html_print_table($table); + ui_pagination(count($array_get_incidents), $url, $offset, 0, false, 'offset', true, 'pagination-bottom'); +} + +// Show button to create incident. +if (check_acl($config['id_user'], 0, 'IR')) { + echo '
'; + echo '
'; + html_print_submit_button(__('Create'), 'create_new_incident', false, 'class="sub next"'); + echo '
'; + echo '
'; +} + +// Datapicker library for show calendar. +ui_require_jquery_file('ui.datepicker-'.get_user_language(), 'include/javascript/i18n/'); +?> + + + \ No newline at end of file diff --git a/pandora_console/operation/menu.php b/pandora_console/operation/menu.php index 936cb6a814..58213ed8ee 100644 --- a/pandora_console/operation/menu.php +++ b/pandora_console/operation/menu.php @@ -479,6 +479,7 @@ if (check_acl($config['id_user'], 0, 'IR') $sub2 = []; $sub2['operation/incidents/incident']['text'] = __('List of Incidents'); $sub2[$sec2sub]['text'] = __('Statistics'); + $sub2['operation/incidents/list_integriaims_incidents']['text'] = __('Integria IMS Tickets'); $sub[$sec2]['sub2'] = $sub2; $sec2 = $temp_sec2; diff --git a/pandora_console/pandoradb_data.sql b/pandora_console/pandoradb_data.sql index 01f069b8b6..3f05bd7bf1 100644 --- a/pandora_console/pandoradb_data.sql +++ b/pandora_console/pandoradb_data.sql @@ -116,7 +116,29 @@ INSERT INTO `tconfig` (`token`, `value`) VALUES ('post_process_custom_values', '{"0.00000038580247":"Seconds to months","0.00000165343915":"Seconds to weeks","0.00001157407407":"Seconds to days","0.01666666666667":"Seconds to minutes","0.00000000093132":"Bytes to Gigabytes","0.00000095367432":"Bytes to Megabytes","0.0009765625":"Bytes to Kilobytes","0.00000001653439":"Timeticks to weeks","0.00000011574074":"Timeticks to days"}'), ('custom_docs_logo', 'default_docs.png'), ('custom_support_logo', 'default_support.png'), -('custom_logo_white_bg_preview', 'pandora_logo_head_white_bg.png'); +('custom_logo_white_bg_preview', 'pandora_logo_head_white_bg.png'), +('integria_enabled', 0), +('integria_user', ''), +('integria_pass', ''), +('integria_hostname', ''), +('integria_api_pass', ''), +('integria_req_timeout', 5), +('default_group', ''), +('default_criticity', ''), +('default_creator', ''), +('default_owner', ''), +('incident_type', ''), +('incident_status', ''), +('incident_title', ''), +('incident_content', ''), +('cr_default_group', ''), +('cr_default_criticity', ''), +('cr_default_creator', ''), +('cr_default_owner', ''), +('cr_incident_type', ''), +('cr_incident_status', ''), +('cr_incident_title', ''), +('cr_incident_content', ''); UNLOCK TABLES; -- diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 667cd7c909..644b983a5c 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -1137,7 +1137,9 @@ sub pandora_execute_action ($$$$$$$$$;$) { load_module_macros ($module->{'module_macros'}, \%macros); } - # User defined alerts + + #logger($pa_config, "Clean name ".$clean_name, 10); + # User defined alert if ($action->{'internal'} == 0) { $macros{_field1_} = subst_alert_macros ($field1, \%macros, $pa_config, $dbh, $agent, $module); $macros{_field2_} = subst_alert_macros ($field2, \%macros, $pa_config, $dbh, $agent, $module); @@ -1442,55 +1444,70 @@ sub pandora_execute_action ($$$$$$$$$;$) { # Integria IMS Ticket } elsif ($clean_name eq "Integria IMS Ticket") { + my $config_api_path = pandora_get_tconfig_token ($dbh, 'integria_hostname', ''); + my $config_api_pass = pandora_get_tconfig_token ($dbh, 'integria_api_pass', ''); + my $config_integria_user = pandora_get_tconfig_token ($dbh, 'integria_user', ''); + my $config_integria_user_pass = pandora_get_tconfig_token ($dbh, 'integria_pass', ''); $field1 = subst_alert_macros ($field1, \%macros, $pa_config, $dbh, $agent, $module); + $field2 = subst_alert_macros ($field2, \%macros, $pa_config, $dbh, $agent, $module); $field3 = subst_alert_macros ($field3, \%macros, $pa_config, $dbh, $agent, $module); + $field4 = subst_alert_macros ($field4, \%macros, $pa_config, $dbh, $agent, $module); $field5 = subst_alert_macros ($field5, \%macros, $pa_config, $dbh, $agent, $module); + $field6 = subst_alert_macros ($field6, \%macros, $pa_config, $dbh, $agent, $module); $field7 = subst_alert_macros ($field7, \%macros, $pa_config, $dbh, $agent, $module); - $field8 = subst_alert_macros ($field8, \%macros, $pa_config, $dbh, $agent, $module); - $field9 = subst_alert_macros ($field9, \%macros, $pa_config, $dbh, $agent, $module); - $field10 = subst_alert_macros ($field10, \%macros, $pa_config, $dbh, $agent, $module); - + # Field 1 (Integria IMS API path) - my $api_path = $field1; + my $api_path = $config_api_path . "/integria/include/api.php"; # Field 2 (Integria IMS API pass) - my $api_pass = $field2; + my $api_pass = $config_api_pass; # Field 3 (Integria IMS user) - my $integria_user = $field3; + my $integria_user = $config_integria_user; # Field 4 (Integria IMS user password) - my $integria_user_pass = $field4; + my $integria_user_pass = $config_integria_user_pass; - # Field 5 (Ticket name) - my $ticket_name = $field5; + # Field 1 (Ticket name) + my $ticket_name = safe_output($field1); if ($ticket_name eq "") { $ticket_name = $pa_config->{'rb_product_name'} . " alert action created by API"; } - # Field 6 (Ticket group ID) - my $ticket_group_id = $field6; + # Field 2 (Ticket group ID) + my $ticket_group_id = $field2; if ($ticket_group_id eq '') { $ticket_group_id = 0; } - # Field 7 (Ticket priority); - my $ticket_priority = $field7; - if ($ticket_priority eq '') { - $ticket_priority = 0; + # Field 3 (Ticket priority); + my $ticket_priority = $field3; + if ($ticket_priority eq '0') { + $ticket_priority = 1; + } + + # Field 4 (Ticket owner) + my $ticket_owner = $field4; + if ($ticket_owner eq '') { + $ticket_owner = 'admin'; } - # Field 8 (Ticket email) - my $ticket_email = $field8; - - # Field 9 (Ticket owner) - my $ticket_owner = $field9; - - # Field 10 (Ticket description); - my $ticket_description = $field10; + # Field 5 (Ticket type) + my $ticket_type = $field5; + if ($ticket_type eq '') { + $ticket_type = 0; + } - pandora_create_integria_ticket($pa_config, $api_path, $api_pass, $integria_user, $integria_user_pass, $ticket_name, $ticket_group_id, $ticket_priority, $ticket_email, $ticket_owner, $ticket_description); + # Field 6 (Ticket status) + my $ticket_status = $field6; + if ($ticket_status eq '0') { + $ticket_status = 1; + } + # Field 7 (Ticket description); + my $ticket_description = safe_output($field7); + + pandora_create_integria_ticket($pa_config, $api_path, $api_pass, $integria_user, $integria_user_pass, $ticket_name, $ticket_group_id, $ticket_priority, $ticket_owner, $ticket_type, $ticket_status, $ticket_description); # Generate notification } elsif ($clean_name eq "Generate Notification") { @@ -5849,55 +5866,21 @@ sub pandora_edit_custom_graph ($$$$$$$$$$$) { } sub pandora_create_integria_ticket ($$$$$$$$$$$) { - my ($pa_config,$api_path,$api_pass,$integria_user,$user_pass,$ticket_name,$group_id,$ticket_priority,$ticket_email,$ticket_owner,$ticket_description) = @_; - + my ($pa_config,$api_path,$api_pass,$integria_user,$user_pass,$ticket_name,$ticket_group_id,$ticket_priority,$ticket_owner,$ticket_type,$ticket_status,$ticket_description) = @_; + my $data_ticket; my $call_api; - if ($api_path eq "") { - return 0; - } - if ($user_pass eq "") { - return 0; - } - if ($integria_user eq "") { - $integria_user = "admin"; - } - if ($ticket_name eq "") { - $ticket_name = "Ticket created by " . $pa_config->{'rb_product_name'}; - } - if ($group_id eq "") { - $group_id = 1; - } - if ($ticket_priority eq "") { - $ticket_priority = 1; - } - if ($ticket_owner eq "") { - $ticket_owner = "admin"; - } - - #~ $data_ticket = $ticket_name . - #~ "|;|" . $group_id . - #~ "|;|" . $ticket_priority . - #~ "|;|" . $ticket_description . - #~ "|;|" . #Id inventory - #~ "|;|" . #Id incident type - #~ "|;|" . $ticket_email . - #~ "|;|" . $ticket_owner . - #~ "|;|" . #Father ticket id - #~ "|;|" . #Status - #~ "|;|" . #Extra info - #~ "|;|"; #Resolution $data_ticket = $ticket_name . - "|;|" . $group_id . + "|;|" . $ticket_group_id . "|;|" . $ticket_priority . "|;|" . $ticket_description . "|;|" . - "|;|" . - "|;|" . $ticket_email . + "|;|" . $ticket_type . + "|;|" . "|;|" . $ticket_owner . "|;|" . - "|;|" . '1' . + "|;|" . $ticket_status . "|;|" . "|;|"; @@ -5908,9 +5891,9 @@ sub pandora_create_integria_ticket ($$$$$$$$$$$) { 'op=create_incident&' . 'params=' . $data_ticket .'&' . 'token=|;|'; - logger($pa_config, "Integria ticket call:" . $call_api . "", 3); + my $content = get($call_api); - logger($pa_config, "Integria ticket res:" . $content . "", 3); + if (is_numeric($content) && $content ne "-1") { return $content; } diff --git a/pandora_server/util/integria_rticket.pl b/pandora_server/util/integria_rticket.pl index 609dd516b0..f296fd9145 100644 --- a/pandora_server/util/integria_rticket.pl +++ b/pandora_server/util/integria_rticket.pl @@ -38,6 +38,7 @@ Where options: Optional parameters: [-priority ] : 10 Maintance, 0 Informative, 1 Low, 2 Medium, 3 Serious, 4 Very serious + [-owner ] : Free text [-desc ] : Free text [-type ] : Type ID (must exist in Integria IMS) [-inventory ] : Inventory ID (must exist in Integria IMS) @@ -94,6 +95,7 @@ sub tool_api_main () { my $ticket_name = ""; my $group_id = -1; my $ticket_priority = 0; + my $ticket_owner = ''; my $ticket_description = ''; my $ticket_type = ''; my $ticket_inventory = ''; @@ -155,6 +157,9 @@ sub tool_api_main () { if ($line eq '-priority') { $ticket_priority = $ARGV[$i + 1]; } + if ($line eq '-owner') { + $ticket_owner = $ARGV[$i + 1]; + } if ($line eq '-desc') { $ticket_description = $ARGV[$i + 1]; } @@ -193,6 +198,7 @@ sub tool_api_main () { $data_ticket = $ticket_name . "|;|" . $group_id . "|;|" . $ticket_priority . + "|;|" . $ticket_owner . "|;|" . $ticket_description . "|;|" . $ticket_inventory . "|;|" . $ticket_type .