Skip to content

Certain Snipe-IT device records are not updated due to Kandji API endpoint hard limit #30

@Jan-Dovetail

Description

@Jan-Dovetail

Issue

When getting the latest device activity from Kandji in the kandji_device_activity function below, it is using the Get Device Activity endpoint and grabbing the last entry in the results.

kandji2snipe/kandji2snipe

Lines 438 to 442 in bd8f525

def get_kandji_device_activity_date(kandji_id):
endpoint=f"/api/v1/devices/{kandji_id}/activity"
logging.debug('Calling for device activity in Kandji against: {}'.format(kandji_base + endpoint))
response = kandji_api(method="GET", endpoint=endpoint)
return response

kandji_time_conversion = datetime.strptime(kandji_device_activity['activity']['results'][-1]['created_at'], '%Y-%m-%dT%H:%M:%S.%fZ')

However, the results of this endpoint have a hard limit of 300 records. Which is why the function does not return the most recent device activity date from Kandji which results in certain device records not being updated in Snipe-IT

Image

Possible fix

It would be better to use the Get Device Details endpoint of the Kandji API as this does not have hard limit. From the results, we can grab the mdm -> last_check_in field to get the most recent device activity.

{
	"general": {
		"device_id": "03f81208-2b6a-4a77-81f5-cf1633bcfb95",
		"device_name": "testuser’s MacBook Air",
		"last_enrollment": "2024-05-13 20:09:27.374451+00:00",
		"first_enrollment": "2024-01-26 16:15:36.087016+00:00",
		"model": "MacBook Air (M1, 2020)",
		"platform": "Mac",
		"os_version": "14.4.1",
		"supplemental_build_version": "23E224",
		"supplemental_os_version_extra": "",
		"system_version": "14.4.1 (23E224)",
		"boot_volume": "Macintosh HD",
		"time_since_boot": "1 month ago",
		"last_user": "root",
		"asset_tag": "sending_tag_to_now",
		"assigned_user": {
			"email": "[email protected]",
			"name": "acchuhive admin",
			"id": "5344c996-8823-4b37-8d6e-8515fc7c3a0a",
			"is_archived": false
		},
		"blueprint_name": "_test_something",
		"blueprint_uuid": "ab102b9d-8e9c-420d-a498-f2a1123091c7"
	},
	"mdm": {
		"mdm_enabled": "True",
		"supervised": "True",
		"install_date": "2024-05-13 20:09:27.213607+00:00",
		"last_check_in": "2024-07-23 12:43:15.675470+00:00",
		"mdm_enabled_user": [
			"testuser"
		]
	},

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions