DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Automating Unix Security Across Hybrid Clouds
  • Cloud Automation Excellence: Terraform, Ansible, and Nomad for Enterprise Architecture
  • Streamlining Event Data in Event-Driven Ansible
  • Clean Up Event Data in Ansible Event-Driven Automation

Trending

  • Designing Frontend Applications for Failure, Not Just Success
  • Supercharging AI Agents with Azure Context: A Hands-On Guide to Azure MCP
  • Deploying Small Language Models on Sovereign Cloud
  • Beyond @Transactional: Solving the Dual-Write Problem in Distributed Microservices

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Monitoring journald Logs With Event-Driven Ansible

Monitoring journald Logs With Event-Driven Ansible

In this article, see how to monitor journald logs in real time and automate actions using Event-Driven Ansible (EDA).

By 
Binoj Melath Nalinakshan Nair
DZone Core CORE ·
Apr. 10, 25 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
6.4K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

Monitoring journald is essential for keeping systems running smoothly and securely. By regularly checking logs generated by systemd, administrators can catch potential issues like failing services or resource constraints — before they turn into major problems. Beyond performance and troubleshooting, journald is a powerful tool for security and compliance. It helps track login attempts, privilege escalations, and unusual service behavior, making it crucial for detecting unauthorized access or potential cyber threats. For organizations that need to meet regulatory requirements, monitoring system logs ensures proper tracking of system changes and security policies. 

About the Module

ansible.eda.journald is an Event-Driven Ansible (EDA) plugin that listens to journald logs in real time and triggers automated responses based on log events. This makes it useful for tasks like automatically restarting failed services, detecting security threats, or alerting administrators when critical system issues occur.

Demo

In this article, we explore how the ansible.eda.journald module monitors journald messages and prints debug output whenever a sudo command is issued (condition: match: "_EXE=/usr/bin/sudo"). However, this module can be used to track all journald messages, making it versatile for various logging and monitoring needs.

YAML
 
---
- name: Journald Demo
  hosts: localhost
  sources:
    - name: range
      ansible.eda.journald:
        match: "_EXE=/usr/bin/sudo"
  rules:
    - name: "Print Journald Event message"
      condition: event.journald._comm == 'sudo'
      action:
        print_event:
          pretty: true
          var_root:
            journald.message: journald.message


To execute the sample rulebook, run the command, ansible-rulebook -i localhost -r journald.yml, which will start monitoring journald logs in real time. Whenever it detects the use of a sudo command, it will trigger the rule and display a message on the console. This setup provides an easy way to track sudo usage, and you can customize the rulebook to monitor other journald events based on your requirements.


Conclusion

The ansible.eda.journald module provides a powerful way to monitor journald logs in real time and automate responses based on specific events. By leveraging Event-Driven Ansible (EDA), administrators can efficiently track system activities, detect security events, and automate actions such as alerts or service restarts. 

This tutorial demonstrated how to set up and run a rulebook to monitor sudo commands, but the same approach can be extended to various other system logs. With its ability to customize rules, ansible.eda.journald is a powerful tool that enhances system monitoring, strengthens security, and automates responses to important events.

Note: The views expressed in this article are my own and do not necessarily reflect the views of my employer.

Ansible (software) Event monitoring

Opinions expressed by DZone contributors are their own.

Related

  • Automating Unix Security Across Hybrid Clouds
  • Cloud Automation Excellence: Terraform, Ansible, and Nomad for Enterprise Architecture
  • Streamlining Event Data in Event-Driven Ansible
  • Clean Up Event Data in Ansible Event-Driven Automation

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook