Skip to content

Commit ba989b8

Browse files
committed
environment support for slack url
added environment support for all config properties, they can beset by passing pm2_slack_{prop_name} to env
1 parent d3f27f6 commit ba989b8

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ To install and setup pm2-slack, run the following commands:
1010
pm2 install pm2-slack
1111
pm2 set pm2-slack:slack_url https://slack_url
1212
```
13+
Also, you can set any variable though envirouyment, just like this (`docker-compose` example):
14+
```
15+
environment:
16+
pm2_slack_slack_url: https://slack_url
17+
```
1318

1419
To get the Slack URL, you need to setup an Incoming Webhook. More details on how to set this up can be found here: https://api.slack.com/incoming-webhooks
1520

@@ -49,6 +54,7 @@ The following options are available:
4954
- `queue_max` (int) - Maximum number of messages, that can be send in one Slack message (in one bufferring round). When the queue exceeds this maximum, next messages are suppresesed and replaced with message "*Next XX messages have been suppressed.*". Default: 100
5055

5156
Set these options in the same way as subscribing to events.
57+
Any of them can be set though environment variable `pm2_slack_{option_name}`.
5258

5359

5460
###### Example

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const slackUrlRouter = {
6868
*/
6969
addMessage: function(message) {
7070
const processName = message.name;
71-
const slackUrl = moduleConfig['slack_url-' + processName] || moduleConfig['slack_url'];
71+
const slackUrl = moduleConfig['slack_url-' + processName] || moduleConfig['slack_url'] || process.env.pm2_slack_slack_url;
7272

7373
if (!slackUrl) {
7474
return;
@@ -83,7 +83,7 @@ const slackUrlRouter = {
8383
const config = {};
8484
configProperties.map((configPropertyName) => {
8585
// Use process based custom configuration values if exist, else use the global configuration values.
86-
config[configPropertyName] = moduleConfig[configPropertyName + '-' + processName] || moduleConfig[configPropertyName];
86+
config[configPropertyName] = moduleConfig[configPropertyName + '-' + processName] || process.env['pm2_slack_'+configPropertyName];
8787
});
8888

8989
this.messageQueues[slackUrl] = new MessageQueue(config);

0 commit comments

Comments
 (0)