Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Datadog transposer, but with modifications: #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
"name": "conviva",
"cases": ["open"]
},
{
"name": "datadog",
"cases": ["open-high", "open-low", "tag-list", "tag-none", "level-unknown"]
},
{
"name": "fastly",
"cases": ["open"]
Expand Down
23 changes: 23 additions & 0 deletions src/cases/datadog/level-unknown.expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"summary": "[P2] [Triggered] [TEST] Test Monitor",
"body": "This is the content of the monitor.",
"level": 0,
"links": [
{
"href": "https://datadoghq.com/event/event?id=238472398472582",
"text": "Datadog Monitor"
}
],
"images": [
{
"src": "https://example.com/pic.png",
"alt": "Snapshot from [P2] [Triggered] [TEST] Signals Test Monitor"
}
],
"tags": [],
"idempotency_key": "18913k2b63ifs",
"status": 1,
"annotations": {
"signals.firehydrant.com/notification-priority": "HIGH"
}
}
25 changes: 25 additions & 0 deletions src/cases/datadog/level-unknown.input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"unique_key": "18913k2b63ifs",
"level": "what???",
"summary": "[P2] [Triggered] [TEST] Test Monitor",
"body": "This is the content of the monitor.",
"annotations": {},
"images": [
{
"src": "null",
"alt": "This should not come through"
},
{
"src": "https://example.com/pic.png",
"alt": "Snapshot from [P2] [Triggered] [TEST] Signals Test Monitor"
}
],
"links": [
{
"href": "https://datadoghq.com/event/event?id=238472398472582",
"text": "Datadog Monitor"
}
],
"status": "Recovered",
"received_at": "2023-11-08T21:56:54.000+00:00"
}
24 changes: 24 additions & 0 deletions src/cases/datadog/open-high.expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"summary": "[P2] [Triggered] [TEST] Test Monitor",
"body": "This is the content of the monitor.",
"level": 1,
"links": [
{
"href": "https://datadoghq.com/event/event?id=238472398472582",
"text": "Datadog Monitor"
}
],
"images": [
{
"src": "https://example.com/pic.png",
"alt": "Snapshot from [P2] [Triggered] [TEST] Signals Test Monitor"
}
],
"tags": ["monitor", "name:myService", "role:computing-node", "region:us-west2"],
"idempotency_key": "18913k2b63ifs",
"status": 0,
"annotations": {
"datadog/priority": "P2",
"signals.firehydrant.com/notification-priority": "HIGH"
}
}
28 changes: 28 additions & 0 deletions src/cases/datadog/open-high.input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"unique_key": "18913k2b63ifs",
"level": "warning",
"summary": "[P2] [Triggered] [TEST] Test Monitor",
"body": "This is the content of the monitor.",
"annotations": {
"datadog/priority": "P2"
},
"images": [
{
"src": "null",
"alt": "This should not come through"
},
{
"src": "https://example.com/pic.png",
"alt": "Snapshot from [P2] [Triggered] [TEST] Signals Test Monitor"
}
],
"links": [
{
"href": "https://datadoghq.com/event/event?id=238472398472582",
"text": "Datadog Monitor"
}
],
"tags": "monitor, name:myService, role:computing-node, region:us-west2",
"status": "Triggered",
"received_at": "2023-11-08T21:56:54.000+00:00"
}
24 changes: 24 additions & 0 deletions src/cases/datadog/open-low.expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"summary": "[P4] [Triggered] [TEST] Test Monitor",
"body": "This is the content of the monitor.",
"level": 1,
"links": [
{
"href": "https://datadoghq.com/event/event?id=238472398472582",
"text": "Datadog Monitor"
}
],
"images": [
{
"src": "https://example.com/pic.png",
"alt": "Snapshot from [P4] [Triggered] [TEST] Signals Test Monitor"
}
],
"tags": ["monitor", "name:myService", "role:computing-node", "region:us-west2"],
"idempotency_key": "18913k2b63ifs",
"status": 0,
"annotations": {
"datadog/priority": "P4",
"signals.firehydrant.com/notification-priority": "LOW"
}
}
28 changes: 28 additions & 0 deletions src/cases/datadog/open-low.input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"unique_key": "18913k2b63ifs",
"level": "warning",
"summary": "[P4] [Triggered] [TEST] Test Monitor",
"body": "This is the content of the monitor.",
"annotations": {
"datadog/priority": "P4"
},
"images": [
{
"src": "null",
"alt": "This should not come through"
},
{
"src": "https://example.com/pic.png",
"alt": "Snapshot from [P4] [Triggered] [TEST] Signals Test Monitor"
}
],
"links": [
{
"href": "https://datadoghq.com/event/event?id=238472398472582",
"text": "Datadog Monitor"
}
],
"tags": "monitor, name:myService, role:computing-node, region:us-west2",
"status": "Triggered",
"received_at": "2023-11-08T21:56:54.000+00:00"
}
23 changes: 23 additions & 0 deletions src/cases/datadog/tag-list.expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"summary": "[P2] [Triggered] [TEST] Test Monitor",
"body": "This is the content of the monitor.",
"level": 1,
"links": [
{
"href": "https://datadoghq.com/event/event?id=238472398472582",
"text": "Datadog Monitor"
}
],
"images": [
{
"src": "https://example.com/pic.png",
"alt": "Snapshot from [P2] [Triggered] [TEST] Signals Test Monitor"
}
],
"tags": ["monitor", "name:myService", "role:computing-node", "region:us-west2"],
"idempotency_key": "18913k2b63ifs",
"status": 1,
"annotations": {
"signals.firehydrant.com/notification-priority": "HIGH"
}
}
26 changes: 26 additions & 0 deletions src/cases/datadog/tag-list.input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"unique_key": "18913k2b63ifs",
"level": "warning",
"summary": "[P2] [Triggered] [TEST] Test Monitor",
"body": "This is the content of the monitor.",
"annotations": {},
"images": [
{
"src": "null",
"alt": "This should not come through"
},
{
"src": "https://example.com/pic.png",
"alt": "Snapshot from [P2] [Triggered] [TEST] Signals Test Monitor"
}
],
"links": [
{
"href": "https://datadoghq.com/event/event?id=238472398472582",
"text": "Datadog Monitor"
}
],
"tags": ["monitor", "name:myService", "role:computing-node", "region:us-west2"],
"status": "Recovered",
"received_at": "2023-11-08T21:56:54.000+00:00"
}
23 changes: 23 additions & 0 deletions src/cases/datadog/tag-none.expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"summary": "[P2] [Triggered] [TEST] Test Monitor",
"body": "This is the content of the monitor.",
"level": 1,
"links": [
{
"href": "https://datadoghq.com/event/event?id=238472398472582",
"text": "Datadog Monitor"
}
],
"images": [
{
"src": "https://example.com/pic.png",
"alt": "Snapshot from [P2] [Triggered] [TEST] Signals Test Monitor"
}
],
"tags": [],
"idempotency_key": "18913k2b63ifs",
"status": 1,
"annotations": {
"signals.firehydrant.com/notification-priority": "HIGH"
}
}
25 changes: 25 additions & 0 deletions src/cases/datadog/tag-none.input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"unique_key": "18913k2b63ifs",
"level": "warning",
"summary": "[P2] [Triggered] [TEST] Test Monitor",
"body": "This is the content of the monitor.",
"annotations": {},
"images": [
{
"src": "null",
"alt": "This should not come through"
},
{
"src": "https://example.com/pic.png",
"alt": "Snapshot from [P2] [Triggered] [TEST] Signals Test Monitor"
}
],
"links": [
{
"href": "https://datadoghq.com/event/event?id=238472398472582",
"text": "Datadog Monitor"
}
],
"status": "Recovered",
"received_at": "2023-11-08T21:56:54.000+00:00"
}
78 changes: 78 additions & 0 deletions src/datadog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
////////////////////
// COPY FROM HERE //
/**
* Translates from Datadog level to FH level.
* See: https://docs.firehydrant.com/docs/events-data-model
*/
function getLevel(level) {
if (level) {
switch (level) {
case 'error':
return 2;
case 'warning':
return 1;
default:
return 0;
}
}

return 0; // INFO
}

/**
* Translates from Datadog priority (P*) to FH level.
* This assumes default behavior but can be modified.
*/
function getPriority(priority) {
if (priority) {
switch (priority) {
case 'P1':
case 'P2':
return 'HIGH';
default:
return 'LOW';
}
}

return 'HIGH'; // Defaults to high priority
}

/*
* Transpose a payload into a Signal
*/
function transpose(input) {
const payload = input.data;
let tags = [];

// Apparently Tags can be comma-delimited string OR an
// array of strings... why wtf
if (payload?.tags) {
if (typeof payload.tags === 'string') {
tags = payload.tags.split(',').map(tag => tag.trim())
} else if (typeof payload.tags === 'object' && payload.tags.constructor === Array) {
tags = payload.tags;
}
}

let signal = {
idempotency_key: payload?.unique_key ? payload.unique_key : (payload?.summary ? payload.summary : ''),
summary: payload?.summary ? payload.summary : 'Alert from Datadog',
body: payload?.body ? payload.body : 'No information provided',
level: getLevel(payload?.level),
links: payload?.links ? payload.links : [],
images: payload?.images.filter((link) => link.src !== 'null'),
tags: tags,
status: payload?.status && payload.status === 'Recovered' ? 1 : 0,
annotations: {
'signals.firehydrant.com/notification-priority': getPriority(payload?.annotations?.['datadog/priority']),
...(payload?.annotations || {})
}
};

return signal;
}
// COPY TO HERE //
//////////////////
module.exports = {
transpose
}