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
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 CRITICALHost 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:
CRITICAL, DOWN
SEV1
WARNING, UNREACHABLE
SEV2
UNKNOWN, OK, UP
SEV3
Prerequisites
Root or
sudoaccess on the Nagios serverbashandcurlon that server. The script needs nothing else, nojqand no PythonA 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.
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.
The order of the arguments in the command definitions below has to match the order the script expects. Nagios keeps environment macros switched off by default (enable_environment_macros=0, and Naemon removed them altogether), which is why every macro is passed as an argument.
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:
Copy
spike-notify.shto/usr/local/nagios/libexec/on the XI server and make it executable, owned bynagios.Go to Configure → Core Config Manager → Commands → Add New. Create
notify-host-by-spikeandnotify-service-by-spikewith the command lines from Step 3, command type notification.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.On the contact's Misc Settings tab add a custom variable named
_SPIKE_WEBHOOK_URLwith your webhook URL as the value.Go to Contact Groups → Add New, create
spike-oncallwithspikeas its only member, then add that contact group to the hosts and services, or to the templates they use.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'sresource.cfgbefore copying the script.Set
SPIKE_SOURCEso incidents record which tool sent them, by puttingSPIKE_SOURCE=naemon(orshinken, oricinga1) 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' defaultillegal_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_charsremoves 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 logsNotifying contact spike ... failed, so failures are visible innagios.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$to0on 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.
Troubleshooting
Last updated
Was this helpful?