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

Log mismatches between operatingSystem name and caption #97

Merged
merged 1 commit into from
Apr 26, 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
4 changes: 2 additions & 2 deletions lansweeper/aws/integration-lambda/lansweeper_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,8 @@ 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 version';
LansweeperClient.osMetadataFields = 'name version endOfSupportDate';
LansweeperClient.operatingSystemFields = 'caption name';
LansweeperClient.osMetadataFields = 'name endOfSupportDate';
LansweeperClient.processorFields = 'numberOfCores';
LansweeperClient.memoryModulesFields = 'size';

Expand Down
34 changes: 30 additions & 4 deletions lansweeper/aws/integration-lambda/lansweeper_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class LansweeperHelper {
this.brands = {};
this.models = {};
this.products = {};
this.osNameMismatches = new Map();
}

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

extractOperatingSystemNames(assets) {
const oss = assets.map(a => a.operatingSystem).filter(os => !!os && !!os.caption);
return this.mapToUnique(oss, os => this.cleanupName(os.caption));
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);
}
}
}
}

extractOperatingSystemEndOfSupport(assets) {
Expand Down Expand Up @@ -151,8 +177,8 @@ class LansweeperHelper {
return known;
}

mapToUnique(assets, getFunction) {
return assets.map(getFunction)
mapToUnique(objects, getFunction) {
return objects.map(getFunction)
.filter((v, i, a) => v && a.indexOf(v) === i);
}

Expand Down
6 changes: 6 additions & 0 deletions lansweeper/aws/integration-lambda/lansweeper_integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ 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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"operatingSystem": {
"version": "22H2",
"caption": "Microsoft Windows 11 Home",
"name": "Microsoft Windows 11 Home",
"buildNumber": "10.0.22621"
},
"memoryModules": [
Expand Down Expand Up @@ -1151,7 +1152,8 @@
},
"operatingSystem": {
"version": "18.04",
"caption": "Linux 18.04"
"caption": "Linux 18.04",
"name": "Linux"
},
"assetCustom": {
"manufacturer": "VMware, Inc.",
Expand Down Expand Up @@ -2154,6 +2156,7 @@
"lastChanged": "2023-03-20T06:20:51.537Z"
},
"operatingSystem": {
"name": "macOS",
"version": "macOS"
},
"assetCustom": {
Expand All @@ -2179,6 +2182,7 @@
"lastChanged": "2023-03-21T06:23:07.403Z"
},
"operatingSystem": {
"name": "Android",
"version": "12"
},
"assetCustom": {
Expand Down Expand Up @@ -2250,7 +2254,8 @@
},
"operatingSystem": {
"version": "20.04",
"caption": "Linux 20.04"
"caption": "Linux 20.04",
"name": "Linux 20.04"
},
"assetCustom": {
"manufacturer": "Dell Inc.",
Expand Down
24 changes: 24 additions & 0 deletions lansweeper/aws/integration-lambda/tests/lansweeper_helper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,15 @@ 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 @@ -349,6 +354,25 @@ describe('extractOperatingSystemNames', () => {
'Microsoft Windows Server 2019 Standard Evaluation',
"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