I was working on the installation and configuration of Elasti.co Heartbeat and found it quite boring to create the required YAML files for all the services that required monitoring. Hence I decided to automate this tasks:
As input a CSV file is used. The first row of this file is treated as header. Its format is
Column | Meaning |
---|---|
0 | Type of check (either tcp or http ) |
1 | Name of support unit (team owning the monitored service, can be used for alarming) |
2 | Name of application |
3 | Environment (e.g. production, staging, test, development) |
4 | Name of service |
5 | Endpoints to monitor (comma-separated) |
6 | Tags (comma-separated) |
7 | Schedule in seconds |
8 | Check timeout in seconds |
The output is a zip archive containing all the YAML files for the services. After unzipping the archive the YAML files may require an update on ownership (to the user running heartbeat) and permissions (0x644).
This CDK application deploys the Ruby application as a Lambda function and makes it available via an API Gateway.
The Lambda layer contains these libraries
$ cd assets
$ mkdir -p ./vendor/bundle
$ bundle config set path ./vendor/bundle
$ bundle install
Fetching gem metadata from https://rubygems.org/..
Resolving dependencies...
Using bundler 2.1.4
Using csv 3.1.9
Using rubyzip 2.3.0
Bundle complete! 2 Gemfile dependencies, 3 gems now installed.
Bundled gems are installed into `./vendor/bundle`
Installing all dependencies required to build the CDK application.
$ npm install
$ npm run build
Deploying the stack
$ cdk deploy --profile <AWS Profile>
Undeploying the stack
$ cdk destroy --profile <AWS Profile>
The CSV file containing the information can be uploaded e.g. via curl.
curl -X POST --data-binary @data.csv -H 'Content-Type:text/csv' https://<api-gateway>.eu-central-1.amazonaws.com/prod/converter --output test.zip