How to deliver Host IP Address via Notification Variables?

CMK version: 2.3.0p28
OS version: Ubuntu Server LTS 24.04

Hello everyone,

I am trying to implement notifications to a Zammad Ticket system in which a ticket is created when a host or service goes down / critical. For that, Zammad offers two pre-made scripts which work fine, but lack the Host’s IP Address for easier identification.

Here’s the service script in my my ~/local/share/check_mk/notifications folder:

#!/bin/bash
# Zammad Service

curl --insecure -X POST \
  -F "event_id=$NOTIFY_SERVICEPROBLEMID" \
  -F "host=$NOTIFY_HOSTNAME" \
  -F "hostip=$NOTIFY_HOSTADDRESS" \
  -F "service=$NOTIFY_SERVICEDESC" \
  -F "state=$NOTIFY_SERVICESTATE" \
  -F "text=$NOTIFY_SERVICEOUTPUT" \
  https://[URL]

Example output is the following:

EventID: 431

Host: [Hostname as set up in checkmk]

Service: Check_MK Discovery

State: CRITICAL

Text: [Text]

RemoteIP: [GatewayIP]

UserAgent: curl/8.5.0

What I want is to have the -F “hostip=$NOTIFY_HOSTADDRESS” line to properly show the host’s IP address when creating a new ticket. This would make troubleshooting way easier for me. I’ve tried different variables for this (such as $NOTIFY_HOST_ADDRESS_4) as well but no matter what I do, the Host IP won’t show up in a new ticket. Does anyone know how to implement this?

Many thanks.

If you add a, or change an existing, notification rule in Setup > Events > Notification configuration, there’s an option to include Complete variable list (for testing) under Information to be displayed in the email body.

Trigger the rule, and you get the variable list in the mail with examples from the host that triggered the rule.

In 2.1, that I’m running, not every variable seems to be available in every part of checkmk.

Edit:
I checked an old mail where I had that list checked, and it shows HOSTADDRESS and HOST_ADDRESS_4 with an IP as value.

So maybe lose the NOTIFY_ prefix?

OP is not sending emails

$NOTIFY_HOSTADDRESS is correct, i think that’s more a problem with your curl command not expanding variables

Continuing the discussion from How to deliver Host IP Address via Notification Variables?:

Thank you for the responses.

I’ve tried this (along with other variables for testing, too) but no matter what variables I add to the script, no content other than the preexisting stuff shows up. The other variables in the script show up without the $Notify in the list of variables as well.

This might be it, do you by chance know how to make it work? I haven’t worked much with curl commands, is there a possible alternative?

For as far as i can see a ‘test-notification’ does not supply a full set of what a ‘real’ notification would hold.

test-notification:

real notification:

so its my best guess that when testing a/the $HOSTADDRESS isnt filled at all.

  • Glowsome
1 Like

Besides the above thoughts, i have quickly setup a docker env with zammad to test notifications.

The notification-script i used is something i wrote myself in python, and as 1st argument in the notification used the supplied url in zammad after enabling the integration.

#!/usr/bin/env python3
#zammad-service

# -*- encoding: utf-8; py-indent-offset: 4 -*-

# This script if for service-notifications to zammad
# Place this in ~/local/share/check_mk/notifications as your site-user.
# Add the url to send the notifications to as first parameter.

import os
import requests
import sys

def build_context():
    return {
        var[7:]: value
        for (var, value) in os.environ.items()
        if var.startswith("NOTIFY_")
    }

def build_message(ctx):
    data = {
        'event_id': (None, ctx.get('SERVICEPROBLEMID', '')),
        'host': (None, ctx.get('HOSTNAME', '')),
        'hostip': (None, ctx.get('HOSTADDRESS', '')),
        'service': (None, ctx.get('SERVICEDESC', '')),
        'state': (None, ctx.get('SERVICESTATE', '')),
        'text':  (None, ctx.get('SERVICEOUTPUT', '')),
        }
    return data

def main():
    ctx = build_context()
    response =  requests.post(ctx.get("PARAMETER_1"), files=build_message(ctx), verify=False)
    
if __name__ == "__main__":
    try:
        main()
    except Exception as e:
        sys.stderr.write("Unhandled exception: %s\n" % e)
        sys.exit(2)

I had some issues with getting it to work, as zammad after enabling the integration in the UI kept complaining about the feature still being disabled ( http/422 error in responce)

After having rebooted the full stack it started to work, and i can confirm that the above python script works, and that the ip of the host where the service is is sent to zammad:


Unfortunately the resulting ticket does not reflect the added hostip, so that must be a ‘zammad’-issue ( template ?)

So i’m guessing on the zammad-side something also needs to be done to include this in the ticket itself.

  • Glowsome

Yes

@RoseD you need to extend the ticket with custom attributes inside Zammad.
Then you can sent also the IP to Zammad.
Here API Reference — Zammad Admin Documentation documentation you can find under the point “Ticket Attributes” what can be done with your own attributes.
The predefined “Checkmk Parameters” cannot be changed if i read the documentation in the right way.

After rereading the article I tried messing with a few things, including adding a “note” paramter as well as trying to change the variables of the fixed parameters of checkmk, and I happened to get a working but unclean solution:

image

I swapped the variable of the “eventid” paramter with the host address, which does give me the IP of my host in return. The text field shown in the screenshot is unreliable as it doesn’t always provide the IP depending on which host or service is down.

I will continue using this method until I figure out a better solution, but this works pretty well already.

Thank you for your time and effort!