For the complete documentation index, see llms.txt. This page is also available as Markdown.

Integrate Spike with Nagios

Connect Nagios Core, Nagios XI, Naemon or Shinken to Spike and get paged on phone, SMS, Slack and Teams when a host goes down or a service turns critical.

Nagios watches your hosts and services and runs a notification command when something breaks. Spike ships a small bash script for that command, so a hard CRITICAL or DOWN opens an incident that escalates through your on-call policy, the recovery closes it, and an acknowledgement made in Nagios stops the escalation in Spike.

The same script and the same Spike integration work on Nagios Core, Nagios XI, Naemon, Shinken and Icinga 1. If you run Icinga 2, use the Icinga 2 guide instead.

What Spike does with each notification

Notification type
What happens in Spike

PROBLEM

Opens an incident for that host and service, or adds an event to the one already open

RECOVERY

Auto-resolves the open incident. Dropped when nothing is open

ACKNOWLEDGEMENT

Acknowledges the open incident and records who acknowledged it and their comment. Dropped when nothing is open

CUSTOM, FLAPPINGSTART, FLAPPINGSTOP, DOWNTIMESTART, DOWNTIMEEND

Added as an event to the open incident. Dropped when nothing is open. They never page anyone

There is one incident per host and service pair, and one incident per host for host checks. Re-notifications every 30 minutes, a WARNING that turns into a CRITICAL, and a flapping check all land on that one incident, so a noisy check never pages the team twice.

Incident titles read well on a phone call and stay the same for every repeat:

  • Service problem: Disk / on db-01 is CRITICAL

  • Host problem: Host db-01 is DOWN

Plugin output, attempt counts, host groups and the Nagios problem id are on the incident page rather than in the title.

Severity comes from the state Nagios reports:

State
Severity

CRITICAL, DOWN

SEV1

WARNING, UNREACHABLE

SEV2

UNKNOWN, OK, UP

SEV3

Severity is set when the incident is created and does not move on repeats. Alert rules can override it, route the incident elsewhere, or suppress it entirely.

Prerequisites

  • Root or sudo access on the Nagios server

  • bash and curl on that server. The script needs nothing else, no jq and no Python

  • A Nagios integration in Spike and its webhook URL

Step 1 — Create the integration in Spike

In Spike, go to Integrations → Add integration → Nagios, attach it to a service and an escalation policy, and copy the webhook URL. It looks like https://hooks.spike.sh/<your-token>/push-events.

Create integration and service on our dashboard

Step 2 — Install the notification script

Save the script below as spike-notify.sh in your plugins directory, which is the directory $USER1$ points at in resource.cfg. On a source install of Nagios Core that is /usr/local/nagios/libexec; on Debian and Ubuntu packages it is /usr/lib/nagios/plugins.

spike-notify.sh

Step 3 — Add the commands, contact and contact group

Create /usr/local/nagios/etc/objects/spike.cfg with the definitions below and put your webhook URL in the _SPIKE_WEBHOOK_URL line of the contact.

Keeping the URL on the contact rather than in the command line means it is not repeated in every notification log entry, and one contact can be reused by every host and service.

Tell Nagios to read the file by adding this line to /usr/local/nagios/etc/nagios.cfg:

Step 4 — Send your hosts and services to Spike

Add the spike-oncall contact group to the hosts and services you want to page for. The easiest way is on a template that everything already inherits:

notification_interval 30 re-notifies every 30 minutes while a problem is open. Those repeats are added to the incident already open in Spike, they do not page again.

Step 5 — Verify and reload

Then send a test incident. It opens an incident called Spike test on <hostname> is CRITICAL and resolves it two seconds later:

A resolved Spike test incident on your service means Nagios can reach Spike and the integration is wired to the right escalation policy.

Nagios XI

Nagios XI runs Nagios Core underneath, so the script and the definitions above are the same. Add them through Core Config Manager instead of editing files:

  1. Copy spike-notify.sh to /usr/local/nagios/libexec/ on the XI server and make it executable, owned by nagios.

  2. Go to Configure → Core Config Manager → Commands → Add New. Create notify-host-by-spike and notify-service-by-spike with the command lines from Step 3, command type notification.

  3. Go to Contacts → Add New. Name the contact spike, set the host and service notification commands to the two commands you just created, and tick the notification options.

  4. On the contact's Misc Settings tab add a custom variable named _SPIKE_WEBHOOK_URL with your webhook URL as the value.

  5. Go to Contact Groups → Add New, create spike-oncall with spike as its only member, then add that contact group to the hosts and services, or to the templates they use.

  6. Click Apply Configuration.

Naemon, Shinken and Icinga 1

All three read Nagios object configuration, so use the Nagios tile in Spike and follow the steps above. Two differences:

  • The configuration lives elsewhere: /etc/naemon/conf.d/ for Naemon, /etc/shinken/ for Shinken and /etc/icinga/objects/ for Icinga 1. Check what $USER1$ resolves to in that tool's resource.cfg before copying the script.

  • Set SPIKE_SOURCE so incidents record which tool sent them, by putting SPIKE_SOURCE=naemon (or shinken, or icinga1) in front of the script path in both command lines.

Things worth knowing

  • A $ in a URL has to be written $$. Nagios treats $ as a macro delimiter, so any literal dollar sign in a command line or a custom variable must be doubled. An & is stripped by Nagios' default illegal_macro_output_chars. Spike webhook URLs contain neither character, so you can paste yours as it is.

  • Quotes in plugin output are safe. Nagios' default illegal_macro_output_chars removes both quote types from macro output, and the script JSON-escapes every value itself, so output containing quotes, backslashes or newlines still produces valid JSON if you narrow that setting.

  • Notifications are not retried by Nagios. The script retries once on its own and gives up after roughly 23 seconds, inside the default 30 second notification_timeout. It then exits non-zero and Nagios logs Notifying contact spike ... failed, so failures are visible in nagios.log.

  • Acknowledging a host problem does not acknowledge its services. Nagios suppresses service notifications while the host is down, so only the host incident in Spike is acknowledged.

  • Problem ids are recorded, not matched on. Nagios resets $SERVICEPROBLEMID$ to 0 on recovery and Naemon may send an empty value, so Spike identifies an incident by host and service name. The problem id is shown on the incident for reference.

Payload reference

The script posts a flat JSON object. Every value is a string.

author and comment carry the name and note of whoever acknowledged the problem in Nagios, and Spike writes them into the incident activity as Acknowledged in Nagios by jane: looking into it.

There is no top-level message key in this payload on purpose. Spike builds the incident title from the host and service fields, which keeps the title identical across a problem, its repeats and its acknowledgement.

Troubleshooting

Nothing arrives in Spike

Run the script by hand as the nagios user with SPIKE_DEBUG=1 to see the payload and the curl error:

If curl reports a connection or timeout error, the Nagios server cannot reach hooks.spike.sh on port 443. If it exits with 2, the webhook URL argument did not reach the script, which usually means the contact is missing the _SPIKE_WEBHOOK_URL custom variable.

Nagios logs "Notifying contact spike ... failed"

The script exited non-zero. Look for its stderr in /usr/local/nagios/var/nagios.log, and confirm the script is executable and owned by the nagios user.

Incidents are created but never resolve

The contact needs the recovery notification option, r in both host_notification_options and service_notification_options, otherwise Nagios never sends RECOVERY. A recovery that arrives when nothing is open in Spike is dropped, which is what should happen if you resolved the incident by hand first.

A check opens a new incident on every notification

Spike groups by host name and service name, so check that the command line passes $HOSTNAME$ and $SERVICEDESC$ in the positions shown in Step 3. If the arguments are in a different order the fields land in the wrong keys.

Last updated

Was this helpful?