Send notification to znuny aka otrs

Hello,

I am trying to configure notifications to send them towards my otrs ticketing system.

OTRS side the configuration is complete, CMK side however, I have a problem:

I created the following script:

#!/bin/bash

# Parametri della notifica
HOSTNAME="$1"
SERVICE="$2"
STATE="$3"
OUTPUT="$4"

# Debug: Verifica che i parametri siano passati correttamente
echo "HOSTNAME: $HOSTNAME"
echo "SERVICE: $SERVICE"
echo "STATE: $STATE"
echo "OUTPUT: $OUTPUT"

# Endpoint di Znuny
ZNUNY_API_URL="https://support.company.it/nph-genericinterface.pl/Webservice/Ticket%20REST%20API/Ticket"

# Credenziali API
API_USER="cmk"
API_PASS="9*********1"

# Creazione JSON per il ticket
JSON_PAYLOAD=$(cat <<EOF
{
    "UserLogin": "$API_USER",
    "Password": "$API_PASS",
    "Ticket": {
        "Title": "Allarme da Checkmk: $SERVICE su $HOSTNAME",
        "Queue": "[TS] Technical Support",
        "State": "new",
        "Priority": "3 normal",
        "CustomerUser": "$API_USER",
        "Type": "Monitoring Alert"
    },
    "Article": {
        "Subject": "Allarme: $SERVICE ($STATE)",
        "Body": "$OUTPUT",
        "ContentType": "",
        "CommunicationChannel": "Email",
        "Charset": "utf-8",
        "MimeType":"text/plain"
    }
}
EOF
)

# Debug: Verifica il corpo JSON
echo "JSON_PAYLOAD: $JSON_PAYLOAD"

# Invio richiesta HTTP POST
curl -u "$API_USER:$API_PASS" \
     -H "Content-Type: application/json" \
     -X POST \
     -d "$JSON_PAYLOAD" \
     "$ZNUNY_API_URL"

if I run it with
OMD[monitoring]:~/local/share/check_mk/notifications$ .notify_znuny.sh ‘icslvpl-expm-mn-01’ ‘Disk’ ‘CRITICAL’ ‘No IP packet received for 15.737259 s (deadline is 15.000000 s)’
it works, if instead I send the notification from checkmk, it goes to errorer, as it doesn’t populate the body and title.

notification logs:

2025-01-27 15:02:38,078 [20] [cmk.base.notify] ----------------------------------------------------------------------
2025-01-27 15:02:38,079 [20] [cmk.base.notify] Got raw notification (icslvtl-expm-sv-01) context with 44 variables
2025-01-27 15:02:38,079 [20] [cmk.base.notify] Global rule 'Znuny'...
2025-01-27 15:02:38,079 [20] [cmk.base.notify]  -> matches!
2025-01-27 15:02:38,079 [20] [cmk.base.notify]    - adding notification of automation, iali, andrea, cmkadmin via notify_znuny_1.sh
2025-01-27 15:02:38,080 [15] [cmk.base.notify] Global rule 'Notify all contacts of a host/service via HTML email'...
2025-01-27 15:02:38,080 [15] [cmk.base.notify]  -> does not match: This rule is disabled
2025-01-27 15:02:38,080 [20] [cmk.base.notify] Executing 1 notifications:
2025-01-27 15:02:38,080 [20] [cmk.base.notify]   * notifying automation, iali, andrea, cmkadmin via notify_znuny_1.sh, parameters: (no parameters), bulk: no
2025-01-27 15:02:38,080 [20] [cmk.base.notify] Creating spoolfile: /omd/sites/monitoring/var/check_mk/notify/spool/dfba7a9a-b671-43a9-b585-db75d9371029
2025-01-27 15:02:38,081 [20] [cmk.base.notify] Creating spoolfile: /omd/sites/monitoring/var/check_mk/notify/spool/bc28a330-c364-43d0-889e-becef59b854f
2025-01-27 15:02:38,082 [20] [cmk.base.notify] Creating spoolfile: /omd/sites/monitoring/var/check_mk/notify/spool/8d6224c6-cbeb-4406-9508-72a7150f519f
2025-01-27 15:02:38,083 [20] [cmk.base.notify] Creating spoolfile: /omd/sites/monitoring/var/check_mk/notify/spool/9eb0d3de-19fd-4477-9a81-9c0307ef4ea3
2025-01-27 15:02:41,759 [20] [cmk.base.notify] ----------------------------------------------------------------------
2025-01-27 15:02:41,760 [20] [cmk.base.notify] Got spool file dfba7a9a (icslvtl-expm-sv-01) for local delivery via notify_znuny_1.sh
2025-01-27 15:02:41,760 [20] [cmk.utils.notify] sending command LOG;HOST NOTIFICATION: automation;icslvtl-expm-sv-01;DOWN;notify_znuny_1.sh;No IP packet received for 15.737259 s (deadline is 15.000000 s)
2025-01-27 15:02:41,760 [20] [cmk.base.notify]      executing /omd/sites/monitoring/local/share/check_mk/notifications/notify_znuny_1.sh
2025-01-27 15:02:41,764 [20] [cmk.base.notify]      Output: HOSTNAME:
2025-01-27 15:02:41,764 [20] [cmk.base.notify]      Output: SERVICE:
2025-01-27 15:02:41,764 [20] [cmk.base.notify]      Output: STATE:
2025-01-27 15:02:41,764 [20] [cmk.base.notify]      Output: OUTPUT:
2025-01-27 15:02:41,769 [20] [cmk.base.notify]      Output: JSON_PAYLOAD: {
2025-01-27 15:02:41,769 [20] [cmk.base.notify]      Output:     "UserLogin": "cmk",
2025-01-27 15:02:41,769 [20] [cmk.base.notify]      Output:     "Password": "9********1",
2025-01-27 15:02:41,769 [20] [cmk.base.notify]      Output:     "Ticket": {
2025-01-27 15:02:41,769 [20] [cmk.base.notify]      Output:         "Title": "Allarme da Checkmk:  su ",
2025-01-27 15:02:41,769 [20] [cmk.base.notify]      Output:         "Queue": "[TS] Technical Support",
2025-01-27 15:02:41,769 [20] [cmk.base.notify]      Output:         "State": "new",
2025-01-27 15:02:41,769 [20] [cmk.base.notify]      Output:         "Priority": "3 normal",
2025-01-27 15:02:41,769 [20] [cmk.base.notify]      Output:         "CustomerUser": "iali",
2025-01-27 15:02:41,769 [20] [cmk.base.notify]      Output:         "Type": "Monitoring Alert"
2025-01-27 15:02:41,769 [20] [cmk.base.notify]      Output:     },
2025-01-27 15:02:41,769 [20] [cmk.base.notify]      Output:     "Article": {
2025-01-27 15:02:41,769 [20] [cmk.base.notify]      Output:         "Subject": "Allarme:  ()",
2025-01-27 15:02:41,769 [20] [cmk.base.notify]      Output:         "Body": "",
2025-01-27 15:02:41,769 [20] [cmk.base.notify]      Output:         "ContentType": "",
2025-01-27 15:02:41,769 [20] [cmk.base.notify]      Output:         "CommunicationChannel": "Email",
2025-01-27 15:02:41,769 [20] [cmk.base.notify]      Output:         "Charset": "utf-8",
2025-01-27 15:02:41,769 [20] [cmk.base.notify]      Output:         "MimeType":"text/plain"
2025-01-27 15:02:41,769 [20] [cmk.base.notify]      Output:     }
2025-01-27 15:02:41,770 [20] [cmk.base.notify]      Output: }
2025-01-27 15:02:41,780 [20] [cmk.base.notify]      Output:   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
2025-01-27 15:02:41,780 [20] [cmk.base.notify]      Output:                                  Dload  Upload   Total   Spent    Left  Speed
2025-01-27 15:02:41,780 [20] [cmk.base.notify]      Output:
2025-01-27 15:02:42,081 [20] [cmk.base.notify]      Output:   0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
2025-01-27 15:02:42,081 [20] [cmk.base.notify]      Output: 100   514  100    11  100   503     36   1676 --:--:-- --:--:-- --:--:--  1707
2025-01-27 15:02:42,081 [20] [cmk.base.notify]      Output: 100   514  100    11  100   503     36   1676 --:--:-- --:--:-- --:--:--  1707

how can i do this?

Thanks

A notification plugin gets the notification details via environment variables, not via command line arguments.

See the docs for details.

I saw the notifications page Notifications - via Email, SMS, ticket system and more but I can’t find the part about variables, also doing printenv with user OMD I don’t see variables for different hosts, could you provide some more details?
thanks

Have you read section 11?

1 Like

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.