Where IT meets innovation, IT-INFO lights the path to technological brilliance
Nagios is a powerful monitoring tool used for monitoring IT infrastructure to ensure systems, applications, and services are running smoothly. Docker provides a convenient way to deploy Nagios with all its dependencies in a containerized environment, simplifying setup and management.
Before proceeding, ensure you have the following:
If you haven't installed Docker yet, follow the installation instructions for your operating system from the official Docker documentation.
Create a docker-compose.yml
file in your preferred directory. This file will define the services required for Nagios:
nagios:
image: jasonrivers/nagios:latest
container_name: nagios
ports:
- "8080:80"
network_mode: "host"
environment:
- NAGIOS_FQDN=nagios.local
- NAGIOSADMIN_USER=nagiosadmin
- NAGIOSADMIN_PASS=nagios
volumes:
- ./nagios:/usr/local/nagios
- ./nagios/etc/nagios.cfg:/opt/nagios/etc/nagios.cfg
- ./logs:/var/log
jasonrivers/nagios:latest
pulls the latest Nagios image from Docker Hub.8080
to container port 80
for Nagios web interface.NAGIOSADMIN_USER
and NAGIOSADMIN_PASS
). Change these values for production setups../nagios
and /usr/local/nagios
to persist configuration and runtime data.Navigate to the directory containing docker-compose.yml
and run:
docker-compose up
Open your web browser and go to http://localhost:8080/nagios. Log in with the credentials specified in the docker-compose.yml
file (nagiosadmin/nagios
by default).
The etc
folder contains custom hosts and services, and Nagios config file:
libexec
folder contains the plugins.var
folder is created by Nagios; we don’t modify it.Inside the etc
folder, we have the objects
folder where we add hosts and services. Each file has its own host and service.
In the following example, we have fastapi
and postgres
files:
commands
file contains some commands that are executed when a service is running.cgi.cfg
file contains some Nagios configurations.nagios.cfg
file is the main config file of Nagios.The cgi.cfg
file content:
main_config_file=/opt/nagios/etc/nagios.cfg
physical_html_path=/usr/local/nagios/share
url_html_path=/nagios
show_context_help=1
use_authentication=1
authorized_for_system_information=nagiosadmin
authorized_for_configuration_information=nagiosadmin
authorized_for_system_commands=nagiosadmin
authorized_for_all_services=nagiosadmin
authorized_for_all_hosts=nagiosadmin
authorized_for_all_service_commands=nagiosadmin
authorized_for_all_host_commands=nagiosadmin
setenforce=0
The main nagios.cfg
contains a lot of configs, but the important thing for us is to add the paths to objects files. Example:
cfg_file=/usr/local/nagios/etc/objects/commands.cfg
cfg_file=/usr/local/nagios/etc/objects/fastapi.cfg
cfg_file=/usr/local/nagios/etc/objects/postgres.cfg
Here is how we create the hosts and services. By default, there are some templates created by Nagios like:
generic-host
generic-service
The templates contain some default important configs:
# nagios/etc/objects/fastapi.cfg
define host {
use generic-host
host_name api
alias FastAPI Application
address localhost:8080
contact_groups admins
max_check_attempts 3
}
define service {
use generic-service
host_name api
service_description HTTP
check_command check_http
notifications_enabled 1
max_check_attempts 1
check_interval 1
}
define service {
use generic-service
host_name api
service_description FastAPI Log Monitoring
check_command check_logfiles!/usr/local/nagios/etc/check_logfiles.cfg
notifications_enabled 1
check_period 24x7
contact_groups admins
max_check_attempts 1
check_interval 1
}
Created on Aug. 28, 2024, 1:29 p.m.