Ticket #211: Set Up Nagios Monitoring Using Puppet Module - SupaHotBall/OE2-Group-D GitHub Wiki
Task
Create Puppet Module:
- Use a Puppet module to install Nagios on the designated server.
- Ensure all dependencies are resolved during installation.
- Apply the Puppet manifest to automate Nagios setup and configuration.
- Verify that Nagios is running and monitoring systems as expected
Configure Nagios:
- Set up Nagios to monitor the database server.
- Use Puppet to manage Nagios configuration files .
Documentation:
- Document the Puppet module structure, parameters, and usage.
- Include troubleshooting steps and solutions if any issues arise.
Validation:
- Test Nagios monitoring functionality.
- Ensure alerts and notifications are working correctly.
Steps Taken
Create the directory for the nagios module in the puppet modules directory
sudo mkdir /etc/puppetlabs/code/modules/nagios
Inside the nagios module directory; create the manifests, files and templates directories
sudo mkdir /etc/puppetlabs/code/modules/nagios/manifests
sudo mkdir /etc/puppetlabs/code/modules/nagios/files
sudo mkdir /etc/puppetlabs/code/modules/nagios/templates
Create the .pp files within the manifests directory
sudo nano /etc/puppetlabs/code/modules/nagios/manifests/config.pp
sudo nano /etc/puppetlabs/code/modules/nagios/manifests/init.pp
sudo nano /etc/puppetlabs/code/modules/nagios/manifests/install.pp
sudo nano /etc/puppetlabs/code/modules/nagios/manifests/service.pp
Configure the install class in the install.pp file
class nagios::install {
package { "nagios4":
ensure => present,
require => User["nagios"],
}
user { "nagios":
ensure => present,
comment => "Nagios user",
gid => "nagios",
shell => "/bin/false",
require => Group["nagios"],
}
group { "nagios":
ensure => present,
}
}
Ensure that the nagios class is created in the init.pp file
class nagios {
include nagios::install
}
Configure the service.pp file next
Test that the configuration has applied to the server
sudo puppet agent --test
sudo systemctl status nagios4.service
Ensure that the service class is included in the init.pp file.
Create the htpasswd.users file and add nagiosadmin as the user
sudo htpasswd -c /etc/puppetlabs/code/environments/production/modules/nagios/files/htpasswd.users nagiosadmin
Configure the config.pp file
class nagios::config {
file { "/etc/nagios4/nagios.cfg":
ensure => present,
source => "puppet:///modules/nagios/nagios.cfg",
mode => "0444",
owner => "root",
group => "root",
require => Class["nagios::install"],
notify => Class["nagios::service"],
}
file { "/etc/nagios4/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 { "/etc/nagios4/conf.d":
ensure => directory,
mode => "0775",
owner => "root",
group => "puppet",
require => Class["nagios::install"],
}
nagios_host { "db-x.oe2.org.nz":
target => "/etc/nagios4/conf.d/ppt_hosts.cfg",
alias => "db",
check_period => "24x7",
max_check_attempts => 3,
check_command => "check-host-alive",
notification_interval => 30,
notification_period => "24x7",
notification_options => "d,u,r",
mode => "0444",
}
}
Apply the module
sudo puppet agent --test
Install the puppet nagios plugin on the puppet master
puppet module install puppetlabs-nagios core
Check Apache configuration. Open the Nagios Apache config file at /etc/apache2/conf-enabled/nagios4-cgi.conf Edit the configuration to allow all ips
Restart apache2.service and nagios4.service to ensure that the changes are applied
Check that the web interface for Nagios is accessible
Challenges
Error: Systemd start for nagios failed!
journalctl log for nagios:
-- No entries --
Error: /Stage[main]/Nagios::Service/Service[nagios]/ensure: change from 'stopped ' to 'running' failed: Systemd start for nagios failed!
journalctl log for nagios:
-- No entries --
The above error was encountered while trying to apply the service.pp configuration to the server with puppet agent test. The reason for this error was because the service name in the file was named incorrectly as "nagios" instead of "nagios4" which is the correct name of the service. Once this was changed, the configuration applied successfully.
To fix the issue of cgi files being downloaded instead of executed, enable the cgi module.
a2endmod cgi
Restart apache2 after
systemctl restart apache2
Language validation error in the init.pp file
This error was caused by a typo within the init.pp file. It was resolved and the configuration applied successfully after correcting the language
External Resources
N/A
Ticket Reference
https://rt.dataraster.com/Ticket/Display.html?id=211