Nagios & ServiceDesk integration

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
ltratkiewicz
Posts: 2
Joined: Fri Jul 01, 2011 4:14 am

Nagios & ServiceDesk integration

Post by ltratkiewicz »

Hello,

im trying to do an integration of Nagios with ManageEngine ServiceDesk Plus.

The idea is to send custom email notification from Nagios, that will be parsed by ServiceDesk in order to create tickets, and close them automaticly if reported service/host returns to OK state.

Therefor, i reedited Nagios notification commandline to get required information and parse it using a bash script. However i cannot make it work properly nad im lost at current point.

This is my edited notify-service-by-email:

Code: Select all

/usr/bin/printf "%b" "$SERVICESTATE$\n" > /usr/local/nagios/etc/status.not|/usr/bin/printf "%b" "$SERVICEDESC$\n" > /usr/local/nagios/etc/name.not|/usr/local/nagios/etc/skrypt.sh
- im just trying to test it, so its very simple, i got only 1 service which is monitored atm, command should only get its name and state and write it to the files: name.not and status.not, it works ok

Next i created script which is executed everytime when notification is generated by Nagios, skrypt.sh:

Code: Select all

name=$(cat /usr/local/nagios/etc/name.not)
status=$(cat /usr/local/nagios/etc/status.not)
if [[$status==*CRITICAL*]];
then
topic=@SDP@$(cat /usr/local/nagios/etc/status.not)
echo @@OPERATION=AddRequest@@ > /usr/local/nagios/etc/mail.not
mail -s $topic mailaddress@xxx.com < /usr/local/nagios/etc/mail.not
sleep 70
mysql -h <sql IP> -u root -P 33366 --skip-column-names --execute="select WORKORDERID from workorder where title='CRITICAL' order by workorderid desc limit 1;" servicedesk > /usr/local/nagios/etc/id.request
elif [[$status==*OK*]];
then
id=$(cat /usr/local/nagios/etc/id.request)
topic=@SDP@
echo @@OPERATION=CloseRequest@@ > /usr/local/nagios/etc/mail.not
echo @@REQUESTID=$id@@ >> /usr/local/nagios/etc/mail.not
mail -s $topic mailaddress@xxx.com < /usr/local/nagios/etc/mail.not
else
touch /usr/local/nagios/etc/ARGGH.ERROR
fi
- the idea of the script (so far) is to check to what the service status in Nagios has changed to, and if it is CRITICAL, it will send email to Service Desk to open a new inccident ticket and then write down its ID to the file, and if the status has changed to OK, then it will send the mail to Service Desk in order to close this inccident, if else it will create an error file.

The script works just fine when i run it manualy on Nagios server and put desired status into file status.not manualy, however if its run through Nagios, it executes the "ELSE" condition of the script and generates ARGGH.ERROR file no matter what is the status. I completely do not understand why its doing so, it seems like its not reading variables correctly?

Please advice.

Nagios Core 3.2.3 running on Ubuntu 11.04
ltratkiewicz
Posts: 2
Joined: Fri Jul 01, 2011 4:14 am

Re: Nagios & ServiceDesk integration

Post by ltratkiewicz »

Edit:
Ok, i reedited abit my script, and if statement works fine now

Code: Select all

#!/bin/bash
        cd /usr/local/nagios/etc
        status=$(cat status.not)
        name=$(cat name.not)
        id=$(cat id.request)
        if [ "x$status" == "xOK" ];
        then
                echo "@@OPERATION=CloseRequest@@">mail.not;
                echo "@@REQUESTID=$id@@">>mail.not;
                mail -s @SDP@ SDtest@betacom.com.pl < mail.not;
        fi;
        if [ "x$status" == "xCRITICAL" ];
        then
                echo "@@OPERATION=AddRequest@@">mail.not;
                echo "@@CATEGORY=General@@">>mail.not;
                echo "Utworzono w Nagios">>mail.not;
                topic="@SDP@Nagios_$name";
                mail -s $topic SDtest@betacom.com.pl < mail.not;
                sleep 90;
                mysql -h 172.30.14.112 -u root -P 33366 --skip-column-names --execute="select WORKORDERID from workorder where title='Nagios_check_nt_2' order by workorderid desc limit 1;" servicedesk > id.request;
        fi;
However i still cannot get 1 functionality to work, its not getting created incident from the database:

Code: Select all

mysql -h 172.30.14.112 -u root -P 33366 --skip-column-names --execute="select WORKORDERID from workorder where title='Nagios_check_nt_2' order by workorderid desc limit 1;" servicedesk > id.request;[code]
If i run it manually, it grabs the id into id.request just fine, if Nagios is performing this script, it doesnt work.

Please advice.
Locked