@@ -187,12 +187,15 @@ def remove_user_from_departing_employee(self, username):
187
187
self ._get_sdk ().detectionlists .departing_employee .remove (user_id )
188
188
return user_id
189
189
190
- def get_all_departing_employees (self ):
190
+ def get_all_departing_employees (self , results ):
191
191
res = []
192
192
pages = self ._get_sdk ().detectionlists .departing_employee .get_all ()
193
193
for page in pages :
194
194
employees = page ["items" ]
195
- res .extend (employees )
195
+ for employee in employees :
196
+ res .append (employee )
197
+ if len (res ) == results :
198
+ return res
196
199
return res
197
200
198
201
def add_user_to_high_risk_employee (self , username , note = None ):
@@ -219,12 +222,16 @@ def remove_user_risk_tags(self, username, risk_tags):
219
222
self ._get_sdk ().detectionlists .remove_user_risk_tags (user_id , risk_tags )
220
223
return user_id
221
224
222
- def get_all_high_risk_employees (self , risk_tags = None ):
225
+ def get_all_high_risk_employees (self , risk_tags , results ):
223
226
risk_tags = _try_convert_str_list_to_list (risk_tags )
224
227
res = []
225
228
pages = self ._get_sdk ().detectionlists .high_risk_employee .get_all ()
226
229
for page in pages :
227
- res .extend (_get_all_high_risk_employees_from_page (page , risk_tags ))
230
+ employees = _get_all_high_risk_employees_from_page (page , risk_tags )
231
+ for employee in employees :
232
+ res .append (employee )
233
+ if len (res ) == results :
234
+ return res
228
235
return res
229
236
230
237
def fetch_alerts (self , start_time , event_severity_filter ):
@@ -578,8 +585,9 @@ def departingemployee_remove_command(client, args):
578
585
579
586
@logger
580
587
def departingemployee_get_all_command (client , args ):
588
+ results = args .get ("results" ) or 50
581
589
try :
582
- employees = client .get_all_departing_employees ()
590
+ employees = client .get_all_departing_employees (results )
583
591
employees_context = [
584
592
{
585
593
"UserID" : e ["userId" ],
@@ -629,10 +637,11 @@ def highriskemployee_remove_command(client, args):
629
637
@logger
630
638
def highriskemployee_get_all_command (client , args ):
631
639
tags = args .get ("risktags" )
640
+ results = args .get ("results" )
632
641
try :
633
- employees = client .get_all_high_risk_employees (tags )
642
+ employees = client .get_all_high_risk_employees (tags , results )
634
643
employees_context = [
635
- {"UserID" : e [ "userId" ] , "Username" : e [ "userName" ] , "Note" : e [ "notes" ] }
644
+ {"UserID" : e . get ( "userId" ) , "Username" : e . get ( "userName" ) , "Note" : e . get ( "notes" ) }
636
645
for e in employees
637
646
]
638
647
readable_outputs = tableToMarkdown ("Retrieved All High Risk Employees" , employees_context )
@@ -671,6 +680,36 @@ def highriskemployee_remove_risk_tags_command(client, args):
671
680
return_error (create_command_error_message (demisto .command (), e ))
672
681
673
682
683
+ @logger
684
+ def securitydata_search_command (client , args ):
685
+ code42_security_data_context = []
686
+ _json = args .get ("json" )
687
+ file_context = []
688
+ # If JSON payload is passed as an argument, ignore all other args and search by JSON payload
689
+ if _json is not None :
690
+ file_events = client .search_file_events (_json )
691
+ else :
692
+ # Build payload
693
+ payload = build_query_payload (args )
694
+ file_events = client .search_file_events (payload )
695
+ if file_events :
696
+ for file_event in file_events :
697
+ code42_context_event = map_to_code42_event_context (file_event )
698
+ code42_security_data_context .append (code42_context_event )
699
+ file_context_event = map_to_file_context (file_event )
700
+ file_context .append (file_context_event )
701
+ readable_outputs = tableToMarkdown (
702
+ "Code42 Security Data Results" ,
703
+ code42_security_data_context ,
704
+ headers = SECURITY_EVENT_HEADERS ,
705
+ )
706
+ security_data_context_key = "Code42.SecurityData(val.EventID && val.EventID == obj.EventID)"
707
+ context = {security_data_context_key : code42_security_data_context , "File" : file_context }
708
+ return readable_outputs , context , file_events
709
+ else :
710
+ return "No results found" , {}, {}
711
+
712
+
674
713
def _create_incident_from_alert_details (details ):
675
714
return {"name" : "Code42 - {}" .format (details ["name" ]), "occurred" : details ["createdAt" ]}
676
715
@@ -680,7 +719,7 @@ def _stringify_lists_if_needed(event):
680
719
shared_with = event .get ("sharedWith" )
681
720
private_ip_addresses = event .get ("privateIpAddresses" )
682
721
if shared_with :
683
- shared_list = [u [ "cloudUsername" ] for u in shared_with ]
722
+ shared_list = [u . get ( "cloudUsername" ) for u in shared_with if u . get ( "cloudUsername" ) ]
684
723
event ["sharedWith" ] = str (shared_list )
685
724
if private_ip_addresses :
686
725
event ["privateIpAddresses" ] = str (private_ip_addresses )
@@ -729,7 +768,7 @@ def _fetch_remaining_incidents_from_last_run(self):
729
768
if remaining_incidents :
730
769
return (
731
770
self ._last_run ,
732
- remaining_incidents [: self ._fetch_limit ],
771
+ remaining_incidents [:self ._fetch_limit ],
733
772
remaining_incidents [self ._fetch_limit :],
734
773
)
735
774
@@ -759,7 +798,11 @@ def _create_incident_from_alert(self, alert):
759
798
return incident
760
799
761
800
def _relate_files_to_alert (self , alert_details ):
762
- for obs in alert_details ["observations" ]:
801
+ observations = alert_details .get ("observations" )
802
+ if not observations :
803
+ alert_details ["fileevents" ] = []
804
+ return
805
+ for obs in observations :
763
806
file_events = self ._get_file_events_from_alert_details (obs , alert_details )
764
807
alert_details ["fileevents" ] = [_process_event_from_observation (e ) for e in file_events ]
765
808
@@ -789,36 +832,6 @@ def fetch_incidents(
789
832
return fetcher .fetch ()
790
833
791
834
792
- @logger
793
- def securitydata_search_command (client , args ):
794
- code42_security_data_context = []
795
- _json = args .get ("json" )
796
- file_context = []
797
- # If JSON payload is passed as an argument, ignore all other args and search by JSON payload
798
- if _json is not None :
799
- file_events = client .search_file_events (_json )
800
- else :
801
- # Build payload
802
- payload = build_query_payload (args )
803
- file_events = client .search_file_events (payload )
804
- if file_events :
805
- for file_event in file_events :
806
- code42_context_event = map_to_code42_event_context (file_event )
807
- code42_security_data_context .append (code42_context_event )
808
- file_context_event = map_to_file_context (file_event )
809
- file_context .append (file_context_event )
810
- readable_outputs = tableToMarkdown (
811
- "Code42 Security Data Results" ,
812
- code42_security_data_context ,
813
- headers = SECURITY_EVENT_HEADERS ,
814
- )
815
- security_data_context_key = "Code42.SecurityData(val.EventID && val.EventID == obj.EventID)"
816
- context = {security_data_context_key : code42_security_data_context , "File" : file_context }
817
- return readable_outputs , context , file_events
818
- else :
819
- return "No results found" , {}, {}
820
-
821
-
822
835
def test_module (client ):
823
836
try :
824
837
# Will fail if unauthorized
0 commit comments