Customize Notification HTML Email - mail.py

Hello,

I would like your opinion.

Problem 1 : I have configured a notification Notification Method (HTML Email) but I do not have the link to my Service note URL in my notification email.

My solution 1 : I modified the check_mk_templates.cfg file and added

define command {
command_name check-mk-notify
command_line \

   NOTIFY_SERVICENOTESURL='$SERVICENOTESURL$' \

Question 1 : Is this the right method?

Problem 2 : Now the link appears but is not clickable

My Solution 2 : I modified the /opt/omd/versions/2.2.0p20.cre/lib/python3/cmk/notification_plugins/mail.py file and I edited this section

(
“notesurl”,
“service”,
False,
“all”,
“Custom Service Notes URL”,
“$SERVICENOTESURL$”,
“$SERVICENOTESURL$”,
),

by

(
    "notesurl",
    "service",
    False,
    "all",
    "Custom Service Notes URL",
    "$SERVICENOTESURL$",
    "<a href=$SERVICENOTESURL$>$SERVICENOTESURL$</a>",
),

now the link is clickable

Question 2 : Is this the right method?

Problem 3 : in my link I have a # and he is transformed into %23

Question 3 : can I change the encoding?

I think whatever I did is not the right method because if I do an update of checkmk I lose everything. I tried to follow Andrea’s solution : Change resolution of graphs in mail notifications - #4 by kaiserchrss

I do it on my systems the following way.

copy ~/lib/python/cmk/notifications/mail.py to ~/local/lib/python
copy ~/share/check_mk/notifications/mail to ~/local/share/check_mk/notifications
modify line 2 of ~/local/share/check_mk/notifications/mail - append a “modified” or something else
also change the import line to import mail
modify the ~/local/lib/python/mail to your needs

my solution that doesn’t work :wink: :

1 - I created a file/opt/omd/sites/mysite/local/share/check_mk/notifications/mail

HTML Email 2

from cmk.notification_plugins import mail

if name == “main”:
mail.main()

2 - I also have to copy /opt/omd/versions/2.2.0p20.cre/lib/python3/cmk/notification_plugins/mail.py but where?
I have to put it in the same tree?

cd /opt/omd/sites/mysite/local/lib/

ll

python/
python3/

cd python or python3?

In python3/cmk/ i create notification_plugins folder and copy mail.py and modify it?

thank you in advance

Stan

I’m not perfectly sure, but don’t these settings in the standard notification rule work for you:

Thanks for you answer Dirk

Insert HTML section* insert a link in the email before the notification

there is a link behind “Host” and “Service” but not behind “Custom Service Notes URL” and an encoding problem in the link

Regards

I think everything you need contains the Service Rule “Notes URL for Services”. Fine Grained you can setup the “Custom Services Notes URL” for your Notifications. I had no issues when Links contain “#”. For example:

1 Like

Thanks,

it s strange, it is possible to have your mail.py file ?

regards
Stan

and your check_mk_templates.cfg file

thanks
regards

No customisations. Everything “out of the box”. Tested on 2.1.0p36.cee. Not sure if this rule exists in cre:

1 Like

Hi,

My version is check-mk-raw-2.2.0p20-el9-38.x86_64

I will explain all my steps.

Step 1 : I created a notification

Step 2 : I created a note URL for services

Step 3 : My first notification does not have the link of my note URL for services

Step 4 : I modified the check_mk_templates.cfg file and added “SERVICENOTESURL”

define command {
command_name check-mk-notify
command_line

NOTIFY_SERVICENOTESURL=‘$SERVICENOTESURL$’

Step 5 : my second notification have the link to my “note URL for services” but is not clickable and there is an encoding problem with the #

Step 6 :

I modified the /opt/omd/versions/2.2.0p20.cre/lib/python3/cmk/notification_plugins/mail.py file and I edited this section

(
“notesurl”,
“service”,
False,
“all”,
“Custom Service Notes URL”,
“$SERVICENOTESURL$”,
“$SERVICENOTESURL$”,
),

by

(
“notesurl”,
“service”,
False,
“all”,
“Custom Service Notes URL”,
“$SERVICENOTESURL$”,
"<a href=$SERVICENOTESURL$>$SERVICENOTESURL$</a>",

),

Step 7 : My third notification has the link to my “note URL for services” and is now clickable and there is still an encoding problem with the #

Here are all my steps to have the link clickable

Is this the right method, I don’t think… your opinions are welcome?

regards

Hi,

Do you have another solution to prevent my changes from being overwritten on the next checkmk update?

Regards
Stan

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.