Skip to content

Commit

Permalink
Merge pull request #1 from drautureau-sonarsource/eu-instance
Browse files Browse the repository at this point in the history
Give the ability to use EU instance
  • Loading branch information
dddaaammmooo authored Feb 25, 2022
2 parents f624cd3 + a414b8f commit cc6c2df
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ This Github action can be used to generate alert to OpsGenie by generating a CUR
* API_KEY

The OpsGenie API key (this will need to be pre-configured via the OpsGenie website)

#### Optional Parameters

* USE_EU_INSTANCE

Use the EU instance of OpsGenie

#### Example Usage

Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ inputs:
api_key:
description: 'OpsGenie API Key'
required: true
use_eu_instance:
description: 'Use EU instance'
required: false

runs:
using: 'docker'
Expand All @@ -28,3 +31,4 @@ runs:
- ${{ inputs.message }}
- ${{ inputs.priority }}
- ${{ inputs.api_key }}
- ${{ inputs.use_eu_instance }}
12 changes: 9 additions & 3 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ ALIAS=${1}
MESSAGE=${2}
PRIORITY=${3}
OPSGENIE_API_KEY=${4}
USE_EU_INSTANCE=${5:-}

# Make sure a message was defined
if [[ -z "${MESSAGE}" ]]; then
Expand All @@ -28,13 +29,18 @@ echo "Alias: ${ALIAS}"
echo "Message: ${MESSAGE}"
echo "Priority: ${PRIORITY}"

HOST="api.opsgenie.com"
if [[ -n "${USE_EU_INSTANCE}" ]]; then
HOST="api.eu.opsgenie.com"
fi

# Send alert via curl request to OpsGenie API
STATUS_CODE=$(curl -s \
-o /dev/null \
-w '%{http_code}' \
-X POST https://api.opsgenie.com/v2/alerts \
-H "Host: api.opsgenie.com" \
-H "Authorization: Basic ${OPSGENIE_API_KEY}" \
-X POST "https://${HOST}/v2/alerts" \
-H "Host: ${HOST}" \
-H "Authorization: GenieKey ${OPSGENIE_API_KEY}" \
-H "User-Agent: EonxGitops/1.0.0" \
-H "cache-control: no-cache" \
-H "Content-Type: application/json" \
Expand Down

0 comments on commit cc6c2df

Please sign in to comment.