Let’s configure EDA and AAP to fix issues coming from zabbix
What’s in this break-fix?
In this section, we will configure Zabbix to monitor node1. On node1 execute an HTTPD. When HTTPD stops working. Zabbix sends an Event to Event-Driven Ansible(Automation Decisions) and thus executes the Jobs Template to solve the HTTPD problem.
Let’s 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
Let’s make sure the project Success syncs
After creating the project in Automation Decision, let’s create the rulebook:
Click on 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 EDA. Fix this before moving on. |
Now click on Create rulebook activation
Validate if the rulebook is running:
Details of how we created the Rulebook:
Click on History to see the issue:
Rulebook will fail to start due to port conflict. Let’s stop eda-debug rulebook.
Click Rulebook action in blue:
Check Box: Yes, I confirm that I want to disable these rulebook activations.
Click on Disable rulebook activations
Disable Rulebook activation successfully:
The big problem is creating the correct regular expression for the payload to execute. |
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 won’t start due to another error. Try to resolve it. |
Let’s now configure Automation Exection.
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 on Create project.
Let’s create the project-http inventory containing only the host localhost:
Name: project-http
Organization: Default
Let’s click on Create Host:
Now let’s add the host localhost:
Name: localhost
Let’s click on Create Host:
Let’s create the job_template: Let’s go to the Automation Execution section in Templates > Create Template > Create job Template:
Name: project-http
Project: rh1-ansible-eda-vars-zabbix
Playbook: project-http/playbook.yml
Credentials: ec2-user
Inventory: project-http
Let’s test Zabbix alerts:
To do this. Let’s stop httpd on node1 and validate in zabbix the sending of the alert.
To generate new alerts we need to start and stop httpd. |
Let’s stop the server’s httpd:
ssh node1
sudo systemctl stop httpd
sudo systemctl start httpd
Now Zabbix will send the notification to Ansible Event Driven:
And Check if the job ran successfully:
Now we can see the logs in Ansible Event Driven
The success of this lab is that Ansible starts HTTPD on node1 with a Zabbix Alert. |
PAUSE
Guided solution
-
Disable eda-debug rulebook.
-
Rulebook will fail to start due to port conflict. Let’s stop eda-debug rulebook.
-
Remember to put the host in disabled mode inside the inventory:
-
Mark the Extra variable check box as Prompt on launch
-
Before stopping Apache service. Need to remove remote_user: root
-
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