Let’s configure Event-Driven and Ansible Automation Platform to fix issues coming from Zabbix
What is in this break-fix
In this section, we will configure Zabbix to monitor node1. On node1, Apache is running. When Apache stops working, Zabbix sends an event to Event-Driven Ansible (Automation Decisions) and runs a job template to solve the problem. == Add the playbook and rulebook to git
Add the files inside this folder to git.
cd 05-lab/ git clone git@server.example.com:root/rh1-ansible-eda-vars-zabbix.git cp -rf project-http rulebooks rh1-ansible-eda-vars-zabbix/ cd rh1-ansible-eda-vars-zabbix/ git add . ; git commit -m add ; git push
[ec2-user@node1 ~]$ cd 05-lab/
[ec2-user@node1 05-lab]$ git clone git@server.example.com:root/rh1-ansible-eda-vars-zabbix.git
[ec2-user@node1 05-lab]$ cp -rf project-http rulebooks rh1-ansible-eda-vars-zabbix/
[ec2-user@node1 05-lab]$ cd rh1-ansible-eda-vars-zabbix/
[ec2-user@node1 rh1-ansible-eda-vars-zabbix]$
[ec2-user@node1 05-lab]$ git add . ; git commit -m add ; git push
In Ansible Automation Platform, we will create the rh1-ansible-eda-vars-zabbix project in Automation Decisions:
Name rh1-ansible-eda-vars-zabbix
Organization Default
Source control type Git
Source control URL https://server.example.com/root/rh1-ansible-eda-vars-zabbix.git
Source control credential: gitlab
Options
uncheck box Verify SSL
Make sure the project syncs successfully:
After creating the project in Automation Decision, create the rulebook.
Click Create rulebook activation:
Add the following information:
Name: rh1-ansible-eda-vars-zabbix
Organization: Default
Project: rh1-ansible-eda-vars-zabbix
Rulebook: webhook-zabbix.yml
Credential: AAP
Decision Enviroment: Default Decision Enviroment
Log Level: Debug
Now click on Create rulebook activation
The webhook-zabbix.yml file will not show in Event-Driven. Fix this before moving on. |
Now, click Create rulebook activation.
Validate if the rulebook is running.
Details of how we created the Rulebook:
Click History to see the issue:
The rulebook will fail to start due to a port conflict. Stop the eda-debug rulebook.
Click on the running rulebook action in blue:
Check the box: Yes, I confirm that I want to disable these rulebook activations.
Click Disable rulebook activations
Disable Rulebook activation successfully:
The big problem is creating the correct regular expression for the payload to run. |
Now it’s time to edit the 05-lab/rh1-ansible-eda-vars-zabbix/rulebooks/webhook-zabbix.yml file and find the correct expression.
---
- name: Listen for events on a webhook
hosts: all
sources:
- ansible.eda.webhook:
host: 0.0.0.0
port: 5000
rules:
- name: Zabbix Apache
condition: event.payload.event_name == "Apache: Service is down"
action:
run_job_template:
name: projeto-http
organization: Default
job_args:
extra_vars:
hosts_update: "{{ event.payload.host_host }}"
You only need to edit this line:
condition: event.payload.event_name == "Apache: Service is down"
Your rulebook will not start due to another error. Try to resolve it. |
Let’s now configure Automation Execution.
Let’s create the rh1-ansible-eda-vars-zabbix project:
name: rh1-ansible-eda-vars-zabbix
Organization: Default
Source Control type: git
Source control URL: git@server.example.com:root/rh1-ansible-eda-vars-zabbix.git
Source control Credential: gitlab
Check box:
Clean,
Update revision on launch
Delete
Click Create project.
Next, create the project-http inventory containing only the host localhost:
Name: project-http
Organization: Default
Click Create Host:
Now add the host localhost:
Name: localhost
Next click Create Host:
Create the job template: In Automation Execution section in
:Name: project-http
Project: rh1-ansible-eda-vars-zabbix
Playbook: project-http/playbook.yml
Credentials: ec2-user
Inventory: project-http
Test the Zabbix alerts:
To do this, stop httpd on node1 and validate in Zabbix the sending of the alert.
To generate new alerts we need to start and stop httpd. |
Next stop the server’s httpd:
ssh node1
sudo systemctl stop httpd
sudo systemctl start httpd
Now Zabbix will send the notification to Event-Driven Ansible:
And Check if the job ran successfully:
Now we can see the logs in Event-Driven Ansible
The success of this lab is that Ansible starts HTTPD on node1 with a Zabbix Alert. |
PAUSE
Guided solution
-
First, you will need to disable the eda-debug rulebook under under Automation Decisions > Rulebook Activations.
-
Next, after creating a new "project-http" inventory and adding localhost as a new host under the Hosts tab, remember to put localhost into disabled mode for this new inventory.
-
Then, the job template should be created with the following parameters:
Name: project-http
Project: rh1-ansible-eda-vars-zabbix
Playbook: project-http/playbook.yml
Credentials: ec2-user
Inventory: project-http
Extra variable: checkbox as Prompt on launch
-
Change remote_user: root to remote_user: ec2-user in playbook project-http/playbook.yml.
-
Change the condition line in the rulebooks/webhook-zabbix.yml file
condition: event.payload.event_name is regex("Apache.*Service is down", ignorecase=true)
cd 05-lab/
cd rh1-ansible-eda-vars-zabbix/
vim project-http/playbook.yml
git add . ; git commit -m add ; git push
[ec2-user@node1 ~]$ cd 05-lab/ [ec2-user@node1 05-lab]$ cd rh1-ansible-eda-vars-zabbix/ [ec2-user@node1 rh1-ansible-eda-vars-zabbix]$ [ec2-user@node1 rh1-ansible-eda-vars-zabbix]$ vim project-http/playbook.yml [ec2-user@node1 05-lab]$ git add . ; git commit -m add ; git push
To test the configuration, you can start and stop the Apache service:
---
sudo systemctl start httpd
sudo systemctl stop httpd
---
Congratulations! You have completed all lab objectives! |