Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
AMPLIFY Central Agent Status Notifier IB Flow
{
"id": 64705,
"name": "AMPLIFY Central Agent Status Notifier",
"debugLoggingExpires": "2021-11-05T08:16:59Z",
"userId": 21107,
"accountId": 18281,
"createdDate": "2021-10-21T18:09:19Z",
"steps": [{
"id": 578768,
"onSuccess": ["sendToTeams"],
"onFailure": [],
"name": "prepareSendToTeams",
"type": "script",
"properties": {
"body": "const url = config.msTeamsWebhookURL;\n\nlet apicentralUrl = config.apiCentralUrl ? config.apiCentralUrl : 'https://apicentral.axway.com';\n\nlet envURL = apicentralUrl+'/topology/environments/'+trigger.args.payload.metadata.scope.name;\n\nlet agentPrefix;\n\ntrigger.args.payload.kind === \"TraceabilityAgent\" ? agentPrefix = \"Traceability\" : agentPrefix = \"Discovery\"\n\nconst message = agentPrefix+\" agent **\"+trigger.args.payload.name+\"** from Environment **\"+trigger.args.payload.metadata.scope.name+\"** has changed it's status to **\"+trigger.args.payload.status.state+\"**\";\n\nvar suffix;\nswitch (trigger.args.payload.status.state) {\n case 'stopped':\n suffix = 'WARNING';\n break;\n case 'unhealthy':\n suffix = 'WARNING';\n break;\n case 'failed':\n suffix = 'ERROR';\n break;\n default:\n suffix = 'UPDATE';\n}\n\nlet body = {\n \"@type\": \"MessageCard\",\n \"@context\": \"http://schema.org/extensions\",\n \"themeColor\": \"0076D7\",\n \"summary\": \"Amplify Central Agent \"+suffix,\n \"sections\": [{\n \"activityTitle\": \"[**Amplify Central Agent**](https://docs.axway.com/bundle/amplify-central/page/docs/connect_manage_environ/index.html) \"+suffix,\n // \"activitySubtitle\": \"Agent Notification\",\n \"facts\": [{\n \"name\": \"Agent Name:\",\n \"value\": trigger.args.payload.name\n },\n {\n \"name\": \"Agent Type:\",\n \"value\": agentPrefix\n },\n {\n \"name\": \"Environment:\",\n \"value\": '[**'+trigger.args.payload.metadata.scope.name+'**]('+envURL+')'\n }],\n \"text\": message,\n \"markdown\": true\n }]\n};\n\ndone({body, url});"
}
}, {
"id": 578769,
"onSuccess": [],
"onFailure": [],
"name": "sendToTeams",
"type": "httpRequest",
"properties": {
"url": "${steps.prepareSendToTeams.url}",
"method": "POST",
"body": "${steps.prepareSendToTeams.body}"
}
}, {
"id": 578767,
"onSuccess": ["prepareSendToTeams"],
"onFailure": [],
"name": "shouldProcess",
"type": "filter",
"properties": {
"body": "const subresourceIsStatus = trigger.args.metadata.subresource === \"status\";\n\n//console.log(subresourceIsStatus);\n\nconst typeIsSubResourceUpdated = trigger.args.type === \"SubResourceUpdated\";\n\n//console.log(typeIsSubResourceUpdated);\n\n// The isAgent check is superfluous and included in case the Integration Resource hook is not configured properly\n\nconst isAgent = trigger.args.payload.kind === \"TraceabilityAgent\" || trigger.args.payload.kind === \"DiscoveryAgent\";\n\n//console.log(isAgent);\n\nconst previousStateExists = trigger.args.payload.status.hasOwnProperty('previousState');\n\nconsole.log('previousStateExists:');\nconsole.log(previousStateExists);\n\nvar isStateChanged = true;\nif(previousStateExists) {\n isStateChanged = trigger.args.payload.status.state != trigger.args.payload.status.previousState; \n}\n\nconsole.log('isStateChanged:');\nconsole.log(isStateChanged);\n\ndone(subresourceIsStatus && typeIsSubResourceUpdated && isAgent && isStateChanged);"
}
}],
"triggers": [{
"id": 52921,
"onSuccess": ["shouldProcess"],
"onFailure": [],
"type": "manual",
"async": true,
"active": true,
"name": "trigger",
"properties": {}
}],
"engine": "v3",
"active": true,
"debugLoggingEnabled": true,
"singleThreaded": false,
"configuration": [{
"id": 101718,
"key": "apiCentralUrl",
"name": "apiCentralUrl",
"type": "value",
"description": "Amplify Central URL base address. Default to https://apicentral.axway.com/",
"required": false
}, {
"id": 101716,
"key": "msTeamsWebhookURL",
"name": "msTeamsWebhookURL",
"type": "value",
"required": true
}]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment