-=Repost=-
I saw some questions about this in the 1.6 forums so I went ahead and did this for 1.7, Icinga 1.9, MySQL 5.1 and Debian squeeze(my virtual box at my ISP)
This is more a method than a MOD.
First you may need a mailing package that allows you to set FROM for mailing the update to an existing ticket. You need to match the email address used by Icinga when it sends out notifications that create tickets in osTicket.
SendEmail is a lightweight, completely command line based, SMTP email agent. It was designed to be used in bash scripts, Perl programs, and web sites, but it is also quite useful in many other contexts. SendEmail is written in Perl
apt-get install sendemail
I use this in the script below to send and update to osTicket when the restoral happens. This allows staff to follow up and manually close the ticket with incident details.
The FROM field is set, a LOG is generated, SUBJECT is set for osTICKET update, TO is set:
/usr/bin/sendemail -f nagios@FQDNhostname -l /tmp/sendemail.log -u -t osTicket@FQDNhostname
Now setup the Icinga "stuff"
Icinga commands.cfg entry:
#recovered_service_handler command definition - single quotes are IMPORTANT
define command{
command_name recovered_service_handler
command_line /usr/local/bin/recovered_service_handler.sh $SERVICESTATE$ $SERVICESTATETYPE$ $HOSTNAME$ '$SERVICEDESC$' $DATE$ $TIME$ '$HOSTALIAS$'
}
A service definition that includes the event_handler:
define service{
use generic-service
host_name FQDNhostname
service_description Total_Processes
check_command check_nrpe_two!check_procs!150!200
event_handler recovered_service_handler
# check_command check_nrpe_two!check_procs!15!20
# I use the check_procs!15!20 above to force a CRITICAL otherwise remarked
}
Here are some settings for a defined contact - remark your existing definition and replace with these lines:
service_notification_options c
host_notification_options d,u
email osTicket@FQDNhostname
Only CRITICAL services and DOWN/UNKNOWN hosts create/update osTickets. I never ever want my monitoring system to close tickets - that is a job for humans.
Debian configuration:
Be sure to update your sudoers file so the monitoring user can run and log results.
nagios ALL=(ALL) NOPASSWD: /usr/bin/ /usr/local/bin/ /tmp
I set the cron job in /etc/crontab:
*/3 * * * * nobody /usr/bin/php /var/www/FQDNhostname/osTicket/api/cron.php
osTicket configuration:
You will need to create the required email accounts and set "Enable POP/IMAP polling" on the admin panel.
The script below will lookup the latest ticket number for the specified service,
host and email that generated the ticket and stuff sendemail with a message body.
I found the original code on the Nagios plugin exchange for OTRS and modified to work with osTicket.
############################################
#!/bin/sh
# recovered_service_handler
# For updating a ticket in osTicket
# Original Author : Nasiruddin Khan
# Revised by Dan Fischer for Icinga, osTicket and MySQL 5.1 on Debian Squeeze
# Last Modified : 05 Aug 2013
# Description : Takes hostname and service name
# as arguments then updates the existing ticket
############################################
# copy the args to variables that make sense:
SERVICESTATE=$1
SERVICESTATETYPE=$2
HOSTNAME=$3
SERVICEDESC=$4
DATE=$5
TIME=$6
HOSTALIAS=$7
# some diagnostic output that was helpful
# this can be removed because we are using
# the MySQL general log to track the queries
# Just query the ticket here to see it works
TICKET=$(mysql wmvops -u root -p'password' -bse "SET GLOBAL general_log = 'ON'; set sql_log_off=0; select ticketID from(select ticket_id,ticketID,name,subject from ost_ticket where subject='** PROBLEM Service Alert: $HOSTALIAS/$SERVICEDESC is CRITICAL **' and name='nagios@FQDNhostname')derived_table_ticket order by ticket_id desc limit 1; set sql_log_off=1; SET GLOBAL general_log = 'OFF';")
#These are the arguments that Icinga sends downstream to us.
echo -e "$@" >>/tmp/args.txt
echo -e "$@" >>/tmp/args.txt
echo -e "$@" >>/tmp/args.txt
echo -e "$@" >>/tmp/args.txt
echo -e "TICKET $TICKET" >>/tmp/args.txt
echo -e "SERVICESTATE $SERVICESTATE" >>/tmp/args.txt
echo -e "SERVICESTATETYPE $SERVICESTATETYPE" >>/tmp/args.txt
echo -e "HOSTNAME $HOSTNAME" >>/tmp/args.txt
echo -e "HOSTALIAS $HOSTALIAS" >>/tmp/args.txt
echo -e "SERVICEDESC $SERVICEDESC" >>/tmp/args.txt
echo -e "DATE $DATE" >>/tmp/args.txt
echo -e "TIME $TIME" >>/tmp/args.txt
case "$2" in
HARD)
case "$1" in
CRITICAL)
;;
WARNING|UNKNOWN)
;;
OK)
#Get the last ticket for this service and host
#from osTicket database - table name ost_ticket
#then send mail to osTicket to update the ticket
TICKET=$(mysql wmvops -u root -p'password' -bse "SET GLOBAL general_log = 'ON'; set sql_log_off=0; select ticketID from(select ticket_id,ticketID,name,subject from ost_ticket where subject='** PROBLEM Service Alert: $HOSTALIAS/$SERVICEDESC is CRITICAL **' and name='nagios@FQDNhostname')derived_table_ticket order by ticket_id desc limit 1; set sql_log_off=1; SET GLOBAL general_log = 'OFF';")
/usr/bin/printf "%b" "*Ticket: $TICKET \n" >>/tmp/args.txt
/usr/bin/printf "%b" " ***** Icinga ***** \n $DATE $TIME\n $TICKET \n Notification Type\n Service: $SERVICEDESC\n Host: $HOSTALIAS\n State: $SERVICESTATE \n" | /usr/bin/sendemail -f nagios@FQDNhostname -l /tmp/sendemail.log -u -t osTicket@FQDNhostname
;;
esac
;;
esac
exit 0