Skip to content

Instantly share code, notes, and snippets.

@senk
Forked from meilon/otrs2mattermost.sh
Last active August 18, 2021 20:13
Show Gist options
  • Save senk/89e842b8528737a343acec346bdd106d to your computer and use it in GitHub Desktop.
Save senk/89e842b8528737a343acec346bdd106d to your computer and use it in GitHub Desktop.
Post OTRS Ticket notifications to Mattermost
#!/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"
@martini
Copy link

martini commented Jan 26, 2018

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:
screen shot 2018-01-26 at 08 32 59

User Unterface where your see ticket changes in Slack/Mattermost:

en_s21_agent_slack_integration

We use it by our self with Mattermost and it's phantasmic.

Sorry for disruption.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment