PDA

View Full Version : Automating creation of new helpdesk items


termx
24-05-04, 12:05 PM
Can anyone advise how I can create new helpdesk items automatically ? I use Nagios for network monitoring and would like to create a new helpdesk item whenever a critical event occurs. Is it possible to create a new helpdesk item via a bash script (either via wget/lynx POSTing or inserting directly into the relevant table using Mysql ) ?

Peter

nsanders
24-05-04, 03:56 PM
Oooh now theres an idea. This would be perfect with Big Brother who all ready makes use of email notification. What you really need is HelpDesk to support gateway.pl

termx
24-05-04, 08:44 PM
After a bit of investigation, I am pretty sure I can use the mysql client to INSERT a new row into table helpdesk_items. I can create new helpdesk items using phpMyadmin. Shouldn't be much of a step to do it from the command line using bash. The data to populate the row will come from Nagios. Anyone have any experience in working directly with the dotproject database ?

dcordes
25-05-04, 02:09 AM
Depending on which version of HelpDesk you're using you'll also need to make an entry into the helpdesk_item_status table.

bigo
23-07-04, 11:13 PM
I'm looking for the same. Have you been to implement a formail or email parser for insert new helpdesk items automatically. Can you share the code?

termx
29-07-04, 12:45 PM
I'm looking for the same. Have you been to implement a formail or email parser for insert new helpdesk items automatically. Can you share the code?

Here is my quick and dirty hack to automatically create helpdesk items in dotproject when a Nagios service goes Critical.

It uses the global_service_event_handler in Nagios to create a file containing various bits of information from Nagios about the particular service and the LOAD DATA LOCAL INFILE function of the mysql client to load the data into the helpdesk_items table.

Yes, it is ugly, but it works for me :)
----------------------------------------------------------------------------------
In nagios.cfg put


global_service_event_handler=create_dotproject_hel pdesk_entry


In misccommands.cfg put


define command{
command_name create_dotproject_helpdesk_entry
command_line /usr/local/nagios/libexec/create_dotproject_helpdesk_entry $SERVICESTATE$ $STATETYPE$ $SERVICEATTEMPT$ $HOSTADDRESS$ "$OUTPUT$" "$SERVICEDESC$" $HOSTNAME$
}


create /usr/local/nagios/libexec/create_dotproject_helpdesk_entry as below

#!/bin/bash
#
# Event handler script for creating helpdesk entries in dotproject automatically
#
#


# What state is the service in?
now=`date "+%Y-%m-%d %H:%M:%S"`
echo $now
echo $1,$2,$3,$4,$5,$now,$7 > /usr/local/nagios/libexec/helpdesk_args_initial
case "$1" in
OK)
# The service just came back up, so don't do anything...
;;
WARNING)
# We don't really care about warning states, since the service is probably still running...
;;
UNKNOWN)
# We don't know what might be causing an unknown error, so don't do anything...
;;
CRITICAL)
# Aha! The service appears to have a problem - perhaps we should restart the server...

# Is this a "soft" or a "hard" state?
case "$2" in

# Let's give it one last try, shall we?
# Note: Contacts have already been notified of a problem with the service at this
# point (unless you disabled notifications for this service)
HARD)
echo -e "0\t$7+$6+$4\t$7+$1+$5+$4\t5\t5\t0\t0\t3\t5\t1\t23\ t23\t1\tNagios Daemon\t23\tnagios.helpdesk@your_email.com\t\N\t1\ t$now\t$now\t0\t60\t2\t" > /usr/local/nagios/libexec/nagiosoutput
/usr/bin/mysql --user=dotproject --password=password --database=dotproject --execute="LOAD DATA LOCAL INFILE '/usr/local/nagios/libexec/nagiosoutput' INTO TABLE helpdesk_items"
cat /usr/local/nagios/libexec/nagiosoutput | mail -s "test" your_email@your_email_address.com
echo "Nagios has created a new Helpdesk item in dotproject. Please check dotproject helpdesk for details" | mail -s "New Nagios Helpdesk item" your_email@your_email_address.com
;;
esac
;;
esac
exit 0

sphildreth
18-09-04, 05:27 AM
Modified version that works with my dotproject (inserts a helpdesk_item_status entry so the ticket is a 'valid' to the system):

#!/bin/bash
#
# Event handler script for creating helpdesk entries in dotproject automatically
#
#

# Do this 1st:
# 'mkdir /usr/local/nagios/libexec/tmp'
# 'chown nagios: /usr/local/nagios/libexec/tmp'

# What state is the service in?
now=`date "+%Y-%m-%d %H:%M:%S"`

# Create a user in Dotproject, named 'Nagios Daemon' and set this to that user_id (NOTE: User account must exist)
nagios_dotproject_user_id="10"

# Email of the user account used to create the ticket
nagios_email="email@yourcompany.com"

# Set this to the company to relate all the tickets to (NOTE: Company must exist)
company_id="1"

# Database properties
db_host="localhost"
db_user="dotproject"
db_passwd="password

echo $now
echo $1,$2,$3,$4,$5,$now,$7 > /usr/local/nagios/libexec/tmp/helpdesk_args_initial

case "$1" in
OK)
# The service just came back up, so don't do anything...
;;

WARNING)
# We don't really care about warning states, since the service is probably still running...
;;

UNKNOWN)
# We don't know what might be causing an unknown error, so don't do anything...
;;

CRITICAL)
# Aha! The service appears to have a problem - perhaps we should restart the server...

# Is this a "soft" or a "hard" state?
case "$2" in

# Let's give it one last try, shall we?
# Note: Contacts have already been notified of a problem with the service at this
# point (unless you disabled notifications for this service)
HARD)
# Makes a file to be used to make a ticket
echo -e "0\t$7+$6+$4\t$7+$1+$5+$4\t5\t5\tNot Applicable\t0\t3\t5\t1\t$nagios_dotproject_user_id \t$nagios_dotproject_user_id\t1\tNagios Daemon\t$nagios_dotproject_user_id\t$nagios_email\ t\N\t1\t$now\t$now\t0\t0\t$company_id\t" > /usr/local/nagios/libexec/tmp/nagiosoutput_helpdesk_item
/usr/bin/mysql --user=$db_user --password=$db_passwd --database=dotproject --execute="LOAD DATA LOCAL INFILE '/usr/local/nagios/libexec/tmp/nagiosoutput_helpdesk_item' INTO TABLE helpdesk_items"

# Return the item_id from the database
ticket_id=`/usr/bin/mysql -s --user=$db_user --password=$db_passwd --database=dotproject --execute='SELECT max(item_id) FROM helpdesk_items where item_requestor = "Nagios Daemon";' | tail -n 1`

# Makes a file to be used to make a ticket status entry
echo -e "0\t$ticket_id\t0\t$now\t$nagios_dotproject_user\tC reated\t" > /usr/local/nagios/libexec/tmp/nagiosoutput_helpdesk_status
/usr/bin/mysql --user=$db_user --password=$db_passwd --database=dotproject --execute="LOAD DATA LOCAL INFILE '/usr/local/nagios/libexec/tmp/nagiosoutput_helpdesk_status' INTO TABLE helpdesk_item_status"

echo "Nagios has created a new Helpdesk item in dotproject. Please check dotproject helpdesk for details" | mail -s "New Nagios Helpdesk item ($ticket_id)" $nagios_email
;;
esac
;;

esac

exit 0




Hope that helps someone.