-
Notifications
You must be signed in to change notification settings - Fork 8
76 lines (73 loc) · 3.02 KB
/
dd-event-post.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
name: (R) Datadog Event Post
on:
workflow_call:
inputs:
title:
description: "Datadog Event title"
required: false
type: string
default: "A Pull Request has been merged. ${{ github.repository }} #${{ github.event.pull_request.number }}"
text:
description: "Datadog Event text"
required: false
type: string
default: "A pull request was merged from ${{ github.head_ref }} to ${{ github.base_ref }}@${{ github.repository }} #${{ github.event.pull_request.number }} ${{ github.event.pull_request.html_url }}"
event:
description: "Datadog Event type"
required: false
type: string
default: "pr-merged"
additional-tags:
description: "Datadog Event additional tags. space separeted tag. example: 'tag1:value1 tag2:value2'"
required: false
type: string
default: "pr_number:${{ github.event.pull_request.number }} event:pr-merged"
alert-type:
description: "Datadog Event alert type, you can use error,warning,info,success,user_update,recommendation,snapshot"
required: false
type: string
default: "info"
jobs:
post:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Load secret
id: op-load-secret
uses: 1password/load-secrets-action@v2
with:
export-env: false
env:
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN_PUBLIC }}
DD_API_KEY: "op://GitHubActionsPublic/DATADOG/credential"
- name: Post to Datadog Event
run: |
echo "::group::Create JSON"
aggregation_key="${_REPOSITORY}/${_BRANCH}/${_EVENT}"
json_tag_array=$(echo -n "repository:$_REPOSITORY branch:$_BRANCH $_ADDITIONAL_TAGS" | jq -R -s 'split(" ")')
json=$(jq -cn --arg title "${_TITLE}" --arg text "${_TEXT}" --arg alert_type "${_ALERT_TYPE}" --arg source_type_name "${_SOURCE_TYPE_NAME}" --arg aggregation_key "${aggregation_key}" --argjson tags "$json_tag_array" '{
"title": $title,
"text": $text,
"alert_type": $alert_type,
"source_type_name": $source_type_name,
"aggregation_key": $aggregation_key,
"tags": $tags
}')
echo "$json"
echo "::endgroup::"
echo "::group::post to datadog"
curl -sSf -X POST "https://api.datadoghq.com/api/v1/events" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "DD-API-KEY: ${{ steps.op-load-secret.outputs.DD_API_KEY }}" \
-d "${json}"
echo "::endgroup::"
env:
_TITLE: ${{ inputs.title }}
_TEXT: ${{ inputs.text }}
_REPOSITORY: ${{ github.repository }}
_BRANCH: ${{ github.base_ref }}
_EVENT: ${{ inputs.event }}
_ADDITIONAL_TAGS: ${{ inputs.additional-tags }}
_ALERT_TYPE: ${{ inputs.alert-type }}
_SOURCE_TYPE_NAME: git