Question about host labels and opsgenie integration

Do host labels get passed into opsgenie integration?
I see in the email integration, the are included one at a time such as
HOSTLABEL_env prod

Edit to change my question:

I switched to the included opsgenie notification, so ignore the following:

In this integration, it has a line in the webhook for HOSTTAGS and HOST_TAGS (same output for some reason)

"HOSTTAGS": "/wato/ cmk-agent ip-v4 ip-v4-only lan prod site:og tcp wato",

Hello? How do I get the opsgenie plugin to send the labels ? Is that a feature request that needs to be made to opsgenie/atlassian?

It lets me define tags as part of the plugin, but that doesn’t give me any of the host or service tags or labels.

Anyone? How do I get help for this?

Late reply but I also encountered this. For anyone seeing this in the future and using the OpsGenie provided integration:

By adding the following code to the OpsGenie notifier script from OpsGenie it will send labels as tags.

    host_tags = context['HOSTTAGS']
    for (var, value) in context.items():
        if var.startswith("HOSTLABEL_"):
            host_tags += " " + var[10:] + ":" + value

    context['HOSTTAGS'] = host_tags

This should be added after where it initialises the context variable.
OpsGenie ignores HOST_TAGS, it uses the HOSTTAGS variable!

Is this the opsgenie script provided with checkmk, or the standalone script that you download from opsgenie’s website?

ETA: would really prefer it be in the checkmk integrated notification

I tried putting the code into into
/opt/omd/versions/2.0.0p18.cee/lib/python3/cmk/notification_plugins/opsgenie_issues.py
and it didn’t seem to work. See below.

def main() -> int:
    context = utils.collect_context()

    if 'PARAMETER_PASSWORD' not in context:
        sys.stderr.write("API key not set\n")
        return 2

# testing hosttags
    host_tags = context['HOSTTAGS']
    for (var, value) in context.items():
        if var.startswith("HOSTLABEL_"):
            host_tags += " " + var[10:] + ":" + value

    context['HOSTTAGS'] = host_tags

# end testing hosttags

    api_key = retrieve_from_passwordstore(context['PARAMETER_PASSWORD'])

I know at least 4 HOSTLABEL_* made it into the ticket as I pass them as fields in the ticket description:

Description
Host:
Service: Fans Chassis 1
Event:
Output: Manually set to Critical by

HOSTLABEL_Env: liveHosting
HOSTLABEL_Game:
HOSTLABEL_Owner:
HOSTLABEL_Studio:

Opsgenie ID: 68babef1-4c77-4ac5-a273-39d53ff3e5fb-1662493259341

Hi [jestertoo], did you manage to solve this? What would be the corect code for this?

I was not able to get this working as @diademiemi suggested.

I had a colleague of mine look at it and he came up with this. (and it works for us now by changing the /omd/sites/####/lib/check_mk/notification_plugins/opsgenie_issues.py file that comes standard with Check_MK)

Change this…

    tags_list: List[str] = []
    if context.get("PARAMETER_TAGSS"):
        tags_list = context.get("PARAMETER_TAGSS", "").split(" ")

to this…

    tags_list: List[str] = []
    tags_list = context['HOSTTAGS'].split(" ")
    if context.get("PARAMETER_TAGSS"):
        tags_list += context.get("PARAMETER_TAGSS", "").split(" ")

How does that code change pull HOSTLABEL items?

This is for Host Tags. Not for Host Labels.
Host labels would be even better but I haven’t found the variable for that.

The previous person mentioned we could do something like this

You shouldn’t directly change files below ~/lib since this is just a symlink (or chain of symlinks) to /opt/omd/versions/x.y.z/lib so your changes will no longer be active once a new version gets installed. Instead, place a copy of the file in ~/local/lib/... and modify that file instead.

1 Like

Placing the file in /omd/site/####/local/lib/check_mk/notifications_plugins does not seem to work.

Where is the original file located? I’m not using opsgenie myself, but I can find the “opsgenie_issues.py” only below .../lib/python3/cmk/notification_plugins/.

So your modified file should probably be placed in ~/local/lib/python3/cmk/notification_plugins/, not ~/local/lib/check_mk/...

1 Like

any help getting HOSTLABEL’s into the opsgenie output?

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.