API / CLI call to determine if device is "new" to the fleet?

I’ve been tasked with creating a configuration container workflow, with the first job of the container being to determine if the device it is installed on is a net new device, or if it already exists in the fleet.

The use case is that the container is deployed to devices in the fleet, and periodically runs to check whether the current device has the latest configuration, via a CMDB.

Is there an API call (from the device) or CLI command that can provide some information on the device configuration at a high level? For example, if a device has had a previous release of the current fleet onto it, that would not be considered a net new device, and vice versa.

Hey there @amoredebore and welcome!

I don’t think I’m understanding the requirement to figure out if the device is ‘new’ or not when it comes to configuration; surely it doesn’t matter if the device is new or not, it still should get the latest configuration via CMDB? I’d recommend trying to take the approach that whatever configuration management process you’re using can handle bringing the device up to date from whatever state it is in. I’d also recommend rolling out configuration to devices in the same way as releases if at all possible, i.e. if there’s a new configuration required, that could be distributed as a new release. That way, balena takes care of the distribution of the update to all devices and ensures they’re all on the latest version for you. With delta updates, if all you change is one configuration parameter, although you’re creating a new release, the amount of download the device has to do to get the change can be as little as a few KB.

Although, I understand there are bound to be use cases out there where that approach doesn’t work. I’d like to hear more if that’s the case though, as it’s always good to understand when the product falls short and doesn’t permit you do to what you need to for your application. Anyway, that being said, I think you may be able to figure it out using the resources available on the cloud API. All the details are here: https://www.balena.io/docs/reference/api/resources/fleet/

It’s worth noting that if you enable the label io.balena.features.balena-api for the container in question, it will be given a BALENA_API_KEY environment variable scoped to that device. This means that from the device, your container will have the ability to query the API for information about itself. See here for more detail: docker-compose.yml fields - Balena Documentation

I hope this information helps you get going, but let us know if not!