Automatically delete host configuration from Zabbix server when in-scaling occurs at AWS EC2.
- Zabbix 3.0
- Python 2.7 or 3.6
- Zabbix remote command must be allowed on each instances
- Import template files (templates/3.0/*.xml) to Zabbix server
- Place script files (externalscripts/*.py) at externalscripts directory of Zabbix server
- ref. default directory:
/usr/lib/zabbix/externalscripts/
- ref. default directory:
- Modify Zabbix API parameters of
delete_host.py
andregister_ec2_instanceid.py
ZABBIX_SERVER
: your Zabbix web URLZABBIX_USER
: your Zabbix web account username (super admin required)ZABBIX_PASSWORD
your Zabbix web account password
- Grant execution privilege to script files
- eg.
chmod +rx /usr/lib/zabbix/externalscripts/*.py
- eg.
Modify /etc/zabbix/zabbix_agentd.conf
- Enable remote commands:
# EnableRemoteCommands=0
->EnableRemoteCommands=1
- Enable remote log commands:
# LogRemoteCommands=0
->LogRemoteCommands=1
- Modify server address (passive):
ServerActive=127.0.0.1
->ServerActive=<YOUR ZABBIX SERVER OR PROXY>
- Modify server address (active):
ServerActive=127.0.0.1
->ServerActive=<YOUR ZABBIX SERVER OR PROXY>
- Remove hostname:
Hostname=Zabbix server
-># Hostname=Zabbix server
- Enable hostname-item:
# HostnameItem=system.hostname
->HostnameItem=system.hostname
- Set host-metadata:
# HostMetadata=
->HostMetadata=<SOMETHING>
Fill in following template macros of AWS EC2 meta-data check
{$REGION}
: EC2 region (eg.us-east-1
){$KEY}
: IAM Access key{$SECRET}
: IAM Secret access key
Note: If you separates AWS accounts or region, please make templates and link to AWS EC2 meta-data check
- Conditions:
- Host metadata like
- Operations:
- Add host
- Link to templates:
AWS EC2 meta-data check
(or child template) - and your liking...
- Conditions:
- Trigger value = OK
- Trigger =
AWS EC2 meta-data check: AWS EC2 meta-data check EC2 instance-id was changed
- Operations:
- Run remote commands on current host
- Operation type: Remote command
- Target list: Current host
- Type: Custom script
- Execute on: Zabbix server
- Commands:
- Run remote commands on current host
/usr/lib/zabbix/externalscripts/register_ec2_instanceid.py --hostname {HOST.HOST} --instanceid {ITEM.LASTVALUE}
- Conditions:
- Maintenance status not in maintenance
- Trigger value = PROBLEM
- Trigger =
AWS EC2 meta-data check: AWS EC2 meta-data check EC2 instance was terminated
- Operations:
- Run remote commands on current host
- Operation type: Remote command
- Target list: Current host
- Type: Custom script
- Execute on: Zabbix server
- Commands:
- Run remote commands on current host
/usr/lib/zabbix/externalscripts/delete_host.py -n "{HOST.HOST}"
- MIT