Skip to content

About

Nagios Plugin for Cacti is a complete UI replacement for Nagios fully integrated into Cacti.

Resources

Stars

4 stars

Watchers

9 watching

Forks

Repository files navigation

NPC Quick Start Guide

NPC is designed to be a complete web based UI replacement to Nagios while fully integrating into Cacti using the Cacti Plugin Architecture. This integration will provide a single point of access for trending and alert monitoring.

IMPORTANT NOTE: Since this is a fresh port of a 10 year old Cacti plugin, you should be using it in a non-production setup until further migration testing has been performed by the Cacti community.

Versions and compatibility

This README describes the develop source branch.

Code Plugin version Minimum Cacti declared in INFO
Source branch 3.1 1.2.1

No GitHub release is published for this repository. The source version above is not a published-release designation. Follow the development caveats and requirements in this README before deployment.

Install this plugin in <cacti-root>/plugins/npc, using the directory name npc rather than plugin_npc.

See CHANGELOG.md for the version history.

Status

The earlier missing-base-controller problem is fixed in this branch: npc.php loads controllers/controller.php before loading the selected module. The non-production warning above still applies; this correction is not a claim that every legacy workflow has been validated.

The screens, settings and scripts described below are what the code provides. Anything that was part of the original ExtJS plugin and is not listed here is not implemented in this version.

Features

  1. An NPC tab in the console header with seven screens: Dashboard, Hosts, Services, Comments, Downtime, Event Log and Process Info, and an Import screen for users who may add devices.

  2. The screens are built with jQuery on the Cacti theme. ExtJS is not used.

  3. The status comes from a running Nagios 4 or Naemon through Livestatus, or, as before, from the NDOUtils tables in the Cacti database. The Data Source setting selects one; NDOUtils stays the default.

  4. The data of a screen is requested as JSON. The Hosts, Services and Event Log screens refresh themselves every Portlet Refresh Rate seconds. Changing the tab loads a new page.

  5. Host and service commands are sent through Livestatus, or written to the Nagios command file for the NDOUtils data source. The command dialog offers Acknowledge Problem, Add Comment, Schedule Downtime, Schedule Check and Enable or Disable Notifications, each with the values Nagios needs. NPC checks every value again before sending the command, and the dialog shows the reason when a command is refused.

  6. A "Nagios Host Mapping" drop-down on the Cacti device page.

  7. The command line scripts perfdata.php and cli.php, which print Nagios performance data in the form a Cacti data input method reads.

Per user screen layouts have server side code but no screen, so they cannot be used from the interface.

Unchecked hosts and services are shown as pending. Active downtime comes from Nagios's status depth, so future schedules do not hide maintenance already in progress and an untriggered flexible window is not shown as active downtime. Host imports preserve IPv6 interface zones and reject addresses that identify multiple Cacti devices. Existing address caches rebuild once for this change.

Importing Nagios hosts

The Import screen lists the Nagios hosts that no Cacti device is mapped to. It is shown to users who hold the Devices realm as well as the NPC realm.

  1. Check the hosts to import and choose the Device Template for new devices (the default comes from the Default Device Template setting), then click Continue.

  2. The next page shows what will happen to each host: a new device is added, the host is mapped to the existing device with the same address, or the host is left out because its address matches more than one device. IPv4 and IPv6 addresses are compared in their canonical form, and the addresses of Cacti devices that are host names are looked up.

  3. Click Continue to import. New devices take the host name as description, the Nagios address as hostname and the SNMP and availability defaults of Cacti. The result of each host is shown as a message.

Usage

With the exception of some installation notes documentation is very slim. Watch the forums and the NPC GitHub for additional info. Here are a few tips to get you started:

  • Click a host or service name to open a dialog with its details.

  • The Hosts and Services screens follow the Nagios status layout: the time of the last update and the refresh interval, the Host Status Totals and Service Status Totals, and a list with the status, last check, duration, attempt, status information and a link to the Cacti graph mapped to the host or service. The Services list is sorted by host and shows each host name once. Each status has its own colour, with the status also written in the cell.

  • A count in the totals lists the hosts or services in that status; All Problems and the Problems only checkbox list those that are not up or ok. The Hosts and Services lists show up to 1000 rows.

  • The gear icon next to a host or service name opens the command dialog. It is shown, and commands are accepted, only when Remote Commands is enabled in the settings and the user holds the NPC Global Commands realm.

    • Acknowledge Problem: sticky, send notification, persistent comment, author and comment.
    • Add Comment: persistent, author and comment.
    • Schedule Downtime: start and end time, fixed or flexible with a duration, author and comment.
    • Schedule Check: the time of the check, forced or not.
  • The Comments screen lists host and service comments. The cross at the end of a host comment deletes it after a confirmation.

  • The Dashboard shows the host and service status counts and the host and service problems.

  • The other lists show the first 25 rows. There are no paging controls.

IMPORTANT NOTE: Since this is a fresh port of a 10 year old Cacti plugin, you should be using it in a non-production setup until further migration testing has been performed by the Cacti community.

Installation

The remainder of the document provides the steps that are required to install and configure the NPC Plugin for Cacti.

Requirements

Below are the minimum requirements:

  • Cacti 1.2.1 or later in the 1.2 series (compat in the INFO file). The CI workflow tests against the Cacti 1.2.x branch only.
  • PHP 8.2 or later. The CI workflow runs PHP 8.2 through 8.5 and includes a non-blocking PHP 8.6 experimental job.
  • MySQL or MariaDB, as required by Cacti.
  • One of:
    • Nagios 4 or Naemon with the Livestatus broker module (the tests use Naemon 1.6.0 with naemon-livestatus).
    • Legacy: Nagios 3.x with NDOUtils 1.4b7.

The plugin needs no PHP extension beyond the ones Cacti itself needs. Imported hosts are added through Cacti's device API, the same way the Devices page adds them.

The NPC Plugin, first written for Cacti 0.8.7, has been updated to work with Cacti 1.2.x. However, testing has been very light. We will need feedback from users as to its usability with this Cacti version.

The default memory limit for PHP probably will not be enough to run NPC. Edit /etc/php.ini and update the memory_limit option if you find times when NPC is causing Cacti to run out of memory.

IMPORTANT NOTE: Since this is a fresh port of a 10 year old Cacti plugin, you should be using it in a non-production setup until further migration testing has been performed by the Cacti community.

Installing NPC

Grab the latest version of NPC from GitHub using the following steps:

  1. cd <path_to_cacti>/plugins

  2. git clone https://github.com/Cacti/plugin_npc.git npc

    The directory has to be named npc.

  3. Ensure permissions are set for the apache user to read

  4. login to Cacti as an admin.

  5. Install the NPC Plugin

    1. Go to Console > Configuration > Plugins

    2. Click the Install Plugin icon to the left of the 'Npc' plugin line. The plugin is listed as "Nagios Plugin for Cacti" with the status Installed.

    3. Next, click the Enable Plugin icon on the same line

    The same can be done from the command line:

    php cli/plugin_manage.php --plugin=npc --install --enable
  6. Grant the realms under Console > Configuration > Users, on the Permissions tab of each user:

    • NPC - the NPC tab and all of its screens.

    • NPC Global Commands - sending commands to Nagios. The NPC realm alone is not enough.

  7. You can find the NPC plugin options under Console > Configuration > Settings in the NPC tab.

Installing creates 62 tables with the prefix npc_ in the Cacti database, one column (npc_host_object_id) on the Cacti host table, the two realms, and the settings npc_date_format, npc_time_format and npc_log_level with their defaults.

Without a Livestatus address, or NDO2DB feeding Nagios data into the NPC tables, the dashboard (and other screens) will be empty.

Next, there are a few NPC settings to add/update. Goto Console > Configuration > Settings > NPC.

  • Data Source - Livestatus or NDOUtils tables (legacy, the default). See Configuring Livestatus.

  • Livestatus Address - The Livestatus Unix socket, for example /var/cache/naemon/live, or host:port of a Livestatus TCP listener, for example 192.0.2.10:6557 or [2001:db8::10]:6557. A path has to be absolute and may not contain . or .. segments; NPC only ever connects to it when it is a socket.

  • Livestatus Timeout - Seconds, 1 to 60, default 10, for connecting to Livestatus and receiving one answer. Answers larger than 16 MB are refused.

  • Remote Commands - Check the checkbox to enable remote commands (off by default). At the moment this is system wide. A user also needs the "NPC Global Commands" realm (granted in the user's Realm Permissions) to execute commands; the realm is checked by name, so no page of that name exists in the plugin directory.

  • Nagios Command File Path - NDOUtils data source only. Add the path to the Nagios command file. It will be something like /usr/local/nagios/var/rw/nagios.cmd. The web server user has to be able to read and write the file. With Livestatus, commands go through the Livestatus socket instead.

  • Nagios URL - The URL of the Nagios web interface. The value is stored and handed to the page, but no screen uses it in this version.

  • Date Format and Time Format - Default Y-m-d and H:i. The choices are the nine date and six time formats in the drop-downs. They format the dates on the Process Info screen. The other screens show the dates as Nagios stored them.

  • Portlet Refresh Rate - Seconds between refreshes of the Hosts, Services and Event Log screens, default 60. The text next to the field gives a minimum of 30 seconds, which is not enforced.

  • Host/Service Config Type - 0 or 1, default 1. It selects the rows with that config_type in the host and service tables. If you can see host and service groups but not hosts or services try the other value.

  • Host Icons and Service Icons - Stored, but no screen uses them in this version.

  • Logging Level - None (default), Error, Warn, Info or Debug. NPC writes to the Cacti log (log/cacti.log) with the component NPC. Debug fills the log quickly.

Upgrading and uninstalling

Replace the files (for example git pull in the plugin directory). When the version in INFO differs from the version Cacti has stored, the next load of Console > Configuration > Settings runs the schema upgrade, removes the files that manifest.json lists as tombstones together with the tests directory and phpunit.xml, resets the stored per user NPC settings and records the new version.

Disable and Uninstall are the same Plugins page icons, or --disable and --uninstall of plugin_manage.php. Uninstalling drops all npc_ tables, including the Nagios data collected in them, drops the npc_host_object_id column, and removes the realms and the NPC settings.

Command line scripts

Both scripts are run with php from any directory and read the Cacti configuration. perfdata.php is the one a Cacti data input method runs, for example php <path_cacti>/plugins/npc/perfdata.php --type=service --id=<service object id>. It prints the numeric performance values of the newest stored service check as label:value pairs separated by spaces, which is the form a Cacti script data input method reads. A service can also be selected with --host=<host name> --service=<service description>. Host checks (--type=host) also use the newest stored check. Unknown values such as load15=U are omitted from poller output. Quoted labels are supported; spaces and colons in labels become underscores in both generated fields and poller output. Labels that collide after normalization are omitted rather than assigning one metric's value to another field.

Options of perfdata.php:

  • --type=host|service and --id=<object id>, --host=<name>, --service=<description> select the object.

  • --list-hosts [--hostgroup=<alias>], --list-hostgroups and --list-services print the objects with their IDs.

  • --hostgroup and --ds are accepted. --ds is not used.

cli.php takes the same options and adds --perfdata (the default), --perf-history with --host, --service, --begin=<date> and --end=<date>, which prints the end time and performance data of the checks in that range. --list-services accepts --host=<display name>. The usage text of both scripts names --datasource and does not list all options; the options above are the ones the code reads.

Configuring Livestatus

Load the Livestatus broker module in Nagios 4 or Naemon. With Naemon's naemon-livestatus package, /etc/naemon/module-conf.d/livestatus.cfg holds the line, with either a Unix socket:

broker_module=/usr/lib/naemon/naemon-livestatus/livestatus.so /var/cache/naemon/live

or a TCP listener:

broker_module=/usr/lib/naemon/naemon-livestatus/livestatus.so inet_addr=0.0.0.0:6557

For a Unix socket, the web server user needs read and write access to the socket, for example by membership in the naemon group. Livestatus over TCP has no authentication: anyone who can reach the port can read the status and send commands, so let only the Cacti server reach it.

Then set Data Source to Livestatus and the Livestatus Address under Console > Configuration > Settings > NPC. NPC gives every host, service and group an ID in the npc_objects table the first time it lists it; objects that NDOUtils listed before keep their ID, so host and graph mappings carry over.

With Livestatus, these parts still read the NDOUtils tables and show nothing without them: the Nagios Host Mapping drop-down on the device page, perfdata.php and cli.php, and the check performance, notification and state history data.

Configuring Nagios for NDOUtils (legacy)

Refer to the Nagios documentation for installation. Some parts of NPC like reporting and the status map use the Nagios interface by wrapping the Nagios CGI's in an Iframe. Be sure to have the Nagios web UI working if you want to use the reporting and status map features.

The following parameters are found in the Nagios configuration file nagios.cfg

The power of NPC is greatly enhanced by the ability to issue commands to the Nagios process. To enable external commands in Nagios set:

check_external_commands=1

Check external commands as often as possible.

command_check_interval=-1

Broker all events.

event_broker_options=-1

The path to the event broker module and config file which you will install next. This example assumes Nagios is installed in /usr/local/nagios. Adjust the path to suit your installation.

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

If you want to use performance data from Nagios plugins to create graphs in Cacti then set the following parameter.

process_performance_data=1

Setting host_perfdata_command and service_perfdata_command is not necessary. The performance data will be written to the NPC database where it can be polled by cacti using the perfdata.php script included with NPC.

Installing/Configuring NDO2DB

NOD2DB is part of the NDOUTILS package. Nagios hands events off to NDO2DB via the event broker. NDO2DB handles the actual inserts of Nagios data into the NPC tables.

Instructions for compiling, installing, and configuring NDO2DB are included in the README file of the ndoutils package. The README has four sections. Skip the section on initializing the database.

  1. Follow the 'COMPILING INSTRUCTIONS' section of the README.

  2. Skip the 'INITIALIZING THE SQL DATABASE' section of the README

  3. Follow the 'INSTALLING THE NDOMOD BROKER MODULE' section of the README

  4. Follow the 'INSTALLING THE NDO2DB DAEMON' section of the README

Edit /usr/local/nagios/etc/ndo2db.cfg and add/update the following parameters:

db_servertype=mysql
db_host=localhost (the host/ip where cacti database is running)
db_port=3306
db_name=cacti (Your cacti database name)
db_prefix=npc_
db_user=<user> (Your cacti database user)
db_pass=<pass> (Your cacti user password)

The user/pass you assign needs select, insert, update, delete on all the npc_ tables.

ndo2db can communicates with the Nagios ndo2db.o module via unix socket or TCP. Use whatever works for you (I use the TCP mode) but you need to set it the same in both the ndo2db.cfg and ndomod.cfg.

NOTE: The config_output_options parameter in ndomod.cfg must be set to 2 (config_output_options=2).

Here are working ndo2db.cfg and ndomod.cfg configs. As noted above the database parameters need to be changed for your database.

ndo2db.cfg

ndo2db_user=nagios
ndo2db_group=nagios
socket_type=tcp
socket_name=/usr/local/nagios/var/ndo.sock
tcp_port=5668
db_servertype=mysql
db_host=localhost
db_port=3306
db_name=DATABASE_NAME
db_user=DATABASE_USER
db_pass=DATABASE_PASSWORD
db_prefix=npc_
max_timedevents_age=1440
max_systemcommands_age=10080
max_servicechecks_age=10080
max_hostchecks_age=10080
max_eventhandlers_age=44640
debug_level=1
debug_verbosity=1
debug_file=/usr/local/nagios/var/ndo2db.debug
max_debug_file_size=1000000

ndomod.cfg

instance_name=default
output_type=tcpsocket
output=127.0.0.1
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=15
data_processing_options=-1
config_output_options=2

NOTE: There have been reports of the ndo2db process dying (regularly) on old versions of ndo2db. To get this, setup the process to respawn via init or systemd. If you have trouble with the daemon dying you can add the following line to /etc/inittab. Only do this if ndo2db frequently dies unexpectedly on you.

ndo:345:respawn:/usr/local/nagios/bin/ndo2db -c /usr/local/nagios/etc/ndo2db.cfg

After editing inittab issue the following command:

telinit Q

You may see messages like the following in your syslog when using init to respawn ndo2db:

Apr 19 11:11:55 acid init: Id "ndo" respawning too fast: disabled for 5 minutes

Besides muddying the logs there is no harm and so far this is the only way I have been able to keep ndo2db running.

Translations

Translatable strings are collected into locales/po/cacti.pot by locales/build_gettext.sh, which needs GNU gettext (xgettext, msgmerge, msgfmt), realpath and GNU sed (the script fails with the BSD sed of macOS). The per language .po and .mo files are maintained on the Cacti translation server (Weblate) and are not changed in pull requests. A pull request that adds or changes a string wrapped in __() includes only the regenerated locales/po/cacti.pot.

Development and tests

The tests run inside a Cacti checkout of the 1.2.x branch that has its development dependencies installed (Pest, in include/vendor/bin), with the plugin at plugins/npc, PHP 8.2 or later with Xdebug for the coverage report, and a database configured in include/config.php. The file tests/.cacti-version has to contain 1.2.x, develop, or the exact contents of the Cacti include/cacti_version.

From the Cacti root:

echo -n "1.2.x" > plugins/npc/tests/.cacti-version
include/vendor/bin/pest --configuration=plugins/npc/phpunit.xml --coverage-clover=plugins/npc/coverage/clover.xml

From the plugin directory, with the branch the change is based on as the reference:

php tests/bin/patch-coverage.php coverage/clover.xml origin/develop 100
php tests/bin/check-i18n-pot.php origin/develop
php tests/bin/validate-manifest.php

The end-to-end tests of the Livestatus data source need a Naemon with Livestatus. tests/naemon builds one with hosts and services in a fixed mix of states; the CI workflow starts it before the tests:

docker build -t npc-naemon-test plugins/npc/tests/naemon
docker run -d --name npc-naemon -p 127.0.0.1:6557:6557 npc-naemon-test
NPC_TEST_LIVESTATUS=127.0.0.1:6557 include/vendor/bin/pest --configuration=plugins/npc/phpunit.xml

Without NPC_TEST_LIVESTATUS those tests are skipped. With NPC_LIVESTATUS_LISTEN=unix the container listens on /var/cache/naemon/live instead, for a test through a shared volume.

patch-coverage.php fails when fewer than 100 percent of the changed lines of the measured files are executed. check-i18n-pot.php fails when translatable strings changed without a regenerated locales/po/cacti.pot. validate-manifest.php fails when the top level files do not match expected in manifest.json.

Bugs and Feature Enhancements

Bug and feature enhancements for the npc plugin are handled in GitHub. If you find a bug, first search the Cacti forums for a solution before creating an issue in GitHub.


Copyright (c) 2004-2026 - The Cacti Group, Inc.

About

Nagios Plugin for Cacti is a complete UI replacement for Nagios fully integrated into Cacti.

Resources

Stars

4 stars

Watchers

9 watching

Forks

Releases

Packages

Used by

Contributors

Languages