Check_MK Discord notification

Hey All,

I am new to using Check_mk v2 but I have a decent knowledge of it so far.

I am trying to set up a discord notifcation I found on a forum post here which linked to: Discord Checkmk Notification Script · GitHub

I have added it to /opt/omd/sites/ad/local/share/check_mk/notifications/ and set it up in WATO against the automation user for sending out notifications

However when I tested it I got the following error in my notify.log:

2022-01-24 02:00:59,353 [20] [cmk.base.notify] ----------------------------------------------------------------------
2022-01-24 02:00:59,353 [20] [cmk.base.notify] Got raw notification (UNKNOWN) context with 0 variables
2022-01-24 02:00:59,353 [20] [cmk.base.events] Error on completing raw context: 'HOSTNAME'
2022-01-24 02:00:59,354 [40] [cmk.base.notify] ERROR:
Traceback (most recent call last):
  File "/omd/sites/ad/lib/python3/cmk/base/notify.py", line 355, in locally_deliver_raw_context
    return notify_rulebased(raw_context, analyse=analyse)
  File "/omd/sites/ad/lib/python3/cmk/base/notify.py", line 474, in notify_rulebased
    why_not = rbn_match_rule(rule, raw_context)
  File "/omd/sites/ad/lib/python3/cmk/base/notify.py", line 804, in rbn_match_rule
    return events.apply_matchers([
  File "/omd/sites/ad/lib/python3/cmk/base/events.py", line 414, in apply_matchers
    result = matcher(rule, context)
  File "/omd/sites/ad/lib/python3/cmk/base/events.py", line 421, in event_match_rule
    return apply_matchers([
  File "/omd/sites/ad/lib/python3/cmk/base/events.py", line 414, in apply_matchers
    result = matcher(rule, context)
  File "/omd/sites/ad/lib/python3/cmk/base/events.py", line 675, in event_match_exclude_hosts
    if context["HOSTNAME"] in rule.get("match_exclude_hosts", []):
KeyError: 'HOSTNAME'

I am using 2.0.0p18.cre (default) on Ubuntu 20.04

As much as I know about check_mk my python knowledge is quite basic.

Can anyone help with this

Thanks

As this is no error from the script itself i would say that there is a wrong configured notification rule the reason.
Is it possible that you defined a exclude host and this field is empty?

2 Likes
2 Likes

Hi @livi6191

welcome to the community and thanks for using my discord script. :sweat_smile:

Because I’ve got a mail notification from github with your initial comment I think there is a misunderstanding on how to setup this notification script.

Hey Guys,
I am looking at setting this up for my homelab use, however I am new to python and advanced check_mk changes I know I need to edit /opt/omd/versions/2.0.0p18.cre/lib/python3/cmk/gui/plugins/wato/notifications.py for this to work and show on Wato, but I am not sure on how to do it.
Would someone be able to advise or even provide example configuration files
Thanks

Here is a step by step guide on how to setup the discord notification script for Checkmk:

  1. Login via SSH to your Checkmk Server

  2. Become the Site User [sudo su - SITENAME]

  3. Go to local/share/check_mk/notifications/ [ OMD[SITENAME]:~$ cd local/share/check_mk/notifications/]

  4. Go to Discord Checkmk Notification Script · GitHub

  5. Click on the RAW Button [It’s possible to skip this step and use the URL from Step 6.]

  6. Copy the URL from your Browser [https://gist.githubusercontent.com/n00rm/32f1334b1dd2efc40122fee36551ef17/raw/4feee30fa2b183bef6fc619e897f541ec23befa8/discord.py]

  7. Go back to your Checkmk site terminal (SSH) and write wget and insert the copied URL.
    [wget https://gist.githubusercontent.com/n00rm/32f1334b1dd2efc40122fee36551ef17/raw/4feee30fa2b183bef6fc619e897f541ec23befa8/discord.py]

  8. Do a chmod +x on the downloaded file to make it executable by Checkmk. [chmod +x discord.py]

  9. Create Discord Webhook:



Change the bot settings to your preferences and copy the webhook URL.

  1. Login to your Checkmk Webinterface and go to notification settings → image

  2. Create a notification rule like this:


    Copy the created webhook url into the parameters

  3. Change the notification conditions to your liking.

  4. Profit!

Hope this helps! No need to edit checkmk core files.

Kind Regards
Norm

10 Likes

@Norm

That is great thanks, I managed to get it installed properly but the error message came up when I tried cmk -notify from ssh.

I think I was looking to deep into it without enough sleep last night :frowning:

I have woken up with discord notifications, so all appears to be working well.

Thanks so much for your assistance with this, and allow me to add a Great script!

1 Like

Hi @livi6191 and welcome to the checkmk community.

Please mark the post as solution. This will help other users to find similar problems and their solutions much easier.

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed. Contact an admin if you think this should be re-opened.