Nagios Configuration with Puppet - KeegMitch/Operations-Engineering-group-c GitHub Wiki

What does Nagios do in the context of our 4 servers?

Nagios is a tool that monitors multiple servers, and network services like HTTP, HTTPS, SSH, and many other protocols. It also monitors things like disk usage, CPU load, which users are logged in, running processes/systems and RAM/memory usage.

When Nagios detects a problem, it sends out alerts for system administrators to promptly fix any critical errors in our servers that arise before they escalate into bigger problems.

Note: To access the puppet modules directory, I have now added an alias called puppet_modules , which directs us to the directory where we configure our own modules

Setting up a Nagios Module

  1. Create a Module structure in the /etc/puppetlabs/code/modules directory
modules/nagios/files
modules/nagios/templates
modules/nagios/manifests
modules/nagios/manifests/install.pp
modules/nagios/manifests/service.pp
modules/nagios/manifests/config.pp
modules/nagios/manifests/init.pp

Example of structure

image

  1. Create the Classes

A. Install

Should create a nagios group and user. It should also install the nagios3 package.

Note that there are a lot of prerequisite packages that need to be installed: https://support.nagios.com/kb/article/nagios-core-installing-nagios-core-from-source-96.html#Ubuntu

class nagios::install {
        package{ "nagios3":
        ensure=>present,
        }
        package { "apache2-utils":
                ensure => present,
        }
        user { "nagios":
        ensure => present,
        }
        group { "nagios":
        ensure => present,
        }
}

B. Service

The Service class should enable the nagios3 service and make sure that it is running. When running the service should be reachable by its web interface at "http:///nagios3" in a web browser

class nagios::service {
  service { "nagios3":
    ensure     => running,
    hasstatus  => true,
    hasrestart => true,
    enable     => true,
    require    => Class["nagios::config"],
    #subscribe  => File['/etc/nagios3/nagios.cfg'],
  }
}

C. Config

class nagios::config {

# File resource that manages the nagios config file
  file { "/etc/nagios3/nagios.cfg":
    ensure  => present,
    source  => "puppet:///modules/nagios/nagios.cfg",
    mode    => "0644",
    owner =>  "root",
    group =>  "root",
    require => Class["nagios::install"],
    notify  => Class["nagios::service"],
  }

# File resource to manage usernames and passwords

# manually do this step first! 
# sudo htpasswd  -c  /etc/puppetlabs/code/modules/nagios/files/htpasswd.users nagiosadmin


  file { "/etc/nagios3/htpasswd.users":
    ensure  => present,
    source  => "puppet:///modules/nagios/htpasswd.users",
    mode    => "0644",
    owner   => "root",
    group   => "root",
    require => Class["nagios::install"],
    notify  => Class["nagios::service"],
  }

# File resource that ensures the /etc/nagios3/conf.d directory is present, sets its group ownership to puppet, and its mode to 0775

file { "/etc/nagios3/conf.d":
    ensure  => directory,
    mode    => "0775",
    owner   => "root",
    group   => "puppet",
    require => Class["nagios::install"],
    notify => Class["nagios::service"],
  }
}
}

  1. Add the classes to init.pp
class nagios {
  include nagios::install, nagios::service, nagios::config
}
  1. Add the module to the site.pp file

Apply the Nagios Module

Only on mgmt server

  1. First test with the nagios install class:

image

image

  1. Testing the config.pp

Screenshot is when adding the htpasswd and conf.d files

image

Screenshot for when adding the nagios host part:

image

Connecting to the Nagios web server

In the OP network

Using the public IP address of the management server with /nagios3 at the end of our url, in our case it's this url: http://20.191.245.182/nagios3

Outside of the OP network

  1. Go to the remote OP web server: remote.op.ac.nz

  2. Login using your OP username and OP password

image

  1. Click Google Chrome on the page, it'll download an RDP file

image

  1. Click on the RDP file that was downloaded

image

  1. This window will pop up, click connect and you'll be prompted a login

image

  1. Enter your OP credentials, the password is the same as your usual OP login. Note the instructions from here

image

  1. A Chrome window should pop up. From here login as nagiosadmin with the password you manually set up for nagios. Sign in with http://<your-mgmt-ip>/nagios3

image

image