ConcatFormat

Returns a string concatenated with given a prefix and suffix which supports DT expressions.

python · Filters And Transformers

Details

IDConcatFormat
Languagepython
From Version6.5.0
Docker Imagedemisto/python3:3.12.13.10404775
Tagstransformer general string

README

Returns a string concatenated with given prefix & suffix which supports DT expressions.

Script Data


Name Description
Script Type python3
Tags transformer, general, string
Cortex XSOAR Version 6.5.0

Inputs


Argument Name Description
value The text to be concatenated with prefix & suffix
prefix A prefix to concat to the start of the argument
suffix A prefix to concat to the end of the argument
ctx_data Context Data: Input . (single dot) on `From previous tasks` to enable to extract the context data.
ctx_inputs `inputs` context: Input ‘inputs’ (no quotation) on `From previous tasks` to enable ${inputs.} expression in DT.
ctx_inc `demisto` context: Input ‘incident’ (no quotation) on `From previous tasks` to enable ${incident.} expression in DT.
variable_markers The pair of start and end markers to bracket a variable name
keep_symbol_to_null Set to true not to replace a value if the variable is null, otherwise false.

Outputs


There are no outputs for this script.

Getting Started


The transformer concatenates prefix and suffix which supports DT expressions to the string.

Examples


Build an email address from a user ID by appending a domain

Parameters

Argument Name Value Note
value jdoe  
prefix    
suffix @${domain}  
ctx_data . Make sure that From previous tasks is selected
ctx_inputs    
ctx_inc    
variable_markers    
keep_symbol_to_null    

Context Data

{
  "domain": "paloaltonetworks.com"
}

Output

jdoe@example.com

Build an email address by adding a user ID to the domain

Parameters

Argument Name Value Note
value paloaltonetworks.com  
prefix ${userid}@  
suffix    
ctx_data . Make sure that From previous tasks is selected
ctx_inputs    
ctx_inc    
variable_markers    
keep_symbol_to_null    

Context Data

{
  "userid": "jdoe"
}

Output

jdoe@example.com

Change the variable start and end marker to the windows command shell style such as %name%

Parameters

Argument Name Value Note
value paloaltonetworks.com  
prefix %userid%@  
suffix    
ctx_data . Make sure that From previous tasks is selected
ctx_inputs    
ctx_inc    
variable_markers %,%  
keep_symbol_to_null    

Context Data

{
  "userid": "jdoe"
}

Output

jdoe@example.com

Change the variable start and end marker to the UNIX shell style such as $name

Parameters

Argument Name Value Note
value paloaltonetworks.com  
prefix $userid@  
suffix    
ctx_data . Make sure that From previous tasks is selected
ctx_inputs    
ctx_inc    
variable_markers $  
keep_symbol_to_null    

Context Data

{
  "userid": "jdoe"
}

Output

jdoe@example.com

Keep variable names if they are missing in the context

Parameters

Argument Name Value Note
value paloaltonetworks.com  
prefix ${userid}@  
suffix    
ctx_data . Make sure that From previous tasks is selected
ctx_inputs    
ctx_inc    
variable_markers    
keep_symbol_to_null true  

Context Data

{
}

Output

${userid}@paloaltonetworks.com

Use DTs to build variables

Parameters

Argument Name Value Note
value paloaltonetworks.com  
prefix ${userid=val.toUpperCase()}@  
suffix    
ctx_data . Make sure that From previous tasks is selected
ctx_inputs    
ctx_inc    
variable_markers    
keep_symbol_to_null    

Context Data

{
  "userid": "jdoe"
}

Output

jdoe@example.com

Use nested DTs to build variables

Parameters

Argument Name Value Note
value John Doe  
prefix Hello,  
suffix . ${message-${messageID}}  
ctx_data . Make sure that From previous tasks is selected
ctx_inputs    
ctx_inc    
variable_markers    
keep_symbol_to_null    

Context Data

{
  "message-1": "This is a test message.",
  "messageID": 1
}

Output

Hello, John Doe. This is a test message.
import json

import demistomock as demisto
from ConcatFormat import main


class TestConcatFormat:
    def __side_effect_demisto_dt(self, obj, dt):
        return demisto.get(obj, dt)

    def test_main(self, mocker):
        with open("./test_data/test.json") as f:
            test_list = json.load(f)

        mocker.patch.object(demisto, "dt", side_effect=self.__side_effect_demisto_dt)

        for t in test_list:
            mocker.patch.object(demisto, "args", return_value=t["args"])
            mocker.patch.object(demisto, "results")
            main()
            assert demisto.results.call_count == 1
            results = demisto.results.call_args[0][0]
            assert json.dumps(results) == json.dumps(t["results"])