Last active
August 15, 2025 14:06
-
-
Save githubfoam/3c4457522155ec602867a8c81f55fb73 to your computer and use it in GitHub Desktop.
nagios_core_container_experience
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-------------------------------------------------------------------------------------------------- | |
# Check if container is running | |
docker-compose -f docker-compose.yml.ubuntu ps | |
Check the container is running | |
docker ps | |
Look for your Nagios container, something like: | |
nagios_core 0.0.0.0:8080->80/tcp Up nagios:4.5.9 | |
# Check logs for any startup issues | |
docker-compose -f docker-compose.yml.ubuntu logs nagios459 | |
docker logs <container_name> | |
Access the web interface | |
URL: | |
http://<docker_host_ip>:<mapped_port> | |
the volume name in your docker-compose.yml.ubuntu is not actually just nagiosetc. | |
When Docker Compose creates a named volume without an absolute path, it prefixes it with the project name from your compose file. | |
$ docker volume ls | grep nagiosetc | |
local docker-nagios-ubuntu_nagiosetc | |
How to inspect the right volume | |
docker volume inspect docker-nagios-ubuntu_nagiosetc | |
How to avoid the long prefix | |
If you want your volumes to be exactly nagiosetc, you can: | |
Run Compose with a custom project name: | |
docker compose -f docker-compose.yml.ubuntu -p nagios up -d | |
Or explicitly declare the volume name in your YAML: | |
volumes: | |
nagiosetc: | |
name: nagiosetc | |
Edit configs in the volume | |
You can either: | |
Edit directly on the host: | |
sudo nano /var/lib/docker/volumes/nagiosetc/_data/nagios.cfg | |
Or enter the container | |
docker exec -it nagios459 bash | |
cd /opt/nagios/etc | |
docker exec -it nagios459 bash ls /opt/nagios/etc | |
# Enter the running container | |
docker exec -it nagios459 bash | |
# Or using docker-compose | |
docker-compose -f docker-compose.yml.ubuntu exec nagios459 bash | |
$ docker exec -it nagios459 ls /opt/nagios/etc | |
docker exec -it nagios459 /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 | |
Or copy them to your host for easier editing | |
docker cp nagios459:/opt/nagios/etc ./nagiosetc | |
Test configuration inside the container | |
docker exec -it nagios459 /opt/nagios/bin/nagios -v /opt/nagios/etc/nagios.cfg | |
-------------------------------------------------------------------------------------------------- | |
Add custom plugins | |
Put scripts in the customplugins volume: | |
docker run --rm -it -v customplugins:/data ubuntu bash | |
# Place your plugin in /data | |
chmod +x /data/check_myplugin.sh | |
11. Add Custom Plugins | |
Your setup has a custom plugins volume. Add plugins to /opt/Custom-Nagios-Plugins/ | |
# Copy plugins from host to container | |
docker cp ./my-custom-plugin.sh nagios459:/opt/Custom-Nagios-Plugins/ | |
# Make executable | |
docker exec nagios459 chmod +x /opt/Custom-Nagios-Plugins/my-custom-plugin.sh | |
-------------------------------------------------------------------------------------------------- | |
Backup your configs | |
Since these are Docker named volumes, back them up with: | |
docker run --rm -v nagiosetc:/data -v $(pwd):/backup ubuntu tar czf /backup/nagiosetc-backup.tar.gz -C /data . | |
docker run --rm -v nagiosvar:/data -v $(pwd):/backup ubuntu tar czf /backup/nagiosvar-backup.tar.gz -C /data . | |
# Create backup of configuration volume | |
docker run --rm -v nagios459_nagiosetc:/data -v $(pwd):/backup alpine tar czf /backup/nagios-config-$(date +%Y%m%d).tar.gz -C /data . | |
-------------------------------------------------------------------------------------------------- | |
13. Monitor Container Health | |
# Check container stats | |
docker stats nagios459 | |
# Check disk usage of volumes | |
docker system df -v | |
14. Configure NagiosGraph (Since It's Included) | |
Check NagiosGraph configuration: | |
ls -la /opt/nagiosgraph/etc/ | |
ls -la /opt/nagiosgraph/var/ | |
-------------------------------------------------------------------------------------------------- | |
5. Initial Configuration Setup | |
Inside the container, check key directories: | |
# Main configuration | |
ls -la /opt/nagios/etc/ | |
# Configuration files | |
ls -la /opt/nagios/etc/objects/ | |
# Custom plugins location | |
ls -la /opt/Custom-Nagios-Plugins/ | |
# Runtime data | |
ls -la /opt/nagios/var/ | |
-------------------------------------------------------------------------------------------------- | |
Validate Configuration | |
Always validate before restarting: | |
/opt/nagios/bin/nagios -v /opt/nagios/etc/nagios.cfg | |
10. Restart Nagios Service | |
Inside the container: | |
# Check if Nagios is running | |
ps aux | grep nagios | |
# Restart Nagios | |
service nagios restart | |
# Or reload configuration | |
service nagios reload | |
# service nagios restart | |
nagios: unrecognized service | |
/# systemctl status nagios 2>/dev/null || echo "systemctl not available" | |
systemctl not available | |
# Check for init scripts | |
ls -la /etc/init.d/ | grep nagios | |
/etc/init.d/nagios restart | |
Restart Methods (Try These in Order) | |
Method 1: Direct Process Control | |
# Kill current Nagios process | |
pkill nagios | |
# Start Nagios directly | |
/opt/nagios/bin/nagios -d /opt/nagios/etc/nagios.cfg | |
Reload Configuration Without Full Restart | |
Send HUP signal to reload config: | |
# Find Nagios PID | |
cat /opt/nagios/var/nagios.lock | |
# Send reload signal (replace PID_NUMBER with actual PID) | |
kill -HUP PID_NUMBER | |
# Or use pkill | |
pkill -HUP nagios | |
-------------------------------------------------------------------------------------------------- | |
Alternative: Restart from Outside Container | |
From your host system: | |
# Restart the entire container | |
docker-compose -f docker-compose.yml.ubuntu restart nagios459 | |
# Or stop and start | |
docker-compose -f docker-compose.yml.ubuntu stop nagios459 | |
docker-compose -f docker-compose.yml.ubuntu start nagios459 | |
-------------------------------------------------------------------------------------------------- | |
Verify Nagios is Running After Restart | |
# Check process | |
ps aux | grep nagios | |
# Check web interface | |
curl -I http://localhost/nagios/ | |
# Check if it's listening on port 80 | |
netstat -tlnp | grep :80 | |
# Verify configuration was loaded | |
tail -f /opt/nagios/var/nagios.log | |
-------------------------------------------------------------------------------------------------- | |
# 1. Validate config first | |
/opt/nagios/bin/nagios -v /opt/nagios/etc/nagios.cfg | |
# 2. If validation passes, restart Nagios directly | |
pkill nagios | |
/opt/nagios/bin/nagios -d /opt/nagios/etc/nagios.cfg | |
# 3. Verify it's running | |
ps aux | grep nagios | |
docker-compose -f docker-compose.yml.ubuntu restart nagios459 | |
-------------------------------------------------------------------------------------------------- | |
Nagios Core does not have true “auto-discovery” like some enterprise monitoring platforms (e.g., Zabbix, PRTG, or LibreNMS). | |
Nagios Core is configuration-driven, meaning it monitors only the hosts and services you explicitly define. | |
Important Notes | |
Nagios Core itself won’t automatically add hosts or services — you always need some script or automation to feed it configs. | |
Using auto-discovery scripts often requires careful testing — you don’t want hundreds of hosts added accidentally. | |
For containers, you can mount a directory like nagiosetc/auto and reload Nagios after scripts generate config files there. | |
-------------------------------------------------------------------------------------------------- | |
Using NRPE or NCPA for agent auto-registration | |
Remote hosts run NRPE or NCPA agents. | |
You can write a small script that detects newly installed agents and appends host/service definitions automatically to Nagios configs. | |
-------------------------------------------------------------------------------------------------- | |
Using configuration management tools | |
Tools like Ansible, Puppet, or Chef can: | |
Scan your network or inventory | |
Automatically generate Nagios config files | |
Deploy them to the Nagios server (or container) | |
Reload Nagios | |
-------------------------------------------------------------------------------------------------- | |
This is the closest to “auto-discovery” for Nagios Core | |
Third-party scripts/plugins | |
There are community scripts like nagios-discover or nagios-autodiscover that combine network scanning + config generation. | |
Typically, they: | |
Scan a network | |
Detect OS/services | |
Generate host/service definitions | |
Reload Nagios | |
-------------------------------------------------------------------------------------------------- | |
Using Nmap or network scanning scripts | |
You can scan a subnet to find hosts, then automatically generate Nagios host definitions. | |
nmap -sn 192.168.1.0/24 -oG - | awk '/Up$/{print $2}' > hosts.txt | |
Then generate define host{} blocks from hosts.txt: | |
awk '{print "define host{\n use linux-server\n host_name host"$1"\n address "$1"\n}\n"}' hosts.txt > newhosts.cfg | |
Place newhosts.cfg in /usr/local/nagios/etc/objects/ (or your container’s nagiosetc volume) and reference it in nagios.cfg. | |
-------------------------------------------------------------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment