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.

Output
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
lab005-001

Let’s make sure the project Success syncs

lab005-000

After creating the project in Automation Decision, let’s create the rulebook:

Click on Create rulebook activation:

lab005-004

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
lab005-005
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:

lab005-008

Click on History to see the issue:

lab005-009

Rulebook will fail to start due to port conflict. Let’s stop eda-debug rulebook.

Click Rulebook action in blue:

lab005-010

Check Box: Yes, I confirm that I want to disable these rulebook activations.

lab005-011

Click on Disable rulebook activations

lab005-012

Disable Rulebook activation successfully:

lab005-013
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
lab005-022

Click on Create project.

Let’s create the project-http inventory containing only the host localhost:

Name: project-http
Organization: Default
lab005-015

Let’s click on Create Host:

lab005-016

Now let’s add the host localhost:

Name: localhost
lab005-017

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:

lab005-014
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:

lab005-023

And Check if the job ran successfully:

lab005-020

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


Before moving ahead

Please take a moment to solve the challenge on your own.

The real value of this activity lies in your effort to troubleshoot independently.

Once you have tried, continue to the next section for guided steps to verify your approach or learn an alternate solution.


CONTINUE


Guided solution

  1. Disable eda-debug rulebook.

  2. Rulebook will fail to start due to port conflict. Let’s stop eda-debug rulebook.

  3. Remember to put the host in disabled mode inside the inventory:

lab005-018
  1. Mark the Extra variable check box as Prompt on launch

lab005-019
  1. Before stopping Apache service. Need to remove remote_user: root

  2. 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
Output
[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