• Get started
  • Documentation

Integrate Opsgenie with Nagios Plugin

How does the integration work?

  • When a host or service state becomes down in Nagios, an alert is created in Opsgenie.

  • Upon creating the new alert, related histogram and trends images from Nagios are automatically attached to the alert.

  • When the Opsgenie alert is acknowledged, the alert in Nagios is also acknowledged automatically, and vice versa.

  • When a note is added to the Opsgenie alert, the alert in Nagios is also updated automatically, and vice versa.

Set up the integration

The Nagios integration plugin utilizes the full capabilities of Opsgenie and provides bi-directional integration with Nagios. The steps in the following procedure describe how to integrate Opsgenie and Nagios using the Nagios integration plugin. Note that slight alteration to these instructions may be necessary depending on the exact Linux distribution and your Nagios configuration.

Installation prerequisites

The installation packages support the following systems:

  • RedHat-based Linux distributions

  • Debian-based Linux distributions

Install the Opsgenie plugin for Nagios

Opsgenie Edge Connector (OEC) is a prerequisite for configuring the outgoing authentication of Nagios integration. You can combinedly use OEC and Nagios scripts to update alerts on Nagios. With this setup, you can deploy your own script, modify the ones provided, or run customized actions on Nagios. Download the latest version of the Nagios package from this repository.

Instructions for RedHat-based distributions

Run the following command: 

rpm -i opsgenie-nagios-<your_version>.rpm

Before rpm upgrades, back up your configuration files.

The rpm package does not overwrite the existing configuration during upgrades. It saves the new default configuration file as integration.conf.rpmnew. Add the-- force parameter to upgrade from version 201X-XX-XX to 2.X.X. For example: rpm -U --force opsgenie-nagios-<your_version>.rpm

Learn more about config file handling for rpm upgrades.

Instructions for Debian-based distributions

Run the following command: 

dpkg -i opsgenie-nagios-<your_version>.deb

Add a Nagios integration

If you're using Opsgenie's Free or Essentials plan or if you’re using Opsgenie with Jira Service Management's Standard plan, you can add this integration from your team dashboard only. The Integrations page under Settings is not available in your plan.

  1. Go to Teams and select your team.

  2. Select Integrations on the left navigation and then select Add integration.

Adding the integration from your team dashboard will make your team the owner of the integration. This means Opsgenie will assign the alerts received through this integration to your team only. Follow the rest of the steps in this section to set up the integration.

To add a Nagios integration in Opsgenie:

  1. Go to Settings > Integrations.

  2. Select Add integration.

  3. Run a search and select “Nagios”.

  4. On the next screen, enter a name for the integration.

  5. Optional: Select a team in Assignee team if you want a specific team to receive alerts from the integration.

  6. Select Continue.
    The integration is saved at this point.

  7. Expand the Steps to configure the integration section and copy the URL.
    You will use this URL while configuring the integration in Nagios later.

  8. Select Turn on integration.
    The rules you create for the integration will work only if you turn on the integration.

Configure the Opsgenie plugin in Nagios

The plugin uses a golang-executable file (included in the plugin as send2opsgenie) to create, acknowledge, and close alerts in Opsgenie. To make send2opsgenie work, you need to make some configurations. The following table lists the parameters and states if they are mandatory. Setting the apiKey is required. Other configuration parameters are set to their default values that work with most Nagios implementations but may also need to be modified.

Configuration Parameters

Description

Mandatory to fill

Location

apiKey

Copy the API key from the Nagios integration you've created above. send2opsgenie uses this key to authenticate to Opsgenie. API key is also used to identify the right integration configuration that should be used to process alerts.

Yes

/home/opsgenie/oec/conf/config.json

baseUrl

If you're using Opsgenie from another domain(eg. EU, sandbox), you should update this configuration.Opsgenie Nagios integration, Advanced Settings page.

Optional

/home/opsgenie/oec/conf/config.json

teams

Teams field is used to specify which teams should be notified for the Nagios alerts. This field is used to set the default teams field value. It can be modified to route different alerts to different teams in Opsgenie Nagios integration, Advanced Settings page.

Optional

/home/opsgenie/oec/conf/opsgenie-integration.conf

tags

Tags field is used to specify the tags of the alert that created in Opsgenie.

Optional

/home/opsgenie/oec/conf/opsgenie-integration.conf

nagios_server

nagios_server field is used to identify the Nagios server in Opsgenie, and only required when there are multiple Nagios servers. This field is used by Opsgenie when sending actions executed by users (acknowledge, close, etc.) back to your Nagios servers via OEC

Optional

/home/opsgenie/oec/conf/opsgenie-integration.conf

logPath

Specifies the full path of the log file. (Default value is /var/log/opsgenie/send2opsgenie.log)

Optional

/home/opsgenie/oec/conf/opsgenie-integration.conf

nagios2opsgenie.http.proxy.enabled

nagios2opsgenie.http.proxy.enabled field is to enable/disable external proxy configuration. The default value is false.

Optional

/home/opsgenie/oec/conf/opsgenie-integration.conf

nagios2opsgenie.http.proxy.host

It is the host of the proxy.

Optional

/home/opsgenie/oec/conf/opsgenie-integration.conf

nagios2opsgenie.http.proxy.port

It is the port of the proxy.

Optional

/home/opsgenie/oec/conf/opsgenie-integration.conf

nagios2opsgenie.http.proxy.scheme

It is the proxy connection protocol. It may be http or https depending on your proxy servers. Its default value is http.

Optional

/home/opsgenie/oec/conf/opsgenie-integration.conf

nagios2opsgenie.http.proxy.username

It is the Proxy authentication username.

Optional

/home/opsgenie/oec/conf/opsgenie-integration.conf

nagios2opsgenie.http.proxy.password

It is the Proxy authentication password.

Optional

/home/opsgenie/oec/conf/opsgenie-integration.conf

Configure the golang-executable file in any of the following three methods:

Method 1: Configure from conf file

Configure from the /home/opsgenie/oec/conf/integration.conf file. This overwrites any configuration you previously made in the script.

Method 2: Configure by using Golang flags

Configure by entering flags to command in the opsgenie.cfg file. Use -apiKey flag for your apiKey and -ns flag for the nagios_server name. If you don't have multiple Nagios servers, you don't have to define the Nagios server. Using flags overwrites all the other configuration methods mentioned earlier.

Configure the apiKey from the opsgenie.cfg file as follows (in JSON format):

1 2 3 4 define command { command_name notify-host-by-opsgenie command_line /home/opsgenie/oec/scripts/opsgenie -apiKey="apiKey1" -entityType=service ... }

When apiKey is added to the cfg file, it overrides the apiKey in the integration.conf file.

To send additional custom arguments, add them after the flags. For example, customArgName1 customArgValue1 customArgName2 customArgValue2. Parse custom arguments by adding {{_payload.customArgName}} to wherever is needed in the input fields. To learn more about using raw parameters, see dynamic fields.

Method 3: Configure from script

Configure apiKey and nagios_server from the send2opsgenie.go script. Build the script again and put the new executable into the /home/opsgenie/oec/scripts directory. Learn more about the location of the send2opsgenie.go and how to build a go script in the “Source for and recompiling send2opsgenie” section of this article.

Define Nagios contacts

1. Copy the /home/opsgenie/oec/opsgenie-nagios/opsgenie.cfg file (configures a contact, its host, and service notification commands) in to /usr/local/nagios/etc/objects directory.

Shell

1 cp /home/opsgenie/oec/opsgenie-nagios/opsgenie.cfg /usr/local/nagios/etc/objects

2. Add the following line to the main Nagios configuration file (NAGIOS_HOME/etc/nagios.cfg):

Shell

1 2 3 ... cfg_file=/usr/local/nagios/etc/objects/opsgenie.cfg ...

3. Add the contact “opsgenie" to the Nagios configuration’s main contact group in  NAGIOS_HOME/etc/objects/contacts.cfg file. If using the default configuration contacts.cfg, add "opsgenie" user to the "admins" contact group.

4. Restart Nagios.

If everything goes well, alerts are seen in Opsgenie for every notification created in Nagios.

Configure Opsgenie to update Nagios

This is an optional step.

Select the Send alert actions To Nagios checkbox on the integration configuration page. You can combinedly use OEC and Nagios scripts to update alerts on Nagios. With this setup, you can deploy your own script, modify the ones provided, or run customized actions on Nagios.

To run actions in Nagios, OEC gets the configuration parameters from the configuration file, config.json (found at /home/opsgenie/oec/conf/oec-config.json).

The downloaded package includes the OEC utility (found in /usr/local/bin) and the script that OEC needs to run (found in /home/opsgenie/oec/scripts). Be sure to run OEC after configuring it. Learn more about running OEC documentation. If using OEC, rich alerts are populated with host or service current status information in Opsgenie for every notification created in Nagios.

The Nagios integration package does not support SSL v1.0. If your Nagios Server has SSL v1.0, upgrade your SSL server.

Source for and recompiling send2opsgenie

The source for the executable send2opsgenie is found in /usr/bin/ and send2opsgenie.go, in /home/opsgenie/oec/scripts respectively and is also available in this repository. To change the behavior of the executable, edit send2opsgenie.go and build it by using the following command: go build send2opsgenie.go

For installing go, refer to http://golang.org/doc/install. Note that the executable in the plugin is built for linux/amd64 systems.

FAQ and troubleshooting

If the integration is not working, review this section and follow the prescribed guidelines.

1. Nagios alerts are not getting created in Opsgenie

Run the following test command from the shell and check if a test alert is created in Opsgenie

1 /home/opsgenie/oec/scripts/send2opsgenie -entityType=host -t=PROBLEM -hs=DOWN -hn=test_host
  • If you get a "Trace/breakpoint trap" error, the send2opsgenie plugin isn't compatible with the server distribution. Rebuild send2opsgenie.go according to the specific server environment as described in the “Source and recompiling send2opsgenie” section in this article.

  • If the alert is created in Opsgenie, the integration is configured correctly. Nagios is probably not notifying the Opsgenie contact for alerts. Check your Nagios alert notifications log.

  • If the alert is not created in Opsgenie, check the logs at /var/log/oec/send2opsgenie.log.
    Look for the following errors in the log file:

    • If you see "RestException[Could not authenticate.]" in the logs, Opsgenie couldn't identify the API key. Check if the API key is set correctly per the steps outlined in the “Configure the Opsgenie plugin in Nagios” section of this article.

    • If unsure of the problem, set the plugin's log level to debug and try again. Contact us and share the logs.

  • If there is no /var/log/oec/send2opsgenie.log file or there are no logs in it, check the following:

    1. Check if the Nagios user has permission to write to /var/log/oec directory. The installation package should automatically do this for you. If you face issues, run the following command: 
      chown -R nagios:opsgenie /var/log/oec

    2. Check the Nagios server logs at /opt/nagios/log/zeneventd.log. See if there are error logs regarding send2opsgenie. Contact us with the logs if needed.

Set send2opsgenie plugin's log level to DEBUG

Set the send2opsgenie plugin's log level to DEBUG. Open the /home/opsgenie/oec/conf/integration.conf file and change the line send2opsgenie.logger=warning to nagios2opsgenie.logger=debug.

2. The Nagios alert is not acknowledged when the alert is acknowledged in Opsgenie

Check the alert logs.

  • If "Posted [Acknowledge] action to Nagios.." is not present in the log, Opsgenie didn't send the Acknowledge action to Nagios. Check the integration configuration, it might not have a matching the alert action.

  • If only the "Posted [Acknowledge] action to Nagios.." log occurs followed by no related logs, it might mean OEC is having connection problems. Check the logs.

3. Could not open Nagios RPM package

  • If you figure out while installing the rpm package that the package is obsolete, use rpm -i opsgenie-nagios-1.0.4-rpm-x86-64.rpm --nodeps instead.

  • If you get "is already installed" error, use rpm -i opsgenie-nagios-1.0.4-rpm-x86-64.rpm --force instead.

4. Permission error occurs while attaching zip file to alert in script

If you get "PermissionError: [Errno 13] Permission denied: details_*" error while running the script, prefix the path of the script to the "file_name" variable in the attach method of the script.

Still need help?

The Atlassian Community is here for you.