create_ticket.pl 



Name

create_ticket.pl - Release notes of create_ticket.pl


Description

create_ticket.pl is a perl script use to open a ticket in RT when an alarm is acknowledged in Nagios. There is yet another script that I found at Nagios Exchange site that claims the same. However, it has no documenation and also it has the following issues that at least prevented me using that script.

1. It wokrs where Nagios and RT both are installed on the same machine

2. There are no spaces in any of the parameters that we pass on to create a ticket in Nagios, including the acknowledgement comments

I wrote this Perl script to over come the above issues. In this script however, I'm not getting the RT ticket ID which is a kind of drawback but I can't seem to find a simple way-around to that problem provided that I have the Nagios and RT are running on two separarte machine.


Installation

1. Extract the zip file and copy the create_ticket.pl to /path-to-Nagios/nagios/libexec/eventhandlers/ (You can put the script anywhere you like but I'm using this path in my system and I'll use the same here).

2. You then need to enable the external command handling on your Nagios installation. Follow the instructions on Nagios Documention. Or else you can edit my sript to work with external commands disabled. Simply change teh line $external = 0; to $external = 1;

3. If you are changing $debug to 1, make sure you have the correct path & filename to the $logfile with necessary access rights.

4. Now you need to defind the command definition. Below is what it looks like in my system. I have this in /path-to-nagios/nagios/etc/misccommands.cfg

# 'notify-rt' command definition
define command{
command_name notify-rt
command_line /usr/local/nagios/libexec/eventhandlers/create_ticket.pl -S \ "$HOSTNAME$^$SERVICEACKCOMMENT$^$SERVICEACKAUTHOR$^$SERVICEOUTPUT$^$SERVICESTATEID$^$NOTIFICATIONTYPE$^$SERVICEDESC$^$CONTACTEMAIL$"

}

# 'host-notify-rt' command definition
define command{
command_name host-notify-rt
command_line /usr/local/nagios/libexec/eventhandlers/create_ticket.pl -S \ "$HOSTNAME$^$HOSTACKCOMMENT$^$HOSTACKAUTHOR$^$HOSTOUTPUT$^$HOSTSTATEID$^$NOTIFICATIONTYPE$^$SERVICEDESC$^$CONTACTEMAIL$"
}

Note the double quotes ( " ) that I have used when passing the parameters with '-S' in the command definitions. That will make sure we pass all the parameters whether there are spaces in the parameters that we are passing or not. This may be not the best way to do that however, it just worked for me.

5. You also need to define a contact for RT. This is what I did.

I defined RT as a contact in my contacts.cfg file in /path-to-nagios/nagios/etc/. It looks like this

define contact{
contact_name RT
alias Ticketing System
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,u,r
service_notification_commands notify-rt
host_notification_commands host-notify-rt
email NetworkTroubles@rt.wightman.ca ;E-mail to RT Queue
}

define contactgroup{
contactgroup_name admins
alias Open a ticket in Ticketing System with notification to admin
members admin, RT
}

Note that the "email" I have. I run RT on a server called rt and the RT queue name is 'NetworkTroubles'. (Queue name is not case sensitive, I guess ?)

I've then defined a service as follows:

define service{
use generic-service ; Name of service template to use
host_name OfficeSwitch
service_description Interface Status ; Note the space in this service description
is_volatile 0
check_period 24x7
max_check_attempts 4
normal_check_interval 5
retry_check_interval 1
contact_groups admins
notification_options w,u,c,r
notification_interval 30
notification_period 24x7
check_command int_status!showme!FastEthernet0/1
}

6. You then need to configure the RT to complete this process. In my case what I have done is, I created a queue called 'NetworkTroubles' in RT with user 'nagios' has 'CreateTicket rights.

NOTE: By default the script create_ticket.pl sends e-mails to RT to open a ticket. The from address of the e-mail is default to 'nagios@wightman.ca' You can change this by manually editing the script and changing the variable '$from' at the top of the script.



Announcement

I'm pleased to announce the release of create_ticket.pl version 1.0.0.

 


Availability

create_ticket.pl is licensed under the GNU General Public License.

(Pl. also note that I have tested this only on Nagios 2.9 and RT 3.4.5 running on separete servers. You are welcome to test this on other versions.)


Author

Priyantha P Kumara <priyantha_AT_wightman_DOT_ca>
Hanover, ON
Canada

Thanks

I'd like to thank Scott for all his support whenever I run into troubles on my test servers. I also want to give a BIG THANK YOU to my wife and two kids for giving me time to work on this while I'm at home.

Also thank you in advance for everyone who is going to test this and send any feedback.


Copyright and Disclaimer

Note that this document is provided `as is'. The information in it is not warranted to be correct. Use it at your own risk.

   Copyright (c) 2007 Priyantha P Kumara <priyantha_AT_wightman_DOT_ca>
   All rights reserved.

This document may be reproduced and distributed in its entirety (including this authorship, copyright, and permission notice), provided that no charge is made for the document itself.


Last modified June 1, 2007 by Priyantha P Kumara