-
-
Save senk/89e842b8528737a343acec346bdd106d to your computer and use it in GitHub Desktop.
Post OTRS Ticket notifications to Mattermost
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This is a script to send a notification from OTRS to Mattermost. | |
# Create a new Generic Agent and select "TicketCreate" under event based events. | |
# Finally, put in the path to the script into the command box. | |
# Of course you could use it for different notifications, but OTRS is only giving the ticket number and id to the script. | |
WEBHOOK_URL="<HOOKURL>" | |
BOT_NAME="OTRSbot" | |
ICON_URL="<ICONURL>" | |
DB_HOST="localhost" | |
DB_NAME="otrs" | |
DB_USER="otrs" | |
DB_PASS="<DBPASS>" | |
TICKET_NUMBER=$1 | |
TICKET_ID=$2 | |
## unless I figure out how to split a single mysql result into multiple variables, | |
## just use two single queries... | |
title=`mysql -h$DB_HOST -u$DB_USER -p$DB_PASS -se "SET NAMES utf8; SELECT title FROM ticket WHERE id = '$TICKET_ID'" $DB_NAME` | |
customerId=`mysql -h$DB_HOST -u$DB_USER -p$DB_PASS -se "SET NAMES utf8; SELECT customer_id FROM ticket WHERE id = '$TICKET_ID'" $DB_NAME` | |
link="https://otrs/index.pl?Action=AgentTicketZoom;TicketID=$TICKET_ID" | |
# not sure if title can be empty, but it's nice to check anyway. | |
# use the link instead | |
if [ -z "$title" ] | |
then | |
title=$link | |
fi | |
header="Content-Type: application/json; charset=utf-8" | |
request_body=$(< <(cat <<EOF | |
{ | |
"username": "$BOT_NAME", | |
"text": "**New Ticket** #$TICKET_NUMBER by $customerId: [$title]($link)", | |
"icon_url": "$ICON_URL" | |
} | |
EOF | |
)) | |
curl -i -X POST -H "$header" -d "$request_body" "$WEBHOOK_URL" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @senk,
I know it's a little bit off topic. But I can't stop writing. There is an OTRS alternativ (and excuse I'm one of the core member) which has an Slack/Mattermost integration out of the box (without external db access and with a nice admin interface).
Admin Interace:
User Unterface where your see ticket changes in Slack/Mattermost:
We use it by our self with Mattermost and it's phantasmic.
Sorry for disruption.