Skip to content

Commit 8a2d30c

Browse files
committed
fix product statuses
1 parent 8238d39 commit 8a2d30c

4 files changed

Lines changed: 43 additions & 1 deletion

File tree

plugins/NinjaOne/v1/dataStreams/deviceHealth.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
}
2424
},
2525
"expandInnerObjects": false,
26+
"postRequestScript": "deviceHealth.js",
2627
"endpointPath": "/v2/queries/device-health",
2728
"pathToData": "results",
2829
"getArgs": [],

plugins/NinjaOne/v1/dataStreams/health.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"mode": "none"
1111
},
1212
"expandInnerObjects": true,
13+
"postRequestScript": "deviceHealth.js",
1314
"endpointPath": "/v2/queries/device-health",
1415
"pathToData": "results",
1516
"getArgs": [
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Handle NinjaOne paged response for device health
2+
const items = (data && data.results ? data.results : (Array.isArray(data) ? data : []));
3+
4+
const convertTimestamps = (obj) => {
5+
if (!obj || typeof obj !== 'object') return obj;
6+
for (const key in obj) {
7+
const val = obj[key];
8+
if (typeof val === 'number') {
9+
const lowerKey = key.toLowerCase();
10+
if (lowerKey.includes('time') || lowerKey.includes('date') || lowerKey.includes('contact') || lowerKey.includes('update') || lowerKey.includes('start') || lowerKey.includes('end') || lowerKey.includes('expires')) {
11+
if (val > 1000000000 && val < 10000000000) {
12+
obj[key] = new Date(val * 1000).toISOString();
13+
}
14+
}
15+
} else if (typeof val === 'object' && val !== null) {
16+
convertTimestamps(val);
17+
}
18+
}
19+
return obj;
20+
};
21+
22+
const formatProductsInstallationStatuses = (statuses) => {
23+
if (!statuses || typeof statuses !== 'object') return statuses;
24+
const parts = [];
25+
for (const [product, status] of Object.entries(statuses)) {
26+
parts.push(`${product}: ${status}`);
27+
}
28+
return parts.join(', ');
29+
};
30+
31+
result = items.map(item => {
32+
const converted = convertTimestamps(item);
33+
const transformed = { ...converted };
34+
if (transformed.deviceId !== undefined) transformed.deviceId = transformed.deviceId.toString();
35+
if (transformed.parentDeviceId !== undefined) transformed.parentDeviceId = transformed.parentDeviceId.toString();
36+
if (transformed.productsInstallationStatuses !== undefined) {
37+
transformed.productsInstallationStatuses = formatProductsInstallationStatuses(transformed.productsInstallationStatuses);
38+
}
39+
return transformed;
40+
});

plugins/NinjaOne/v1/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "ninja-one",
33
"displayName": "NinjaOne",
4-
"version": "1.1.6",
4+
"version": "1.1.7",
55
"author": {
66
"name": "SquaredUp Labs",
77
"type": "labs"

0 commit comments

Comments
 (0)