DevOps Classroom Series – 10/Jul/2020

Nagios (contd..)

  • Nagios tries to read configuration from the file ("/usr/local/nagios/etc/nagios.cfg").
  • In this file look into all the enabled lines for cfg_file Preview Preview
  • So if we need to monitor other instances, we need to write the object configurations which are referred as object definitions

Object Configuration & Object Definitions

  • What are Objects
    • Objects are elements involved in monitoring & notifications
    • Types of objects
      • Services
      • Service Groups
      • Hosts
      • Host Groups
      • Contacts
      • Contact Groups
      • Commands
      • Timeperiods
      • Notification & Execution Dependencies
      • Escalations
    • Where are these objects defined?
      • Objects can be defined in file or a directory having multiple files (.cfg) defined in main nagios configuration file (/usr/local/nagios/etc/nagios.cfg) under section cfg_file or cfg_dir
    • How do i define then?
      • Nagios objects can be defined in a template format. Basic information about them is over here as object Definitions

Create one linux machine and add it to your monitoring using nagios

  1. Create a linux vm (Using aws) Preview
  2. Since we have a new host now, lets add host definition Refer Here
  3. Create a new webserver.cfg file
define host {
    host_name                   webserver
    max_check_attempts          3
    check_period                24x7
    contacts                    generic-contact
    notification_interval       60
    notification_period         24x7
  • Lets enable webserver.cfg in main nagios configuration Preview
  • Nagios will not show new objects till we restart nagios. There is one catch here, if there is any mistake in object definition and if you to restart nagios, nagios will not start.
  • There is a way to verify your nagios configuration, which is referred as pre-flight check
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg


  • Now this error has to be resolved, but for the time being i would use the syntax adopted by localhost.cfg

define host {

    use                     linux-server            
    host_name               webserver
    alias                   webserver
  • Now lets rerun preflight check
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg


  • Since preflight checks have passed, lets restart nagios
sudo systemctl restart nagios.service

Preview Preview

  • So service is the check which we want to perform, so lets copy one simple service from localhost.cfg into webserver.cfg. Add this to your webserver.cfg
define service {

    use                     local-service           ; Name of service template to use
    host_name               webserver
    service_description     PING
    check_command           check_ping!100.0,20%!500.0,60%
  • Run preflight check and if it successful restart nagios and navigate to web page Preview Preview
  • So our next steps would creating object definitions from scratch, understanding inheritance.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About learningthoughtsadmin