A notifier is used in StackRox to send notifications to a third-party system such as Splunk, Microsoft Sentinel or PagerDuty.
Each notifier must implement the interfaces of the notifications it wants to support. Following notifier types exist.
| Type | Interface | Description |
|---|---|---|
| AlertNotifier | pkg/notifiers/alert_notifier.go | The alert notifications used to send alerts generated by StackRox's policy engine. Examples are the Microsoft Sentinel or PagerDuty notifier. |
| AuditNotifier | pkg/notifiers/audit_notifier.go | The AuditLog notifications are used to send notifications about AuditLogs. |
| NetworkPolicyNotifier | pkg/notifiers/network_policy_notifier.go | NetworkPolicyNotifier sends notifications about Network Policies. |
| ResolvableAlertNotifier | pkg/notifiers/resolvable_alert_notifier.go | The ResolvableAlertNotifier is used to resolve alerts from a third party system. PagerDuty and AWS Security Hub implement these. |
| ReportNotifier | pkg/notifiers/report_notifier.go | The Report notifier defines to send reports, e.g. acscs email and email support this type. |
To write a notifier you have to follow these steps:
- Create a new pkg for your notifier in
central/notifiers, e.g.externalsystem. - Create a new Go file,
externalsystem/my_notifier.goand add a struct which implements one of the interfaces above, e.g. theAlertNotifierinterface. - Import the new package in
central/notifiers/all/all.go. - Depending on your needs of custom data, create a new configuration in the Notifier message for your notifier.
- Register the notifier in the
initfunc of theexternalsystem/my_notifier.goGo file by using thenotifiers.Addfunction. You can find several examples of this in other notifier implementations. - Implement the functions of the interface, create the client for the external service and try to send a message.
- Implement the
Testfunction with example data to trigger an alert with a simple HTTP call. This can be called via sending the config to `/v1/notifiers/test -X POST --data $notifier -H "Content-Type: application/json". - Implement encryption, see next
Encryptionchapter. - Use the admin events logger, see
Admin Events Loggerchapter.
To display logs of a notifier in the Admin Events overview in StackRox you need to use the logger as here.
log = logging.LoggerForModule(option.EnableAdministrationEvents())
This will display the logs in StackRox under /main/administration-events?s[Resource%20Type]=Notifier in the UI.
Encryption of notifier secrets is used in ACS Cloud Service. The encryption feature is disabled by default and is enabled by setting ROX_ENC_NOTIFIER_CREDS=true.
An example PR can be found here.
For this you need to:
- Add your notifier to
central/notifiers/utils/encryption.goto return the credentials of the notifier. - Add test cases to
central/notifiers/utils/encryption_test.go. - Load the encryption keys in the notifier's
initfunction and protect it by the env settingenv.EncNotifierCreds.BooleanSetting(),ROX_ENC_NOTIFIER_CREDS. - Test it by enabling notifier secrets in StackRox by running
./../../dev-tools/setup-notifier-encryption.sh. - Create a new notifier with a secret and check that data doesn't contain unencrypted data by running:
go run tools/deserialize-proto/main.go --type storage.Notifier --id <UUID>