Debian Codegraph @

ansible_collections/splunk/es/plugins/modules/splunk_correlation_searches.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright 2022 Red Hat
5 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 DOCUMENTATION = """
8 ---
9 module: splunk_correlation_searches
10 short_description: Splunk Enterprise Security Correlation searches resource module
11 description:
12 - This module allows for creation, deletion, and modification of Splunk
13 Enterprise Security correlation searches
14 - Tested against Splunk Enterprise Server v8.2.3 with Splunk Enterprise Security v7.0.1
15 installed on it.
16 version_added: "2.1.0"
17 options:
18 config:
19 description:
20 - Configure file and directory monitoring on the system
21 type: list
22 elements: dict
23 suboptions:
24 name:
25 description:
26 - Name of correlation search
27 type: str
28 required: true
29 disabled:
30 description:
31 - Disable correlation search
32 type: bool
33 default: false
34 description:
35 description:
36 - Description of the coorelation search, this will populate the description field for the web console
37 type: str
38 search:
39 description:
40 - SPL search string
41 type: str
42 app:
43 description:
44 - Splunk app to associate the correlation seach with
45 type: str
46 default: "SplunkEnterpriseSecuritySuite"
47 annotations:
48 description:
49 - Add context from industry standard cyber security mappings in Splunk Enterprise Security
50 or custom annotations
51 type: dict
52 suboptions:
53 cis20:
54 description:
55 - Specify CIS20 annotations
56 type: list
57 elements: str
58 kill_chain_phases:
59 description:
60 - Specify Kill 10 annotations
61 type: list
62 elements: str
63 mitre_attack:
64 description:
65 - Specify MITRE ATTACK annotations
66 type: list
67 elements: str
68 nist:
69 description:
70 - Specify NIST annotations
71 type: list
72 elements: str
73 custom:
74 description:
75 - Specify custom framework and custom annotations
76 type: list
77 elements: dict
78 suboptions:
79 framework:
80 description:
81 - Specify annotation framework
82 type: str
83 custom_annotations:
84 description:
85 - Specify annotations associated with custom framework
86 type: list
87 elements: str
88 ui_dispatch_context:
89 description:
90 - Set an app to use for links such as the drill-down search in a notable
91 event or links in an email adaptive response action. If None, uses the
92 Application Context.
93 type: str
94 time_earliest:
95 description:
96 - Earliest time using relative time modifiers.
97 type: str
98 default: "-24h"
99 time_latest:
100 description:
101 - Latest time using relative time modifiers.
102 type: str
103 default: "now"
104 cron_schedule:
105 description:
106 - Enter a cron-style schedule.
107 - For example C('*/5 * * * *') (every 5 minutes) or C('0 21 * * *') (every day at 9 PM).
108 - Real-time searches use a default schedule of C('*/5 * * * *').
109 type: str
110 default: "*/5 * * * *"
111 scheduling:
112 description:
113 - Controls the way the scheduler computes the next execution time of a scheduled search.
114 - >
115 Learn more:
116 https://docs.splunk.com/Documentation/Splunk/7.2.3/Report/Configurethepriorityofscheduledreports#Real-time_scheduling_and_continuous_scheduling
117 type: str
118 default: "realtime"
119 choices:
120 - "realtime"
121 - "continuous"
122 schedule_window:
123 description:
124 - Let report run at any time within a window that opens at its scheduled run time,
125 to improve efficiency when there are many concurrently scheduled reports.
126 The "auto" setting automatically determines the best window width for the report.
127 type: str
128 default: "0"
129 schedule_priority:
130 description:
131 - Raise the scheduling priority of a report. Set to "Higher" to prioritize
132 it above other searches of the same scheduling mode, or "Highest" to
133 prioritize it above other searches regardless of mode. Use with discretion.
134 type: str
135 default: "default"
136 choices:
137 - "default"
138 - "higher"
139 - "highest"
140 trigger_alert:
141 description:
142 - Notable response actions and risk response actions are always triggered for each result.
143 Choose whether the trigger is activated once or for each result.
144 type: str
145 default: "once"
146 choices:
147 - "once"
148 - "for each result"
149 trigger_alert_when:
150 description:
151 - Raise the scheduling priority of a report. Set to "Higher" to prioritize
152 it above other searches of the same scheduling mode, or "Highest" to
153 prioritize it above other searches regardless of mode. Use with discretion.
154 type: str
155 default: "number of events"
156 choices:
157 - "number of events"
158 - "number of results"
159 - "number of hosts"
160 - "number of sources"
161 trigger_alert_when_condition:
162 description:
163 - Conditional to pass to C(trigger_alert_when)
164 type: str
165 default: "greater than"
166 choices:
167 - "greater than"
168 - "less than"
169 - "equal to"
170 - "not equal to"
171 - "drops by"
172 - "rises by"
173 trigger_alert_when_value:
174 description:
175 - Value to pass to C(trigger_alert_when)
176 type: str
177 default: "10"
178 throttle_window_duration:
179 description:
180 - How much time to ignore other events that match the field values specified in Fields to group by.
181 type: str
182 throttle_fields_to_group_by:
183 description:
184 - Type the fields to consider for matching events for throttling.
185 type: list
186 elements: str
187 suppress_alerts:
188 description:
189 - To suppress alerts from this correlation search or not
190 type: bool
191 default: false
192 running_config:
193 description:
194 - The module, by default, will connect to the remote device and retrieve the current
195 running-config to use as a base for comparing against the contents of source.
196 There are times when it is not desirable to have the task get the current running-config
197 for every task in a playbook. The I(running_config) argument allows the implementer
198 to pass in the configuration to use as the base config for comparison. This
199 value of this option should be the output received from device by executing
200 command.
201 type: str
202 state:
203 description:
204 - The state the configuration should be left in
205 type: str
206 choices:
207 - merged
208 - replaced
209 - deleted
210 - gathered
211 default: merged
212
213 author: Ansible Security Automation Team (@pranav-bhatt) <https://github.com/ansible-security>
214 """
215
216 EXAMPLES = """
217 # Using gathered
218 # --------------
219
220 - name: Gather correlation searches config
221 splunk.es.splunk_correlation_searches:
222 config:
223 - name: Ansible Test
224 - name: Ansible Test 2
225 state: gathered
226
227 # RUN output:
228 # -----------
229
230 # "gathered": [
231 # {
232 # "annotations": {
233 # "cis20": [
234 # "test1"
235 # ],
236 # "custom": [
237 # {
238 # "custom_annotations": [
239 # "test5"
240 # ],
241 # "framework": "test_framework"
242 # }
243 # ],
244 # "kill_chain_phases": [
245 # "test3"
246 # ],
247 # "mitre_attack": [
248 # "test2"
249 # ],
250 # "nist": [
251 # "test4"
252 # ]
253 # },
254 # "app": "DA-ESS-EndpointProtection",
255 # "cron_schedule": "*/5 * * * *",
256 # "description": "test description",
257 # "disabled": false,
258 # "name": "Ansible Test",
259 # "schedule_priority": "default",
260 # "schedule_window": "0",
261 # "scheduling": "realtime",
262 # "search": '| tstats summariesonly=true values(\"Authentication.tag\") as \"tag\",dc(\"Authentication.user\") as \"user_count\",dc(\"Authent'
263 # 'ication.dest\") as \"dest_count\",count from datamodel=\"Authentication\".\"Authentication\" where nodename=\"Authentication.Fai'
264 # 'led_Authentication\" by \"Authentication.app\",\"Authentication.src\" | rename \"Authentication.app\" as \"app\",\"Authenticatio'
265 # 'n.src\" as \"src\" | where \"count\">=6',
266 # "suppress_alerts": false,
267 # "throttle_fields_to_group_by": [
268 # "test_field1"
269 # ],
270 # "throttle_window_duration": "5s",
271 # "time_earliest": "-24h",
272 # "time_latest": "now",
273 # "trigger_alert": "once",
274 # "trigger_alert_when": "number of events",
275 # "trigger_alert_when_condition": "greater than",
276 # "trigger_alert_when_value": "10",
277 # "ui_dispatch_context": "SplunkEnterpriseSecuritySuite"
278 # }
279 # ]
280
281 # Using merged
282 # ------------
283
284 - name: Merge and create new correlation searches configuration
285 splunk.es.splunk_correlation_searches:
286 config:
287 - name: Ansible Test
288 disabled: false
289 description: test description
290 app: DA-ESS-EndpointProtection
291 annotations:
292 cis20:
293 - test1
294 mitre_attack:
295 - test2
296 kill_chain_phases:
297 - test3
298 nist:
299 - test4
300 custom:
301 - framework: test_framework
302 custom_annotations:
303 - test5
304 ui_dispatch_context: SplunkEnterpriseSecuritySuite
305 time_earliest: -24h
306 time_latest: now
307 cron_schedule: "*/5 * * * *"
308 scheduling: realtime
309 schedule_window: "0"
310 schedule_priority: default
311 trigger_alert: once
312 trigger_alert_when: number of events
313 trigger_alert_when_condition: greater than
314 trigger_alert_when_value: "10"
315 throttle_window_duration: 5s
316 throttle_fields_to_group_by:
317 - test_field1
318 suppress_alerts: false
319 search: >
320 '| tstats summariesonly=true values(\"Authentication.tag\") as \"tag\",dc(\"Authentication.user\") as \"user_count\",dc(\"Authent'
321 'ication.dest\") as \"dest_count\",count from datamodel=\"Authentication\".\"Authentication\" where nodename=\"Authentication.Fai'
322 'led_Authentication\" by \"Authentication.app\",\"Authentication.src\" | rename \"Authentication.app\" as \"app\",\"Authenticatio'
323 'n.src\" as \"src\" | where \"count\">=6'
324 state: merged
325
326 # RUN output:
327 # -----------
328
329 # "after": [
330 # {
331 # "annotations": {
332 # "cis20": [
333 # "test1"
334 # ],
335 # "custom": [
336 # {
337 # "custom_annotations": [
338 # "test5"
339 # ],
340 # "framework": "test_framework"
341 # }
342 # ],
343 # "kill_chain_phases": [
344 # "test3"
345 # ],
346 # "mitre_attack": [
347 # "test2"
348 # ],
349 # "nist": [
350 # "test4"
351 # ]
352 # },
353 # "app": "DA-ESS-EndpointProtection",
354 # "cron_schedule": "*/5 * * * *",
355 # "description": "test description",
356 # "disabled": false,
357 # "name": "Ansible Test",
358 # "schedule_priority": "default",
359 # "schedule_window": "0",
360 # "scheduling": "realtime",
361 # "search": '| tstats summariesonly=true values(\"Authentication.tag\") as \"tag\",dc(\"Authentication.user\") as \"user_count\",dc(\"Authent'
362 # 'ication.dest\") as \"dest_count\",count from datamodel=\"Authentication\".\"Authentication\" where nodename=\"Authentication.Fai'
363 # 'led_Authentication\" by \"Authentication.app\",\"Authentication.src\" | rename \"Authentication.app\" as \"app\",\"Authenticatio'
364 # 'n.src\" as \"src\" | where \"count\">=6',
365 # "suppress_alerts": false,
366 # "throttle_fields_to_group_by": [
367 # "test_field1"
368 # ],
369 # "throttle_window_duration": "5s",
370 # "time_earliest": "-24h",
371 # "time_latest": "now",
372 # "trigger_alert": "once",
373 # "trigger_alert_when": "number of events",
374 # "trigger_alert_when_condition": "greater than",
375 # "trigger_alert_when_value": "10",
376 # "ui_dispatch_context": "SplunkEnterpriseSecuritySuite"
377 # },
378 # ],
379 # "before": [],
380
381 # Using replaced
382 # --------------
383
384 - name: Replace existing correlation searches configuration
385 splunk.es.splunk_correlation_searches:
386 state: replaced
387 config:
388 - name: Ansible Test
389 disabled: false
390 description: test description
391 app: SplunkEnterpriseSecuritySuite
392 annotations:
393 cis20:
394 - test1
395 - test2
396 mitre_attack:
397 - test3
398 - test4
399 kill_chain_phases:
400 - test5
401 - test6
402 nist:
403 - test7
404 - test8
405 custom:
406 - framework: test_framework2
407 custom_annotations:
408 - test9
409 - test10
410 ui_dispatch_context: SplunkEnterpriseSecuritySuite
411 time_earliest: -24h
412 time_latest: now
413 cron_schedule: "*/5 * * * *"
414 scheduling: continuous
415 schedule_window: auto
416 schedule_priority: default
417 trigger_alert: once
418 trigger_alert_when: number of events
419 trigger_alert_when_condition: greater than
420 trigger_alert_when_value: 10
421 throttle_window_duration: 5s
422 throttle_fields_to_group_by:
423 - test_field1
424 - test_field2
425 suppress_alerts: true
426 search: >
427 '| tstats summariesonly=true values(\"Authentication.tag\") as \"tag\",dc(\"Authentication.user\") as \"user_count\",dc(\"Authent'
428 'ication.dest\") as \"dest_count\",count from datamodel=\"Authentication\".\"Authentication\" where nodename=\"Authentication.Fai'
429 'led_Authentication\" by \"Authentication.app\",\"Authentication.src\" | rename \"Authentication.app\" as \"app\",\"Authenticatio'
430 'n.src\" as \"src\" | where \"count\">=6'
431
432 # RUN output:
433 # -----------
434
435 # "after": [
436 # {
437 # "annotations": {
438 # "cis20": [
439 # "test1",
440 # "test2"
441 # ],
442 # "custom": [
443 # {
444 # "custom_annotations": [
445 # "test9",
446 # "test10"
447 # ],
448 # "framework": "test_framework2"
449 # }
450 # ],
451 # "kill_chain_phases": [
452 # "test5",
453 # "test6"
454 # ],
455 # "mitre_attack": [
456 # "test3",
457 # "test4"
458 # ],
459 # "nist": [
460 # "test7",
461 # "test8"
462 # ]
463 # },
464 # "app": "SplunkEnterpriseSecuritySuite",
465 # "cron_schedule": "*/5 * * * *",
466 # "description": "test description",
467 # "disabled": false,
468 # "name": "Ansible Test",
469 # "schedule_priority": "default",
470 # "schedule_window": "auto",
471 # "scheduling": "continuous",
472 # "search": '| tstats summariesonly=true values(\"Authentication.tag\") as \"tag\",dc(\"Authentication.user\") as \"user_count\",dc(\"Authent'
473 # 'ication.dest\") as \"dest_count\",count from datamodel=\"Authentication\".\"Authentication\" where nodename=\"Authentication.Fai'
474 # 'led_Authentication\" by \"Authentication.app\",\"Authentication.src\" | rename \"Authentication.app\" as \"app\",\"Authenticatio'
475 # 'n.src\" as \"src\" | where \"count\">=6',
476 # "suppress_alerts": true,
477 # "throttle_fields_to_group_by": [
478 # "test_field1",
479 # "test_field2"
480 # ],
481 # "throttle_window_duration": "5s",
482 # "time_earliest": "-24h",
483 # "time_latest": "now",
484 # "trigger_alert": "once",
485 # "trigger_alert_when": "number of events",
486 # "trigger_alert_when_condition": "greater than",
487 # "trigger_alert_when_value": "10",
488 # "ui_dispatch_context": "SplunkEnterpriseSecuritySuite"
489 # }
490 # ],
491 # "before": [
492 # {
493 # "annotations": {
494 # "cis20": [
495 # "test1"
496 # ],
497 # "custom": [
498 # {
499 # "custom_annotations": [
500 # "test5"
501 # ],
502 # "framework": "test_framework"
503 # }
504 # ],
505 # "kill_chain_phases": [
506 # "test3"
507 # ],
508 # "mitre_attack": [
509 # "test2"
510 # ],
511 # "nist": [
512 # "test4"
513 # ]
514 # },
515 # "app": "DA-ESS-EndpointProtection",
516 # "cron_schedule": "*/5 * * * *",
517 # "description": "test description",
518 # "disabled": false,
519 # "name": "Ansible Test",
520 # "schedule_priority": "default",
521 # "schedule_window": "0",
522 # "scheduling": "realtime",
523 # "search": '| tstats summariesonly=true values(\"Authentication.tag\") as \"tag\",dc(\"Authentication.user\") as \"user_count\",dc(\"Authent'
524 # 'ication.dest\") as \"dest_count\",count from datamodel=\"Authentication\".\"Authentication\" where nodename=\"Authentication.Fai'
525 # 'led_Authentication\" by \"Authentication.app\",\"Authentication.src\" | rename \"Authentication.app\" as \"app\",\"Authenticatio'
526 # 'n.src\" as \"src\" | where \"count\">=6',
527 # "suppress_alerts": false,
528 # "throttle_fields_to_group_by": [
529 # "test_field1"
530 # ],
531 # "throttle_window_duration": "5s",
532 # "time_earliest": "-24h",
533 # "time_latest": "now",
534 # "trigger_alert": "once",
535 # "trigger_alert_when": "number of events",
536 # "trigger_alert_when_condition": "greater than",
537 # "trigger_alert_when_value": "10",
538 # "ui_dispatch_context": "SplunkEnterpriseSecuritySuite"
539 # }
540 # ]
541
542 # Using deleted
543 # -------------
544
545 - name: Example to delete the corelation search
546 splunk.es.splunk_correlation_searches:
547 config:
548 - name: Ansible Test
549 state: deleted
550
551 # RUN output:
552 # -----------
553
554 # "after": [],
555 # "before": [
556 # {
557 # "annotations": {
558 # "cis20": [
559 # "test1"
560 # ],
561 # "custom": [
562 # {
563 # "custom_annotations": [
564 # "test5"
565 # ],
566 # "framework": "test_framework"
567 # }
568 # ],
569 # "kill_chain_phases": [
570 # "test3"
571 # ],
572 # "mitre_attack": [
573 # "test2"
574 # ],
575 # "nist": [
576 # "test4"
577 # ]
578 # },
579 # "app": "DA-ESS-EndpointProtection",
580 # "cron_schedule": "*/5 * * * *",
581 # "description": "test description",
582 # "disabled": false,
583 # "name": "Ansible Test",
584 # "schedule_priority": "default",
585 # "schedule_window": "0",
586 # "scheduling": "realtime",
587 # "search": '| tstats summariesonly=true values(\"Authentication.tag\") as \"tag\",dc(\"Authentication.user\") as \"user_count\",dc(\"Authent'
588 # 'ication.dest\") as \"dest_count\",count from datamodel=\"Authentication\".\"Authentication\" where nodename=\"Authentication.Fai'
589 # 'led_Authentication\" by \"Authentication.app\",\"Authentication.src\" | rename \"Authentication.app\" as \"app\",\"Authenticatio'
590 # 'n.src\" as \"src\" | where \"count\">=6',
591 # "suppress_alerts": false,
592 # "throttle_fields_to_group_by": [
593 # "test_field1"
594 # ],
595 # "throttle_window_duration": "5s",
596 # "time_earliest": "-24h",
597 # "time_latest": "now",
598 # "trigger_alert": "once",
599 # "trigger_alert_when": "number of events",
600 # "trigger_alert_when_condition": "greater than",
601 # "trigger_alert_when_value": "10",
602 # "ui_dispatch_context": "SplunkEnterpriseSecuritySuite"
603 # },
604 # ],
605 """
606
607 RETURN = """
608 before:
609 description: The configuration as structured data prior to module invocation.
610 returned: always
611 type: list
612 sample: The configuration returned will always be in the same format of the parameters above.
613 after:
614 description: The configuration as structured data after module completion.
615 returned: when changed
616 type: list
617 sample: The configuration returned will always be in the same format of the parameters above.
618 gathered:
619 description: Facts about the network resource gathered from the remote device as structured data.
620 returned: when state is I(gathered)
621 type: dict
622 sample: >
623 This output will always be in the same format as the
624 module argspec.
625 """