From 5639077ad6954f56d5e15d763d49f049e682492f Mon Sep 17 00:00:00 2001 From: Gaston Yelmini Date: Wed, 3 Jul 2024 15:14:00 -0300 Subject: [PATCH 1/2] INT-11156: add logger to application relationships step --- src/configuration-manager/client.ts | 5 +++++ src/steps/applications/index.ts | 30 +++++++++++++++-------------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/configuration-manager/client.ts b/src/configuration-manager/client.ts index 8bcad1f..5d95cf7 100644 --- a/src/configuration-manager/client.ts +++ b/src/configuration-manager/client.ts @@ -9,6 +9,7 @@ import { buildLocalUserList, } from './queries'; import pMap from 'p-map'; +import { IntegrationLogger } from '@jupiterone/integration-sdk-core'; type ResourceIteratee = (each: T) => Promise | void; @@ -96,6 +97,7 @@ class MicrosoftConfigurationManagerClient { async listApplicationDeviceTargets( iteratee: ResourceIteratee, pageSize: number = 600, + logger: IntegrationLogger, ) { let offset = 0; let hasMoreRecords = true; @@ -111,6 +113,9 @@ class MicrosoftConfigurationManagerClient { ); const records = result.recordset; + + logger.info(`Proccesed ${records.length} records from query`); + if (records.length > 0) { await pMap( records, diff --git a/src/steps/applications/index.ts b/src/steps/applications/index.ts index c1912d5..0b1b0f4 100644 --- a/src/steps/applications/index.ts +++ b/src/steps/applications/index.ts @@ -94,20 +94,22 @@ export async function buildApplicationRelationships({ logger, ); - await client.listApplicationDeviceTargets(async (application: any) => { - const appID = createApplicationKey(application.CIGUID?.toString()); - const deviceID = createDeviceKey(application.ResourceID?.toString()); - const applicationEntity = await jobState.findEntity(appID); - const deviceEntity = await jobState.findEntity(deviceID); - if (applicationEntity && deviceEntity) { - const deviceApplicationRelationship = createDeviceApplicationRelationship( - deviceEntity, - applicationEntity, - ); + await client.listApplicationDeviceTargets( + async (application: any) => { + const appID = createApplicationKey(application.CIGUID?.toString()); + const deviceID = createDeviceKey(application.ResourceID?.toString()); + const applicationEntity = await jobState.findEntity(appID); + const deviceEntity = await jobState.findEntity(deviceID); + if (applicationEntity && deviceEntity) { + const deviceApplicationRelationship = + createDeviceApplicationRelationship(deviceEntity, applicationEntity); - if (!jobState.hasKey(deviceApplicationRelationship._key)) { - await jobState.addRelationship(deviceApplicationRelationship); + if (!jobState.hasKey(deviceApplicationRelationship._key)) { + await jobState.addRelationship(deviceApplicationRelationship); + } } - } - }); + }, + 600, + logger, + ); } From 6800406e1791219f6ecfc1bf6f1562f06cbe94c5 Mon Sep 17 00:00:00 2001 From: Gaston Yelmini Date: Wed, 3 Jul 2024 15:15:51 -0300 Subject: [PATCH 2/2] Add error logging --- src/configuration-manager/client.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/configuration-manager/client.ts b/src/configuration-manager/client.ts index 5d95cf7..fddb303 100644 --- a/src/configuration-manager/client.ts +++ b/src/configuration-manager/client.ts @@ -271,10 +271,12 @@ class MicrosoftConfigurationManagerClient { private async wrapWithRequestFailedHandler( fn: () => Promise, + logger?: IntegrationLogger, ) { try { return await fn(); } catch (err) { + logger?.error(`Received error from SQL query: ${err}`); throw this.onRequestFailed(err); } }