Python 3 supported.
This script checks availability of AWS EC2 instances in Zabbix, and if they do not exist in default AWS region (because of termination for ex.), they will be removed from Zabbix.
Script runs periodically with $TIMEOUT, which you can set as environment variable.
Set these environment variables inside the docker container or on the host, if you would like to run it directly. Zabbix API user should have read/write permissions.
- ZABBIX_USER=<zabbix_api_user>
- ZABBIX_PASSWORD=<zabbix_api_password>
- ZABBIX_URL=https://<url_or_ip>
- AWS_ACCESS_KEY_ID=<access_id>
- AWS_SECRET_ACCESS_KEY=<access_key>
- AWS_DEFAULT_REGION=us-west-2
- TIMEOUT=30
- PYTHONUNBUFFERED=1
docker-compose up -d
docker logs -f ec2-cleaner
Add String and Password Parameters into the Job (environment variables).
Add Git Source Code Management:
Repository URL: https://github.com/vensder/remove-ec2-from-zabbix.git
Add build step "Execute shell" in Jenkins job:
#!/usr/bin/env bash
set -e
python3 --version
virtualenv --version
PATH=$WORKSPACE/env3/bin:/usr/local/bin:$PATH
if [ ! -d "env3" ]; then
virtualenv -p python3 env3
fi
. env3/bin/activate
pip install -r requirements.txt --download-cache=/tmp/$JOB_NAME
python --version
python remove_terminated_instances.py
Python 3 and vitrualenv should be installed on the host.