Custom Integration

Hello,

We are using the Freshservice ITSM system. It supports notifcations sent to it in json format that can be maps to fields and create new tickets.

Is it possible that I can provide an end-point to CheckMK where it will send json notifications? As I do not see Freshservice as a listed integration.

Yes and no.
ServiceNow basically also accepts JSON notifications. But you can’t send the ServiceNow notifications to Freshservice as very likely the API specifications of both tools don’t match.

As every tool is unique, every tool needs a custom integration.

Take for example issue resolution, when an issue occurs temporarily and the service goes CRIT in Checkmk and then OK. You don’t want the ticket to remain open in your ITSM tool. But does your ITSM tool support this with an API endpoint?

Thus, you won’t come around custom development for such an integration. Either by you or someone who does that on a daily basis (there is a huge network of people who are freelancing to do these things or are Checkmk partners).

If you want to try it yourself, a good starting point is the ServiceNow integration (part of the Enterprise Edition). Or any other notification script.

2 Likes

@GlenUK Did you have any luck with this? I am looking to try this as well. I did see there is also a document for nagios integration but this hasn’t helped me enough. Integrate Nagios XI with Freshservice Alert Management : Freshservice

We are also looking to do the same thing - did you ever get this resolved?

So I think I’m going to have a stab at creating a custom Freshservice plugin, ripping the Nagios integration apart - we are migrating from Nagios, so it makes it a bit easier, and Nagios uses the same OMD backend as Checkmk. With a few tweaks to alert payloads in Fresh, and tweaks to the JSON notifications sent via a custom bash script, I think this can work. Will get back with how I got on, but will take some time to test as I get to grips with it.

I got close. So I started by copying the way Nagios does its integration with FreshService - since Fresh actually has a pre-built plugin for Nagios, and Checkmk uses the same OMD monitoring platform as Nagios, I thought it would be a breeze. Not so easy, although I did succeed in getting it to log a ticket in Fresh! The data was all munged up though, and I suspect its because CMK is not sending the payload in JSON format, which Fresh is setup to receive.

I need to find out a way to get CMK to send the alert payload as JSON, but reeeeeally struggling. There doesnt seem to be many people on here doing similar things.

The way I got it to partially work is to essentially copy the Nagios commands over to CMK using a custom bash script in the ~/local/share/check_mk/notifications folder. I created 2 scripts, 1 for host alerts, and 1 for service alerts (exactly as setup in Nagios).

The script is essentially a curl post containing the API URL, auth header and payload data from the alert.

I can then create a new notification rule using this method, and bingo, CMK is logging tickets in Fresh. But the data is unintelligible, since I believe the payload is not coming through in JSON, OR the payload data uses completely different payload headers to Nagios.

Ideally I need to see what the payload is, but really struggling to find a way to do this, as there is not much information on the forums for it, and they seem to be pushing us to pay for some consultancy hours (which is not cheap!!). We are ent-edition customers btw :slight_smile:

If anyone can help further that would be amazing.

I am using a bash script with curl that does something similar:

local/share/check_mk/notifications/my-custom-notify.sh

#!/bin/bash
# Custom Notify by JSON HTTP
# In the second line after the comment character # is a Title for the script.
# As a rule this will be shown when selecting the notification method.
....

timeout 5 curl \
	--silent \
	--request POST \
	--header 'Content-type: application/json' \
	--data '{"text":'"'$msg'"'}' \
	--connect-timeout 3 \
        "${hook_url}"

Oooh what does that end up looking like on the payload?

The scripts I’m using (actually just a bash one-liner) are as follows:

#!/bin/bash
# FreshService Host Notification

curl -X POST -H "Authorization: auth-key <key>" -H "Content-Type: application/json" --data "{\"metric_name\": \"Availability\", \"hostname\": \"$HOSTNAME$\", \"message\": \"$NOTIFICATIONTYPE$ - $HOSTNAME$ is $HOSTSTATE$\", \"ip_address\": \"$HOSTADDRESS$\", \"severity\": \"$HOSTSTATE$\", \"event_id\": \"$HOSTEVENTID$\", \"output\": \"$HOSTOUTPUT$\", \"perf_data\": \"$HOSTPERFDATA$\", \"action_url\": \"$HOSTACTIONURL$\", \"check_command\": \"$HOSTCHECKCOMMAND$\", \"problem_id\": \"$HOSTPROBLEMID$\" , \"long_datetime\": \"$LONGDATETIME$\", \"notification_comment\": \"$NOTIFICATIONCOMMENT$\", \"notification_type\": \"$NOTIFICATIONTYPE$\", \"contact_name\": \"$CONTACTNAME$\" }" <api-post-url>
#!/bin/bash
# FreshService Service Notification

curl -X POST -H "Authorization: auth-key <key>" -H "Content-Type: application/json" --data "{\"metric_name\": \"$SERVICEDESC$\", \"hostname\": \"$HOSTNAME$\", \"message\": \"$NOTIFICATIONTYPE$ - $HOSTNAME$ - $SERVICEDESC$\", \"description\": \"$SERVICEDESC$\", \"ip_address\": \"$HOSTADDRESS$\", \"severity\": \"$SERVICESTATE$\", \"event_id\": \"$SERVICEEVENTID$\", \"output\": \"$SERVICEOUTPUT$\", \"perf_data\": \"$SERVICEPERFDATA$\", \"action_url\": \"http://nagios/$SERVICEACTIONURL$\", \"check_command\": \"$SERVICECHECKCOMMAND$\", \"problem_id\": \"$SERVICEPROBLEMID$\" , \"long_datetime\": \"$LONGDATETIME$\", \"notification_comment\": \"$NOTIFICATIONCOMMENT$\", \"notification_type\": \"$NOTIFICATIONTYPE$\", \"notification_url\": \"http://nagios/adagios/status/detail?host_name=$HOSTNAME$&service_description=$SERVICEDESC$&backend=\", \"contact_name\": \"$CONTACTNAME$\" }" <api-post-url>

So basically I’m trying to get it to use the variables that come from the alert, but it needs to be JSON. These get mapped in Fresh. But I think these commands dont actually export any data, or its not in JSON.

I think you are close to a solution.
The point is that the environ variables in the notification systems are prefixed with NOTIFY_
You can use this notification script to get an idea what is available.

OMD[central22]:~$ cat local/share/check_mk/notifications/notify-by-file.sh 
#!/usr/bin/env bash
# 00 notify-by-file.sh

printenv | grep -P '^NOTIFY_.+=.+'  > /tmp/notify-by-file.$$.log

This documentation is old but still a little helpful:

https://web.archive.org/web/20190531154256id_/https://checkmk.com/cms_notifications.html

More recent docs:

Best explanation currently available is probably this:

1 Like

Wow, thanks thats all it was! Using the wrong environment variable names!

I used your little script and seperated host and service notifications, and basically updated my curl commands to use the correct variable names, and with some tweaking its now working!

The tickets are auto-closing too when problems clear.

Success! Thanks for your assist!

For reference, here are the scripts finalised:

Host alerts:

#!/bin/bash
# FreshService Host Notification

curl -X POST -H "Authorization: auth-key <key>" -H "Content-Type: application/json" --data "{\"metric_name\": \"Availability\", \"hostname\": \"$NOTIFY_HOSTALIAS\", \"message\": \"$NOTIFY_WHAT - $NOTIFY_HOSTALIAS is $NOTIFY_HOSTSTATE\", \"ip_address\": \"$NOTIFY_HOSTADDRESS\", \"severity\": \"$NOTIFY_HOSTSTATE\", \"event_id\": \"$NOTIFY_NOTIFICATIONTYPE\", \"output\": \"$NOTIFY_HOSTOUTPUT\", \"perf_data\": \"$NOTIFY_HOSTOUTPUT\", \"action_url\": \"http://cmk.ctshirts.co.uk/ctshirts$NOTIFY_HOSTURL\", \"check_command\": \"$NOTIFY_HOSTCHECKCOMMAND\", \"problem_id\": \"$NOTIFY_HOSTPROBLEMID\" , \"long_datetime\": \"$NOTIFY_LONGDATETIME\", \"notification_comment\": \"$NOTIFY_HOSTOUTPUT\", \"notification_type\": \"$NOTIFY_NOTIFICATIONTYPE\", \"contact_name\": \"$NOTIFY_CONTACTNAME\" }" <api-url>

Service alerts:

#!/bin/bash
# FreshService Service Notification

curl -X POST -H "Authorization: auth-key <key>" -H "Content-Type: application/json" --data "{\"metric_name\": \"$NOTIFY_SERVICEDESC\", \"hostname\": \"$NOTIFY_HOSTALIAS\", \"message\": \"$NOTIFY_WHAT - $NOTIFY_HOSTALIAS - $NOTIFY_SERVICEDESC\", \"description\": \"$NOTIFY_SERVICEDISPLAYNAME\", \"ip_address\": \"$NOTIFY_HOSTADDRESS\", \"severity\": \"$NOTIFY_SERVICESTATE\", \"event_id\": \"$NOTIFY_HOSTPROBLEMID\", \"output\": \"$NOTIFY_SERVICEOUTPUT\", \"perf_data\": \"$NOTIFY_SERVICEOUTPUT\", \"action_url\": \"http://cmk.ctshirts.co.uk/ctshirts$NOTIFY_HOSTURL\", \"check_command\": \"$NOTIFY_HOSTCHECKCOMMAND\", \"problem_id\": \"$NOTIFY_SERVICEPROBLEMID\" , \"long_datetime\": \"$NOTIFY_LONGDATETIME\", \"notification_comment\": \"$NOTIFY_SERVICEOUTPUT\", \"notification_type\": \"$NOTIFY_NOTIFICATIONTYPE\", \"notification_url\": \"http://cmk.ctshirts.co.uk/ctshirts$NOTIFY_SERVICEURL\", \"contact_name\": \"$NOTIFY_CONTACTNAME\" }" <api-url>

Replace the text in <> with your API key and POST URL.

Its not perfect - e.g. some variables were used twice. I think with additional tweaking and customising the FreshService monitoring tool plugin properly this could be refined more.

I will keep refining it and eventually package this into an MKP for the exchange. I need to figure out how to make the API key and URL a text box on the notification rule first! Need to brush off my Python.

Hi,

Would this work with other item tools such as manage engine service desk plus?

Not sure, it entirely depends on how that particular ITSM accepts alerts and deals with them. With Freshservice, it accepts web API requests containing the information required to generate a ticket, which I then mapped using the variables output on alerts by CMK.

I have never used Manage Engine Service Desk Plus before though!