Skip to content
Notifications
Clear all

TIL: You can use SentinelOne's API to pull asset inventory, super useful.

2 Posts
2 Users
0 Reactions
1 Views
(@ci_cd_enthusiast)
Estimable Member
Joined: 5 months ago
Posts: 117
Topic starter   [#8066]

Just had one of those "why didn't I do this sooner?" moments today. I was tired of manually reconciling our SentinelOne agent list with our internal CMDB for infrastructure-as-code tracking. Turns out, their API is pretty robust for pulling a clean, automated asset inventory.

I set up a simple scheduled job in our CI system (GitLab CI in this case) to fetch the data nightly. It's perfect for keeping an eye on agent health, OS distributions, and even last user login. This beats waiting for the weekly CSV export hands down.

Here's a quick curl example to get you started. You'll need your API token and a site ID (or use the "console" scope).

```bash
curl -X GET "https://usea1.sentinelone.net/web/api/v2.1/agents"
-H "Authorization: ApiToken YOUR_TOKEN_HERE"
-H "Content-Type: application/json"
-G --data-urlencode "siteIds=YOUR_SITE_ID"
--data-urlencode "limit=1000"
```

The response is a JSON payload with everything you'd see in the "Agents" table. I pipe it into a Python script to filter and format, then push the output to a dashboard. Some useful fields I'm leveraging:
* `networkStatus` - Is the agent communicating?
* `osType` and `osName` - Great for patch compliance tracking.
* `lastActiveDate` - Flag stale agents for cleanup.
* `externalId` - We map this to our internal instance IDs.

This is a game-changer for us DevOps folks who want to treat security posture as code. You could easily trigger alerts if, say, more than 5% of your agents go "disconnected," or automate decommissioning workflows for stale assets.

Anyone else using the API for similar pipeline integrations? I'm curious about how you're handling pagination for large environments or if you've built any cool monitoring checks with the data.

-pipelinepilot


Pipeline Pilot


   
Quote
(@billyj)
Reputable Member
Joined: 1 week ago
Posts: 137
 

That's a solid use case, and it mirrors how I've integrated other security tooling into our observability stack. The JSON payload is indeed rich, but you'll want to be mindful of the pagination default.

Your example uses `limit=1000`, but if your fleet exceeds that, you must handle the `pagination.nextToken` in the response to iterate through all agents. I've seen scripts fail silently when they only pull the first thousand.

Another field I've found critical for IaC reconciliation is `domain`. When machines are re-provisioned with the same hostname, the `domain` field coupled with `lastLoggedInUserName` helps distinguish between the old stale entry and the new instance. Have you run into any issues with decommissioned agents lingering in the API output versus your CMDB?



   
ReplyQuote