Skip to content

Commit 7f47f4d

Browse files
committed
added silentpush-list-domain-infratags
1 parent e446541 commit 7f47f4d

File tree

2 files changed

+105
-5
lines changed

2 files changed

+105
-5
lines changed

Packs/SilentPush/Integrations/SilentPush/SilentPush.py

Lines changed: 77 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,7 @@ def search_domains(self,
157157
"""
158158
demisto.debug(f'Searching domains with query: {query}')
159159
url_suffix = 'explore/domain/search'
160-
161-
# Build parameters dictionary with only non-None values
160+
162161
params = {k: v for k, v in {
163162
'query': query,
164163
'start_date': start_date,
@@ -169,7 +168,41 @@ def search_domains(self,
169168
}.items() if v is not None}
170169

171170
return self._http_request('GET', url_suffix, params=params)
171+
172+
def list_domain_infratags(self, domains: list, cluster: Optional[bool] = False, mode: Optional[str] = 'live', match: Optional[str] = 'self', as_of: Optional[str] = None) -> dict:
173+
"""
174+
Get infratags for multiple domains with optional clustering and additional filtering options.
175+
176+
Args:
177+
domains (list): A list of domains to retrieve infratags for.
178+
cluster (bool, optional): Whether to cluster the results. Defaults to False.
179+
mode (str, optional): Mode for the lookup, either 'live' (default) or 'padns'.
180+
match (str, optional): Handling of self-hosted infrastructure, either 'self' (default) or 'full'.
181+
as_of (str, optional): Date or timestamp for filtering the data.
172182
183+
Returns:
184+
dict: A dictionary containing infratags for the provided domains.
185+
"""
186+
demisto.debug(f'Fetching infratags for domains: {domains} with cluster={cluster}, mode={mode}, match={match}, as_of={as_of}')
187+
188+
# Loop through the domains to create individual requests
189+
results = {}
190+
for domain in domains:
191+
url = f'https://api.silentpush.com/api/v1/merge-api/explore/domain/infratag/{domain}'
192+
data = {
193+
'cluster': cluster,
194+
'mode': mode,
195+
'match': match,
196+
'as_of': as_of
197+
}
198+
try:
199+
response = self._http_request('GET', url, params=data) # Assuming GET method for this endpoint
200+
results[domain] = response
201+
except Exception as e:
202+
demisto.error(f"Error fetching infratags for domain {domain}: {str(e)}")
203+
results[domain] = {"error": str(e)}
204+
205+
return results
173206

174207
def test_module(client: Client) -> str:
175208
"""
@@ -215,7 +248,6 @@ def list_domain_information_command(client: Client, args: dict) -> CommandResult
215248
"""
216249
domain = args.get('domain', 'silentpush.com')
217250
demisto.debug(f'Processing domain: {domain}')
218-
219251
raw_response = client.list_domain_information(domain)
220252
demisto.debug(f'Response from API: {raw_response}')
221253

@@ -256,7 +288,6 @@ def get_domain_certificates_command(client: Client, args: dict) -> CommandResult
256288

257289
def search_domains_command(client: Client, args: dict) -> CommandResults:
258290

259-
# Extract parameters from args with type conversion
260291
query = args.get('query')
261292
start_date = args.get('start_date')
262293
end_date = args.get('end_date')
@@ -284,6 +315,47 @@ def search_domains_command(client: Client, args: dict) -> CommandResults:
284315
readable_output=readable_output,
285316
raw_response=raw_response
286317
)
318+
319+
def list_domain_infratags_command(client: Client, args: dict) -> CommandResults:
320+
"""
321+
Command handler for fetching infratags for multiple domains.
322+
323+
Args:
324+
client (Client): The client instance to fetch the data.
325+
args (dict): The arguments passed to the command, including domains, clustering option, and optional filters.
326+
327+
Returns:
328+
CommandResults: The command results containing readable output and the raw response.
329+
"""
330+
331+
domains = argToList(args.get('domains', ''))
332+
cluster = argToBoolean(args.get('cluster', False))
333+
mode = args.get('mode', 'live') # Default to 'live'
334+
match = args.get('match', 'self') # Default to 'self'
335+
as_of = args.get('as_of', None) # Default to None
336+
337+
if not domains:
338+
raise ValueError('"domains" argument is required and cannot be empty.')
339+
340+
demisto.debug(f'Processing infratags for domains: {domains} with cluster={cluster}, mode={mode}, match={match}, as_of={as_of}')
341+
342+
try:
343+
raw_response = client.list_domain_infratags(domains, cluster, mode, match, as_of)
344+
demisto.debug(f'Response from API: {raw_response}')
345+
except Exception as e:
346+
demisto.error(f'Error occurred while fetching infratags: {str(e)}')
347+
raise
348+
349+
readable_output = tableToMarkdown('Domain Infratags', raw_response.get('results', []))
350+
351+
return CommandResults(
352+
outputs_prefix='SilentPush.InfraTags',
353+
outputs_key_field='domain',
354+
outputs=raw_response,
355+
readable_output=readable_output,
356+
raw_response=raw_response
357+
)
358+
287359

288360

289361
''' MAIN FUNCTION '''
@@ -326,6 +398,7 @@ def main():
326398
'silentpush-list-domain-information': list_domain_information_command,
327399
'silentpush-get-domain-certificates': get_domain_certificates_command,
328400
'silentpush-search-domains': search_domains_command,
401+
'silentpush-list-domain-infratags': list_domain_infratags_command,
329402
}
330403

331404
if command in command_handlers:

Packs/SilentPush/Integrations/SilentPush/SilentPush.yml

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,34 @@ script:
9898
description: The domain name in the search results
9999
type: string
100100

101+
- name: silentpush-list-domain-infratags
102+
description: Fetches infratag information for a given domain
103+
arguments:
104+
- name: domain
105+
description: The domain to fetch infratags for
106+
required: true
107+
default: false
108+
- name: mode
109+
description: The mode for fetching infratags (live or padns)
110+
required: false
111+
default: "live"
112+
- name: match
113+
description: How to handle self-hosted infrastructure (self or full)
114+
required: false
115+
default: "self"
116+
- name: as_of
117+
description: The date or epoch time to use for fetching infratags from PADNS data
118+
required: false
119+
default: false
120+
outputs:
121+
- contextPath: SilentPush.Infratags
122+
description: Infratag information for the domain
123+
type: unknown
124+
- contextPath: SilentPush.Infratags.domain
125+
description: The domain name
126+
type: string
127+
101128
dockerimage: demisto/python3:3.10
102129
fromversion: 6.0.0
103130
tests:
104-
- No tests
131+
- No tests

0 commit comments

Comments
 (0)