78 lines
3.5 KiB
JSON
78 lines
3.5 KiB
JSON
{
|
|
"name": "Cleanup Stale BYOD Items",
|
|
"description": "SCHEDULED (nightly 2am): Unassigns Customer Provided Router items that have no active IP assignment. Keeps items with active IPs intact.",
|
|
"trigger": {
|
|
"type": "SCHEDULE",
|
|
"cron": "0 2 * * *",
|
|
"nextSteps": [{ "slug": "find-stale-byod" }]
|
|
},
|
|
"steps": [
|
|
{
|
|
"name": "Find stale BYOD items",
|
|
"slug": "find-stale-byod",
|
|
"type": "GAIIA_API_GATEWAY_V1_GRAPHQL_REQUEST",
|
|
"nodeSlug": "gaiia-public-api-gateway-graphql-request",
|
|
"allowSkipExecution": false,
|
|
"outputMapper": "({ output }) => {\n const items = output.response.inventoryItems.nodes;\n const stale = [];\n for (const item of items) {\n const assigns = item.ipAddressAssignments?.nodes || [];\n const hasActive = assigns.some((a) => a.isActive !== false);\n if (!hasActive) {\n const assignee = item.assignation?.assignee || {};\n if (assignee.__typename === 'Account' && assignee.id) {\n stale.push({ inventoryId: item.id, accountId: assignee.id, accountName: assignee.name || '' });\n }\n }\n }\n return stale;\n}",
|
|
"inputs": [
|
|
{
|
|
"key": "query",
|
|
"type": "LITERAL",
|
|
"value": "string:query {\n inventoryItems(\n first: 250\n filters: { modelId: { equals: \"inventory_model_522SxVU9VvPaMXYqWNbfbx\" }, assigneeType: { equals: ACCOUNT } }\n ) {\n nodes {\n id\n ipAddressAssignments {\n nodes { ipAddress macAddress isActive }\n }\n assignation {\n assignee { __typename ... on Account { id name } }\n }\n }\n totalCount\n }\n}"
|
|
},
|
|
{
|
|
"key": "variables",
|
|
"type": "FUNCTION",
|
|
"value": "({ secrets, state, utils, variables }) => ({})"
|
|
}
|
|
],
|
|
"nextSteps": [{ "slug": "if-any-stale" }]
|
|
},
|
|
{
|
|
"name": "Any stale items?",
|
|
"slug": "if-any-stale",
|
|
"type": "CONDITION",
|
|
"nodeSlug": "condition",
|
|
"condition": "({ secrets, state, utils, variables }) => {\n const items = state.steps['find-stale-byod'].output;\n return Array.isArray(items) && items.length > 0;\n}",
|
|
"elseSteps": [{ "slug": "end" }],
|
|
"thenSteps": [{ "slug": "unassign-stale" }]
|
|
},
|
|
{
|
|
"name": "Unassign each stale item",
|
|
"slug": "unassign-stale",
|
|
"type": "PARALLEL_LOOP",
|
|
"nodeSlug": "parallel-loop",
|
|
"maxConcurrentIterations": 10,
|
|
"inputs": [
|
|
{
|
|
"key": "iterable",
|
|
"type": "FUNCTION",
|
|
"value": "({ state }) => state.steps['find-stale-byod'].output"
|
|
}
|
|
],
|
|
"initialSteps": [{ "slug": "unassign-one" }],
|
|
"nextSteps": [{ "slug": "end" }]
|
|
},
|
|
{
|
|
"name": "Unassign from account",
|
|
"slug": "unassign-one",
|
|
"type": "GAIIA_API_GATEWAY_V1_GRAPHQL_REQUEST",
|
|
"nodeSlug": "gaiia-public-api-gateway-graphql-request",
|
|
"parentParallelLoopSlug": "unassign-stale",
|
|
"allowSkipExecution": false,
|
|
"inputs": [
|
|
{
|
|
"key": "query",
|
|
"type": "LITERAL",
|
|
"value": "string:mutation UnassignItem($input: UnassignCustomerOwnedItemInput!) {\n unassignCustomerOwnedItem(input: $input) {\n customerOwnedItem { id }\n }\n}"
|
|
},
|
|
{
|
|
"key": "variables",
|
|
"type": "FUNCTION",
|
|
"value": "({ state }) => {\n const item = state.currentParallelLoopIterations['unassign-stale'];\n return { input: { id: item.inventoryId } };\n}"
|
|
}
|
|
],
|
|
"nextSteps": [{ "slug": "unassign-stale-end" }]
|
|
}
|
|
]
|
|
}
|