Notification error for custom script

I have a custom notification script which uses POST to create a servicenow record.
Script installed, but getting the following:

CEE 1.6.0p10

OMD[BIMS]:~/local/share/check_mk/notifications$ python custom-snow.py
Traceback (most recent call last):
    File "custom-snow.py", line 36, in <module>
        if   os.environ['NOTIFY_WHAT'] == 'HOST':
   File "/omd/sites/BIMS/lib/python2.7/UserDict.py", line 40, in __getitem__
       raise KeyError(key)
KeyError: 'NOTIFY_WHAT'

That is because the environment variable NOTIFY_WHAT is not set when you call the script manually like you did. The same is true for all the other NOTIFY_* variables in your script.

But if the script gets called by checkmk to issue a notification, these variables are set to sensible values. For example, NOTIFY_WHAT will be set to either HOST or SERVICE depending on what caused the notification.

3 Likes

Ah ok thanks. So testing would basically involve adding the variables manually.

Should I be able to see custom notification scripts in the notify.log?

Either that, e.g. in the shell:

NOTIFY_WHAT=HOST
NOTIFY_HOSTSTATE=CRIT
NOTIFY_HOSTADDRESS=192.4.18.312
...
./custom-snow.py

Or fake a check result in the checkmk GUI to trigger a notification:

Sure. There will be a line that says

executing /omd/sites/.../local/share/check_mk/notifications/custom-snow.py
2 Likes

In the log:
The custom script rule matches the notification, but notification is not created

Difficult to diagnose without seeing your notification rule test. Did you select something in the CONTACT SELECTION pane? Maybe checkmk simply doesn’t know whom to notify.

Ok, I don’t understand the contact selection bit. The script is using a POST, so why would I want to select any contact?

Yes, I know exactly what you mean and had the same thoughts before. I believe checkmk “thinks” if nobody is on the contact list, then nobody needs to be notified. Maybe this is kind of legacy code as the first notification method that jumps to mind is email. I’m pretty sure checkmk started with that. Meanwhile we have other notiication methods which by themselves do not require a dedicated recipient (like your POST request) but checkmk apparently requires one.

Try checking the Notify all contacts of the notified host or service. box and make sure at least one user is a contact for the host in question. I created a technical notification user for that purpose and made him a contact for everything. He doesn’t even have a password set so I assume he cannot login but because he’s a contact, he gets notifications.

1 Like

Ah ok makes sense.

I have done this, and it’s now working!

You have been of great help. Thanks very much!

1 Like

You are welcome. Another possibility is to create such a technical notification-user but don’t make him contact for anything. Create him as a regular user (no admin rights required), and disable his login. Then, in the notification rule, select just this particular user as a contact:

This approach is perhaps easier to understand. At least I thought so. Also, this avoids the following question: “How many POST requests are sent if multiple users are in the contact list for a problem?”

1 Like