Configure Nagios Core for Log Monitoring

1 hour
  • 4 Learning Objectives

About this Hands-on Lab

No matter how well we set up our infrastructure, eventually something will go wrong that needs to be fixed. When that happens, the first step is to check the logs for errors and warnings. In this hands-on lab, we will create a Nagios service that monitors the logs for errors and warnings using the `check_log` plugin.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Define Two Command Objects that Check the Logs **/var/log/messages** for Errors and Warnings in **/usr/local/nagios/etc/objects/commands.cfg**
  1. Add the following text to the commands.cfg file:

    define command {
    
            command_name    check_log_error
            command_line    /usr/local/nagios/libexec/check_log -F /var/log/messages -O /home/nagios/check_log.error -q "error"
    
    }
    
    define command {
    
            command_name    check_log_warning
            command_line    /usr/local/nagios/libexec/check_log -F /var/log/messages -O /home/nagios/check_log.warning -q "warning"
    
    }
    
Define Two Services that Use the Commands
  1. Add the following text to the localhost.cfg file:

    define service {
    
            use                     local-service
            host_name               localhost
            service_description     Check Log Error
            check_command           check_log_error
    
    }
    define service {
    
            use                     local-service
            host_name               localhost
            service_description     Check Log Warnings
            check_command           check_log_warning
    
    }
Give the `nagios` User Read Permissions for `/var/log/messages`
  1. Run the following command:
    sudo setfacl -R -m u:nagios:r-- /var/log/messages
Restart and Log In to the Nagios Server
  1. Restart the Nagios server.
    sudo systemctl restart nagios
  2. Navigate to http://NAGIOS_SERVER_IP/nagios, and log in with the following credentials:
    • User Name: nagiosadmin
    • Password: BlaBla321
  3. Navigate to Services.
  4. Reschedule the checks for the two services to run 10-20 seconds from the current server time.
  5. Verify that there are no errors under Status Information.

Additional Resources

  1. Define two command objects:
    • Check /var/log/messages for strings that contain error.
    • Check /var/log/messages for strings that contain warning.
  2. Define two service objects for localhost using the local-service template. Add the service object definitions to the file /usr/local/nagios/etc/objects/localhost.cfg.
  3. Give the nagios user read permissions for /var/log/messages.
  4. Restart the Nagios server and log in to the web interface.
  5. Verify that you can see the newly created services for localhost and that they run without errors.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?