Skip to main content

Nagios smart home integration, free and open source

Nagios integration for Gladys Assistant

Your Nagios Core hosts and services in Gladys, with scenes when a host goes down or a service fails.

Bring your Nagios Core monitoring into Gladys: each host becomes a device (up, services WARNING, CRITICAL and UNKNOWN, unhandled problems, acknowledged, downtime), a "Nagios" device sums up the whole setup and tells whether Nagios runs, and your scenes react when a host goes down or a service fails — a red light when the NAS is down, a message when a backup is CRITICAL. A scene can also acknowledge the problems of a host or have it checked right away, and a dashboard widget lists the problems in progress.

The integration reads the JSON CGIs of the Nagios web interface on your local network, with a web user. Nothing goes through a cloud.

Tested against a real Nagios Core 4.5 (4.5.12, jasonrivers/nagios Docker image, dummy checks forced to WARNING, CRITICAL and UNKNOWN, a host DOWN, a host UNREACHABLE behind it, a downtime, acknowledgements, a host never checked, the daemon stopped). Feedback welcome: github.com/guim31/gladys-nagios/issues.

What you need​

  • Gladys Assistant 5.1.0 or later.
  • Nagios Core 4 (4.0 or later: the JSON CGIs statusjson.cgi and objectjson.cgi came with it) and its web interface, reachable from the Gladys machine. Nagios XI, Icinga, Naemon and Shinken are other products.
  • A web user for Gladys, with the rights it needs in cgi.cfg.

Getting started​

1. Create a web user​

On the Nagios server, add a user to the password file of the web interface (the path depends on the installation):

htpasswd /usr/local/nagios/etc/htpasswd.users gladys

Then give it the rights in cgi.cfg, by adding gladys to these lines (comma separated):

authorized_for_all_hosts=nagiosadmin,gladys
authorized_for_all_services=nagiosadmin,gladys
authorized_for_all_host_commands=nagiosadmin,gladys
authorized_for_all_service_commands=nagiosadmin,gladys

The last two are only needed to acknowledge or check now from Gladys: leave them out if Gladys must only read. Without the first two, the user sees only the hosts and services it is a contact of. No restart is needed: the CGIs read cgi.cfg at each request. The commands also need check_external_commands=1 in nagios.cfg (the default).

2. Configure the integration​

In Gladys, open the configuration of the integration:

  • Address: the address of the Nagios web interface, e.g. 192.168.1.2/nagios. http:// and /nagios are added unless you type others (/nagios4 on Debian and Ubuntu packages); the address of a page of the interface, copied from the browser, works too.
  • Web user and Password: the user of step 1.
  • Host groups (optional): names of Nagios host groups (hostgroup_name) separated by commas, e.g. homelab, linux-servers: a host in one of them is kept. Empty: every host.
  • Refresh interval: 30 seconds to 5 minutes (1 minute by default).
  • Allow acknowledging from scenes and Allow checking now from scenes: untick to turn these actions off.
  • Accept self-signed certificates: only for an https:// address with a certificate of your own; the certificate is then not verified.
  • Language of the names: language of the feature names and of the scene results.

Save, then click Test the connection: it shows the Nagios version, the number of hosts, of hosts down and of services in problem.

3. Add the devices​

Open the Discover tab of the integration and add the hosts to follow, and the "Nagios" device if you want the totals. The scene triggers work for every host, added to Gladys or not.

The devices​

Each host (named after its alias in Nagios):

FeatureValue
Host up1 UP, 0 DOWN or UNREACHABLE; empty while the host is PENDING
Services WARNINGnumber of services WARNING
Services CRITICALnumber of services CRITICAL
Services UNKNOWNnumber of services UNKNOWN
Unhandled problemshost and service problems neither acknowledged nor in a downtime
Host acknowledged1 while the host is DOWN or UNREACHABLE and its problem acknowledged
In downtime1 while the host is in a scheduled downtime

The Nagios device: Nagios running (1 while the Nagios daemon updates its status, 0 once it is stopped), Hosts down (DOWN or UNREACHABLE), Services WARNING, Services CRITICAL, Services UNKNOWN and Unhandled problems, over the hosts of the configuration.

A host is UNREACHABLE when it is down behind a parent (parents) that is down too. The service counts include the states Nagios is still confirming (SOFT), as its web interface shows them. Values are sent to Gladys only when they change, and every 6 hours otherwise.

Dashboard​

The Nagios problems widget shows three tiles — the hosts down, the services CRITICAL, the unhandled problems — and the problems: hosts DOWN, then UNREACHABLE, then services CRITICAL, UNKNOWN and WARNING, the newest first. Each row gives the service and its state, the host, ✓ once acknowledged and ⏸ in a downtime. Ten rows at most. Refresh reads Nagios again. In its settings, choose hosts to show only theirs (empty: every host).

Scenes​

Triggers​

  • A host goes down: a host goes DOWN or UNREACHABLE. Filter: hosts (empty: any). Variables: host name, state (DOWN, UNREACHABLE). A host going from DOWN to UNREACHABLE is not announced twice.
  • A host is back up: a host announced down is UP again. Variables: host name, duration in minutes.
  • A service has a problem: a service enters WARNING, CRITICAL or UNKNOWN, or changes between them (WARNING to CRITICAL, for example). Filters: hosts, states (empty: any; for "CRITICAL only", choose CRITICAL). Variables: host name, service, state, check output (its first line).
  • A service is OK again: a service announced in problem is OK again. Filters: hosts, the last problem state announced. Variables: host name, service, last problem state, duration in minutes.
  • Nagios no longer watches: the web interface fails to answer twice in a row, or the Nagios daemon is stopped (variables: address, error).

The problems already there when the integration starts are not announced, but their end is. Only confirmed (HARD) states count: while Nagios retries a check (SOFT state, up to max_check_attempts), nothing is announced, as Nagios does not notify either. A change that happens while Gladys or the integration restarts is announced once at the next read. A problem in a downtime (of the service or of its host) is not announced; one that is still there when the downtime ends is announced then.

Actions​

  • Acknowledge the problems of a host: acknowledges in Nagios the host problem (DOWN, UNREACHABLE) and each of its services in problem not acknowledged yet, with a comment (empty: "Acknowledged from Gladys"). The acknowledgement is sticky (until the host is UP or the service OK) and its comment is kept across restarts; the author is the web user (the alias of its contact when lock_author_names is on, the default). Returns the number acknowledged. Turn it off with "Allow acknowledging from scenes".
  • Check a host now: asks Nagios to check the host and all its services right away (forced, as "Re-schedule the next check" of the web interface), for example after a repair or a reboot. The new states come with the next reads. Turn it off with "Allow checking now from scenes".
  • Read the problems: counts and lists the problems of one host, or of all, for the next actions: number, unhandled, hosts down, services CRITICAL, WARNING and UNKNOWN, and the list "host: problem".

Scene ideas​

  • A red light when the NAS is down: trigger "A host goes down", host NAS → turn the living-room lamp red and send {{triggerEvent.data.host}}: {{triggerEvent.data.state_name}}.
  • Critical services only: trigger "A service has a problem", state CRITICAL → message \{\{triggerEvent.data.host\}\} / \{\{triggerEvent.data.service\}\}: \{\{triggerEvent.data.output\}\}.
  • Back after a reboot: when the smart plug of the NAS is turned on again, wait 3 minutes, then "Check a host now" on the NAS: no need to wait for the next check.
  • Morning report: every day at 8:00, "Read the problems" → send the count and the list when the count is above 0.
  • Seen from the couch: a dashboard button or a Zigbee remote runs "Acknowledge the problems of a host" on the NAS.

Troubleshooting​

  • "User or password refused by the web server": check the user in htpasswd.users (log in to the web interface with it).
  • "Nagios does not answer": check the address from the Gladys machine. localhost is the integration container itself: use the IP address of the Nagios machine.
  • "No Nagios Core 4 at this address": the web path is wrong (/nagios, /nagios4…), or another program answers there. Copy the address of the Nagios home page from the browser.
  • "The Nagios daemon is not running": the web server answers but Nagios itself is stopped or hung (its status file is missing or old): restart Nagios, and check its configuration with nagios -v nagios.cfg.
  • "No host visible": add the user to authorized_for_all_hosts and authorized_for_all_services in cgi.cfg, or make it a contact of the hosts.
  • "A host group of the configuration does not exist": check the spelling, it is the hostgroup_name, not its alias.
  • "Certificate refused": tick "Accept self-signed certificates".
  • The acknowledgement or the check is refused: add the user to authorized_for_all_host_commands and authorized_for_all_service_commands in cgi.cfg; "Nagios does not accept external commands": set check_external_commands=1 in nagios.cfg and restart Nagios.

Limits​

  • One Nagios per integration. Nagios XI and the forks (Icinga, Naemon) are not supported: their interfaces differ.
  • Host states and service states only: no metrics, no performance data.
  • The integration reads Nagios at the chosen interval: an event that comes and goes between two reads is missed. Nagios writes its status every 10 seconds (status_update_interval): an acknowledgement shows a few seconds later.
  • "A service is OK again" also fires when a service in problem is removed from monitoring; a host removed from Nagios or from the scope ends quietly.
  • At most 30 scene events per read: a network outage can raise dozens at once; the rest follows at the next reads.
  • No quota: each read sends three requests to the CGIs (one more per host group, and the list of the objects once an hour, for the aliases). A command is two requests (the form, for the anti-CSRF token of Nagios 4.5, then the command).

Not affiliated with Nagios Enterprises.

Configuration settings​

These are the settings Nagios asks for in its configuration screen in Gladys.

SettingTypeRequiredDescription
Your Nagios CoresectionNoNagios Core 4 with its web interface (JSON CGIs). Use a web user of htpasswd.users listed in cgi.cfg under authorized_for_all_hosts and authorized_for_all_services, plus the *_commands lines to acknowledge or check now. Then add the hosts from the Discover tab.
AddressstringYesThe address of the Nagios web interface; http:// and /nagios unless you type others.
Web userstringYesA user of htpasswd.users, the one you log in to the Nagios web interface with.
PasswordsecretYesIts password. A dedicated user is best: give it only the rights listed above.
Host groups (optional)stringNoNames of Nagios host groups (hostgroup_name), separated by commas: a host in one of them is kept. Empty: every host.
OptionssectionNo
Refresh intervalselectNoHow often Nagios is read: three requests to the JSON CGIs each time.
Allow acknowledging from scenesbooleanNoUntick to turn off the "Acknowledge the problems of a host" scene action.
Allow checking now from scenesbooleanNoUntick to turn off the "Check a host now" scene action.
Accept self-signed certificatesbooleanNoOnly for https:// with a certificate of your own: the certificate is then not verified.
Language of the namesselectNoLanguage of the feature names (set when a device is added) and of the scene results.

How to install Nagios in Gladys​

  1. In Gladys, open Integrations: Nagios appears in the catalog, next to the native integrations, with a community badge.
  2. Click Install. Gladys pulls the Docker image (ghcr.io/guim31/gladys-nagios:1.0.0), starts it in a sandbox isolated from the core, and generates the integration's interface (devices, discovery and configuration).
  3. Open the Configuration screen of the integration, fill in the settings, and save.
  4. You can also install it directly from its repository URL: https://github.com/guim31/gladys-nagios.

Nagios requires Gladys >=5.1.0. The catalog inside Gladys refreshes every hour, so a new version becomes available at most one hour after its release.

Not running Gladys yet? It is free and open source: follow the installation guide to get started.

About external integrations​

Nagios is an external integration: a community integration packaged as a Docker container and published on GitHub, that Gladys installs in one click and runs in a sandbox isolated from its core. It is published and maintained by guim31, not by the Gladys core team.

Subscribe to the Gladys Assistant newsletter

A few emails per month about new releases and project news. Sent by Pierre-Gilles Leymarie, founder of the project. Unsubscribe anytime 🙂