Skip to content

Instantly share code, notes, and snippets.

@tyzbit
Created August 17, 2023 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tyzbit/1472561d52750425a9d36fa886becebe to your computer and use it in GitHub Desktop.
Save tyzbit/1472561d52750425a9d36fa886becebe to your computer and use it in GitHub Desktop.
n8n Plex to NewRelic workflow
{
"meta": {
"instanceId": "aa9435bb3ce60270561861142bd6fad2007ec1f2f21b7e4ae8cd074b32d19840"
},
"nodes": [
{
"parameters": {},
"name": "Start",
"type": "n8n-nodes-base.start",
"typeVersion": 1,
"position": [
240,
160
],
"id": "ef86fc22-8857-4a84-928e-03ec6ee21355"
},
{
"parameters": {
"webhookUri": "YOUR DISCORD WEBHOOK HERE",
"text": "={{$node[\"Function\"].json[\"message\"]}}",
"options": {}
},
"name": "Discord",
"type": "n8n-nodes-base.discord",
"typeVersion": 1,
"position": [
860,
140
],
"id": "cb046155-67cc-47c1-a4ee-fc275b6a1c57"
},
{
"parameters": {
"functionCode": "const flattenJSON = (obj = {}, res = {}, extraKey = '') => {\n for(key in obj){\n if(typeof obj[key] !== 'object'){\n res[extraKey + key] = obj[key];\n }else{\n flattenJSON(obj[key], res, `${extraKey}${key}.`);\n };\n };\n return res;\n};\n\nvar parsedPayload = JSON.parse(items[0].json.body.payload);\nvar user = parsedPayload.Account.title;\nvar event = parsedPayload.event.replace('media.','') + 'ed';\nvar server = parsedPayload.Server.title;\nvar type = parsedPayload.Metadata.type;\nvar title = parsedPayload.Metadata.title;\nvar grandparenttitle = parsedPayload.Metadata.grandparentTitle;\n\nif (grandparenttitle) {\n content = grandparenttitle + ' ' + type + ' ' + title\n} else {\n content = type + ' ' + title\n}\n\nitems[0].json.message = user + ' ' + event + ' the ' + content + ' on ' + server;\nitems[0].json.library = parsedPayload.Metadata.librarySectionTitle;\nparsedPayload.eventType = 'PlexEvent';\nitems[0].json.parsedPayload = flattenJSON(parsedPayload);\n\nreturn items;"
},
"name": "Function",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
440,
160
],
"id": "dc34037f-2706-40db-a0e0-0610c0296ebc"
},
{
"parameters": {
"authentication": "headerAuth",
"requestMethod": "POST",
"url": "https://insights-collector.newrelic.com/v1/accounts/YOUR ACCOUNT ID HERE/events",
"jsonParameters": true,
"options": {},
"bodyParametersJson": "={{$json[\"parsedPayload\"]}}"
},
"name": "HTTP Request",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 1,
"position": [
860,
-20
],
"id": "2691bf80-5b73-44b6-9089-46fa72f3b662",
"credentials": {
"httpHeaderAuth": {
"id": "5",
"name": "NewRelic Insert"
}
}
},
{
"parameters": {
"httpMethod": "POST",
"path": "364b110a-389b-43a9-a061-4c43bebf12a4",
"options": {}
},
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 1,
"position": [
240,
10
],
"webhookId": "364b110a-389b-43a9-a061-4c43bebf12a4",
"id": "ed964169-5dc8-412c-b67a-693b5d8a1747"
},
{
"parameters": {
"conditions": {
"string": [
{
"value1": "={{$json[\"message\"]}}",
"operation": "contains",
"value2": "played"
}
]
}
},
"name": "IF1",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
700,
160
],
"id": "bcf7b738-2e1e-4902-933d-7e3efecd6b6e"
},
{
"parameters": {},
"name": "NoOp1",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
860,
320
],
"id": "a6a3d88c-90bc-4d36-b44b-f6a9beaf2465"
}
],
"connections": {
"Start": {
"main": [
[
{
"node": "Function",
"type": "main",
"index": 0
}
]
]
},
"Function": {
"main": [
[
{
"node": "IF1",
"type": "main",
"index": 0
},
{
"node": "HTTP Request",
"type": "main",
"index": 0
}
]
]
},
"Webhook": {
"main": [
[
{
"node": "Function",
"type": "main",
"index": 0
}
]
]
},
"IF1": {
"main": [
[
{
"node": "Discord",
"type": "main",
"index": 0
}
],
[
{
"node": "NoOp1",
"type": "main",
"index": 0
}
]
]
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment