Nagios integration

Updated at:

This topic describes how to integrate with a Nagios monitoring source.

Introduction

Nagios is a product for monitoring enterprise IT infrastructure. Event Center supports quick and easy integration with Nagios for unified alert and event management. Follow the steps below to complete the integration.

How to integrate Nagios monitoring

Step 1: Find the Nagios monitoring source

Log on to Event Center. In the navigation pane on the left, choose Integration Center > Integration Configuration. Find and click Nagios to view the integration steps.

Step 2: Configure the Nagios alert medium

  1. Locate the installation folder for the configuration file.

Place the nagios-alert.py configuration file in the nagios/libexec/ directory. In the file, replace the URL in api_url = "URL" with the following URL:

https://public-alert.aliyuncs.com/event/nagios/{integration-key} 

To import the requests library in the Python script, run the pip install requests command.

The nagios-alert.py configuration file is as follows:

#!/usr/bin/python
# -*- coding: utf-8 -*-

import requests
import json
import sys
import os

headers = {'Content-Type': 'application/json;charset=utf-8'}
api_url = "URL"

def msg(text):
    json_text= {
     "msgtype": "text",
        "text": {
            "content": text
        }
    }
    print requests.post(api_url,json.dumps(json_text),headers=headers).content

if __name__ == '__main__':
    text = sys.argv[1]
    msg(text)
  1. Configure the Nagios push method.

# 'notify-host-by-alert' command definition
define command{
    command_name    notify-host-by-alert
    command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/local/nagios/libexec/nagios-alert.py '[$NOTIFICATIONTYPE$] Host Alert: $HOSTNAME$ is $HOSTSTATE$ [ECS Nagios Monitoring]'
    }

# 'notify-service-by-alert' command definition
define command{
    command_name    notify-service-by-alert
    command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /usr/local/nagios/libexec/nagios-alert.py '[$NOTIFICATIONTYPE$] Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ [ECS Nagios Monitoring]'
    }
  1. Configure Nagios contact information.

Modify the contacts.cfg configuration file and add the following two lines. The file is located at /usr/local/nagios/etc/contacts.cfg.

    service_notification_commands   notify-service-by-alert        
    host_notification_commands      notify-host-by-alert            

The contacts.cfg configuration file is as follows:

define contact {
    contact_name                     nagiosadmin
    alias                            Nagios Admin
    host_notifications_enabled       1
    service_notifications_enabled    1
    host_notification_period         nagiosadmin_notification_times
    service_notification_period      nagiosadmin_notification_times
    host_notification_options        d,u,r,f,s
    service_notification_options     w,u,c,r,f,s
    email                            nagios@localhost
    use                              xi_contact_generic
    service_notification_commands   notify-service-by-alert        
    host_notification_commands      notify-host-by-alert            
}
  1. Restart Nagios.

systemctl restart nagios

Step 3: Confirm the integration

After you complete the configuration, click the Confirm Integration button below the integration key to complete the integration.

Step 4: Verify the integration

Configure alert and push rules in Nagios and trigger an alert. Then, navigate to the Integration Configuration page. If the status of the Nagios monitoring source changes to "Accepted", the integration is successful.