Provides a Node docker image running the included Express server.
This server listens for requests from Prometheus Alert Manager, translates the request to be compliant with the LINE Notify API and forwards the request to the LINE Notify server.
- Gateway Configuration
- Ports
- TLS Configuration
- Endpoints
- Alertmanager Configuration
- Running the Server
- Adding colors for Severity Levels
- Tests
- Contact Information
Configure the LINE Gateway with the following environmental variables:
ENV Variable Name | Required/Optional | Type | Description |
---|---|---|---|
REQUEST_URL | Required | string | URL to forward requests to |
PROXY_URL | Optional | string | Proxy server address |
DEFAULT_LINE_TOKEN | Optional | string | Default token that will be used if one is not specified in the Alertmanager Configuration |
ENABLE_TLS | Optional | boolean | Enables HTTPS Server |
NODE_TLS_REJECT_UNAUTHORIZED | Optional | integer | Disable TLS Reject Unauthorized (0 to disable) |
NODE_ENV | Optional | String | Set node Environment. Defaults to development, set to production for production environment |
This server listens for HTTP requests on port 8080.
If TLS is enabled the server listens for HTTPS requests on 8443
The server expects an SSL certificate named crt.pem
and an unencrypted private key named key.pem
. Place these two files in the ssl
folder prior to building the docker image or running the server in a Node environment.
Post alert requets to this endpoint
Request methods/headers | value |
---|---|
Method | POST |
authorization | Bearer <LINE_token> |
content-type | application/json |
Name | Type | Description |
---|---|---|
status | string | Status of alert |
alerts | array <Alert> | array of Alerts |
Name | Type | Description |
---|---|---|
labels | Key-Value pairs | Alert labels |
annotations | Key-Value pairs | Alert Annotations |
For further details see Alertmanager Documentation
Returns this readme
Status Code | Type | Description |
---|---|---|
200 | HealthCheck | Basic Health Check |
Name | Type | Notes |
---|---|---|
uptime | string | Time server has been running |
message | string | Response message |
timestamp | string | Time of health check |
Prometheus metrics
The server expects a request from the Prometheus Alertmanager with LINE token specified in the header:
{gateway-configuration
'user-agent': 'Alertmanager/0.26.0',
'content-length': '894',
authorization: 'Bearer <line_token>',
'content-type': 'application/json'
}
A properly formatted request can be generated by the following Alertmanager receiver configuration:
webhook_configs:
- url: <gateway_server_url>/notify
http_config:
authorization:
type: Bearer
credentials_file: <path_to_credential_file>
With such a configuration the LINE token is stored in a credential file:
xjHyPpa8FukJU0EDJpRpP8dzT0G8uEPH13yJZbKnCMG
In order not to be exposed, the credential file can be stored as a secret which the docker image can mount.
You can run this project in several ways:
docker build -t <ImageTag> .
docker run <ImageTag>
The docker file included in this project set up the server and uses PM2 process manager to manage the process. A basic PM2 configuraiton is provided in ecosystem.config.cjs
, please see PM2 Docker Integration Documentation for more information.
If you want to specify environmental variables add them to your docker run
command as needed. For example to specify a proxy:
docker run -e PROXY_URL=<proxy_url> <ImageTag>
Or to specify a request url:
docker run -e REQUEST_URL=<request_url> <ImageTag>
- Run
npm install
to install packages - Run
npm start
to start server
- Run
npm install
to install packages - Run
npm run build
to compile the typescript app to./dist
- In the
./dist
folder runnode Server.js
to start the server
Colors for severity levels are mapped in src/utils/TextUtils.ts
const SEVERITY_LOOKUP = new Map([
["none", "π΅"],
["warning", "π‘"],
["critical", "π΄"],
["default", "βͺ"],
]);
For other severity levels, add another mapping:
const SEVERITY_LOOKUP = new Map([
["none", "π΅"],
["warning", "π‘"],
["critical", "π΄"],
["default", "βͺ"],
["resolved", "π’"]
]);
A similar map for Status icons is present in src/utils/TextUtils.ts
as well and can be edited in the same fasion as Severity.
This project includes a suite of tests located in the src/tests
directory. You can run all tests by running
npm run test
You can also run individual tests with the following commands:
Test | Command |
---|---|
MessageUtils | npm run test-message-utils |
TextUtils | npm run test-text-utils |
NotifyController | npm run test-notify-controller |
LineNotifyService | npm run test-line-notify-service |
Please contact the author Alex Holliday if you have any questions or require assistance