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.

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

Make sure the project syncs successfully:

lab005-000

After creating the project in Automation Decision, create the rulebook.

Click 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 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:

lab005-008

Click History to see the issue:

lab005-009

The rulebook will fail to start due to a port conflict. Stop the eda-debug rulebook.

Click on the running rulebook action in blue:

lab005-010

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

lab005-011

Click Disable rulebook activations

lab005-012

Disable Rulebook activation successfully:

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

Click Create project.

Next, create the project-http inventory containing only the host localhost:

Name: project-http
Organization: Default
lab005-015

Click Create Host:

lab005-016

Now add the host localhost:

Name: localhost
lab005-017

Next click Create Host:

Create the job template: In 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

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:

lab005-023

And Check if the job ran successfully:

lab005-020

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


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. First, you will need to disable the eda-debug rulebook under under Automation Decisions > Rulebook Activations.

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

  3. 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
lab005-new001
  1. Change remote_user: root to remote_user: ec2-user in playbook project-http/playbook.yml.

  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

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!