How to add custom service attribute inside service notification

Hi,

Can someone please help me to add a custom service attribute inside the service notification?

Thank you

Hi @ETSystems , can you be more specific on the use case you need to accomplish ?

Cheers,

Hi,

I am trying to set custom attributes for the hosts and services. We had this feature inside nagios.
For example, based on criticality, I set defcon values for the hosts/services and this defcon value will be shown inside the mail notification subject. I am checking for the same settings inside checkmk.

If the scenario is not clear please let me know. I am happy to elaborate more. :slight_smile:

Hi @ETSystems

I am not sure if custom attributes are a variable you can use in the subject line. But this can be found out using this:

My understanding is: If custom attributes show up in the variable list, you can add them to the subject line.

But others here know a lot more about this than I do. :slight_smile:

1 Like

Hi @elias.voelker ,

Thank you for the suggestion.
I tried this option but I am not able to find custom attribute details in that.

I found this article related to custom attributes,
Custom service attributes can now be configured and I tried adding $Service_[ID]$ inside notification template but it’s still not working.

can someone please help me to sort this out?
I am still not able to figure out a way to include custom attributes inside mail notifications.

Hi All,

I have solved the issue.
As per the blog Custom service attributes can now be configured , i defined a custom service attribute inside global settings,

eg, DEFCON VALUE

image

and then created a service monitoring rule,

image

and added $SERVICE_DEFCON_VALUE$ inside the notification subject template for retrieving the corresponding value and it worked as expected.

Thank you all.

1 Like

I tried to replicate this on Checkmk 2.2.0p17 Raw Edition and it does not work. I created a custom service attribute with ID “OPOMBA” and configured a rule to add it to 4 service checks. When I trigger the notification for one of these services, I cannot get this CSA into an email message. I tried including it in a subject as $OPOMBA$ and $SERVICE_OPOMBA$. I selected the option “Display additional information: Complete variable list (for testing)”. I even created a test notification script to output all environment variables to a text file. Nothing works, the attribute simply isn’t there. Can someone confirm this? Am I missing something?

hi @bogdan.vosnjak ,

Please try to view the notification context to have a better understanding of the notification parameters.

image

@ETSystems , thank you for your reply. I’ve triggered an event and checked the notification context, but none of the custom service attributes is in the list. Currently I have two on the service I triggered an alarm for.

I believe there is an issue in the raw edition of the Nagios configuration. I have tested it with versions 2.2p14 and 2.2p18. The problem is that custom attributes do not appear in the context according to the documentation.

However, I have managed to make adjustments in the ~/etc/nagios/conf.d/check_mk_templates.cfg file. Specifically, I added the Host custom attribute with ‘JB_CUSTOM’ and the Service custom attribute with ‘JB_ATTR_CUST’.

      NOTIFY_HOST_ADDRESS_FAMILY='$_HOSTADDRESS_FAMILY$' \
       NOTIFY_HOST_JB_CUSTOM='$_HOSTJB_CUSTOM$' \
       NOTIFY_SERVICE_JB_CUSTOM1='$_SERVICEJB_ATTR_CUST$' \
       check_mk --notify
}

It’s important to note that in the Nagios configuration, the prefix ‘_HOST’ or ‘_SERVICE’ should precede the name of the custom attribute.

After the change, restart the site.

In the context, the name of the attribute should match the Nagios notification attribute name, as illustrated in the figure below:
image

Please, test.

Yes, thank you, it works!

I have created a service custom attribute “OPOMBA” and Custom host attribute “CHA_NOTIFICATION_HELPER1” which I included in ~/etc/nagios/conf.d/check_mk_templates.cfg like this:

       NOTIFY_HOST_ADDRESS_FAMILY='$_HOSTADDRESS_FAMILY$' \
       NOTIFY_SERVICE_CSA_OPOMBA='$_SERVICEOPOMBA$' \
       NOTIFY_HOST_CHA_NOTIFICATION_HELPER='$_HOSTCHA_NOTIFICATION_HELPER1$' \
       check_mk --notify
}

Important thing to mention is that, within the context of notification, the names of these variables are SERVICE_CSA_OPOMBA and HOST_CHA_NOTIFICATION_HELPER. So, when I included them in the e-mail subject, I used the following sytax:

$SERVICE_CSA_OPOMBA$ for SERVICE_CSA_OPOMBA
$HOST_CHA_NOTIFICATION_HELPER$ for HOST_CHA_NOTIFICATION_HELPER

So, a lot of tiny details that you need to configure correctly. But in the end it works.