Skip to content
This repository has been archived by the owner on Sep 3, 2024. It is now read-only.

Commit

Permalink
Merge pull request #62 from JupiterOne/INT-11375-bussiness-unit
Browse files Browse the repository at this point in the history
Int 11375 bussiness unit / undefined key
  • Loading branch information
Gonzalo-Avalos-Ribas authored Aug 1, 2024
2 parents e6bd841 + cf76689 commit 4b449da
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/steps/cmdb/__snapshots__/converters.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ exports[`createCMDBEntity that properties are converted correctly 1`] = `
"id": "test-id",
"installStatus": undefined,
"ipAddress": undefined,
"isSysIdUndefined": false,
"macAddress": undefined,
"managedBy": undefined,
"managedByGroup": undefined,
Expand Down
13 changes: 11 additions & 2 deletions src/steps/cmdb/converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Entities } from '../../constants';
import { CMDBItem } from '../../types';
import { skippedRawDataSource } from '../../util/graphObject';
import { camelCase } from 'lodash';
import { createHash } from 'crypto';

export function createCMDBEntity(
data: CMDBItem,
Expand Down Expand Up @@ -35,22 +36,30 @@ export function createCMDBEntity(
customFields[customFieldsKey] = finalValue;
}
}
// Sys_id could be undefined this should be a case of currupted or deleted data, using sha1 to have a uniquekey for the cmdb objects
let objectKey = data.sys_id;
if (!objectKey) {
const hash = createHash('sha1');
hash.update(JSON.stringify(data));
objectKey = hash.digest('base64');
}

return createIntegrationEntity({
entityData: {
source: skippedRawDataSource, // Raw data is really big.
assign: {
_class: Entities.CMDB_OBJECT._class,
_type: Entities.CMDB_OBJECT._type,
_key: data.sys_id,
_key: objectKey,
id: data.sys_id,
isSysIdUndefined: !data.sys_id,
correlationId: data.correlation_id,
name: data.name,
displayName: data.name,
sysClassNames: sysClassNames,
installStatus: data.install_status,
attributes: data.attributes,
businessUnit: data.business_unit,
businessUnit: data.business_unit?.value,
category: data.category,
environment: data.environment,
ipAddress: data.ip_address,
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export type CMDBItem = {
owned_by: Asset | undefined;
checked_out: string;
sys_domain_path: string;
business_unit: string;
business_unit: Asset | undefined;
delivery_date: string;
maintenance_schedule: string;
install_status: string;
Expand All @@ -66,7 +66,7 @@ export type CMDBItem = {
last_discovered: string;
sys_class_name: string;
manufacturer: Asset | undefined;
sys_id: string;
sys_id: string | undefined;
po_number: string;
checked_in: string;
sys_class_path: string;
Expand Down

0 comments on commit 4b449da

Please sign in to comment.