Increased number of possible custom fields for Integria action

This commit is contained in:
alejandro.campos@artica.es 2021-03-10 10:28:27 +01:00
parent 901d12fec0
commit 5913313bae
5 changed files with 60 additions and 45 deletions

View File

@ -388,32 +388,23 @@ $(document).ready (function () {
function ajax_get_integria_custom_fields(ticket_type_id, values, recovery_values) {
var values = values || [];
var recovery_values = recovery_values || [];
var max_macro_fields = <?php echo $config['max_macro_fields']; ?>;
if (ticket_type_id === null || ticket_type_id === '' || (Array.isArray(values) && values.length === 0 && Array.isArray(recovery_values) && recovery_values.length === 0)) {
$('[name=field8_value\\[\\]').val('');
$('[name=field9_value\\[\\]').val('');
$('[name=field10_value\\[\\]').val('');
$('[name=field8_recovery_value\\[\\]').val('');
$('[name=field9_recovery_value\\[\\]').val('');
$('[name=field10_recovery_value\\[\\]').val('');
for (var i=8; i <= max_macro_fields; i++) {
$('[name=field'+i+'_value\\[\\]').val('');
$('[name=field'+i+'_recovery_value\\[\\]').val('');
}
}
// On ticket type change, hide all table rows and inputs corresponding to custom fields, regardless of what its type is.
$('[name=field8_value\\[\\]').hide();
$('[name=field9_value\\[\\]').hide();
$('[name=field10_value\\[\\]').hide();
$('[name=field8_recovery_value\\[\\]').hide();
$('[name=field9_recovery_value\\[\\]').hide();
$('[name=field10_recovery_value\\[\\]').hide();
$('#table_macros-field8').hide();
$('#table_macros-field9').hide();
$('#table_macros-field10').hide();
$('[name=field8_value_container').hide();
$('[name=field9_value_container').hide();
$('[name=field10_value_container').hide();
$('[name=field8_recovery_value_container').hide();
$('[name=field9_recovery_value_container').hide();
$('[name=field10_recovery_value_container').hide();
for (var i=8; i <= max_macro_fields; i++) {
$('[name=field'+i+'_value\\[\\]').hide();
$('[name=field'+i+'_recovery_value\\[\\]').hide();
$('#table_macros-field'+i).hide();
$('[name=field'+i+'_value_container').hide();
$('[name=field'+i+'_recovery_value_container').hide();
}
jQuery.post(
"ajax.php",
@ -689,23 +680,16 @@ $(document).ready (function () {
// Ad-hoc solution for Integria IMS command: get Integia IMS Ticket custom fields only when this command is selected and we selected a ticket type to retrieve fields from.
// Check command by name since it is unvariable in any case, unlike its ID.
if ($("#id_command option:selected").text() === "Integria IMS Ticket") {
var max_macro_fields = <?php echo $config['max_macro_fields']; ?>;
// At start hide all rows and inputs corresponding to custom fields, regardless of what its type is.
$('[name=field8_value\\[\\]').hide();
$('[name=field9_value\\[\\]').hide();
$('[name=field10_value\\[\\]').hide();
$('[name=field8_recovery_value\\[\\]').hide();
$('[name=field9_recovery_value\\[\\]').hide();
$('[name=field10_recovery_value\\[\\]').hide();
$('#table_macros-field8').hide();
$('#table_macros-field9').hide();
$('#table_macros-field10').hide();
$('[name=field8_value_container').hide();
$('[name=field9_value_container').hide();
$('[name=field10_value_container').hide();
$('[name=field8_recovery_value_container').hide();
$('[name=field9_recovery_value_container').hide();
$('[name=field10_recovery_value_container').hide();
for (var i=8; i <= max_macro_fields; i++) {
$('[name=field'+i+'_value\\[\\]').hide();
$('[name=field'+i+'_recovery_value\\[\\]').hide();
$('#table_macros-field'+i).hide();
$('[name=field'+i+'_value_container').hide();
$('[name=field'+i+'_recovery_value_container').hide();
}
if ($('#field5_value').val() !== '') {
ajax_get_integria_custom_fields($('#field5_value').val(), integria_custom_fields_values, integria_custom_fields_rvalues);

View File

@ -105,8 +105,8 @@ if (get_parameter('update_config', 0) == 1) {
'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').'","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_"]',
'fields_values' => '["", "", "","","'.$types_string.'","","","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_"]',
'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').'","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_"]',
'fields_values' => '["", "", "","","'.$types_string.'","","","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_"]',
]
);
@ -136,7 +136,7 @@ if (get_parameter('update_config', 0) == 1) {
$sql_update_command_values = sprintf(
'
UPDATE talert_commands
SET fields_values = \'["","","","","%s","","","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_"]\'
SET fields_values = \'["","","","","%s","","","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_","_integria_type_custom_field_"]\'
WHERE name="%s"',
$types_string,
io_safe_input('Integria IMS Ticket')

View File

@ -441,6 +441,7 @@ CREATE TABLE IF NOT EXISTS `talert_actions` (
`field19_recovery` text NOT NULL,
`field20_recovery` text NOT NULL,
`previous_name` text,
`create_wu_integria` tinyint(1) default NULL,
PRIMARY KEY (`id`),
FOREIGN KEY (`id_alert_command`) REFERENCES talert_commands(`id`)
ON DELETE CASCADE ON UPDATE CASCADE

View File

@ -1586,6 +1586,16 @@ sub pandora_execute_action ($$$$$$$$$;$) {
$field8 = subst_alert_macros ($field8, \%macros, $pa_config, $dbh, $agent, $module, $alert);
$field9 = subst_alert_macros ($field9, \%macros, $pa_config, $dbh, $agent, $module, $alert);
$field10 = subst_alert_macros ($field10, \%macros, $pa_config, $dbh, $agent, $module, $alert);
$field11 = subst_alert_macros ($field11, \%macros, $pa_config, $dbh, $agent, $module, $alert);
$field12 = subst_alert_macros ($field12, \%macros, $pa_config, $dbh, $agent, $module, $alert);
$field13 = subst_alert_macros ($field13, \%macros, $pa_config, $dbh, $agent, $module, $alert);
$field14 = subst_alert_macros ($field14, \%macros, $pa_config, $dbh, $agent, $module, $alert);
$field15 = subst_alert_macros ($field15, \%macros, $pa_config, $dbh, $agent, $module, $alert);
$field16 = subst_alert_macros ($field16, \%macros, $pa_config, $dbh, $agent, $module, $alert);
$field17 = subst_alert_macros ($field17, \%macros, $pa_config, $dbh, $agent, $module, $alert);
$field18 = subst_alert_macros ($field18, \%macros, $pa_config, $dbh, $agent, $module, $alert);
$field19 = subst_alert_macros ($field19, \%macros, $pa_config, $dbh, $agent, $module, $alert);
$field20 = subst_alert_macros ($field20, \%macros, $pa_config, $dbh, $agent, $module, $alert);
# Field 1 (Integria IMS API path)
my $api_path = $config_api_path . "/integria/include/api.php";
@ -1648,8 +1658,18 @@ sub pandora_execute_action ($$$$$$$$$;$) {
my $ticket_custom_field1 = $field8;
my $ticket_custom_field2 = $field9;
my $ticket_custom_field3 = $field10;
my $ticket_custom_field4 = $field11;
my $ticket_custom_field5 = $field12;
my $ticket_custom_field6 = $field13;
my $ticket_custom_field7 = $field14;
my $ticket_custom_field8 = $field15;
my $ticket_custom_field9 = $field16;
my $ticket_custom_field10 = $field17;
my $ticket_custom_field11 = $field18;
my $ticket_custom_field12 = $field19;
my $ticket_custom_field13 = $field20;
pandora_create_integria_ticket($pa_config, $api_path, $api_pass, $integria_user, $integria_user_pass, $agent->{'nombre'}, $agent->{'alias'}, $agent->{'id_os'}, $agent->{'direccion'}, $agent->{'id_agente'}, $agent->{'id_grupo'}, $ticket_name, $ticket_group_id, $ticket_priority, $ticket_owner, $ticket_type, $ticket_status, $ticket_description, $create_wu_on_close_recovery, $ticket_custom_field1, $ticket_custom_field2, $ticket_custom_field3);
pandora_create_integria_ticket($pa_config, $api_path, $api_pass, $integria_user, $integria_user_pass, $agent->{'nombre'}, $agent->{'alias'}, $agent->{'id_os'}, $agent->{'direccion'}, $agent->{'id_agente'}, $agent->{'id_grupo'}, $ticket_name, $ticket_group_id, $ticket_priority, $ticket_owner, $ticket_type, $ticket_status, $ticket_description, $create_wu_on_close_recovery, $ticket_custom_field1, $ticket_custom_field2, $ticket_custom_field3, $ticket_custom_field4, $ticket_custom_field5, $ticket_custom_field6, $ticket_custom_field7, $ticket_custom_field8, $ticket_custom_field9, $ticket_custom_field10, $ticket_custom_field11, $ticket_custom_field12, $ticket_custom_field13);
# Generate notification
} elsif ($clean_name eq "Generate Notification") {
@ -6214,8 +6234,8 @@ sub pandora_edit_custom_graph ($$$$$$$$$$$) {
return $res;
}
sub pandora_create_integria_ticket ($$$$$$$$$$$$$$$$$$$$$$) {
my ($pa_config,$api_path,$api_pass,$integria_user,$user_pass,$agent_name,$agent_alias,$agent_os,$agent_addr,$agent_id,$agent_group,$ticket_name,$ticket_group_id,$ticket_priority,$ticket_owner,$ticket_type,$ticket_status,$ticket_description, $create_wu_on_close_recovery, $ticket_custom_field1, $ticket_custom_field2, $ticket_custom_field3) = @_;
sub pandora_create_integria_ticket ($$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$) {
my ($pa_config,$api_path,$api_pass,$integria_user,$user_pass,$agent_name,$agent_alias,$agent_os,$agent_addr,$agent_id,$agent_group,$ticket_name,$ticket_group_id,$ticket_priority,$ticket_owner,$ticket_type,$ticket_status,$ticket_description, $create_wu_on_close_recovery, $ticket_custom_field1, $ticket_custom_field2, $ticket_custom_field3, $ticket_custom_field4, $ticket_custom_field5, $ticket_custom_field6, $ticket_custom_field7, $ticket_custom_field8, $ticket_custom_field9, $ticket_custom_field10, $ticket_custom_field11, $ticket_custom_field12, $ticket_custom_field13) = @_;
use URI::URL;
use URI::Escape;
@ -6252,7 +6272,17 @@ sub pandora_create_integria_ticket ($$$$$$$$$$$$$$$$$$$$$$) {
"|;|" . $ticket_create_wu .
"|;|" . $ticket_custom_field1 .
"|;|" . $ticket_custom_field2 .
"|;|" . $ticket_custom_field3;
"|;|" . $ticket_custom_field3 .
"|;|" . $ticket_custom_field4 .
"|;|" . $ticket_custom_field5 .
"|;|" . $ticket_custom_field6 .
"|;|" . $ticket_custom_field7 .
"|;|" . $ticket_custom_field8 .
"|;|" . $ticket_custom_field9 .
"|;|" . $ticket_custom_field10 .
"|;|" . $ticket_custom_field11 .
"|;|" . $ticket_custom_field12 .
"|;|" . $ticket_custom_field13;
$call_api = $api_path . '?' .
'user=' . $integria_user . '&' .

View File

@ -1115,8 +1115,8 @@ if (scalar(@types) != 0) {
$query_string .= $type->{'id'} . ',' . $type->{'name'} . ';';
}
db_do($dbh, "UPDATE talert_commands SET fields_descriptions='[\"Ticket&#x20;title\",\"Ticket&#x20;group&#x20;ID\",\"Ticket&#x20;priority\",\"Ticket&#x20;owner\",\"Ticket&#x20;type\",\"Ticket&#x20;status\",\"Ticket&#x20;description\",\"_integria_type_custom_field_\",\"_integria_type_custom_field_\",\"_integria_type_custom_field_\"]' WHERE name=\"Integria&#x20;IMS&#x20;Ticket\"");
db_do($dbh, "UPDATE talert_commands SET fields_values='[\"\", \"\", \"\",\"\",\"" . $query_string . "\",\"\",\"\",\"_integria_type_custom_field_\",\"_integria_type_custom_field_\", \"_integria_type_custom_field_\"]' WHERE name=\"Integria&#x20;IMS&#x20;Ticket\"");
db_do($dbh, "UPDATE talert_commands SET fields_descriptions='[\"Ticket&#x20;title\",\"Ticket&#x20;group&#x20;ID\",\"Ticket&#x20;priority\",\"Ticket&#x20;owner\",\"Ticket&#x20;type\",\"Ticket&#x20;status\",\"Ticket&#x20;description\",\"_integria_type_custom_field_\",\"_integria_type_custom_field_\",\"_integria_type_custom_field_\",\"_integria_type_custom_field_\",\"_integria_type_custom_field_\",\"_integria_type_custom_field_\",\"_integria_type_custom_field_\",\"_integria_type_custom_field_\",\"_integria_type_custom_field_\",\"_integria_type_custom_field_\",\"_integria_type_custom_field_\",\"_integria_type_custom_field_\",\"_integria_type_custom_field_\"]' WHERE name=\"Integria&#x20;IMS&#x20;Ticket\"");
db_do($dbh, "UPDATE talert_commands SET fields_values='[\"\", \"\", \"\",\"\",\"" . $query_string . "\",\"\",\"\",\"_integria_type_custom_field_\",\"_integria_type_custom_field_\",\"_integria_type_custom_field_\",\"_integria_type_custom_field_\",\"_integria_type_custom_field_\",\"_integria_type_custom_field_\",\"_integria_type_custom_field_\",\"_integria_type_custom_field_\",\"_integria_type_custom_field_\",\"_integria_type_custom_field_\",\"_integria_type_custom_field_\",\"_integria_type_custom_field_\",\"_integria_type_custom_field_\"]' WHERE name=\"Integria&#x20;IMS&#x20;Ticket\"");
}
# Release the lock