Skip to content

Commit 6403e96

Browse files
enhancement: Add information about environment variables in the notification plugins
1 parent 194e6c2 commit 6403e96

File tree

1 file changed

+31
-0
lines changed
  • crowdsec-docs/docs/local_api/notification_plugins

1 file changed

+31
-0
lines changed

crowdsec-docs/docs/local_api/notification_plugins/intro.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,22 @@ CrowdSec rejects the plugins binaries if one of the following is true :
2727

2828
It is possible to set configuration values based on environment variables.
2929

30+
However, depending on which key is using the environment variable, the syntax is different.
31+
32+
#### Format
33+
34+
The `format` key is a string that uses the [go template](https://pkg.go.dev/text/template) syntax. To use an environment variable in the `format` key, you can use the `env` function provided by [sprig](https://masterminds.github.io/sprig/).
35+
36+
```yaml
37+
format: |
38+
Received {{ len . }} alerts
39+
Environment variable value: {{env "ENV_VAR"}}
40+
```
41+
42+
#### Other keys
43+
44+
All other keys than `format` can use the typical `${ENV_VAR}` or `$ENV_VAR` syntax.
45+
3046
For example, if you don't want to store your SMTP host password in the configuration file, you can do this:
3147

3248
```yaml
@@ -40,6 +56,21 @@ sender_email: [email protected]
4056
email_subject: "CrowdSec Notification"
4157
```
4258

59+
:::warning
60+
Please note that `cscli notifications inspect` command does not interpolate environment variables and will always show the raw value of the key.
61+
:::
62+
63+
If you wish to use `cscli notifications test` command, you must provide the environment variables in the command line. For example, if you have a `SMTP_PASSWORD` environment variable, you can test the email_default plugin with the following command:
64+
65+
:::warning
66+
Some shells may hold this information in history, so please consult your shell documentation to ensure that the password is not stored in history.
67+
:::
68+
69+
```bash
70+
SMTP_PASSWORD=your_password cscli notifications test email_default
71+
```
72+
73+
If you wish to not use the environment variable whilst running the command, you must configure the environment variables within your shell this is out of scope for this documentation so please use your favourite search engine.
4374

4475
### Registering plugin to profile
4576

0 commit comments

Comments
 (0)