Integrate Nagios with JIRA

Posted on Posted in Nagios

Hello to everybody and welcome to other sysadmin tip. In this case I’ll explain how integrate the Monitor System Nagios with the issue tracking JIRA, the idea is that when a CRITICAL problem occur in some monitoring system, the Nagios server create a JIRA issue with the description problem.

In my case in the University of Navarra, where I work, some modifications were necessary to adapt this system to our policy, but by default the system consist:

  1. Only create one JIRA issue per CRITICAL problem.
  2. Save historical file to eliminate duplicate creation issues.
  3. If the JIRA issue and the problem persist, the system automatically add comment to it.
  4. In case of problem solution, the system remove it from his historical file

Installation

Pre-requisites

Install php-client and curl-devel

yum install php-cli curl-devel

PHP with CURL

Ensure that you PHP installation have CURL activate (–with-curl)

./configure --prefix=/usr/local/etc/apache/php \
--with-apxs2=/usr/local/etc/apache/bin/apxs \
--with-config-file-path=/usr/local/etc/apache/conf/ \
--with-libdir=lib64 \
--with-openssl \
--with-ldap --with-mysql=/usr/include/mysql \
--with-gettext \
--with-gd --with-zlib --enable-sockets --enable-mbstring --with-curl

Install

make
make install

And load library’s

libtool --finish /root/php-5.3.6/libs
ldconfig

Install TO-JIRA

You can download it via SVN or directly from my web

SVN

Create a directory in your Nagios scripts (libexec).

mkdir /usr/local/etc/nagios/libexec/to-jira
 cd /usr/local/etc/nagios/libexec/to-jira
 svn co http://svn.spiga.id.au/svn/COR/trunk COR
 svn co http://svn.spiga.id.au/svn/NTJ/trunk NTJ

OBTAIN TAR.GZ

If you decided to obtain this scripts from my web, extract it in your Nagios scripts directory

mkdir /usr/local/etc/nagios/libexec/to-jira
cd /usr/local/etc/nagios/libexec/to-jira
wget http://albertolarripa.com/wordpress/wp-content/uploads/2012/11/to-jira.tar.gz
tar xvfz to-jira.tar.gz

Change permission

chown -R nagios:nagios COR NTJ

Configuration

Configure your JIRA options

To do that copy the original configuration file nagios_to_jira_config_orig.php to nagios_to_jira_config.php,

cd /usr/local/etc/nagios/libexec/to-jira/NTJ
cp nagios_to_jira_config_orig.php nagios_to_jira_config.php
vi nagios_to_jira_config.php

The configuration file contains a number of PHP define statements; each of which should be edited according to the table below:

Key Value
JIRA_BASE The URL that is used to access your JIRA installation from the host that NTJ is running on. The URL should start with “http://” or “https://”.
JIRA_PORT The TCP port that your JIRA instance is accessible on. The port is usually “80” , “443” or “8080”.
JIRA_HOST_HEADER The FQDN that is configured as the “Base URL” within JIRA. In most cases, this will be the same as the “JIRA_BASE” definition above, without the “http://” or “https://” prefix.
JIRA_PROJECT_ID The Project ID that you want NTJ to use for creating issues, or commenting on them.
JIRA_ISSUE_TYPE The ID of the Issue Type that you want NTJ to create issues with.
JIRA_USERNAME The user name that should be used when authenticating with the JIRA installation.
JIRA_PASSWORD The password for the above user name.
HISTORY_FILE The name of the history file that NTJ will use to track relationships between Nagios Problem IDs and JIRA Issue IDs. This value generally only needs to be changed if you want to story your history file in an alternate location.
ISSUE_FIELDS Any additional URL arguments that NTJ should use when creating issues (for example, to ensure that an issue is assigned to a specific user – in which case, you’d configure the statement to be “assingee=user”).
COMMENT_FIELDS Any additional URL arguments that NTJ should use when creating comments.

This is my configuration JIRA file

define('JIRA_BASE', "https://jira.unav.es");
define('JIRA_PORT', "443");
define('JIRA_HOST_HEADER', "jira.unav.es");
define('JIRA_PROJECT_ID', "1548");
define('JIRA_ISSUE_TYPE', "25");
define('JIRA_USERNAME', "nagios");
define('JIRA_PASSWORD', "password");
define('HISTORY_FILE', "nagios_to_jira_history.txt");
define('ISSUE_FIELDS', "");
define('COMMENT_FIELDS', "");
The JIRA_PROJECT_ID and JIRA_ISSUE_TYPE are obtained from the JIRA server, adjust it for your JIRA issue Project and issue Type

Configure Nagios server

It’s the moment to configure you Nagios server, the first step to do is define a new command, edit your command.cfg file and add:

define command {
    command_name nagios-to-jira
    command_line /usr/bin/php -q $USER1$/to-jira/NTJ/nagios_to_jira.php
}

Now add a new time period to activate the issue JIRA creation only in some specific hours, like this (timeperiods.cfg)

define timeperiod{
        timeperiod_name working_hours
        alias           Working Hours
        monday          08:00-19:30
        tuesday         08:00-19:30
        wednesday       08:00-19:30
        thursday        08:00-19:30
        friday          08:00-19:30
        }

Define a new contact for this plugin

define contact {
    contact_name jira
    alias JIRA
    host_notifications_enabled 0
    service_notifications_enabled 0
    host_notification_period working_hours
    service_notification_period working_hours
    host_notification_options d,r
    service_notification_options c,r
    host_notification_commands nagios-to-jira
    service_notification_commands nagios-to-jira
    can_submit_commands 0
    retain_status_information 1
    retain_nonstatus_information 1
    _JIRA_PRIORITY_ID 2
}

Finally and this user for your alarms group

define contactgroup{
        contactgroup_name       alerts
        alias                   Nagios alerts group
        members                 user1,user2,user3,jira
        }

And this is all.

Remember that I said, in my case, I had to modificate the nagios_to_jira.php to adapt it four our systems and JIRA rules.

Comments to Nagios

One recommendation, if you need to comment your JIRA URL creations in your Nagios system, this is my solution 😉

    //START THE COMMENT CREATION
    $time = shell_exec("/bin/date +%s");
    $time = substr($time, 0, - 1);
    $host = getenv("NAGIOS_HOSTNAME");
        //IF IS A SERVICE PROBLEM
        if (getenv("NAGIOS_SERVICEDESC")) {
                $service = getenv("NAGIOS_SERVICEDESC");
                $command = "/usr/bin/printf '[%lu] ADD_SVC_COMMENT;$host;$service;1;nagios;$url\n' $time > /usr/local/etc/nagios/var/rw/nagios.cmd";
        //IF IS A HOST PROBLEM
        } else {
                $command = "/usr/bin/printf '[%lu] ADD_HOST_COMMENT;$host;1;nagios;$url\n' $time > /usr/local/etc/nagios/var/rw/nagios.cmd";
        }
        shell_exec($command);

3 thoughts on “Integrate Nagios with JIRA

  1. Hi,

    I have some escalation page, I want to add them in Nagios pre escalation procedure so that any alarm come so that person can see the escalation page by clicking on pre-escalation tab so please help me out for this. I am using jira ticketing tool with nagios.

    Thanks in advance.

    Thanks
    Ankit

  2. Hi,

    How do I check all I set well, I followed the above doc and tried the php manually,,, here the error msg

    /usr/bin/php -q /usr/local/nagios/libexec/to-jira/NTJ/nagios_to_jira.php
    PHP Fatal error: Script was called, but there were no Nagios environment variables present. Script was most likely not called from Nagios. Aborting. in /usr/local/nagios/libexec/to-jira/NTJ/nagios_to_jira.php on line 499

    pls let me know where and what I missed. I can able to telnet Jira server from Nagios.

    Thanks,
    sathish

  3. I have followed all the steps mentioned and facing an error.

    PHP Fatal error: Script was called, but there were no Nagios environment variables present. Script was most likely not called from Nagios. Aborting. in /usr/local/nagios/libexec/to-jira/NTJ/nagios_to_jira.php on line 500

    I am running “/usr/bin/php -q nagios_to_jira.php” as nagios also I have Nagios runing the command normally.

    Please help.

Leave a Reply

Your email address will not be published. Required fields are marked *