Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use operatingSystem.name instead of caption #103

Merged
merged 3 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ class DiscoveryMutationHelper {
ci.ciRelations = {childIds: softwareIDs};
}
}
if (asset.operatingSystem && asset.operatingSystem.caption) {
const softwareIDs = this.mapSoftwareName([asset.operatingSystem.caption]);
if (asset.operatingSystem && asset.operatingSystem.name) {
const softwareIDs = this.mapSoftwareName([asset.operatingSystem.name]);
if (softwareIDs.length > 0) {
ci.operatingSystemId = softwareIDs[0];
}
Expand Down
2 changes: 1 addition & 1 deletion lansweeper/aws/integration-lambda/lansweeper_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ LansweeperClient.basicInfoFields = 'name type description ipAddress firstSeen la
LansweeperClient.assetCustomFields = 'model manufacturer stateName purchaseDate warrantyDate serialNumber sku';
LansweeperClient.usersFields = 'name email fullName';
LansweeperClient.softwaresFields = 'name';
LansweeperClient.operatingSystemFields = 'caption name';
LansweeperClient.operatingSystemFields = 'name';
LansweeperClient.osMetadataFields = 'name endOfSupportDate';
LansweeperClient.processorFields = 'numberOfCores';
LansweeperClient.memoryModulesFields = 'size';
Expand Down
40 changes: 8 additions & 32 deletions lansweeper/aws/integration-lambda/lansweeper_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ class LansweeperHelper {
this.brands = {};
this.models = {};
this.products = {};
this.osNameMismatches = new Map();
}

extractProductCategories(assets) {
Expand Down Expand Up @@ -68,46 +67,23 @@ class LansweeperHelper {
}

extractOperatingSystemNames(assets) {
const oss = assets.map(a => a.operatingSystem).filter(os => !!os);
this.captureOsMismatches(oss);
const captions = oss.filter(os => !!os.caption);
return this.mapToUnique(captions, os => this.cleanupName(os.caption));
}

captureOsMismatches(oss) {
for (const os of oss) {
const cleanCaption = os.caption && this.cleanupName(os.caption);
const cleanName = os.name && this.cleanupName(os.name);
let message = null;
if (cleanCaption && !cleanName) {
message = `No name for ${cleanCaption}`;
} else if (!cleanCaption && cleanName) {
message = `No caption for ${cleanName}`;
} else if (cleanCaption && cleanName && cleanCaption !== cleanName) {
message = `Mismatch between caption and name: '${cleanCaption}' != '${cleanName}'`;
}
if (message) {
const currentCount = this.osNameMismatches.get(message);
if (currentCount) {
this.osNameMismatches.set(message, currentCount + 1);
} else {
this.osNameMismatches.set(message, 1);
}
}
}
const oss = assets.map(a => a.operatingSystem).filter(os => !!os && !!os.name);
return this.mapToUnique(oss, os => this.cleanupName(os.name));
}

extractOperatingSystemEndOfSupport(assets) {
const endOfSupportDates = new Map();
for (const asset of assets) {
if (asset.operatingSystem && asset.operatingSystem.caption &&
if (asset.operatingSystem && asset.operatingSystem.name &&
asset.recognitionInfo && asset.recognitionInfo.osMetadata) {
const metadata = asset.recognitionInfo.osMetadata;
if (metadata.name && metadata.endOfSupportDate) {
const caption = this.cleanupName(asset.operatingSystem.caption);
const name = this.cleanupName(asset.operatingSystem.name);
const metaName = this.cleanupName(metadata.name);
if (caption.includes(metaName)) {
endOfSupportDates.set(caption, metadata.endOfSupportDate);
if (name.includes(metaName)) {
endOfSupportDates.set(name, metadata.endOfSupportDate);
} else {
console.warn(`operatingSystem and osMetadata mismatch: '${asset.operatingSystem.name}' vs '${metadata.name}'`);
}
}
}
Expand Down
6 changes: 0 additions & 6 deletions lansweeper/aws/integration-lambda/lansweeper_integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,6 @@ class LansweeperIntegration {
result.info['operatingSystems'] = `Stored end-of-support for ${cisUpdated.length} item(s)`;
}
}
const osNameMismatches = this.referenceHelper?.lansweeperHelper?.osNameMismatches;
if (osNameMismatches && osNameMismatches.size > 0) {
osNameMismatches.forEach((count, message) => {
console.log(`OS name mismatch: ${message}; count: ${count}`)
});
}
if (this.referenceHelper.peopleFound.size > 0 || this.referenceHelper.peopleNotFound.length > 0) {
console.log(`User lookup: found ${this.referenceHelper.peopleFound.size} people (not found ${this.referenceHelper.peopleNotFound.length})`);
}
Expand Down
6 changes: 3 additions & 3 deletions lansweeper/aws/integration-lambda/os_ci_mutation_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class OsCiMutationHelper {
}
console.log('End of support dates: %j', [...osEndOfSupports]);
const cisToUpdate = [];
for (const osCaption of osEndOfSupports.keys()) {
const ciId = ciIds.get(osCaption);
for (const osNames of osEndOfSupports.keys()) {
const ciId = ciIds.get(osNames);
if (ciId) {
const endOfSupportDate = osEndOfSupports.get(osCaption);
const endOfSupportDate = osEndOfSupports.get(osNames);
cisToUpdate.push({id: ciId, endOfSupportDate: endOfSupportDate});
}
}
Expand Down
33 changes: 11 additions & 22 deletions lansweeper/aws/integration-lambda/tests/assets/asset_array.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
"lastChanged": "2023-03-01T16:08:54.427Z"
},
"operatingSystem": {
"version": "22H2",
"caption": "Microsoft Windows 11 Home",
"name": "Microsoft Windows 11 Home",
"buildNumber": "10.0.22621"
"name": "Microsoft Windows 11 Home"
},
"memoryModules": [
{
Expand Down Expand Up @@ -462,7 +459,7 @@
"stateName": "Active"
},
"operatingSystem": {
"caption": "Microsoft Windows Server 2012 R2 Standard"
"name": "Microsoft Windows Server 2012 R2 Standard"
},
"softwares": [
{
Expand Down Expand Up @@ -549,8 +546,7 @@
"stateName": "Active"
},
"operatingSystem": {
"version": "16.04",
"caption": "Linux 16.04"
"name": "Linux 16.04"
},
"recognitionInfo": {
"osMetadata": {
Expand Down Expand Up @@ -669,8 +665,7 @@
"stateName": "Active"
},
"operatingSystem": {
"caption": "Microsoft Windows Server 2012 R2 Standard",
"buildNumber": "6.3.9600"
"name": "Microsoft Windows Server 2012 R2 Standard"
},
"users": [
{
Expand Down Expand Up @@ -1151,9 +1146,7 @@
"lastChanged": "2021-08-23T15:55:48.747Z"
},
"operatingSystem": {
"version": "18.04",
"caption": "Linux 18.04",
"name": "Linux"
"name": "Linux 18.04"
},
"assetCustom": {
"manufacturer": "VMware, Inc.",
Expand Down Expand Up @@ -1186,7 +1179,7 @@
"stateName": "Active"
},
"operatingSystem": {
"caption": "Linux 16.04"
"name": "Red Hat Enterprise Linux 8.9 (Ootpa)"
},
"url": "https://app.lansweeper.com/jest-site/asset/MjEtQXNzZXQtZjNmNGRiMjMtMWJlNS00MDk1LWIyYTktODY5ZWE3YzFhZjEw/summary"
},
Expand All @@ -1211,7 +1204,7 @@
"stateName": "Active"
},
"operatingSystem": {
"caption": "Microsoft Windows Server 2019 Standard Evaluation"
"name": "Microsoft Windows Server 2019 Standard Evaluation"
},
"users": [
{
Expand Down Expand Up @@ -1572,7 +1565,7 @@
"stateName": "Active"
},
"operatingSystem": {
"caption": "Microsoft Windows Server 2019 Standard Evaluation"
"name": "Microsoft Windows Server 2019 Standard Evaluation"
},
"url": "https://app.lansweeper.com/jest-site/asset/NjYtQXNzZXQtZjNmNGRiMjMtMWJlNS00MDk1LWIyYTktODY5ZWE3YzFhZjEw/summary"
},
Expand Down Expand Up @@ -2042,7 +2035,7 @@
"stateName": "Active"
},
"operatingSystem": {
"caption": "Microsoft Windows Server 2012 R2 Standard"
"name": "Microsoft Windows Server 2012 R2 Standard"
},
"softwares": [
{
Expand Down Expand Up @@ -2156,8 +2149,7 @@
"lastChanged": "2023-03-20T06:20:51.537Z"
},
"operatingSystem": {
"name": "macOS",
"version": "macOS"
"name": "macOS 14.4.1 (23E224)"
},
"assetCustom": {
"manufacturer": "Apple",
Expand All @@ -2182,8 +2174,7 @@
"lastChanged": "2023-03-21T06:23:07.403Z"
},
"operatingSystem": {
"name": "Android",
"version": "12"
"name": "Android"
},
"assetCustom": {
"manufacturer": "Oppo",
Expand Down Expand Up @@ -2253,8 +2244,6 @@
"lastChanged": "2021-08-23T15:56:04.153Z"
},
"operatingSystem": {
"version": "20.04",
"caption": "Linux 20.04",
"name": "Linux 20.04"
},
"assetCustom": {
Expand Down
27 changes: 3 additions & 24 deletions lansweeper/aws/integration-lambda/tests/lansweeper_helper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,15 +333,10 @@ describe('extractSoftwareNames', () => {
});

describe('extractOperatingSystemNames', () => {
beforeEach(() => {
helper.osNameMismatches.clear();
});

it('handles empty', () => {
const names = helper.extractOperatingSystemNames([]);

expect(names).toEqual([]);
expect(helper.osNameMismatches.size).toEqual(0);
});

it('extracts unique values', () => {
Expand All @@ -351,28 +346,12 @@ describe('extractOperatingSystemNames', () => {
'Microsoft Windows Server 2012 R2 Standard',
'Linux 16.04',
"Linux 18.04",
'Red Hat Enterprise Linux 8.9 (Ootpa)',
'Microsoft Windows Server 2019 Standard Evaluation',
'macOS 14.4.1 (23E224)',
'Android',
"Linux 20.04",
]);
expect(helper.osNameMismatches.size).toBeGreaterThan(0);
});

describe('capturesOsMismatches', () => {
it('counts mismatches', () => {
helper.extractOperatingSystemNames(assetArray);

expect([...helper.osNameMismatches.keys()])
.toEqual([
"No name for Microsoft Windows Server 2012 R2 Standard",
"No name for Linux 16.04",
"Mismatch between caption and name: 'Linux 18.04' != 'Linux'",
"No name for Microsoft Windows Server 2019 Standard Evaluation",
"No caption for macOS",
"No caption for Android",
]);
expect(helper.osNameMismatches.get("No name for Microsoft Windows Server 2012 R2 Standard")).toEqual(3);
expect(helper.osNameMismatches.get("No caption for macOS")).toEqual(1);
});
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ describe('lookup4meReferences', () => {
"Microsoft Windows Server 2012 R2 Standard",
"Linux 16.04",
"Linux 18.04",
"Microsoft Windows Server 2019 Standard Evaluation",
'Red Hat Enterprise Linux 8.9 (Ootpa)',
'Microsoft Windows Server 2019 Standard Evaluation',
'macOS 14.4.1 (23E224)',
'Android',
"Linux 20.04",
]);
expect(helper.osEndOfSupports)
Expand Down