Skip to content

Instantly share code, notes, and snippets.

@rcollette
Forked from JefStat/sumo_logic.config
Last active September 25, 2020 21:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rcollette/95667454dc054d9d308e5b4d9a80f419 to your computer and use it in GitHub Desktop.
Save rcollette/95667454dc054d9d308e5b4d9a80f419 to your computer and use it in GitHub Desktop.
Elastic Beanstalk Sumo Logic Config via Gitlab Environment Variable
# This will automatically install the Sumo Logic collector on AWS Elastic
# Beanstalk instances. Add this to the .ebextensions folder in your app root
# To add or remove tracked files, simply add or remove source hashes to the
# sources array.
packages:
rpm:
SumoCollector: https://collectors.sumologic.com/rest/download/rpm/64
files:
"/home/ec2-user/setup-sumo.sh":
mode: "000755"
owner: root
group: root
# beanstalk environment variables are available here because this is a shell script.
# To not have the variable replaced by Gitlab during build, use double dollar signs.
content: |
cat >/opt/SumoCollector/config/user.properties <<EOL
name=$TEAM_SHORT_NAME-$SUMOLOGIC_APP_NAME-$${DEPLOYMENT_ENVIRONMENT}-$$(hostname)
accessid=$SUMOLOGIC_ACCESS_ID
accesskey=$SUMOLOGIC_ACCESS_KEY
category=$TEAM_SHORT_NAME/$${DEPLOYMENT_ENVIRONMENT}/$SUMOLOGIC_APP_NAME
rpmAutoStart=false
ephemeral=true
clobber=false
syncSources=/opt/SumoCollector/config/sumo_sources.json
sources=/opt/SumoCollector/config/sumo_sources.json
EOL
"/opt/SumoCollector/config/sumo_sources.json":
mode: "000755"
owner: root
group: root
#beanstalk environment variables are not available here.
content: |
{
"api.version": "v1",
"sources": [
{
"name": "docker",
"sourceType": "LocalFile",
"multilineProcessingEnabled": true,
"useAutolineMatching": true,
"pathExpression": "/var/lib/docker/containers/*/*.log",
"automaticDateParsing": true
},
{
"name": "nginx",
"sourceType": "LocalFile",
"automaticDateParsing": true,
"multilineProcessingEnabled": "false",
"useAutolineMatching": true,
"pathExpression": "/var/log/nginx/*.log"
}
]
}
"/opt/elasticbeanstalk/tasks/taillogs.d/sumo-logic.conf":
mode: "000755"
owner: root
group: root
content: |
/opt/SumoCollector/logs/*
"/opt/elasticbeanstalk/tasks/bundlelogs.d/sumo-logic.conf":
mode: "000755"
owner: root
group: root
content: |
/opt/SumoCollector/logs/*
"/opt/elasticbeanstalk/tasks/publishlogs.d/sumo-logic.conf":
mode: "000755"
owner: root
group: root
content: |
/opt/SumoCollector/logs/*
container_commands:
01_setup_sumo:
command: /home/ec2-user/setup-sumo.sh
# The service restart is required because the rpm installation seems to start the service before commands are run.
02_restart_service:
command: /sbin/service collector restart
services:
sysvinit:
collector:
enabled: true
ensureRunning: true
#Note the following commands usage does not actually restart the service after setup-sumo.sh has run.
#commands:
#- 01_setup_sumo
@rcollette
Copy link
Author

This gist provide an example of configuring a Sumo Logic collector for an AWS Elastic Beanstalk, via a Gitlab variable. We define this variable at a gitlab group level.

The variable is copied to a file in gitlab-ci.yml like:

- echo "${BEANSTALK_SUMOLOGIC_COLLECTOR_CONFIG}" >beanstalk_bundle/.ebextensions/01-sumologic-collector.config

The order of the properties (packages, files, container_commands, services) in this file reflect the documented order of execution from
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html#linux-services

Changing the order of these properties will not change the order of execution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment