Integrate Nagios Core 4.5 with Grafana dashboards for advanced monitoring visualization

Intermediate 45 min Apr 09, 2026 91 views
Ubuntu 24.04 Debian 12 AlmaLinux 9 Rocky Linux 9

Connect Nagios Core 4.5 with Grafana through NDOUtils and MySQL to create powerful monitoring dashboards. This integration provides advanced visualization capabilities, real-time alerting, and comprehensive monitoring insights for your infrastructure.

Prerequisites

  • Nagios Core 4.5 installed and configured
  • Root or sudo access
  • At least 2GB RAM
  • 10GB free disk space

What this solves

This tutorial shows you how to integrate Nagios Core 4.5 with Grafana dashboards for advanced monitoring visualization. By connecting Nagios data through NDOUtils to a MySQL database, you'll create powerful Grafana dashboards that provide real-time insights, historical trending, and customizable alerting for your infrastructure monitoring.

Step-by-step installation

Update system packages

Start by updating your package manager to ensure you get the latest versions of all components.

sudo apt update && sudo apt upgrade -y
sudo dnf update -y

Install required dependencies

Install the necessary packages for NDOUtils, MySQL, and build tools that will be needed for compilation.

sudo apt install -y mysql-server mysql-client build-essential libmysqlclient-dev \
make gcc g++ automake autoconf libtool pkg-config libssl-dev wget
sudo dnf install -y mysql-server mysql-devel gcc gcc-c++ make automake \
autoconf libtool pkgconfig openssl-devel wget tar

Configure MySQL for Nagios integration

Start MySQL service and create a dedicated database and user for NDOUtils to store Nagios monitoring data.

sudo systemctl start mysql
sudo systemctl enable mysql
sudo systemctl start mysqld
sudo systemctl enable mysqld

Secure MySQL installation

Run the MySQL security script to set root password and remove test databases for production security.

sudo mysql_secure_installation
Note: Choose a strong root password and answer 'Y' to all security questions for a production environment.

Create Nagios database and user

Connect to MySQL and create the necessary database schema and user permissions for NDOUtils.

sudo mysql -u root -p
CREATE DATABASE nagios;
CREATE USER 'nagios'@'localhost' IDENTIFIED BY 'NagiosDBPassword123!';
GRANT ALL PRIVILEGES ON nagios.* TO 'nagios'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Download and compile NDOUtils

Download the NDOUtils source code and compile it to enable Nagios database integration.

cd /tmp
wget https://github.com/NagiosEnterprises/ndoutils/archive/ndoutils-2.1.3.tar.gz
tar -xzf ndoutils-2.1.3.tar.gz
cd ndoutils-ndoutils-2.1.3

Configure and compile NDOUtils

Run the configuration script and compile NDOUtils with MySQL support enabled.

./configure --prefix=/usr/local/nagios --enable-mysql --disable-pgsql
make all

Install NDOUtils binaries

Install the compiled NDOUtils binaries and configuration files to the Nagios directory.

sudo make install

Import NDO database schema

Import the NDOUtils database schema to create the necessary tables for storing Nagios data.

mysql -u nagios -p nagios < db/mysql.sql

Configure NDOUtils daemon

Create the NDOUtils configuration file to connect to MySQL and process Nagios events.

lock_file=/usr/local/nagios/var/ndo2db.lock
config_file=/usr/local/nagios/etc/ndo2db.cfg
db_servertype=mysql
db_host=localhost
db_port=3306
db_name=nagios
db_prefix=nagios_
db_user=nagios
db_pass=NagiosDBPassword123!
max_timedevents_age=1440
max_systemcommands_age=10080
max_servicechecks_age=5760
max_hostchecks_age=5760
max_eventhandlers_age=44640
debug_level=0
debug_verbosity=1
debug_file=/usr/local/nagios/var/ndo2db.debug
max_debug_file_size=1000000

Configure Nagios NDO module

Configure the NDO broker module to send Nagios events to the NDOUtils daemon.

instance_name=default
output_type=unixsocket
output=/usr/local/nagios/var/ndo.sock
tcp_port=5668
output_buffer_items=5000
buffer_file=/usr/local/nagios/var/ndomod.tmp
file_rotation_interval=14400
file_rotation_timeout=60
reconnect_interval=15
reconnect_warning_interval=900
data_processing_options=-1
config_output_options=2

Update Nagios main configuration

Add the NDO broker module to the main Nagios configuration to enable database integration.

sudo cp /usr/local/nagios/bin/ndomod.o /usr/local/nagios/bin/
broker_module=/usr/local/nagios/bin/ndomod.o config_file=/usr/local/nagios/etc/ndomod.cfg

Create NDOUtils systemd service

Create a systemd service file for NDOUtils to manage the daemon automatically.

[Unit]
Description=NDOUtils Database Daemon
After=mysql.service
Requires=mysql.service

[Service]
Type=forking
User=nagios
Group=nagios
ExecStart=/usr/local/nagios/bin/ndo2db -d -c /usr/local/nagios/etc/ndo2db.cfg
PIDFile=/usr/local/nagios/var/ndo2db.lock
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target

Set correct permissions

Set the proper ownership and permissions for NDOUtils files and directories.

sudo chown -R nagios:nagios /usr/local/nagios/var/
sudo chown nagios:nagios /usr/local/nagios/etc/ndo2db.cfg
sudo chown nagios:nagios /usr/local/nagios/etc/ndomod.cfg
sudo chmod 640 /usr/local/nagios/etc/ndo2db.cfg
sudo chmod 640 /usr/local/nagios/etc/ndomod.cfg
Never use chmod 777. It gives every user on the system full access to your files. Instead, fix ownership with chown and use minimal permissions.

Enable and start services

Enable and start both NDOUtils and Nagios services to begin data collection.

sudo systemctl daemon-reload
sudo systemctl enable ndo2db
sudo systemctl start ndo2db
sudo systemctl restart nagios

Install Grafana

Install Grafana from the official repository to create monitoring dashboards.

sudo apt-get install -y software-properties-common
wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
sudo apt-get update
sudo apt-get install -y grafana
sudo dnf install -y https://dl.grafana.com/oss/release/grafana-10.2.3-1.x86_64.rpm

Configure Grafana

Configure Grafana with security settings and database options for production use.

[server]
http_port = 3000
domain = example.com
root_url = http://example.com:3000/

[security]
admin_user = admin
admin_password = GrafanaAdminPassword123!
secret_key = SW2YcwTIb9zpOOhoPsMm

[database]
type = sqlite3
path = grafana.db

[auth.anonymous]
enabled = false

[log]
mode = file
level = info

Enable and start Grafana

Enable Grafana to start on boot and start the service to access the web interface.

sudo systemctl daemon-reload
sudo systemctl enable grafana-server
sudo systemctl start grafana-server

Configure firewall access

Open firewall ports for Grafana web interface access while maintaining security.

sudo ufw allow 3000/tcp
sudo ufw reload
sudo firewall-cmd --permanent --add-port=3000/tcp
sudo firewall-cmd --reload

Create Grafana MySQL data source

Configure Grafana to connect to the Nagios MySQL database as a data source for creating dashboards.

curl -X POST http://admin:GrafanaAdminPassword123!@localhost:3000/api/datasources \
-H "Content-Type: application/json" \
-d '{
  "name": "nagios-mysql",
  "type": "mysql",
  "url": "localhost:3306",
  "database": "nagios",
  "user": "nagios",
  "secureJsonData": {
    "password": "NagiosDBPassword123!"
  },
  "isDefault": true
}'

Create custom Nagios dashboard

Import a pre-configured dashboard JSON to visualize Nagios host and service data in Grafana.

{
  "dashboard": {
    "id": null,
    "title": "Nagios Infrastructure Overview",
    "tags": ["nagios", "monitoring"],
    "timezone": "browser",
    "panels": [
      {
        "id": 1,
        "title": "Host Status Summary",
        "type": "stat",
        "targets": [
          {
            "refId": "A",
            "rawSql": "SELECT COUNT(*) as total_hosts FROM nagios_hosts WHERE is_active=1",
            "format": "table"
          }
        ],
        "gridPos": {"h": 8, "w": 6, "x": 0, "y": 0}
      },
      {
        "id": 2,
        "title": "Service Status Distribution",
        "type": "piechart",
        "targets": [
          {
            "refId": "A",
            "rawSql": "SELECT current_state, COUNT(*) as count FROM nagios_servicestatus GROUP BY current_state",
            "format": "table"
          }
        ],
        "gridPos": {"h": 8, "w": 6, "x": 6, "y": 0}
      },
      {
        "id": 3,
        "title": "Recent Alerts",
        "type": "table",
        "targets": [
          {
            "refId": "A",
            "rawSql": "SELECT h.display_name as Host, s.display_name as Service, ss.output, FROM_UNIXTIME(ss.last_check) as Last_Check FROM nagios_servicestatus ss JOIN nagios_services s ON ss.service_object_id = s.service_object_id JOIN nagios_hosts h ON s.host_object_id = h.host_object_id WHERE ss.current_state > 0 ORDER BY ss.last_check DESC LIMIT 20",
            "format": "table"
          }
        ],
        "gridPos": {"h": 8, "w": 12, "x": 0, "y": 8}
      }
    ],
    "time": {"from": "now-1h", "to": "now"},
    "refresh": "30s"
  }
}

Import dashboard to Grafana

Import the custom dashboard configuration into Grafana using the REST API.

curl -X POST http://admin:GrafanaAdminPassword123!@localhost:3000/api/dashboards/db \
-H "Content-Type: application/json" \
-d @/tmp/nagios-dashboard.json

Configure Grafana alerting

Set up alert notifications to integrate with your existing notification systems.

curl -X POST http://admin:GrafanaAdminPassword123!@localhost:3000/api/alert-notifications \
-H "Content-Type: application/json" \
-d '{
  "name": "email-alerts",
  "type": "email",
  "settings": {
    "addresses": "admin@example.com",
    "subject": "Grafana Alert: {{range .Alerts}}{{.AlertName}}{{end}}"
  },
  "isDefault": true
}'

Verify your setup

Run these commands to verify that all components are working correctly and data is flowing from Nagios to Grafana.

sudo systemctl status ndo2db
sudo systemctl status nagios
sudo systemctl status grafana-server
mysql -u nagios -p -e "SELECT COUNT(*) FROM nagios.nagios_hosts;"
mysql -u nagios -p -e "SELECT COUNT(*) FROM nagios.nagios_servicestatus;"

Access Grafana at http://your-server-ip:3000 and log in with admin credentials. You should see the Nagios Infrastructure Overview dashboard with live monitoring data. For comprehensive monitoring tutorials, check out our guide on monitoring Linux system resources with automated alerts.

Common issues

SymptomCauseFix
NDO2DB fails to startMySQL connection issuesCheck database credentials and MySQL service status
No data in GrafanaNDOUtils not processing eventsVerify ndomod.o is loaded in nagios.cfg and restart Nagios
Permission denied errorsIncorrect file ownershipRun chown nagios:nagios on NDOUtils directories
Grafana dashboard shows no dataWrong MySQL query or data sourceTest data source connection and verify table names
High CPU usage from ndo2dbToo frequent data processingIncrease data_processing_options intervals in ndo2db.cfg

Next steps

Automated install script

Run this to automate the entire setup

Need help?

Don't want to manage this yourself?

We handle managed devops services for businesses that depend on uptime. From initial setup to ongoing operations.