Common¶
The functions of common.core, taken from their docstrings.
common.core
¶
retention_days(name)
¶
Days kept, from the setting called name; 0 (or nothing usable) keeps everything.
purge_history(dry_run=False)
¶
Take out the summaries and the activity journal lines older than their retention, the journal in batches (a long delete
holds the table). The latest summary of each kind is always kept. With dry_run it only counts.
Returns {'summaries': n, 'timeline': n}.
cleanup_history()
¶
Scheduled job (every night): the retention of the AI summaries and of the activity journal.
start_scheduler()
¶
Launch multiple planning tasks in background:
- Fire Legitimate Domains RDAP every 30 minutes (the sites have theirs, in site_monitoring, every 15 minutes)
- Fire SSL certificate check every 6 hours
- Fire Connectors health check every Monday at 06:00
generate_ref()
¶
Generate unique 'sourceRef' for an alert.
watcher_object_url(app_name, context_data)
¶
Link to the object of a detection in Watcher: the page opens on it. None when it cannot be told, and the notification then links to the page of the module.
thehive_alert_tags(app_name, context_data, base_tags)
¶
Tags of a TheHive alert: the configured ones (the domain ones only on alerts about a domain), the module, and what Watcher knows about the detection.
thehive_severity_for(app_name, context_data, default)
¶
Severity of a TheHive alert (1 low to 4 critical): the notification's, raised when the detection is worse.
thehive_comment(app_name, context_data)
¶
What changed, for the comment added to an alert that already exists. None when there is nothing to say.
collect_observables(app_name, context_data)
¶
Observables of a TheHive alert. Only a suspicious domain, URL or address is an indicator; the victim, group, sector, country or keyword of a detection are context and go in the tags of the alert instead.
html_to_slack_attachments(html_text)
¶
Parses the summary's HTML to construct the Slack JSON blocks with their respective colors.
html_to_citadel_html(html_text)
¶
Converts the web summary HTML (details/summary, Bootstrap classes, Material icons)
into the HTML subset supported by Matrix/Citadel (strong, em, font data-mx-color, a, br).
Output contains no newline, since the caller turns '\n' into '
'.
clean_html_for_email(html_text)
¶
Removes web interface artifacts (icons, buttons) for static display in emails.
remove_html_tags(text)
¶
Remove HTML tags from a string.
citadel_content(type_id, ctx)
¶
A Citadel (Matrix) message: the HTML of the notification, and the same text without markup in body, which is what
a client or a notification preview shows when it does not display HTML.
send_app_specific_notifications(app_name, context_data, subscribers)
¶
Notify an alert on Slack, Citadel, TheHive and e-mail, where the Notifications tab has it on; the e-mail goes to the
subscribers who ticked it.
send_app_specific_notifications_group(app_name, context_data, subscribers)
¶
Send group notifications based on app type (Slack, Citadel, Email), when the instance has them switched on.
send_only_thehive_notifications(app_name, context_data, subscribers)
¶
Open one TheHive alert for an alert of a group notification (the group message itself goes out on the other
channels). Only when the instance has TheHive switched on for this notification; subscribers is not used, it is
kept so the callers do not change.
update_legitimate_domains_rdap_data()
¶
Update the registry data (expiry and registration dates) of the legitimate domains.
update_all_ssl_certificates()
¶
Update SSL certificate information for all monitored sites and for the legitimate domains.
capture_failure_message(reason)
¶
The sentence an API answers when a capture failed.
capture_page_result(url)
¶
The JPEG of a page and why it is missing: (image, None), or (None, reason) when the service is off, refuses the address or
fails (said in the log). reason is a key of CAPTURE_FAILURES.
capture_page(url)
¶
The JPEG of a page, or None when the service is off, refuses the address or fails (said in the log).
take_screenshot_result(target, target_id, url, user=None)
¶
Take a screenshot of a page for an object and keep it; only the newest ones of an object are kept. Every capture is a visit from Watcher: it is logged with who asked for it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
kind of object, |
required |
Returns:
| Type | Description |
|---|---|
|
(the Screenshot, None), or (None, why it could not be taken: a key of CAPTURE_FAILURES). |
take_screenshot(target, target_id, url, user=None)
¶
The Screenshot taken for an object, or None when it could not be taken (see take_screenshot_result).
forget_screenshots(target, target_id)
¶
Delete the screenshots of an object that goes away.