Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for summarized and scheduled notifications #3925

Open
wants to merge 88 commits into
base: feature-322-scheduled-notifications
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
d79d2e5
added javacron dependency
MM-msr Apr 29, 2024
f2da839
added scheduled properties in NotificationRule, added configurable de…
MM-msr Apr 29, 2024
5ff2daa
changed type of cron configuration to string
MM-msr Apr 29, 2024
279f35a
added fallback for last execution time if not set
MM-msr Apr 29, 2024
0e42dd8
moved scheduled properties from NotificationRule to new class
MM-msr May 2, 2024
919bfaf
added persistence entry for ScheduledNotificationRule
MM-msr May 2, 2024
a6c5389
added scheduled crud methods to query managers
MM-msr May 2, 2024
6c49eaf
added api for scheduled notification rules
MM-msr May 2, 2024
aa54531
added some minor validation in scheduled api
MM-msr May 3, 2024
ff6ab5b
fixed wrong database usage (data stored in notificationrule table), w…
MM-msr May 3, 2024
0d325ca
Updated NotificationQueryManager to use UTC time for ScheduledNotific…
MM-msr May 7, 2024
eacbb29
Add new methods for retrieving new policy violations and vulnerabilit…
MM-msr May 7, 2024
d169d57
Added basic Task for sending scheduled notifications (originates main…
MM-msr May 7, 2024
28a81ee
added update method for last execution after scheduled task completion
MM-msr May 8, 2024
68f56b9
fixed VulnerabilityQueryManager SQL query for new vulnerabilities
MM-msr May 10, 2024
9ab3118
added basic support for scheduled publishing in notification publishers
MM-msr May 13, 2024
444e77a
Added API endpoints for filtering publishers
MM-msr May 13, 2024
27942ad
Unique serialVersionUID for ScheduledNotificationRule instead of same…
MM-msr May 14, 2024
4dfc2c6
fixed setting last execution time on update
MM-msr May 14, 2024
6238a4a
fixed wrong method usage for updating last execution time in QueryMan…
MM-msr May 15, 2024
32c8a08
fixed last execution to only update after successful publishing
MM-msr May 15, 2024
08bcc6a
code cleanup
MM-msr May 16, 2024
fd052bb
abstracted NotificationRule with interface for reusing existing Publi…
MM-msr May 16, 2024
5bb66bb
basic rebuild of scheduled publish task to match idea of multiple pub…
MM-msr May 16, 2024
f1e9e92
null checks in query managers for new events since last scheduled exe…
MM-msr May 17, 2024
efc2209
generation of basic notification content in task
MM-msr May 17, 2024
22c0c66
fixed missing header part in Rule
MM-msr May 24, 2024
9ef230e
fixed query in policy and vulnerability querymanagers when project li…
MM-msr May 24, 2024
bf84140
changed retrieval of default publishers from db to support multiple d…
MM-msr May 24, 2024
13aaf87
fixed missing detach for scheduled notification items
MM-msr May 24, 2024
dc54f0e
added scheduled default publisher with testing email template, suppor…
MM-msr May 27, 2024
828a774
modified scheduled task to deliver test data with new subject classes
MM-msr May 28, 2024
9b6c3f3
added cron task management on CRUD operations with automatic re-sched…
MM-msr May 28, 2024
c64f248
removed test date in scheduled task
MM-msr May 28, 2024
6af8b9c
fixed missing update of last execution time after successful publish
MM-msr May 28, 2024
c039e6d
initialize scheduled notification tasks at startup
MM-msr May 29, 2024
f7f8a8f
added option to run scheduled notification rule manually instant
MM-msr May 29, 2024
ce2d621
support to read default cron expression from environment variables
MM-msr May 29, 2024
b9e3402
update last execution time of rule without publishing, if no errors o…
MM-msr May 29, 2024
3f3cfa9
added informational logging
MM-msr May 29, 2024
2d559ae
removed author tags
MM-msr May 29, 2024
e9e3e6f
removed unnecessary code in publisher task
MM-msr May 29, 2024
65efb4a
moved notification title and content generation to NotificationUtil c…
MM-msr May 29, 2024
8a4e635
removed check for instant execution api payload to match UI changes (…
MM-msr May 30, 2024
d8c783a
added json serializer for ZonedDateTime for better readability in api…
MM-msr May 31, 2024
621a677
Merge branch 'msr-scheduled-tests' into msr-issue-322
MM-msr Jun 3, 2024
2eeff21
added new data models to match new provided pebble template
MM-msr Jun 5, 2024
b544e67
changed depending classes to use new template models
MM-msr Jun 5, 2024
1908048
fixed wrong query in getting findings with since-date-filter
MM-msr Jun 5, 2024
4894831
fixed typo in overview model
MM-msr Jun 5, 2024
408bc48
fixed StackOverflowException due to missing method definition
MM-msr Jun 6, 2024
2306436
fixed ignore of suppressed violations, fixed error on pebble template…
MM-msr Jun 6, 2024
d398017
added child projects audit in scheduled notification mail
MM-msr Jun 6, 2024
ed39d2e
ignore version label in template if not set
MM-msr Jun 6, 2024
1a9b7e2
fixed detach in scheduled task to avoid implicit modification of noti…
MM-msr Jun 6, 2024
bcb5eb2
fixed determination of affected project in scheduled notification rul…
MM-msr Jun 7, 2024
29faf49
updated console default publisher and template to support scheduled n…
MM-msr Jun 10, 2024
f5295c6
hide details part in mail if no new vulnerabilities were found
MM-msr Jun 10, 2024
83286e4
added new policy violation processing in scheduled notification, refa…
MM-msr Jun 11, 2024
c824f48
refactored scheduled models to retrieve data from db only once
MM-msr Jun 12, 2024
13b16be
changed PolicyViolationDetails back to PolicyViolation base type to r…
MM-msr Jun 12, 2024
1794ab1
fixed typo
MM-msr Jun 12, 2024
8b574fe
added publisher tests
MM-msr Jun 13, 2024
24c93c3
removed notification level in scheduled rule from persistence and usage
MM-msr Jun 13, 2024
383d8e4
minor refactoring
MM-msr Jun 13, 2024
13bbcc8
removed unneeded tests
MM-msr Jun 13, 2024
1ee15e7
fixed Exception in PublishContext due missing notificationlevel
MM-msr Jul 2, 2024
c651d0e
changed suppressed type in template models to bool due to better json…
MM-msr Jun 14, 2024
622f3d4
fixed json structure of template models
MM-msr Jun 14, 2024
99d7819
added documentation for notification models in templates
MM-msr Jun 14, 2024
0fbdda4
changed notification title + content to support single occurrences
MM-msr Jun 14, 2024
b7ef739
fixed total vulnerabilities determination (without regarding last not…
MM-msr Jun 14, 2024
b5659c6
added new publisher types in documentation
MM-msr Jun 14, 2024
243dd93
updated mail template
MM-msr Jun 14, 2024
d6d018e
added class comments for all relevant new introduced classes
MM-msr Jun 14, 2024
2768015
removed debug code
MM-msr Jun 14, 2024
368bd7b
fixed not resolvable characters in policy mail template part
MM-msr Jul 3, 2024
d729f91
use system local time instead of UTC for last execution time in sched…
MM-msr Jul 3, 2024
be97263
use ISO string instead of manual date format string
MM-msr Jul 3, 2024
f526cc9
Merge remote-tracking branch 'origin/master' into msr-322-pr-schedule…
MM-msr Jul 7, 2024
7ea910c
fixed test failures
MM-msr Jul 8, 2024
7c5ffc0
added tests, removed some unused imports in tests
MM-msr Jul 28, 2024
cc081c1
fixed missing filter for suppressed findings
MM-msr Jul 28, 2024
98076d3
restructured scheduled payload to records with factory
MM-msr Jul 28, 2024
4676870
added mail content tests for vulnerabilities and policy violations
MM-msr Aug 1, 2024
4cc0da3
removed unnecessary database fetching
MM-msr Aug 1, 2024
6064b54
fixed enum and cron related test errors
MM-msr Aug 12, 2024
d8e4779
fixed test error for invalid cron config (add mandatory setters)
MM-msr Sep 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
203 changes: 191 additions & 12 deletions docs/_docs/integrations/notifications.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,18 @@ multiple levels, while others can only ever have a single level.
A notification publisher is a Dependency-Track concept allowing users to describe the structure of a notification (i.e. MIME type, template) and how to send a notification (i.e. publisher class).
The following notification publishers are included by default :

| Publisher | Description |
|------------|-----------------------------------------------------|
| Slack | Publishes notifications to Slack channels |
| Teams | Publishes notifications to Microsoft Teams channels |
| Mattermost | Publishes notifications to Mattermost channels |
| WebEx | Publishes notifications to Cisco WebEx channels |
| Webhook | Publishes notifications to a configurable endpoint |
| Email | Sends notifications to an email address |
| Console | Displays notifications on the system console |
| Jira | Publishes notifications to Jira |
| Publisher | Description |
| ----------------- | ---------------------------------------------------------------------------------------------- |
| Slack | Publishes notifications to Slack channels |
| Teams | Publishes notifications to Microsoft Teams channels |
| Mattermost | Publishes notifications to Mattermost channels |
| WebEx | Publishes notifications to Cisco WebEx channels |
| Webhook | Publishes notifications to a configurable endpoint |
| Email | Sends notifications to an email address |
| Console | Displays notifications on the system console |
| Jira | Publishes notifications to Jira |
| Scheduled Email | Sends a summary of all subscribed events since last notification to an email address |
| Scheduled Console | Displays a slim summary of all subscribed events since last notification to the system console |

### Templating

Expand All @@ -96,7 +98,7 @@ The template context is enhanced with the following variables :
> subject will be present at all times. Some fields are optional since the underlying fields in the datamodel are optional.
> The section below will describe the portfolio notifications in JSON format.

#### NEW_VULNERABILITY
#### NEW_VULNERABILITY (per event)
This type of notification will always contain:
* 1 component
* 1 vulnerability
Expand Down Expand Up @@ -160,6 +162,96 @@ This type of notification will always contain:

> The `cwe` field is deprecated and will be removed in a later version. Please use `cwes` instead.

#### NEW_VULNERABILITY (scheduled summary)

```json
{
"notification": {
"level": "INFORMATIONAL",
"scope": "PORTFOLIO",
"group": "NEW_VULNERABILITY",
"timestamp": "2024-05-16T23:26:22.961",
"title": "123 new Vulnerabilities in 45 components in Scheduled Rule 'ABC'",
"content": "Find below a summary of new vulnerabilities since 2024-05-16T00:00:00Z in Scheduled Notification Rule 'ABC'.",
"subject": {
"overview": {
"affectedProjectsCount": 7,
"newVulnerabilitiesCount": 123,
"affectedComponentsCount": 45,
"suppressedNewVulnerabilitiesCount": 0,
"newVulnerabilitiesBySeverity": {
"CRITICAL": 13,
"HIGH": 24,
"MEDIUM": 56,
"LOW": 10,
"INFO": 17,
"UNASSIGNED": 3
}
},
"summary": {
"projectSummaries": [
{
"project": {
"uuid": "6fb1820f-5280-4577-ac51-40124aabe307",
"name": "Acme Example",
"version": "1.0.0"
},
"summary": {
"newVulnerabilitiesBySeverity": {
"CRITICAL": 3,
"HIGH": 4,
"LOW": 2,
"INFO": 7
},
"totalProjectVulnerabilitiesBySeverity": {
"CRITICAL": 35,
"HIGH": 57,
"MEDIUM": 13,
"LOW": 105,
"INFO": 23,
"UNASSIGNED": 13
},
"suppressedNewVulnerabilitiesBySeverity": {
"HIGH": 2,
"LOW": 5,
"INFO": 1
}
}
}
]
},
"details": {
"projectDetails": [
{
"project": {
"uuid": "6fb1820f-5280-4577-ac51-40124aabe307",
"name": "Acme Example",
"version": "1.0.0"
},
"findings": [
{
"componentUuid": "4d0da61c-b462-4895-b296-da0b4bb34744",
"componentName": "axis",
"componentVersion": "1.4",
"componentGroup": "apache",
"vulnerabilitySource": "NVD",
"vulnerabilityId": "CVE-2012-5784",
"vulnerabilitySeverity": "MEDIUM",
"analyzer": "OSSINDEX_ANALYZER",
"attributionReferenceUrl": "https://ossindex.sonatype.org/vulnerability/CVE-2012-5784",
"attributedOn": "2024-05-16T12:34:39Z",
"analysisState": "IN_TRIAGE",
"suppressed": false
}
]
}
]
}
}
}
}
```

#### NEW_VULNERABLE_DEPENDENCY
This type of notification will always contain:
* 1 project
Expand Down Expand Up @@ -324,7 +416,7 @@ This type of notification will always contain:
}
```

#### POLICY_VIOLATION
#### POLICY_VIOLATION (per event)

```json
{
Expand Down Expand Up @@ -368,6 +460,93 @@ This type of notification will always contain:
}
```

#### POLICY_VIOLATION (scheduled summary)

```json
{
"notification": {
"level": "INFORMATIONAL",
"scope": "PORTFOLIO",
"group": "POLICY_VIOLATION",
"timestamp": "2022-05-12T23:07:59.611303",
"title": "2 new Policy Violations in 2 components in Scheduled Rule 'Policy Guard'",
"content": "Find below a summary of new policy violations since 2022-05-12T00:00:00Z in Scheduled Notification Rule 'Policy Guard'.",
"subject": {
"overview": {
"affectedProjectsCount": 1,
"newViolationsCount": 2,
"affectedComponentsCount": 2,
"suppressedNewViolationsCount": 0,
"newViolationsByRiskType": {
"LICENSE": 0,
"SECURITY": 0,
"OPERATIONAL": 2
}
},
"summary": {
"affectedProjectSummaries": [
{
"project": {
"uuid": "7a36e5c0-9f09-42dd-b401-360da56c2abe",
"name": "Acme Example",
"version": "1.0.0"
},
"summary": {
"newViolationsByRiskType": {
"OPERATIONAL": 2
},
"totalProjectViolationsByRiskType": {
"LICENSE": 5,
"OPERATIONAL": 2
},
"suppressedNewViolationsByRiskType": {
}
}
}
]
}
"details": {
"projectDetails": [
{
"project": {
"uuid": "7a36e5c0-9f09-42dd-b401-360da56c2abe",
"name": "Acme Example",
"version": "1.0.0"
},
"violations": [
{
"component": {
"uuid": "4e04c695-9acd-46fc-9bf6-ed23d7eb551e",
"group": "apache",
"name": "axis",
"version": "1.4"
},
"violation": {
"uuid": "c82fcb50-029a-4636-a657-96242b20680e",
"type": "OPERATIONAL",
"timestamp": "2022-05-12T20:34:46Z",
"policyCondition": {
"uuid": "8e5c0a5b-71fb-45c5-afac-6c6a99742cbe",
"subject": "COORDINATES",
"operator": "MATCHES",
"value": "{\"group\":\"apache\",\"name\":\"axis\",\"version\":\"*\"}",
"policy": {
"uuid": "6d4c7398-689a-4ec7-b5c5-9abb6b5393e9",
"name": "Banned Components",
"violationState": "FAIL"
}
}
}
}
]
}
]
}
}
}
}
```

#### USER_CREATED

```json
Expand Down
21 changes: 21 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
<lib.greenmail.version>2.0.1</lib.greenmail.version>
<lib.jackson.version>2.17.1</lib.jackson.version>
<lib.jackson-databind.version>2.17.1</lib.jackson-databind.version>
<lib.javax.validation>2.0.1.Final</lib.javax.validation>
<lib.json-java.version>20240303</lib.json-java.version>
<lib.json-unit.version>3.3.0</lib.json-unit.version>
<lib.lucene.version>8.11.3</lib.lucene.version>
Expand All @@ -116,12 +117,14 @@
<lib.testcontainers.version>1.19.8</lib.testcontainers.version>
<lib.wiremock.version>2.35.2</lib.wiremock.version>
<lib.woodstox.version>6.6.2</lib.woodstox.version>
<lib.junit.version>4.13.2</lib.junit.version>
<lib.junit-params.version>1.1.1</lib.junit-params.version>
<lib.signpost-core.version>2.1.1</lib.signpost-core.version>
<lib.httpclient.version>4.5.14</lib.httpclient.version>
<lib.httpclient5.version>5.3.1</lib.httpclient5.version>
<lib.log4j-over-slf4j.version>2.0.13</lib.log4j-over-slf4j.version>
<lib.org-kohsuke-github-api.version>1.321</lib.org-kohsuke-github-api.version>
<lib.com-asahaf-javacron.version>1.4.0</lib.com-asahaf-javacron.version>
<!-- JDBC Drivers -->
<lib.jdbc-driver.mssql.version>12.6.1.jre11</lib.jdbc-driver.mssql.version>
<lib.jdbc-driver.mysql.version>8.0.33</lib.jdbc-driver.mysql.version>
Expand Down Expand Up @@ -150,6 +153,18 @@
</repositories>

<dependencies>
<!--
Workaround for:
"The type javax.validation.Payload cannot be resolved. It is indirectly referenced
from required type com.github.packageurl.validator.PackageURLJava"
in Component.java & Project.java at least.
-->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>${lib.javax.validation}</version>
</dependency>

<!-- Alpine -->
<dependency>
<groupId>us.springett</groupId>
Expand Down Expand Up @@ -390,6 +405,12 @@
<version>${lib.org-kohsuke-github-api.version}</version>
</dependency>

<dependency>
<groupId>com.asahaf.javacron</groupId>
<artifactId>javacron</artifactId>
<version>${lib.com-asahaf-javacron.version}</version>
</dependency>

<!-- Test Dependencies -->
<dependency>
<groupId>junit</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public enum ConfigPropertyConstants {
ACCESS_MANAGEMENT_ACL_ENABLED("access-management", "acl.enabled", "false", PropertyType.BOOLEAN, "Flag to enable/disable access control to projects in the portfolio"),
NOTIFICATION_TEMPLATE_BASE_DIR("notification", "template.baseDir", SystemUtils.getEnvironmentVariable("DEFAULT_TEMPLATES_OVERRIDE_BASE_DIRECTORY", System.getProperty("user.home")), PropertyType.STRING, "The base directory to use when searching for notification templates"),
NOTIFICATION_TEMPLATE_DEFAULT_OVERRIDE_ENABLED("notification", "template.default.override.enabled", SystemUtils.getEnvironmentVariable("DEFAULT_TEMPLATES_OVERRIDE_ENABLED", "false"), PropertyType.BOOLEAN, "Flag to enable/disable override of default notification templates"),
NOTIFICATION_CRON_DEFAULT_EXPRESSION("notification", "cron.default.expression", SystemUtils.getEnvironmentVariable("DEFAULT_SCHEDULED_CRON_EXPRESSION", "0 12 * * *"), PropertyType.STRING, "The default interval of scheduled notifications as cron expression"),
TASK_SCHEDULER_LDAP_SYNC_CADENCE("task-scheduler", "ldap.sync.cadence", "6", PropertyType.INTEGER, "Sync cadence (in hours) for LDAP"),
TASK_SCHEDULER_GHSA_MIRROR_CADENCE("task-scheduler", "ghsa.mirror.cadence", "24", PropertyType.INTEGER, "Mirror cadence (in hours) for Github Security Advisories"),
TASK_SCHEDULER_OSV_MIRROR_CADENCE("task-scheduler", "osv.mirror.cadence", "24", PropertyType.INTEGER, "Mirror cadence (in hours) for OSV database"),
Expand Down
Loading
Loading