1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
| import pandas as pd
import numpy as np
from datetime import datetime, timedelta
import json
class ThirdPartyIncidentManagement:
def __init__(self):
self.incidents = {}
self.third_parties = {}
self.response_teams = {}
self.communication_channels = {}
self.escalation_rules = {}
self.lessons_learned = {}
def register_third_party(self, party_id, party_data):
"""Register third party"""
self.third_parties[party_id] = {
'party_id': party_id,
'name': party_data['name'],
'type': party_data['type'],
'criticality': party_data.get('criticality', 'medium'),
'contact_info': party_data.get('contact_info', {}),
'incident_contact': party_data.get('incident_contact', {}),
'escalation_contacts': party_data.get('escalation_contacts', []),
'sla_requirements': party_data.get('sla_requirements', {}),
'data_shared': party_data.get('data_shared', []),
'systems_accessed': party_data.get('systems_accessed', []),
'last_incident': None,
'incident_count': 0
}
def create_incident(self, incident_id, incident_data):
"""Create third party incident"""
incident = {
'incident_id': incident_id,
'title': incident_data['title'],
'description': incident_data['description'],
'severity': incident_data['severity'],
'category': incident_data['category'],
'affected_third_parties': incident_data.get('affected_third_parties', []),
'discovered_by': incident_data.get('discovered_by', 'unknown'),
'discovery_date': incident_data.get('discovery_date', datetime.now()),
'status': 'open',
'priority': self.calculate_priority(incident_data),
'impact_assessment': {},
'response_actions': [],
'communications': [],
'timeline': [],
'lessons_learned': [],
'created_date': datetime.now()
}
self.incidents[incident_id] = incident
# Update incident counter for affected third parties
for party_id in incident['affected_third_parties']:
if party_id in self.third_parties:
self.third_parties[party_id]['incident_count'] += 1
self.third_parties[party_id]['last_incident'] = incident['discovery_date']
return incident
def calculate_priority(self, incident_data):
"""Calculate incident priority"""
severity = incident_data['severity']
affected_parties = len(incident_data.get('affected_third_parties', []))
# Calculate priority based on severity and number of affected third parties
priority_scores = {
'critical': 4,
'high': 3,
'medium': 2,
'low': 1
}
base_priority = priority_scores.get(severity, 2)
# Adjust by number of affected third parties
if affected_parties > 5:
base_priority += 1
elif affected_parties > 2:
base_priority += 0.5
# Determine final priority
if base_priority >= 4:
return 'critical'
elif base_priority >= 3:
return 'high'
elif base_priority >= 2:
return 'medium'
else:
return 'low'
def assess_impact(self, incident_id, impact_data):
"""Assess incident impact"""
if incident_id not in self.incidents:
return False
incident = self.incidents[incident_id]
impact_assessment = {
'business_impact': impact_data.get('business_impact', 'unknown'),
'financial_impact': impact_data.get('financial_impact', 0),
'reputation_impact': impact_data.get('reputation_impact', 'unknown'),
'regulatory_impact': impact_data.get('regulatory_impact', 'unknown'),
'data_compromised': impact_data.get('data_compromised', []),
'systems_affected': impact_data.get('systems_affected', []),
'customers_affected': impact_data.get('customers_affected', 0),
'estimated_downtime': impact_data.get('estimated_downtime', 0),
'recovery_time': impact_data.get('recovery_time', 0),
'assessed_by': impact_data.get('assessed_by', 'unknown'),
'assessment_date': datetime.now()
}
incident['impact_assessment'] = impact_assessment
# Update priority based on impact
incident['priority'] = self.update_priority_based_on_impact(incident)
return True
def update_priority_based_on_impact(self, incident):
"""Update priority based on impact"""
impact = incident['impact_assessment']
# Check high impact factors
high_impact_factors = 0
if impact['business_impact'] == 'critical':
high_impact_factors += 2
elif impact['business_impact'] == 'high':
high_impact_factors += 1
if impact['financial_impact'] > 1000000: # > $1M
high_impact_factors += 2
elif impact['financial_impact'] > 100000: # > $100K
high_impact_factors += 1
if impact['reputation_impact'] == 'severe':
high_impact_factors += 2
elif impact['reputation_impact'] == 'moderate':
high_impact_factors += 1
if impact['regulatory_impact'] == 'severe':
high_impact_factors += 2
elif impact['regulatory_impact'] == 'moderate':
high_impact_factors += 1
if impact['customers_affected'] > 10000:
high_impact_factors += 2
elif impact['customers_affected'] > 1000:
high_impact_factors += 1
# Determine updated priority
if high_impact_factors >= 6:
return 'critical'
elif high_impact_factors >= 4:
return 'high'
elif high_impact_factors >= 2:
return 'medium'
else:
return 'low'
def add_response_action(self, incident_id, action_data):
"""Add response action"""
if incident_id not in self.incidents:
return False
action_id = f"ACTION-{len(self.incidents[incident_id]['response_actions']) + 1}"
action = {
'action_id': action_id,
'description': action_data['description'],
'assigned_to': action_data['assigned_to'],
'third_party': action_data.get('third_party'),
'action_type': action_data.get('action_type', 'general'),
'priority': action_data.get('priority', 'medium'),
'due_date': action_data.get('due_date'),
'status': 'pending',
'created_date': datetime.now(),
'completed_date': None,
'notes': action_data.get('notes', '')
}
self.incidents[incident_id]['response_actions'].append(action)
# Add to timeline
self.incidents[incident_id]['timeline'].append({
'timestamp': datetime.now(),
'event': f"Response action added: {action['description']}",
'actor': action_data.get('created_by', 'system')
})
return True
def update_action_status(self, incident_id, action_id, status, notes=None):
"""Update action status"""
if incident_id not in self.incidents:
return False
incident = self.incidents[incident_id]
for action in incident['response_actions']:
if action['action_id'] == action_id:
action['status'] = status
if notes:
action['notes'] = notes
if status == 'completed':
action['completed_date'] = datetime.now()
# Add to timeline
incident['timeline'].append({
'timestamp': datetime.now(),
'event': f"Action {action_id} updated to {status}",
'actor': 'system'
})
return True
return False
def add_communication(self, incident_id, communication_data):
"""Add communication"""
if incident_id not in self.incidents:
return False
communication_id = f"COMM-{len(self.incidents[incident_id]['communications']) + 1}"
communication = {
'communication_id': communication_id,
'type': communication_data['type'],
'direction': communication_data['direction'], # 'inbound' or 'outbound'
'third_party': communication_data.get('third_party'),
'subject': communication_data['subject'],
'content': communication_data['content'],
'sent_by': communication_data['sent_by'],
'sent_to': communication_data['sent_to'],
'timestamp': datetime.now(),
'priority': communication_data.get('priority', 'normal'),
'status': 'sent'
}
self.incidents[incident_id]['communications'].append(communication)
# Add to timeline
self.incidents[incident_id]['timeline'].append({
'timestamp': datetime.now(),
'event': f"Communication {communication['type']} sent to {communication['sent_to']}",
'actor': communication['sent_by']
})
return True
def escalate_incident(self, incident_id, escalation_data):
"""Escalate incident"""
if incident_id not in self.incidents:
return False
incident = self.incidents[incident_id]
escalation = {
'escalation_id': f"ESC-{len(incident.get('escalations', [])) + 1}",
'reason': escalation_data['reason'],
'escalated_to': escalation_data['escalated_to'],
'escalated_by': escalation_data['escalated_by'],
'timestamp': datetime.now(),
'priority': escalation_data.get('priority', 'high'),
'status': 'active'
}
if 'escalations' not in incident:
incident['escalations'] = []
incident['escalations'].append(escalation)
# Update incident priority
if escalation['priority'] == 'critical':
incident['priority'] = 'critical'
# Add to timeline
incident['timeline'].append({
'timestamp': datetime.now(),
'event': f"Incident escalated to {escalation['escalated_to']}",
'actor': escalation['escalated_by']
})
return True
def close_incident(self, incident_id, closure_data):
"""Close incident"""
if incident_id not in self.incidents:
return False
incident = self.incidents[incident_id]
# Verify all actions are completed
pending_actions = [a for a in incident['response_actions'] if a['status'] == 'pending']
if pending_actions:
return False # Cannot close with pending actions
incident['status'] = 'closed'
incident['closure_date'] = datetime.now()
incident['closure_reason'] = closure_data.get('reason', 'resolved')
incident['closure_notes'] = closure_data.get('notes', '')
incident['closed_by'] = closure_data.get('closed_by', 'unknown')
# Add to timeline
incident['timeline'].append({
'timestamp': datetime.now(),
'event': f"Incident closed: {incident['closure_reason']}",
'actor': incident['closed_by']
})
return True
def generate_incident_report(self, incident_id):
"""Generate incident report"""
if incident_id not in self.incidents:
return None
incident = self.incidents[incident_id]
# Calculate metrics
total_actions = len(incident['response_actions'])
completed_actions = len([a for a in incident['response_actions'] if a['status'] == 'completed'])
pending_actions = len([a for a in incident['response_actions'] if a['status'] == 'pending'])
total_communications = len(incident['communications'])
escalations = len(incident.get('escalations', []))
# Calculate duration
if incident['status'] == 'closed':
duration = incident['closure_date'] - incident['discovery_date']
else:
duration = datetime.now() - incident['discovery_date']
report = {
'incident_id': incident_id,
'title': incident['title'],
'status': incident['status'],
'priority': incident['priority'],
'severity': incident['severity'],
'discovery_date': incident['discovery_date'],
'closure_date': incident.get('closure_date'),
'duration': duration,
'affected_third_parties': incident['affected_third_parties'],
'impact_assessment': incident['impact_assessment'],
'response_metrics': {
'total_actions': total_actions,
'completed_actions': completed_actions,
'pending_actions': pending_actions,
'completion_rate': (completed_actions / total_actions * 100) if total_actions > 0 else 0
},
'communication_metrics': {
'total_communications': total_communications,
'escalations': escalations
},
'timeline': incident['timeline'],
'lessons_learned': incident.get('lessons_learned', []),
'recommendations': self.generate_incident_recommendations(incident)
}
return report
def generate_incident_recommendations(self, incident):
"""Generate recommendations based on incident"""
recommendations = []
# Recommendations based on duration
if incident['status'] == 'closed':
duration = incident['closure_date'] - incident['discovery_date']
if duration.days > 7:
recommendations.append({
'type': 'response_time',
'priority': 'high',
'description': "Improve response time - incident lasted more than 7 days"
})
# Recommendations based on escalations
escalations = incident.get('escalations', [])
if len(escalations) > 2:
recommendations.append({
'type': 'escalation_management',
'priority': 'medium',
'description': f"Review escalation process - {len(escalations)} escalations"
})
# Recommendations based on pending actions
pending_actions = [a for a in incident['response_actions'] if a['status'] == 'pending']
if len(pending_actions) > 0:
recommendations.append({
'type': 'action_management',
'priority': 'high',
'description': f"Complete {len(pending_actions)} pending actions"
})
# Recommendations based on affected third parties
if len(incident['affected_third_parties']) > 3:
recommendations.append({
'type': 'third_party_management',
'priority': 'medium',
'description': "Review third party management - multiple affected"
})
return recommendations
# Usage example
incident_mgmt = ThirdPartyIncidentManagement()
# Register third party
incident_mgmt.register_third_party('TP-001', {
'name': 'Cloud Provider',
'type': 'cloud_provider',
'criticality': 'high',
'contact_info': {'email': 'security@cloudprovider.com'},
'incident_contact': {'email': 'incidents@cloudprovider.com'},
'data_shared': ['customer_data', 'financial_data'],
'systems_accessed': ['production_db', 'backup_systems']
})
# Create incident
incident = incident_mgmt.create_incident('INC-001', {
'title': 'Data Breach at Cloud Provider',
'description': 'Suspected data breach affecting customer data',
'severity': 'high',
'category': 'data_breach',
'affected_third_parties': ['TP-001'],
'discovered_by': 'Security Team'
})
# Assess impact
incident_mgmt.assess_impact('INC-001', {
'business_impact': 'high',
'financial_impact': 500000,
'reputation_impact': 'moderate',
'regulatory_impact': 'moderate',
'data_compromised': ['customer_data'],
'customers_affected': 5000
})
# Add response action
incident_mgmt.add_response_action('INC-001', {
'description': 'Contact cloud provider for incident details',
'assigned_to': 'Security Team',
'third_party': 'TP-001',
'action_type': 'communication',
'priority': 'high'
})
# Generate report
report = incident_mgmt.generate_incident_report('INC-001')
print(f"Incident report: {report['title']}")
print(f"Priority: {report['priority']}")
print(f"Affected third parties: {len(report['affected_third_parties'])}")
|