Common Server Python
Common functions that will be appended to the code of each integration/script before being executed.
#
AutoFocusKeyRetrieverAutoFocus API Key management class
Arguments:
api_key
str: Auto Focus API key coming from the integration parametersoverride_default_credentials
bool: Whether to override the default credentials and use the Cortex XSOAR given AutoFocus API Key
#
BarColumnPieWidgetBar/Column/Pie Widget representation
Arguments:
categories
list: a list of categories to display(Better use the add_category function to populate the data.
#
add_categoryAdd a category to widget.
Arguments:
name
str: the name of the category to add.number
int: the number value of the category.
#
to_display#
CommandResultsCommandResults class - use to return results to warroom
Arguments:
outputs_prefix
str: should be identical to the prefix in the yml contextPath in yml file. for example: CortexXDR.Incidentoutputs_key_field
str or list[str]: primary key field in the main object. If the command returns Incidents, and of the properties of Incident is incident_id, then outputs_key_field='incident_id'. If object has multiple unique keys, then list of strings is supported outputs_key_field=['id1', 'id2']outputs
list or dict: the data to be returned and will be set to contextindicators
list: DEPRECATED: use 'indicator' instead.indicator
Common.Indicator: single indicator like Common.IP, Common.URL, Common.File, etc.readable_output
str: (Optional) markdown string that will be presented in the warroom, should be human readable - (HumanReadable) - if not set, readable output will be generatedraw_response
dict | list: must be dictionary, if not provided then will be equal to outputs. usually must be the original raw response from the 3rd party service (originally Contents)indicators_timeline
IndicatorsTimeline: must be an IndicatorsTimeline. used by the server to populate an indicator's timeline.ignore_auto_extract
bool: must be a boolean, default value is False. Used to prevent AutoExtract on output.relationships
list of EntityRelationship: List of relationships of the indicator.mark_as_note
bool: must be a boolean, default value is False. Used to mark entry as note.tags
list: must be a list, default value is None. Used to tag war room entries.entry_type
int code of EntryType: type of return value, see EntryTypescheduled_command
ScheduledCommand: manages the way the command should be polled.execution_metrics
ExecutionMetrics: contains metric data about a command's executionreplace_existing
bool: Replace the context value at outputs_prefix if it exists. Works only if outputs_prefix is a path to a nested value i.e., contains a period. For example, the "next token" result should always be overwritten. This response can be returned as follows:
Examples:
#
to_context#
CommandRunnerClass for executing multiple commands and save the results of each command.
#
CommandData class with the data required to execute a command.
Arguments:
commands
__: The commands list or a single commandargs_lst
str + List[str]: The args list or a single argsbrand
List[Dict] + Dict: The brand to useinstance
str: The instance to use
#
_is_validError handling of the given arguments
Arguments:
commands
__: list of commandsargs_lst
__: list of args
#
ResultClass for the result of the command.
Arguments:
command
__: command that was run. :type commandstr
args
__: args that was run.brand
dict: The brand that was used.instance
str: The instance that was used.result
str: The result of the command.
#
execute_commandsRuns the demisto.executeCommand()
and gets all the results, including the errors, returned from the command.
Arguments:
command
Command: The commands to run. (required)extract_contents
bool: Whether to extract Contents part of the results. Default is True.
Returns:
Tuple[List[ResultWrapper], List[ResultWrapper]]
- A tuple of two lists: the command results list and command errors list.
#
run_commands_with_summaryGiven a list of commands, return a list of results (to pass to return_results).
In addition, it will create a CommandResult
of the summary of the commands, which is a readable_output
.
Arguments:
commands
__: A list of commands.
#
get_results_summaryGet a Human Readable result for all the results of the commands.
Arguments:
results
__: list of returned resultserrors
__: list of returned errors
#
ConfKeyYML configuration key fields.
This is an empty class, used for code autocompletion when using demisto-sdk generate_yml_from_python command syntax. For more information, visit the command's README.md.
Returns:
ConfKey
- The ConfKey object
#
DBotScoreReliabilityEnum: Source reliability levels Values are case sensitive
A_PLUS
A
B
C
D
E
F
#
is_valid_type#
get_dbot_score_reliability_from_str#
DBotScoreTypeEnum: contains all the indicator types DBotScoreType.IP DBotScoreType.FILE DBotScoreType.DOMAIN DBotScoreType.URL DBotScoreType.CVE DBotScoreType.ACCOUNT DBotScoreType.CRYPTOCURRENCY DBotScoreType.EMAIL DBotScoreType.ATTACKPATTERN DBotScoreType.CUSTOM
IP
FILE
DOMAIN
URL
CVE
ACCOUNT
CIDR
DOMAINGLOB
CERTIFICATE
CRYPTOCURRENCY
EMAIL
ATTACKPATTERN
CUSTOM
#
is_valid_type#
DebugLoggerWrapper to initiate logging at logging.DEBUG level.
Is used when debug-mode=True
.
#
__del__#
log_start_debugUtility function to log start of debug mode logging
#
DemistoHandlerHandler to route logging messages to an IntegrationLogger or demisto.debug if not supplied
#
emit#
EntityRelationshipXSOAR entity relationship.
Arguments:
name
str: Relationship name.relationship_type
str: Relationship type. (e.g. IndicatorToIndicator...).entity_a
str: A value, A aka source of the relationship.entity_a_family
str: Entity family of A, A aka source of the relationship. (e.g. Indicator...)entity_a_type
str: Entity A type, A aka source of the relationship. (e.g. IP/URL/...).entity_b
str: B value, B aka destination of the relationship.entity_b_family
str: Entity family of B, B aka destination of the relationship. (e.g. Indicator...)entity_b_type
str: Entity B type, B aka destination of the relationship. (e.g. IP/URL/...).source_reliability
str: Source reliability.fields
dict: Custom fields. (Optional)brand
str: Source brand name. (Optional)
#
RelationshipsTypesRelationships Types objects.
#
RELATIONSHIP_TYPES#
is_valid_type#
RelationshipsFamilyRelationships Family object list.
#
INDICATOR#
is_valid_type#
RelationshipsEnum: Relations names and their reverse
APPLIED
ATTACHMENT_OF
ATTACHES
ATTRIBUTE_OF
ATTRIBUTED_BY
ATTRIBUTED_TO
AUTHORED_BY
BEACONS_TO
BUNDLED_IN
BUNDLES
COMMUNICATED_WITH
COMMUNICATED_BY
COMMUNICATES_WITH
COMPROMISES
CONTAINS
CONTROLS
CREATED_BY
CREATES
DELIVERED_BY
DELIVERS
DETECTS
DETECTED_BY
DOWNLOADS
DOWNLOADS_FROM
DROPPED_BY
DROPS
DUPLICATE_OF
EMBEDDED_IN
EMBEDS
EXECUTED
EXECUTED_BY
EXFILTRATES_TO
EXPLOITS
HAS
HOSTED_ON
HOSTS
IMPERSONATES
INDICATED_BY
INDICATOR_OF
INJECTED_FROM
INJECTS_INTO
INVESTIGATES
IS_ALSO
LOCATED_AT
MITIGATED_BY
MITIGATES
ORIGINATED_FROM
OWNED_BY
OWNS
PART_OF
RELATED_TO
REMEDIATES
RESOLVED_BY
RESOLVED_FROM
RESOLVES_TO
SEEN_ON
SENT
SENT_BY
SENT_FROM
SENT_TO
SIMILAR_TO
SUB_DOMAIN_OF
SUB_TECHNIQUE_OF
PARENT_TECHNIQUE_OF
SUPRA_DOMAIN_OF
TARGETED_BY
TARGETS
TYPES
UPLOADED_TO
USED_BY
USED_ON
USES
VARIANT_OF
RELATIONSHIPS_NAMES
#
is_validArguments:
_type
str: the data to be returned and will be set to context
Returns:
bool
- Is the given type supported
#
get_reverseArguments:
name
str: Relationship name
Returns:
str
- Returns the reversed relationship name
#
to_entryConvert object to XSOAR entry
Returns:
dict
- XSOAR entry representation.
#
to_indicatorConvert object to XSOAR entry
Returns:
dict
- XSOAR entry representation.
#
to_contextConvert object to XSOAR context
Returns:
dict
- XSOAR context representation.
#
EntryFormatEnum: contains all the entry formats (e.g. HTML, TABLE, JSON, etc.)
HTML
TABLE
JSON
TEXT
DBOT_RESPONSE
MARKDOWN
#
is_valid_type#
EntryTypeEnum: contains all the entry types (e.g. NOTE, ERROR, WARNING, FILE, etc.)
NOTE
DOWNLOAD_AGENT
FILE
ERROR
PINNED
USER_MANAGEMENT
IMAGE
PLAYGROUND_ERROR
ENTRY_INFO_FILE
VIDEO_FILE
WARNING
STATIC_VIDEO_FILE
MAP_ENTRY_TYPE
WIDGET
EXECUTION_METRICS
#
ErrorTypesEnum: contains all the available error types
SUCCESS
QUOTA_ERROR
GENERAL_ERROR
AUTH_ERROR
SERVICE_ERROR
CONNECTION_ERROR
PROXY_ERROR
SSL_ERROR
TIMEOUT_ERROR
RETRY_ERROR
#
ExecutionMetricsExecutionMetrics is used to collect and format metric data to be reported to the XSOAR server.
#
is_supported#
success#
success#
quota_error#
quota_error#
general_error#
general_error#
auth_error#
auth_error#
service_error#
service_error#
connection_error#
connection_error#
proxy_error#
proxy_error#
ssl_error#
ssl_error#
timeout_error#
timeout_error#
retry_error#
retry_error#
get_metric_list#
update_metrics#
FeedIndicatorTypeType of Indicator (Reputations), used in TIP integrations
#
Account#
CVE#
Domain#
DomainGlob#
Email#
File#
FQDN#
Host#
IP#
CIDR#
IPv6#
IPv6CIDR#
Registry#
SSDeep#
URL#
AS#
MUTEX#
Malware#
Identity#
Location#
Software#
X509#
is_valid_type#
list_all_supported_indicators#
ip_to_indicator_typeReturns the indicator type of the input IP.
Arguments:
ip
str: IP address to get it's indicator type.
Returns:
str
- : Indicator type from FeedIndicatorType, or None if invalid IP address.
#
indicator_type_by_server_versionReturns the indicator type of the input by the server version. If the server version is 6.2 and greater, remove the STIX prefix of the type
Arguments:
indicator_type
str: Type of an indicator.
Returns:
str
- : Indicator type .
#
FileAttachmentTypeEnum: contains the file attachment types, Used to add metadata to the description of the attachment whether the file content is expected to be inline or attached as a file
Returns:
str
- : The file attachment typeATTACHED
#
FormatADTimestampFormats an Active Directory timestamp into human readable time representation
Arguments:
ts
int: The timestamp to be formatted (required)
Returns:
str
- A string represeting the time
#
FormatIso8601Convert a time expressed in seconds to ISO 8601 time format string
Arguments:
t
int: Time expressed in seconds (required)
Returns:
str
- An ISO 8601 time format string
#
GetDemistoVersionCallable class to replace get_demisto_version function
#
__call__Returns the Demisto version and build number.
Returns:
dict
- Demisto version object if Demisto class has attribute demistoVersion, else raises AttributeError
#
GetMappingFieldsResponseHandler for the mapping fields object.
Arguments:
scheme_types_mapping
list: List of all the mappings in the remote system.
#
add_scheme_typeAdd another incident type mapping.
Arguments:
scheme_type_mapping
dict: mapping of a singular field.
#
extract_mappingExtracts the mapping into XSOAR mapping screen.
Returns:
dict
- the mapping object for the current field.
#
GetModifiedRemoteDataArgsget-modified-remote-data args parser
Arguments:
args
dict: arguments for the command.
#
GetModifiedRemoteDataResponseget-modified-remote-data response parser
Arguments:
modified_incident_ids
list: The incidents that were modified since the last check.
#
to_entryExtracts the response
Returns:
list
- List of incidents to run the get-remote-data command on.
#
GetRemoteDataArgsget-remote-data args parser
Arguments:
args
dict: arguments for the command.
#
GetRemoteDataResponseget-remote-data response parser
Arguments:
mirrored_object
dict: The object you are mirroring, in most cases the incident.entries
list: The entries you want to add to the war room.
#
extract_for_localExtracts the response into the mirrored incident.
Returns:
list
- List of details regarding the mirrored incident.
#
IncidentSeverityEnum: contains all the incident severity types
UNKNOWN
INFO
LOW
MEDIUM
HIGH
CRITICAL
#
IncidentStatusEnum: contains all the incidents status types (e.g. pending, active, done, archive)
PENDING
ACTIVE
DONE
ARCHIVE
#
IndicatorsSearcherUsed in order to search indicators by the paging or serachAfter param
Arguments:
page
int: the number of page from which we start search indicators from.filter_fields
Optional[str]: comma separated fields to filter (e.g. "value,type")from_date
Optional[str]: the start date to search from.query
Optional[str]: indicator search queryto_date
Optional[str]: the end date to search until to.value
str: the indicator value to search.limit
Optional[int]: the current upper limit of the search (can be updated after init)sort
List[Dict]: An array of sort params ordered by importance. Item structure: {"field": string, "asc": boolean}
#
SEARCH_AFTER_TITLE#
__iter__#
next#
__next__#
page#
total#
limit#
limit#
is_search_doneReturn True if one of these conditions is met (else False):
- self.limit is set, and it's updated to be less or equal to zero - return True
- for search_after if self.total was populated by a previous search, but no self._search_after_param
- for page if self.total was populated by a previous search, but page is too large
#
search_indicators_by_versionThere are 2 cases depends on the sever version:
- Search indicators using paging, raise the page number in each call.
- Search indicators using searchAfter param, update the _search_after_param in each call.
Arguments:
from_date
Optional[str]: the start date to search from.query
Optional[str]: indicator search querysize
int: limit the number of returned results.to_date
Optional[str]: the end date to search until to.value
str: the indicator value to search.
Returns:
dict
- object contains the search results
#
IndicatorsTimelineIndicatorsTimeline class - use to return Indicator Timeline object to be used in CommandResults
Arguments:
indicators
list: expects a list of indicators.category
str: indicator category.message
str: indicator message.
#
InputArgumentYML input argument for a command.
This is an empty class, used for code autocompletion when using demisto-sdk generate_yml_from_python command syntax. For more information, visit the command's README.md.
Returns:
InputArgument
- The InputArgument object
#
IntegrationLoggera logger for python integrations:
use LOG(<message>)
to add a record to the logger (message can be any object with str)
use LOG.print_log(verbose=True/False)
to display all records in War-Room (if verbose) and server log.
use add_replace_strs
to add sensitive strings that should be replaced before going to the log.
Arguments:
message
str: The message to be logged
#
_iter_sensistive_dict_obj#
encode#
__call__#
add_replace_strsAdd strings which will be replaced when logging. Meant for avoiding passwords and so forth in the log.
#
set_bufferingset whether the logger buffers messages or writes staight to the demisto log
Arguments:
state
__: True/False
#
print_log#
build_curlParses the HTTP client "send" log messages and generates cURL queries out of them.
Arguments:
text
str: The HTTP client log message.
#
write#
print_override#
JsonTransformerA class to transform a json to
Arguments:
flatten
bool: Should we flatten the json usingflattenCell
(for BC)keys
Set[str]: Set of keys to keepis_nested
bool: If look for nestedfunc
Callable: A function to parse the json
Constructor for JsonTransformer
Arguments:
flatten
bool: Should we flatten the json usingflattenCell
(for BC)keys
Iterable[str]: an iterable of relevant keys list from the json. Notice we save it as a set in the classis_nested
bool: Whether to search in nested keys or notfunc
Callable: A function to parse the json
#
json_to_str#
json_to_path_generatorArguments:
json_input
list or dict: The json input to transformpath
List[str + int]: The path of the key, value pair inside the json
:rtype Tuple[List[str + int], str, str]
#
LineWidgetLine Widget representation
Arguments:
categories
Any: a list of categories to display(Better use the add_category function to populate the data.
#
add_categoryAdd a category to widget.
Arguments:
name
str: the name of the category to add.number
int: the number value of the category.group
str: the name of the relevant group.
#
to_display#
NormalizeRegistryPathNormalizes a registry path string
Arguments:
strRegistryPath
str: The registry path (required)
Returns:
str
- The normalized string
#
NumberWidgetNumber Widget representation
Arguments:
number
int: The number for the widget to display.
#
to_display#
OutputArgumentYML output argument.
This is an empty class, used for code autocompletion when using demisto-sdk generate_yml_from_python command syntax. For more information, visit the command's README.md.
Returns:
OutputArgument
- The OutputArgument object
#
ParameterTypesYML ConfKey key_type type.
This is an empty class, used for code autocompletion when using demisto-sdk generate_yml_from_python command syntax. For more information, visit the command's README.md.
Returns:
ParameterTypes
- The ParameterTypes enum
#
STRING#
NUMBER#
ENCRYPTED#
BOOLEAN#
AUTH#
DOWNLOAD_LINK#
TEXT_AREA#
INCIDENT_TYPE#
TEXT_AREA_ENCRYPTED#
SINGLE_SELECT#
MULTI_SELECT#
PollResultThe response object for polling functions. This object contains information about whether to run again, and what the CommandResults are in case of success, or failure.
Returns:
PollResult
- PollResult
Constructor for PollResult
Arguments:
response
Any: The response of the command in the event of success, or in case of failure but Polling is falsecontinue_to_poll
Union[bool, Callable]: An iterable of relevant keys list from the json. Notice we save it as a set in the classargs_for_next_run
Dict: The arguments to use in the next iteration. Will use the input args in case of Nonepartial_result
CommandResults: CommandResults to return, even though we will poll again
#
PrettifyCompactedTimestampFormats a compacted timestamp string into human readable time representation
Arguments:
x
str: The timestamp to be formatted (required)
Returns:
str
- A string represeting the time
#
ScheduledCommandScheduledCommand configuration class Holds the scheduled command configuration for the command result - managing the way the command should be polled.
Arguments:
command
str: The command that'll run after next_run_in_seconds has passed.next_run_in_seconds
int: How long to wait before executing the command.args
Optional[Dict[str, Any]]: Arguments to use when executing the command.timeout_in_seconds
Optional[int]: Number of seconds until the polling sequence will timeout.items_remaining
Optional[int]: Number of items that are remaining to be polled.
#
VERSION_MISMATCH_ERROR#
raise_error_if_not_supported#
supports_pollingCheck if the integration supports polling (if server version is greater than 6.2.0). Returns: Boolean
#
to_resultsReturns the result dictionary of the polling command
#
SchemeTypeMappingScheme type mappings builder.
Arguments:
type_name
str: The name of the remote incident type.fields
dict: The dict of fields to their description.
#
add_fieldAdds a field to the incident type mapping.
Arguments:
name
str: The name of the field.description
str: The description for that field.a
#
extract_mappingExtracts the mapping into XSOAR mapping screen.
Returns:
dict
- the mapping object for the current field.
#
SmartGetDictA dict that when called with get(key, default) will return the default passed value, even if there is a value of "None" in the place of the key. Example with built-in dict:
Example with SmartGetDict:
#
TableOrListWidgetTable/List Widget representation
Arguments:
data
Any: a list of data to display(Better use the add_category function to populate the data.
#
add_rowAdd a row to the widget.
Arguments:
data
Any: the data to add to the list/table.
#
to_display#
TextWidgetText Widget representation
Arguments:
text
str: The text for the widget to display
#
to_displayText Widget representation
Arguments:
text
str: The text for the widget to display
#
ThreatIntelXSOAR Threat Intel Objects
#
ObjectsNamesEnum: Threat Intel Objects names.
CAMPAIGN
ATTACK_PATTERN
REPORT
MALWARE
COURSE_OF_ACTION
INTRUSION_SET
TOOL
THREAT_ACTOR
INFRASTRUCTURE
TACTIC
#
ObjectsScoreEnum: Threat Intel Objects Score.
CAMPAIGN
ATTACK_PATTERN
REPORT
MALWARE
COURSE_OF_ACTION
INTRUSION_SET
TOOL
THREAT_ACTOR
INFRASTRUCTURE
TACTIC
#
KillChainPhasesEnum: Kill Chain Phases names.
BUILD_CAPABILITIES
PRIVILEGE_ESCALATION
ADVERSARY_OPSEC
CREDENTIAL_ACCESS
EXFILTRATION
LATERAL_MOVEMENT
DEFENSE_EVASION
PERSISTENCE
COLLECTION
IMPACT
INITIAL_ACCESS
DISCOVERY
EXECUTION
INSTALLATION
DELIVERY
WEAPONIZATION
ACT_ON_OBJECTIVES
COMMAND_AND_CONTROL
#
TrendWidgetTrend Widget representation
Arguments:
current_number
int: The Current number in the trend.previous_number
int: The previous number in the trend.
#
to_display#
UpdateRemoteSystemArgsupdate-remote-system args parser
Arguments:
args
dict: arguments for the command of the command.
#
YMLMetadataCollectorThe YMLMetadataCollector class provides decorators for integration functions which contain details relevant to yml generation.
This is an empty class, used for code autocompletion when using demisto-sdk generate_yml_from_python command syntax. For more information, visit the command's README.md.
Returns:
YMLMetadataCollector
- The YMLMetadataCollector object
#
command#
_find_relevant_moduleFind which module contains the given line number.
Arguments:
trace_str
int: Line number to search. (required)
Returns:
str
- The name of the module.
#
add_http_prefix_if_missingThis function adds http://
prefix to the proxy address in case it is missing.
Arguments:
address
string: Proxy address.
Returns:
string
- proxy address after the 'http://' prefix was added, if needed.
#
add_sensitive_log_strsAdds the received string to both LOG and DebugLogger. The logger will mask the string each time he encounters it.
Arguments:
sensitive_str
str: The string to be replaced.
#
appendContextAppend data to the investigation context
Arguments:
key
str: The context path (required)data
any: Data to be added to the context (required)dedup
bool: True if de-duplication is required. Default is False.
#
append_metricsReturns a 'CommandResults' list appended with metrics.
Arguments:
execution_metrics
ExecutionMetrics: Metrics object to be added to CommandResults list(optional).results
list: 'CommandResults' list to append metrics to (required).
Returns:
list
- results appended with the metrics if the server version is supported.
#
argToBooleanBoolean-ish arguments that are passed through demisto.args() could be type bool or type string. This command removes the guesswork and returns a value of type bool, regardless of the input value's type. It will also return True for 'yes' and False for 'no'.
Arguments:
value
__: the value to evaluate
Returns:
bool
- a boolean representatation of 'value'
#
argToListConverts a string representation of args to a python list
Arguments:
arg
str or list: Args to be converted (required)separator
str: A string separator to separate the strings, the default is a comma.transform
callable: A function transformer to transfer the returned list arguments.
Returns:
list
- A python list of args
#
arg_to_datetimeConverts an XSOAR argument to a datetime
This function is used to quickly validate an argument provided to XSOAR
via demisto.args()
into an datetime
. It will throw a ValueError if the input is invalid.
If the input is None, it will throw a ValueError if required is True
,
or None
if required is ``False.
Arguments:
arg
Any: argument to convertarg_name
str: argument nameis_utc
bool: if True then date converted as utc timezone, otherwise will convert with local timezone.required
bool: throws exception ifTrue
and argument provided is Nonesettings
dict: If provided, passed to dateparser.parse function.
returns an datetime
if conversion works
returns None
if arg is None
and required is set to False
otherwise throws an Exception
Returns:
Optional[datetime]
-
#
arg_to_numberConverts an XSOAR argument to a Python int
This function is used to quickly validate an argument provided to XSOAR
via demisto.args()
into an int
type. It will throw a ValueError
if the input is invalid. If the input is None, it will throw a ValueError
if required is True
, or None
if required is ``False.
Arguments:
arg
Any: argument to convertarg_name
str: argument namerequired
bool: throws exception ifTrue
and argument provided is None
returns an int
if arg can be converted
returns None
if arg is None
and required is set to False
otherwise throws an Exception
Returns:
Optional[int]
-
#
assign_paramsCreates a dictionary from given kwargs without empty values. empty values are: None, '', [], {}, ()
Examples:
Arguments:
keys_to_ignore
tuple or list: Keys to ignore if existsvalues_to_ignore
tuple or list: Values to ignore if existskwargs
kwargs: kwargs to filter
Returns:
dict
- dict without empty values
#
auto_detect_indicator_typeInfer the type of the indicator.
Arguments:
indicator_value
str: The indicator whose type we want to check. (required)
Returns:
str
- The type of the indicator.
#
aws_table_to_markdownConverts a raw response from AWS into a markdown formatted table. This function checks to see if there is only one nested dict in the top level of the dictionary and will use the nested data.
Arguments:
response
__: Raw response from AWStable_header
dict: The header string to use for the table.
Returns:
str
- Markdown formatted table as a string.
#
b64_decodeDecode a str in a base 64 format to a picture. Replaces the use of base64.b64decode function which doesn't add padding to the supplied str.
Arguments:
b64_str
__: string to decode
Returns:
bytes
- decoded binary
#
b64_encodeBase64 encode a string. Wrapper function around base64.b64encode which will accept a string In py3 will encode the string to binary using utf-8 encoding and return a string result decoded using utf-8
Arguments:
text
__: string to encode
Returns:
str
- encoded string
#
batchGets an iterable and yields slices of it.
Arguments:
iterable
list: list or other iterable object.batch_size
int: the size of batches to fetch
Returns:
list
-
#
build_dbot_entryBuild a dbot entry. if score is 3 adds malicious
Examples:
Arguments:
indicator
str: indicator field. if using file hashes, can be dictindicator_type
str: type of indicator ('url, 'domain', 'ip', 'cve', 'email', 'md5', 'sha1', 'sha256', 'crc32', 'sha512', 'ctph')vendor
str: Integration IDscore
int: DBot score (0-3)description
str or None: description (will be added to malicious if dbot_score is 3). can be Nonebuild_malicious
bool: if True, will add a malicious entry
Returns:
dict
- dbot entry
#
build_malicious_dbot_entryBuild Malicious dbot entry
Examples:
Arguments:
indicator
str: Value (e.g. 8.8.8.8)indicator_type
str: e.g. 'IP'vendor
str: Integration IDdescription
str: Why it's malicious
Returns:
dict
- A malicious DBot entry
#
calculate_new_offsetThis calculates the new offset based on the response
Arguments:
old_offset
int: The offset from the previous runnum_incidents
int: The number of incidents returned by the API.total_incidents
int: The total number of incidents returned by the API.
Returns:
int
- The new offset for the next run.
#
camel_case_to_underscoreConverts a camelCase string to snake_case
Arguments:
s
str: The string to convert (e.g. helloWorld) (required)
Returns:
str
- The converted string (e.g. hello_world)
#
camelizeConvert all keys of a dictionary (or list of dictionaries) to CamelCase (with capital first letter)
Arguments:
src
dict or list: The dictionary (or list of dictionaries) to convert the keys for. (required)delim
str: The delimiter between two words in the key (e.g. delim=' ' for "Start Date"). Default ' '.upper_camel
bool: When True then transforms dictionary keys to camel case with the first letter capitalised (for example: demisto_content to DemistoContent), otherwise the first letter will not be capitalised (for example: demisto_content to demistoContent).
Returns:
dict or list
- The dictionary (or list of dictionaries) with the keys in CamelCase.
#
camelize_stringTransform snake_case to CamelCase
Arguments:
src_str
str: snake_case string to convert.delim
str: indicator category.upper_camel
bool: When True then transforms string to camel case with the first letter capitalised (for example: demisto_content to DemistoContent), otherwise the first letter will not be capitalised (for example: demisto_content to demistoContent).
Returns:
str
- A CammelCase string.
#
censor_request_logsCensors the request logs generated from the urllib library directly by replacing sensitive information such as tokens and cookies with a mask. In most cases, the sensitive value is the first word after the keyword, but in some cases, it is the second one.
Arguments:
request_log
__: The request log to censor
Returns:
str
- The censored request log
#
comma_separated_mapping_to_dictTransforming a textual comma-separated mapping into a dictionary object.
Arguments:
raw_text
str: Comma-separated mapping e.g ('key1=value1', 'key2=value2', ...)
Returns:
dict
-
#
content_profilerA decorator for profiling the execution time and performance of a function.
This decorator is useful for identifying performance bottlenecks and understanding the time complexity of your code. It collects and displays detailed profiling information, including the total execution time, the number of calls, and the average time per call. When to use it:
- When you need to debug and optimize the performance of your functions or methods.
- When you want to identify slow or inefficient parts of your code.
- During the development and testing phases to ensure that your code meets performance requirements.
To use, decorate the function that calls the function you want to profile with @content_profiler. Example: I want to profile the function_to_profile() function:
Analyze the Profiling Data with SnakeViz: Download the <automation_name>.prof from the war room and run: pip install snakeviz; snakveiz <automation_name>.prof
Tested with Python 3.10
Arguments:
func
function: The function to be profiled.
Returns:
any
- The profiled function.
#
convert_dict_values_bytes_to_strConverts byte dict values to str
Arguments:
input_dict
dict: dict to converts its values.
Returns:
dict
- dict contains str instead of bytes.
#
createContextReceives a dict with flattened key values, and converts them into nested dicts
Arguments:
data
dict or list: The data to be added to the context (required)id
str: The ID of the context entrykeyTransform
function: A formatting function for the markdown table headersremoveNull
bool: True if empty columns should be removed, false otherwise
Returns:
list
- The converted context list
#
createContextSingleReceives a dict with flattened key values, and converts them into nested dicts
Arguments:
obj
dict or list: The data to be added to the context (required)id
str: The ID of the context entrykeyTransform
function: A formatting function for the markdown table headersremoveNull
bool: True if empty columns should be removed, false otherwise
Returns:
list
- The converted context list
#
create_clickable_urlMake the given url clickable when in markdown format by concatenating itself, with the proper brackets
Arguments:
url
Union[List[str], str]: the url of interest or a list of urlstext
Union[List[str], str, None]: the text of the url or a list of texts of urls.
Returns:
Union[List[str], str]
- Markdown format for clickable url
#
create_indicator_result_with_dbotscore_unknownUsed for cases where the api response to an indicator is not found, returns CommandResults with readable_output generic in this case, and indicator with DBotScore unknown
Arguments:
indicator
str: The value of the indicatorindicator_type
DBotScoreType: use DBotScoreType class [Unsupport in types CVE and ATTACKPATTERN]reliability
DBotScoreReliability: use DBotScoreReliability classcontext_prefix
str: Use only in case that the indicator is CustomIndicatoraddress_type
str: Use only in case that the indicator is Cryptocurrencyrelationships
list of EntityRelationship: List of relationships of the indicator.
Returns:
CommandResults
-
#
create_updated_last_run_objectCalculates the next fetch time and limit depending the incidents result and creates an updated LastRun object with the new time and limit.
Arguments:
last_run
dict: The LastRun objectincidents
list: List of the incidents resultfetch_limit
int: The fetch limitlook_back
int: The time to look back in fetch in minutesstart_fetch_time
str: The time the fetch started to fetch fromend_fetch_time
str: The end time in which the fetch incidents endedcreated_time_field
str: The incident created time fielddate_format
str: The date formatincrease_last_run_time
bool: Whether to increase the last run time with one millisecondnew_offset
int | None: The new offset to set in the last run
Returns:
Dict
- The new LastRun object
#
date_to_timestampParses date_str_or_dt in the given format (default: %Y-%m-%dT%H:%M:%S) to milliseconds Examples: ('2018-11-06T08:56:41', '2018-11-06T08:56:41', etc.)
Arguments:
date_str_or_dt
str or datetime.datetime: The date to be parsed. (required)date_format
str: The date format of the date string (will be ignored if date_str_or_dt is of type datetime.datetime). (optional)
Returns:
int
- The parsed timestamp.
#
datetime_to_stringConverts a datetime object into a string. When used with json.dumps()
for the default
parameter,
e.g. json.dumps(response, default=datetime_to_string)
datetime_to_string allows entire JSON objects
to be safely added to context without causing any datetime marshalling errors.
Arguments:
datetime_obj
__: Datetime object.
Returns:
str
- String representation of a datetime object.
#
detect_file_indicator_typeDetect the type of the file indicator.
Arguments:
indicator_value
str: The indicator whose type we want to check. (required)
Returns:
str
- The type of the indicator.
#
dict_safe_getRecursive safe get query (for nested dicts and lists), If keys found return value otherwise return None or default value. Example:
Examples:
Arguments:
dict_object
dict: dictionary to query.keys
list: keys for recursive get.default_return_value
object: Value to return when no key available.return_type
type: Excepted return type.raise_return_type
bool: Whether to raise an error when the value didn't match the expected return type.
Returns:
object
-
#
elem2jsonConvert an ElementTree or Element into a JSON string.
#
elem_to_internalConvert an Element into an internal dictionary (not JSON!).
#
encode_string_resultsEncode string as utf-8, if any unicode character exists.
Arguments:
text
__: string to encode
Returns:
str
- encoded string
#
ensure_proxy_has_http_prefixThe function checks if proxy environment vars are missing http/https prefixes, and adds http if so.
#
execute_commandRuns the demisto.executeCommand()
function and checks for errors.
Arguments:
command
str: The command to run. (required)args
dict: The command arguments. (required)extract_contents
bool: Whether to return only the Contents part of the results. Default is True.fail_on_error
bool: Whether to fail the command when receiving an error from the command. Default is True.
Returns:
- `` - The command results.
- When
fail_on_error
is True -list
ordict
orstr
. - When
fail_on_error
is False -bool
andstr
.
Note:
For backward compatibility, only when fail_on_error
is set to False, two values will be returned.
#
fileResultCreates a file from the given data
Arguments:
filename
str: The name of the file to be created (required)data
str or bytes: The file data (required)file_type
str: one of the entryTypes file or entryInfoFile (optional)
Returns:
dict
- A Demisto war room entry
#
file_result_existing_fileRename an existing file
Arguments:
filename
str: The name of the file to be modified (required)saveFilename
str: The new file name
Returns:
dict
- A Demisto war room entry
#
filter_incidents_by_duplicates_and_limitRemoves duplicate incidents from response and returns the incidents till limit. The function should be called after getting the get-incidents API response, and by passing the id_field it will filter out the incidents that were already fetched by checking the incident IDs that are saved from the previous fetch in the last run object
Arguments:
incidents_res
list: The incidents from the API responselast_run
dict: The LastRun objectfetch_limit
int: The incidents limit to returnid_field
str: The incident id field
Returns:
list
- List of incidents after filtering duplicates when len(incidents) <= limit
#
fix_traceback_line_numbersFixes the given traceback line numbers.
Arguments:
trace_str
str: The traceback string to edit. (required)
Returns:
str
- The new formated traceback.
#
flattenCellFlattens a markdown table cell content into a single string
Arguments:
data
str or list: The cell content (required)is_pretty
bool: Should cell content be pretified (default is True)
Returns:
str
- A sting representation of the cell content
#
flattenRowFlatten each element in the given rowDict
Arguments:
rowDict
dict: The dict to be flattened (required)
Returns:
dict
- A flattened dict
#
flattenTableFlatten each row in the given tableDict
Arguments:
tableDict
dict: The table to be flattened (required)
Returns:
dict
- A flattened table
#
formatAllArgsmakes a nice string representation of all the arguments
Arguments:
args
list: function arguments (required)kwds
dict: function keyword arguments (required)
Returns:
string
- string representation of all the arguments
#
formatCellConvert a given object to md while decending multiple levels
Arguments:
data
str or list or dict: The cell content (required)is_pretty
bool: Should cell content be prettified (default is True)json_transform
JsonTransformer: The Json transform object to transform the data
Returns:
str
- The formatted cell content as a string
#
formatEpochDateConvert a time expressed in seconds since the epoch to a string representing local time
Arguments:
t
int: Time represented in seconds (required)
Returns:
str
- A string representing local time
#
generic_http_requestA wrapper for the BaseClient._http_request() method, that allows performing HTTP requests without initiating a BaseClient object. Note: Avoid using this method if unnecessary. It is more recommended to use the BaseClient class.
Args:
method (str): HTTP request method (e.g., GET, POST, PUT, DELETE).
server_url (str): Base URL of the server.
timeout (int, optional): Timeout in seconds for the request (defaults to 10).
verify (bool, optional): Whether to verify SSL certificates (defaults to True).
proxy (bool or str, optional): Use a proxy server. Can be a boolean (defaults to False)
or a proxy URL string.
client_headers (dict, optional): Additional headers to be included in all requests
made by the client (overrides headers argument).
headers (dict, optional): Additional headers for this specific request.
url_suffix (str, optional): Path suffix to be appended to the server URL.
data (object, optional): Data to be sent in the request body (e.g., dictionary for POST requests).
ok_codes (list of int, optional): A list of HTTP status codes that are considered successful responses
(defaults to [200]).
auth (tuple, optional): Authentication credentials (username, password) for the request.
error_handler (callable, optional): Function to handle request errors.
files (dict, optional): Dictionary of files to be uploaded (for multipart/form-data requests).
params (dict, optional): URL parameters to be included in the request.
retries (int, optional): Number of times to retry the request on failure (defaults to 0).
retries (int, optional): Number of times to retry the request on failure (defaults to 0).
status_list_to_retry (int, optional): A set of integer HTTP status codes that we should force a retry on.
A retry is initiated if the request method is in ['GET', 'POST', 'PUT']
and the response status code is in status_list_to_retry
.
resp_type (iterable, optional): Determines which data format to return from the HTTP request. The default
is 'json'.
json_data (dict, optional): The dictionary to send in a 'POST' request.
backoff_factor (float, optional): A backoff factor to apply between attempts after the second try
(most errors are resolved immediately by a second try without a
delay). urllib3 will sleep for::
{backoff factor} * (2 ** ({number of total retries} - 1))
seconds. If the backoff_factor is 0.1, then :func:.sleep
will sleep
for [0.0s, 0.2s, 0.4s, ...] between retries. It will never be longer
than :attr:Retry.BACKOFF_MAX
.
By default, backoff_factor set to 5
raise_on_redirect (bool, optional): Whether, if the number of redirects is exhausted, to raise a MaxRetryError, or to return a response with a response code in the 3xx range.
raise_on_status (bool,optional): Similar meaning to raise_on_redirect
:
whether we should raise an exception, or return a response,
if status falls in status_forcelist
range and retries have
been exhausted.
empty_valid_codes (list, optional): A list of all valid status codes of empty responses (usually only 204, but can vary)
return_empty_response (bool, optional): Whether to return an empty response body if the response code is in empty_valid_codes
params_parser (callable, optional): How to quote the params. By default, spaces are replaced with +
and /
to %2F
.
see here for more info: https://docs.python.org/3/library/urllib.parse.html#urllib.parse.urlencode
Note! supported only in python3.
with_metrics (bool, optional): Whether or not to calculate execution metrics from the response
Returns:
Returns:
dict or str or bytes or xml.etree.ElementTree.Element or requests.Response
- Depends on the resp_type parameter
Raises: exceptions.RequestException: If an error occurs during the request.
#
get_current_timeGets the current time in a given timezone, as time awared datetime.
Arguments:
time_zone
int: The time zone offset in hours.
Returns:
datetime
- The current time.
#
get_demisto_version_as_strGet the Demisto Server version as a string <version>-<build>
. If unknown will return: 'Unknown'.
Meant to be use in places where we want to display the version. If you want to perform logic based upon vesrion
use: is_demisto_version_ge.
Returns:
dict
- Demisto version as string
#
get_engine_base_urlGets the xsoar engine id and returns it's base url. For example: for engine_id = '4ccccccc-5aaa-4000-b666-dummy_id', base url = '11.180.111.111:1443'.
Arguments:
engine_id
str: The xsoar engine id.
Returns:
str
- The base URL of the engine.
#
get_errorexecute_command_result must contain error entry - check the result first with is_error function if there is no error entry in the result then it will raise an Exception
Arguments:
execute_command_result
dict or list: result of demisto.executeCommand()
Returns:
string
- Error message extracted from the demisto.executeCommand() result
#
get_feed_last_runThis function gets the feed's last run: using demisto.getLastRun()
.
Returns:
dict
-
#
get_fetch_run_time_rangeCalculates the time range for fetch depending the look_back argument and the previous fetch start time given from the last_run object.
Arguments:
last_run
dict: The LastRun objectfirst_fetch
str: The first time to fetch, used in the first fetch of an instancelook_back
int: The time to look back in fetch in minutestimezone
int: The time zone offset in hoursdate_format
str: The date format
Returns:
Tuple
- The time range (start_time, end_time) of the creation date for the incidents to fetch in the current run.
#
get_found_incident_idsGets the found incident ids from the last run object and adds the new fetched incident IDs.
Arguments:
last_run
dict: The LastRun objectincidents
list: List of incidents to addlook_back
int: The look back time in minutesid_field
str: The incident id field
Returns:
dict
- The new incident ids.
#
get_hash_typeChecks the type of the given hash. Returns 'md5', 'sha1', 'sha256' or 'Unknown'.
Arguments:
hash_file
str: The hash to be checked (required)
Returns:
str
- The hash type
#
get_integration_contextGets the integration context.
Arguments:
sync
bool: Whether to get the integration context directly from the DB.with_version
bool: Whether to return the version.
Returns:
dict
-
#
get_integration_context_with_versionGet the latest integration context with version, if available.
Arguments:
sync
bool: Whether to get the context directly from the DB.
Returns:
tuple
-
#
get_integration_instance_nameGetting calling integration instance name
Returns:
str
- Calling integration instance name
#
get_integration_nameGetting calling integration's name
Returns:
str
- Calling integration's name
#
get_last_mirror_runThis function gets the last run of the mirror, from XSOAR version 6.6.0, using demisto.getLastMirrorRun()
.
Before XSOAR version 6.6.0, the given data is not returned and an exception will be raised.
Returns:
dict
- we did not set anything yet).
#
get_latest_incident_created_timeGets the latest incident created time
Arguments:
incidents
list: List of incidentscreated_time_field
str: The incident created time fielddate_format
str: The date formatincrease_last_run_time
bool: Whether to increase the last run time with one millisecond
Returns:
str
- The latest incident time
#
get_message_classes_dumpA function that returns the printable message about classes dump
Arguments:
classes_as_list
list: The classes to print to the log
Returns:
str
- Message to print.
#
get_message_global_varsA function that returns the printable message about global variables
Returns:
str
- Message to print.
#
get_message_local_varsA function that returns the printable message about local variables
Returns:
str
- Message to print.
#
get_message_memory_dumpListener function to dump the memory to log info
Arguments:
_sig
int: The signal number_frame
Any: The current stack frame
Returns:
str
- Message to print.
#
get_message_modules_sizesA function that returns the printable message about the loaded modules by size
Returns:
str
- Message to print.
#
get_message_threads_dumpListener function to dump the threads to log info
Arguments:
_sig
int: The signal number_frame
Any: The current stack frame
Returns:
str
- Message to print.
#
get_pack_versionGet a pack version. The version can be retrieved either by a pack name or by the calling script/integration in which script/integration is part of.
To get the version of the pack in which the calling script/integration is part of, just call the function without pack_name.
Arguments:
pack_name
str: the pack name as mentioned in the pack metadata file to query its version. use only if querying by a pack name.
case provided. in case not found returns empty string.
Returns:
str
- The pack version in which the integration/script is part of / the version of the requested pack name in
#
get_schedule_metadataGet the entry schedule metadata if available
Arguments:
context
dict: Context in which the command was executed.
Returns:
dict
- Dict with metadata of scheduled entry
#
get_script_nameGetting calling script name
Returns:
str
- Calling script name
#
get_server_configRetrieves XSOAR server configuration.
Returns:
dict
-
#
get_size_of_objectA function that recursively iterate to sum size of object & members.
Arguments:
input_object
Any: The object to calculate its memory footprint
Returns:
int
- Size of input_object in bytes, or -1 if cannot determine the size.
#
get_tenant_account_nameGets the tenant name from the server url.
Returns:
str
- The account name.
#
get_x_content_info_headersGet X-Content-* headers to send in outgoing requests to use when performing requests to external services such as oproxy.
Returns:
dict
- headers dict
#
handle_proxyHandle logic for routing traffic through the system proxy. Should usually be called at the beginning of the integration, depending on proxy checkbox state.
Additionally will unset env variables REQUESTS_CA_BUNDLE and CURL_CA_BUNDLE if handle_insecure is speficied (default). This is needed as when these variables are set and a requests.Session object is used, requests will ignore the Sesssion.verify setting. See: https://github.com/psf/requests/blob/master/requests/sessions.py#L703
Arguments:
proxy_param_name
string: name of the "use system proxy" integration parametercheckbox_default_value
bool: Default value of the proxy param checkboxhandle_insecure
bool: Whether to check the insecure param and unset env variablesinsecure_param_name
string: Name of insecure param. If None will search insecure and unsecure
Returns:
dict
- proxies dict for the 'proxies' parameter of 'requests' functions
#
handle_proxy_for_long_runningHandle logic for long running integration routing traffic through the system proxy. Should usually be called at the beginning of the integration, depending on proxy checkbox state. Long running integrations on hosted tenants XSOAR8 and XSIAM has a dedicated env. var.: CRTX_HTTP_PROXY. Fallback call to handle_proxy in cases long running integration on engine or XSOAR6
Arguments:
proxy_param_name
string: name of the "use system proxy" integration parametercheckbox_default_value
bool: Default value of the proxy param checkboxhandle_insecure
bool: Whether to check the insecure param and unset env variablesinsecure_param_name
string: Name of insecure param. If None will search insecure and unsecure
Returns:
Tuple[dict, boolean]
- proxies dict for the 'proxies' parameter of 'requests' functions and use_ssl boolean
#
has_passed_time_thresholdChecks if the time difference between the current time and the timestamp is greater than the threshold.
Arguments:
timestamp_str
str: The timestamp to compare the current time to.seconds_threshold
int: The threshold in seconds.
Returns:
bool
- True if the time difference is greater than the threshold, otherwise False.
#
hash_djb2Hash string with djb2 hash function
Arguments:
s
str: The input string to hashseed
int: The seed for the hash function (default is 5381)
Returns:
int
- The hashed value
#
indicators_value_to_clickableFunction to get the indicator url link for indicators
Arguments:
indicators
dict + List[dict]: An indicator or a list of indicators
Returns:
dict
-
#
internal_to_elemConvert an internal dictionary (not JSON!) into an Element. Whatever Element implementation we could import will be used by default; if you want to use something else, pass the Element class as the factory parameter.
#
isCommandAvailableCheck the list of available modules to see whether a command is currently available to be run.
Arguments:
cmd
str: The command to check (required)
Returns:
bool
- True if command is available, False otherwise
#
is_debug_modeReturn if this script/command was passed debug-mode=true option
Returns:
bool
- true if debug-mode is enabled
#
is_demisto_version_geUtility function to check if current running integration is at a server greater or equal to the passed version
Arguments:
version
str: Version to checkbuild_number
str: Build number to check
Returns:
bool
- True if running within a Server version greater or equal than the passed version
#
is_errorCheck if the given execute_command_result has an error entry
Arguments:
execute_command_result
dict or list: Demisto entry (required) or result of demisto.executeCommand()
Returns:
bool
- True if the execute_command_result has an error entry, false otherwise
#
is_filename_validChecking if the file name contains invalid characters.
Arguments:
filename
__: The file name
Returns:
bool
- True if valid otherwise False.
#
is_integration_command_executionThis function determines whether the current execution a script execution or a integration command execution.
Returns:
bool
- Is the current execution a script execution or a integration command execution.
#
is_integration_instance_running_on_engineDetermines whether the current integration instance runs on an xsoar engine. If yes - returns the engine id.
Returns:
str
- The engine id iff the instance is running on an xsaor engine.
#
is_ip_validChecks if the given string represents a valid IP address. By default, will only return 'True' for IPv4 addresses.
Arguments:
s
str: The string to be checked (required)accept_v6_ips
bool: A boolean determining whether the function should accept IPv6 addresses
Returns:
bool
- True if the given string represents a valid IP address, False otherwise
#
is_ipv6_validChecks if the given string represents a valid IPv6 address.
Arguments:
address
str: The string to check.
Returns:
bool
- True if the given string represents a valid IPv6 address.
#
is_mac_addressTest for valid mac address
Arguments:
mac
str: MAC address in the form of AA:BB:CC:00:11:22
Returns:
bool
- True/False
#
is_scheduled_command_retryDetermines if the current command is a polling retry command. This is useful if some actions should not be performed when a command is polling for a response such as submitting data for processing.
Returns:
Bool
- True if the command is part of a polling retry, otherwise false
#
is_time_sensitiveChecks if the command reputation (auto-enrichment) is called as auto-extract=inline. This function checks if the 'isTimeSensitive' attribute exists in the 'demisto' object and if it's set to True.
Returns:
bool
- bool
#
is_using_engineDetermines whether or not the platform is using engine. NOTE:
- This method works only for system integrations (not custom).
- On xsoar 8, this method works only for integrations that runs on the xsoar pod - not on the engine-0 (mainly long running integrations) such as: EDL, Cortex Core - IOC, Cortex Core - IR, ExportIndicators, Generic Webhook, PingCastle, Publish List, Simple API Proxy, Syslog v2, TAXII Server, TAXII2 Server, Web File Repository, Workday_IAM_Event_Generator, XSOAR-Web-Server, Microsoft Teams, AWS-SNS-Listener.
Returns:
bool
- True iff the platform is using engine.
#
is_versioned_context_availableDetermines whether versioned integration context is available according to the server version.
Returns:
bool
-
#
is_xsiamDetermines whether or not the platform is XSIAM.
Returns:
bool
- True iff the platform is XSIAM.
#
is_xsiam_or_xsoar_saasDetermines whether or not the platform is XSIAM or XSOAR SAAS.
Returns:
bool
- True iff the platform is XSIAM or XSOAR SAAS.
#
is_xsoarDetermines whether or not the platform is XSOAR.
Returns:
bool
- True iff the platform is XSOAR.
#
is_xsoar_hostedDetermines whether or not the platform is XSOAR hosted.
Returns:
bool
- True iff the platform is XSOAR hosted.
#
is_xsoar_on_premDetermines whether or not the platform is a XSOAR on-prem.
Returns:
bool
- True iff the platform is XSOAR on-prem.
#
is_xsoar_saasDetermines whether or not the platform is XSOAR SAAS.
Returns:
bool
- True iff the platform is XSOAR SAAS.
#
json2elemConvert a JSON string into an Element. Whatever Element implementation we could import will be used by default; if you want to use something else, pass the Element class as the factory parameter.
#
json2xmlConvert a JSON string into an XML string. Whatever Element implementation we could import will be used by default; if you want to use something else, pass the Element class as the factory parameter.
#
loggerdecorator function to log the function call using LOG
Arguments:
func
function: function to call (required)
Returns:
any
- returns the func return value.
#
merge_listsReplace values in a list with those in an updated list. Example:
Examples:
Arguments:
original_list
list: The original list.updated_list
list: The updated list.key
str: The key to replace elements by.
Returns:
list
-
#
parse_date_rangeTHIS FUNCTTION IS DEPRECATED - USE dateparser.parse instead
Parses date_range string to a tuple date strings (start, end). Input must be in format 'number date_range_unit') Examples: (2 hours, 4 minutes, 6 month, 1 day, etc.)
Arguments:
date_range
str: The date range to be parsed (required)date_format
str: Date format to convert the date_range to. (optional)to_timestamp
bool: If set to True, then will return time stamp rather than a datetime.datetime. (optional)timezone
int: timezone should be passed in hours (e.g if +0300 then pass 3, if -0200 then pass -2).utc
bool: If set to True, utc time will be used, otherwise local time.
Returns:
(datetime.datetime, datetime.datetime) or (int, int) or (str, str)
- The parsed date range.
#
parse_date_stringParses the date_string function to the corresponding datetime object. Note: If possible (e.g. running Python 3), it is suggested to use dateutil.parser.parse or dateparser.parse functions instead.
Examples:
Arguments:
date_string
str: The date string to parse. (required)date_format
str: The date format of the date string. If the date format is known, it should be provided. (optional)
Returns:
(datetime.datetime, datetime.datetime)
- The parsed datetime.
#
parse_json_stringParse a JSON string into a Python dictionary.
Arguments:
json_string
str: The JSON string to be parsed.
Returns:
dict
-
#
pascalToSpaceConverts pascal strings to human readable (e.g. "ThreatScore" -> "Threat Score", "thisIsIPAddressName" -> "This Is IP Address Name"). Could be used as headerTransform
Arguments:
s
str: The string to be converted (required)
Returns:
str
- The converted string
#
polling_functionTo use on a function that should rerun itself Commands that use this decorator must have a Polling argument, polling: true in yaml, and a hidden hide_polling_output argument. Commands that use this decorator should return a PollResult. Will raise an DemistoException if the server version doesn't support Scheduled Commands (< 6.2.0)
Arguments:
name
str: The name of the commandinterval
int: How many seconds until the next runtimeout
int: How longpoll_message
str: The message to display in the war room while pollingrequires_polling_arg
bool: Whether a polling argument should be expected as one of the demisto args
Returns:
Function
- Decorator for polling functions
#
positiveFileChecks if the given entry from a file reputation query is positive (known bad) (deprecated)
Arguments:
entry
dict: File entry (required)
Returns:
bool
- True if bad, false otherwise
#
positiveIpChecks if the given entry from a file reputation query is positive (known bad) (deprecated)
Arguments:
entry
dict: IP entry (required)
Returns:
bool
- True if bad, false otherwise
#
positiveUrlChecks if the given entry from a URL reputation query is positive (known bad) (deprecated)
Arguments:
entry
dict: URL entry (required)
Returns:
bool
- True if bad, false otherwise
#
register_module_lineRegister a module in the line mapping for the traceback line correction algorithm.
Arguments:
module_name
str: The name of the module. (required)start_end
str: Whether to register the line as the start or the end of the module. Possible values: start, end. (required)line
int: the line number to record. (required)wrapper
int: Wrapper size (used for inline replacements with headers such as ApiModules). (optional)
#
register_signal_handler_profiling_dumpFunction that registers the threads and memory dump signal listener
Arguments:
profiling_dump_rows_limit
int: The max number of profiling related rows to print to the logprofiling_dump_rows_limit
int: The max number of profiling related rows to print to the log
#
remove_duplicates_from_list_argRemoves duplicates from a list after calling argToList. For example: args: {'ids': "1,2,1"}, field='ids' The return output will be ["1", "2"]
Arguments:
args
dict: Args to be converted (required)field
str: Field in args to be converted into list without duplicates (required)
Returns:
list
- A python list of args without duplicates
#
remove_empty_elementsRecursively remove empty lists, empty dicts, or None elements from a dictionary.
Arguments:
d
__: Input dictionary.
Returns:
dict
- Dictionary with all empty lists, and empty dictionaries removed.
#
remove_nulls_from_dictionaryRemove Null values from a dictionary. (updating the given dictionary)
Arguments:
data
dict: The data to be added to the context (required)
#
remove_old_incidents_idsRemoves old incident ids from the last run object to avoid overloading.
Arguments:
found_incidents_ids
dict: Dict of incidents idscurrent_time
int: The current epoch time to compare with the existing IDs added timelook_back
int: The look back time in minutes
Returns:
dict
- The new incidents ids
#
replace_in_keysReplace a substring in all of the keys of a dictionary (or list of dictionaries)
Arguments:
src
dict or list: The dictionary (or list of dictionaries) with keys that need replacement. (required)existing
str: substring to replace.new
str: new substring that will replace the existing substring.
Returns:
dict or list
- The dictionary (or list of dictionaries) with keys after substring replacement.
#
replace_spaces_in_credentialThis function is used in case of credential from type: 9 is in the wrong format of one line with spaces instead of multiple lines.
Arguments:
credential
str or None: the credential to replace spaces in.
otherwise the credential will be returned as is.
#
response_to_contextRecursively creates a data dictionary where all key starts with capital letters. If a key include underscores, removes underscores, capitalize every word. Example: "one_two" to "OneTwo
Arguments:
reponse_obj
Any: The response object to update. :user_predefiend_keys: An optional argument, a dict with predefined keys where the key is the key in the response and value is the key we want to turn the key into.
Returns:
Any
- A response with all keys (if there're any) starts with a capital letter.
#
retryretries to execute a function until an exception isn't raised anymore.
Arguments:
times
int: The number of times to trigger the retry mechanism.delay
int: The time in seconds to sleep between each timeexceptions
Exception: The exceptions that should be caught when executing the function (Union[tuple[type[Exception], ...], type[Exception]])
Returns:
Any
- Any
#
return_errorReturns error entry with given message and exits the script
Arguments:
message
str: The message to return to the entry (required)error
str or Exception: The raw error message to log (optional)outputs
dict or None: the outputs that will be returned to playbook/investigation context (optional)
Returns:
dict
- Error entry object
#
return_outputsDEPRECATED: use return_results() instead
This function wraps the demisto.results(), makes the usage of returning results to the user more intuitively.
Arguments:
readable_output
str | int: markdown string that will be presented in the warroom, should be human readable - (HumanReadable)outputs
dict: the outputs that will be returned to playbook/investigation context (originally EntryContext)raw_response
dict | list | str: must be dictionary, if not provided then will be equal to outputs. usually must be the original raw response from the 3rd party service (originally Contents)timeline
dict | list: expects a list, if a dict is passed it will be put into a list. used by server to populate an indicator's timeline. if the 'Category' field is not present in the timeline dict(s), it will automatically be be added to the dict(s) with its value set to 'Integration Update'.ignore_auto_extract
bool: expects a bool value. if true then the warroom entry readable_output will not be auto enriched.
#
return_resultsThis function wraps the demisto.results(), supports.
Arguments:
results
CommandResults or PollResult or str or dict or BaseWidget or list or GetMappingFieldsResponse or GetModifiedRemoteDataResponse or GetRemoteDataResponse: A result object to return as a War-Room entry.
#
return_warningReturns a warning entry with the specified message, and exits the script.
Arguments:
message
str: The message to return in the entry (required).exit
bool: Determines if the program will terminate after the command is executed. Default is False.warning
str: The warning message (raw) to log (optional).outputs
dict or None: The outputs that will be returned to playbook/investigation context (optional).ignore_auto_extract
bool: Determines if the War Room entry will be auto-enriched. Default is false.
Returns:
dict
- Warning entry object
#
safe_load_jsonSafely loads a JSON object from an argument. Allows the argument to accept either a JSON in string form, or an entry ID corresponding to a JSON file.
Arguments:
json_object
__: Entry ID or JSON string.
Returns:
dict
- Dictionary object from a parsed JSON file or string.
#
safe_sleepSleeps for the given duration, but raises an error if it would exceed the TTL.
Arguments:
duration_seconds
float: The desired sleep duration in seconds.
#
scoreToReputationConverts score (in number format) to human readable reputation format
Arguments:
score
int: The score to be formatted (required)
Returns:
str
- The formatted score
#
sectionsToMarkdownConverts a list of Demisto JSON tables to markdown string of tables
Arguments:
root
dict or list: The JSON table - List of dictionaries with the same keys or a single dictionary (required)
Returns:
str
- A string representation of the markdown table
#
send_data_to_xsiamSend the supported fetched data types into the XDR data-collector private api.
Arguments:
data
Union[str, list]: The data to send to XSIAM server. Should be of the following:
- List of strings or dicts where each string or dict represents an event or asset.
- String containing raw events separated by a new line.
vendor
str: The vendor corresponding to the integration that originated the data.product
str: The product corresponding to the integration that originated the data.data_format
str: Should only be filled in case the 'events' parameter contains a string of raw events in the format of 'leef' or 'cef'. In other cases the data_format will be set automatically.url_key
str: The param dict key where the integration url is located at. the default is 'url'.num_of_attempts
int: The num of attempts to do in case there is an api limit (429 error codes)chunk_size
int: Advanced - The maximal size of each chunk size we send to API. Limit of 9 MB will be inforced.data_type
str: Type of data to send to Xsiam, events or assets.should_update_health_module
bool: whether to trigger the health module showing how many events were sent to xsiam This can be useful when using send_data_to_xsiam in batches for the same fetch.add_proxy_to_request
bool: whether to add proxy to the send evnets request.snapshot_id
str: the snapshot id.items_count
str: the asset snapshot items count.multiple_threads
bool: whether to use multiple threads to send the events to xsiam or not. Note that when set to True, the updateModuleHealth should be done from the itnegration itself.
In case of running with multiple threads, the list of futures will hold the number of events sent and can be accessed by: for future in concurrent.futures.as_completed(futures): data_size += future.result()
#
send_events_to_xsiamSend the fetched events into the XDR data-collector private api.
Arguments:
events
Union[str, list]: The events to send to XSIAM server. Should be of the following:
- List of strings or dicts where each string or dict represents an event.
- String containing raw events separated by a new line.
vendor
str: The vendor corresponding to the integration that originated the events.product
str: The product corresponding to the integration that originated the events.data_format
str: Should only be filled in case the 'events' parameter contains a string of raw events in the format of 'leef' or 'cef'. In other cases the data_format will be set automatically.url_key
str: The param dict key where the integration url is located at. the default is 'url'.num_of_attempts
int: The num of attempts to do in case there is an api limit (429 error codes)chunk_size
int: Advanced - The maximal size of each chunk size we send to API. Limit of 9 MB will be inforced.should_update_health_module
bool: whether to trigger the health module showing how many events were sent to xsiamadd_proxy_to_request
bool: whether to add proxy to the send evnets request.multiple_threads
bool: whether to use multiple threads to send the events to xsiam or not.
In case of running with multiple threads, the list of futures will hold the number of events sent and can be accessed by: for future in concurrent.futures.as_completed(futures): data_size += future.result()
#
set_feed_last_runThis function sets the feed's last run: using demisto.setLastRun()
.
Arguments:
last_run_indicators
dict: Indicators to save in "lastRun" object.
#
set_integration_contextSets the integration context.
Arguments:
context
dict: The context to set.sync
bool: Whether to save the context directly to the DB.version
Any: The version of the context to set.
Returns:
dict
-
#
set_last_mirror_runThis function sets the last run of the mirror, from XSOAR version 6.6.0, by using demisto.setLastMirrorRun()
.
Before XSOAR version 6.6.0, we don't set the given data and an exception will be raised.
Arguments:
last_mirror_run
dict: Data to save in the "LastMirrorRun" object.
#
set_to_integration_context_with_retriesUpdate the integration context with a dictionary of keys and values with multiple attempts. The function supports merging the context keys using the provided object_keys parameter. If the version is too old by the time the context is set, another attempt will be made until the limit after a random sleep.
Arguments:
context
dict: A dictionary of keys and values to set.object_keys
dict: A dictionary to map between context keys and their unique ID for merging them.sync
bool: Whether to save the context directly to the DB.max_retry_times
int: The maximum number of attempts to try.
#
shortCrowdStrikeDisplay CrowdStrike Intel results in Markdown (deprecated)
Arguments:
entry
dict: CrowdStrike result entry (required)
Returns:
dict
- A Demisto entry containing the shortened CrowdStrike info
#
shortDomainFormats a domain reputation entry into a short table (deprecated)
Arguments:
entry
dict: Domain result entry (required)
Returns:
dict
- A Demisto entry containing the shortened domain info
#
shortFileFormats a file reputation entry into a short table (deprecated)
Arguments:
entry
dict: File result entry (required)
Returns:
dict
- A Demisto entry containing the shortened file info
#
shortIpFormats an ip reputation entry into a short table (deprecated)
Arguments:
entry
dict: IP result entry (required)
Returns:
dict
- A Demisto entry containing the shortened IP info
#
shortUrlFormats a URL reputation entry into a short table (deprecated)
Arguments:
entry
dict: URL result entry (required)
Returns:
dict
- A Demisto entry containing the shortened URL info
#
shorten_string_for_printingFunction that removes the middle of a long str, for printint or logging. If needed, it will replace the middle with '...',
Examples:
Arguments:
source_string
str: A long str that needs shortening.max_length
int: Maximum length of the returned str, should be higher than 0. Default is 64.
Returns:
str
- : A string no longer than max_length.
#
signal_handler_profiling_dumpListener function to dump the threads and memory to log info
Arguments:
_sig
int: The signal number_frame
Any: The current stack frame
#
skip_cert_verificationThe function deletes the self signed certificate env vars in order to http requests to skip certificate validation.
#
skip_proxyThe function deletes the proxy environment vars in order to http requests to skip routing through proxy
#
snakifyConvert all keys of a dictionary to snake_case (underscored separated)
Arguments:
src
dict: The dictionary to convert the keys for. (required)
Returns:
dict
- The dictionary (or list of dictionaries) with the keys in CamelCase.
#
split_data_to_chunksSplits a string of data into chunks of an approximately specified size. The actual size can be lower.
Arguments:
data
list or a string: A list of data or a string delimited with \n to split to chunks.target_chunk_size
int: The maximum size of each chunk. The maximal size allowed is 9MB.
Returns:
collections.Iterable[list]
- An iterable of lists where each list contains events with approx size of chunk size.
#
stringEscapeEscape newline chars in the given string.
Arguments:
st
str: The string to be modified (required).
Returns:
str
- A modified string.
#
stringEscapeMDEscape any chars that might break a markdown string
Arguments:
st
str: The string to be modified (required)minimal_escaping
bool: Whether replace all special characters or table format only (optional)escape_multiline
bool: Whether convert line-ending characters (optional)
Returns:
str
- A modified string
#
stringUnEscapeUnescape newline chars in the given string.
Arguments:
st
str: The string to be modified (required).
Returns:
str
- A modified string.
#
string_to_context_keyChecks if string, removes underscores, capitalize every word. Example: "one_two" to "OneTwo"
Arguments:
string
str: The string to be converted (required)
Returns:
str
- The converted string
#
string_to_table_headerChecks if string, change underscores to spaces, capitalize every word. Example: "one_two" to "One Two"
Arguments:
string
str: The string to be converted (required)
Returns:
str
- The converted string
#
support_multithreadingAdds lock on the calls to the Cortex XSOAR server from the Demisto object to support integration which use multithreading.
#
tableToMarkdownConverts a demisto table in JSON form to a Markdown table
Arguments:
name
str: The name of the table (required)t
dict or list: The JSON table - List of dictionaries with the same keys or a single dictionary (required)headers
list or string: A list of headers to be presented in the output table (by order). If string will be passed then table will have single header. Default will include all available headers.headerTransform
function: A function that formats the original data headers (optional)removeNull
bool: Remove empty columns from the table. Default is Falsemetadata
str: Metadata about the table contentsurl_keys
list: a list of keys in the given JSON table that should be turned in to clickabledate_fields
list: A list of date fields to format the value to human-readable output.json_transform_mapping
Dict[str, JsonTransformer]: A mapping between a header key to corresponding JsonTransformeris_auto_json_transform
bool: Boolean to try to auto transform complex jsonsort_headers
bool: Sorts the table based on its headers only if the headers parameter is not specified
Returns:
str
- A string representation of the markdown table
#
timestamp_to_datestringParses timestamp (milliseconds) to a date string in the provided date format (by default: ISO 8601 format) Examples: (1541494441222, 1541495441000, etc.)
Arguments:
timestamp
int or str: The timestamp to be parsed (required)date_format
str: The date format the timestamp should be parsed to. (optional)is_utc
bool: Should the string representation of the timestamp use UTC time or the local machine time
Returns:
str
- The parsed timestamp in the date_format
#
underscoreToCamelCaseConvert an underscore separated string to camel case
Arguments:
s
str: The string to convert (e.g. hello_world) (required)upper_camel
bool: When True then transforms dictionarykeys to camel case with the first letter capitalised (for example: demisto_content to DemistoContent), otherwise the first letter will not be capitalised (for example: demisto_content to demistoContent).
Returns:
str
- The converted string (e.g. HelloWorld)
#
update_integration_contextUpdate the integration context with a given dictionary after merging it with the latest integration context.
Arguments:
context
dict: The keys and values to update in the integration context.object_keys
dict: A dictionary to map between context keys and their unique ID for merging them with the latest context.sync
bool: Whether to use the context directly from the DB.
Returns:
tuple
-
#
update_last_run_objectUpdates the LastRun object with the next fetch time and limit and with the new fetched incident IDs.
Arguments:
last_run
dict: The LastRun objectincidents
list: List of the incidents resultfetch_limit
int: The fetch limitstart_fetch_time
str: The time the fetch started to fetch fromend_fetch_time
str: The end time in which the fetch incidents endedlook_back
int: The time to look back in fetch in minutescreated_time_field
str: The incident created time fieldid_field
str: The incident id fielddate_format
str: The date formatincrease_last_run_time
bool: Whether to increase the last run time with one millisecondnew_offset
int | None: The new offset to set in the last run
Returns:
Dict
- The updated LastRun object
#
url_to_clickable_markdownTurn the given urls fields in to clickable url, used for the markdown table.
Arguments:
data
[Union[str, List[Any], Dict[str, Any]]]: a dictionary or a list containing data with some values that are urlsurl_keys
List[str]: the keys of the url's wished to turn clickable
Returns:
[Union[str, List[Any], Dict[str, Any]]]
- markdown format for clickable url
#
urljoinWill join url and its suffix
Example: "https://google.com/", "/" => "https://google.com/" "https://google.com", "/" => "https://google.com/" "https://google.com", "api" => "https://google.com/api" "https://google.com", "/api" => "https://google.com/api" "https://google.com/", "api" => "https://google.com/api" "https://google.com/", "/api" => "https://google.com/api"
Arguments:
url
string: URL string (required)suffix
string: the second part of the url
Returns:
string
- Full joined url
#
vtCountPositivesCounts the number of detected URLs in the entry
Arguments:
entry
dict: Demisto entry (required)
Returns:
int
- The number of detected URLs
#
xml2jsonConvert an XML string into a JSON string.
Arguments:
xmlstring
str: The string to be converted (required)
Returns:
dict or list
- The converted JSON
#
xsiam_api_call_with_retriesSend the fetched events or assests into the XDR data-collector private api.
Arguments:
client
BaseClient: base client containing the XSIAM url.xsiam_url
str: The URL of XSIAM to send the api request.zipped_data
bytes: encoded eventsheaders
dict: headers for the requesterror_msg
str: The error message prefix in case of an error.num_of_attempts
int: The num of attempts to do in case there is an api limit (429 error codes).events_error_handler
callable: error handler functiondata_type
str: events or assets
Returns:
requests.Response or DemistoException
- Response object or DemistoException