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
- Create a Module structure in the
/etc/puppetlabs/code/modulesdirectory
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
- 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"],
}
}
}
- Add the classes to
init.pp
class nagios {
include nagios::install, nagios::service, nagios::config
}
- Add the module to the
site.ppfile
Apply the Nagios Module
Only on mgmt server
- First test with the nagios install class:
- Testing the config.pp
Screenshot is when adding the htpasswd and conf.d files
Screenshot for when adding the nagios host part:
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
-
Go to the remote OP web server:
remote.op.ac.nz -
Login using your OP username and OP password
- Click Google Chrome on the page, it'll download an RDP file
- Click on the RDP file that was downloaded
- This window will pop up, click connect and you'll be prompted a login
- Enter your OP credentials, the password is the same as your usual OP login. Note the instructions from here
- 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