feat: listen mode for scanning by the NetBox Synchronizer, Intune and GPO deployment
- New "mode" setting: "netbox" (default, unchanged), "listen" (no NetBox access needed; the inventory is served on a TCP port for the NetBox Synchronizer desktop app) or "both" - Listen protocol v1: HMAC-SHA256 signed requests with nonce and timestamp, AES-256-GCM encrypted inventory, optional allowed_networks; the inventory has the shape of the desktop app's WinRM scan - New options --serve, --print and --version - install.ps1 sets up the listener task (at startup, restarted on failure) and the firewall rule for listen mode, removes what a changed mode no longer needs and stays idempotent - New gpo-startup.ps1 for Group Policy startup scripts: installs or updates from a share only when agent.exe or config.json changed - README, messages and scripts in English Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
d632f0d383
commit
0098b49787
14 files changed
+791
-93
No files matched your search
@@ -1,6 +1,6 @@
|
||||
# NetBox Client Agent for Windows
|
||||
|
||||
Inventories a Windows PC automatically in NetBox and in the
|
||||
Inventories a Windows PC for NetBox and the
|
||||
[netbox-inventory](https://github.com/ArnesSI/netbox-inventory) plugin. The
|
||||
result is a single, self-contained `agent.exe`; the client does not need .NET
|
||||
installed.
|
||||
@@ -10,11 +10,27 @@ installed.
|
||||
| **Type** | Command-line agent (.NET 8) |
|
||||
| **Platform** | Windows (x64, ARM64) |
|
||||
| **NetBox** | `4.2` or newer recommended |
|
||||
| **Deployment** | Intune (Win32 app) or Group Policy (startup script), fully unattended |
|
||||
| **Repository** | <https://git.mrblake.cc/MrBlake/Netbox-Client-Agent-for-Windows> |
|
||||
|
||||
## Modes
|
||||
|
||||
The agent runs in one of three modes, set by `mode` in `config.json`:
|
||||
|
||||
| Mode | What it does | Needs on the client |
|
||||
|---|---|---|
|
||||
| `netbox` (default) | Writes the PC directly to NetBox once a day | NetBox URL and API token |
|
||||
| `listen` | Serves the inventory on a TCP port; the **NetBox Synchronizer** desktop app scans IP ranges and transfers the PCs to NetBox after a preview | Only a shared scan key – **no NetBox access** |
|
||||
| `both` | Both of the above | Both |
|
||||
|
||||
The agent is invisible to users: it runs as SYSTEM in the background (session
|
||||
0), shows no window and causes no prompts. The installer creates the firewall
|
||||
rule before the listener starts, so Windows never asks users to allow network
|
||||
access.
|
||||
|
||||
## Features
|
||||
|
||||
After the first run, the agent creates or updates:
|
||||
In mode `netbox`, the agent creates or updates after the first run:
|
||||
|
||||
- a `DCIM > Device` for the Windows PC,
|
||||
- a linked inventory asset,
|
||||
@@ -30,8 +46,19 @@ the existing objects. No NetBox objects are ever deleted.
|
||||
> from 4.2 on. Modules are meant for replaceable hardware in NetBox; for PC
|
||||
> inventory, CPU, memory and disks are deliberately mapped onto this model.
|
||||
|
||||
In mode `listen`, the NetBox Synchronizer (page *Windows-Clients*, target
|
||||
mode *NetBox-Agent*) scans IP ranges, lists every PC that answers and
|
||||
transfers the selected ones with model, serial number, operating system,
|
||||
interfaces, MAC and IP addresses – the same way as its agentless WinRM scan.
|
||||
Disks, memory modules and the software list are shown in the app as well.
|
||||
|
||||
## Requirements
|
||||
|
||||
Building requires the [.NET 8 SDK](https://dotnet.microsoft.com/download/dotnet/8.0)
|
||||
or newer.
|
||||
|
||||
For mode `netbox`:
|
||||
|
||||
1. `netbox-inventory` is installed.
|
||||
2. A device role with the slug `windows-client` exists.
|
||||
3. The site and location named in the configuration exist, if used.
|
||||
@@ -45,8 +72,8 @@ The agent deliberately does not create sites or device roles. NetBox requires a
|
||||
site for every device; a location is optional. Manufacturers, device types and
|
||||
detected hardware types are created as needed.
|
||||
|
||||
Building requires the [.NET 8 SDK](https://dotnet.microsoft.com/download/dotnet/8.0)
|
||||
or newer.
|
||||
For mode `listen`: the NetBox Synchronizer desktop app and TCP access from the
|
||||
admin PC to the clients on `listen_port` (default 8731).
|
||||
|
||||
## Installation
|
||||
|
||||
@@ -63,20 +90,34 @@ powershell.exe -NoProfile -ExecutionPolicy Bypass `
|
||||
-Runtime win-x64
|
||||
```
|
||||
|
||||
The result is `dist\win-x64\agent.exe`.
|
||||
The result is `dist\win-x64\agent.exe` (`-Runtime win-arm64` for ARM devices).
|
||||
|
||||
### 2. Create the configuration
|
||||
|
||||
Mode `netbox`:
|
||||
|
||||
```powershell
|
||||
Copy-Item .\config.example.json .\dist\win-x64\config.json
|
||||
notepad .\dist\win-x64\config.json
|
||||
```
|
||||
|
||||
Mode `listen`: in the NetBox Synchronizer open *Windows-Clients*, choose
|
||||
*NetBox-Agent (Netzwerk-Scan)*, create a key and click
|
||||
*Agent-Konfiguration speichern …*. This writes a ready `config.json`
|
||||
(see also `config.listen.example.json`).
|
||||
|
||||
See [Configuration](#configuration) for all options.
|
||||
|
||||
### 3. Test the connection
|
||||
### 3. Test
|
||||
|
||||
The dry run reads hardware and NetBox but deliberately writes nothing:
|
||||
Show what the agent collects (any mode):
|
||||
|
||||
```powershell
|
||||
.\dist\win-x64\agent.exe --config .\dist\win-x64\config.json --print
|
||||
```
|
||||
|
||||
Mode `netbox` – the dry run reads hardware and NetBox but deliberately writes
|
||||
nothing:
|
||||
|
||||
```powershell
|
||||
.\dist\win-x64\agent.exe `
|
||||
@@ -84,14 +125,25 @@ The dry run reads hardware and NetBox but deliberately writes nothing:
|
||||
--dry-run
|
||||
```
|
||||
|
||||
Expected output (the agent's messages are in German):
|
||||
Expected output:
|
||||
|
||||
```text
|
||||
Erfasst: CLIENT01, LENOVO 21MW, S/N ABC123
|
||||
Dry-Run erfolgreich; keine Änderungen geschrieben.
|
||||
Collected: CLIENT01, LENOVO 21MW, S/N ABC123
|
||||
Dry run successful; nothing was written.
|
||||
```
|
||||
|
||||
### 4. First real synchronisation
|
||||
Mode `listen` – serve in the foreground (Ctrl+C stops) and scan this PC from
|
||||
the NetBox Synchronizer:
|
||||
|
||||
```powershell
|
||||
.\dist\win-x64\agent.exe --config .\dist\win-x64\config.json --serve
|
||||
```
|
||||
|
||||
When started by hand like this, Windows Firewall may ask once whether
|
||||
`agent.exe` may accept connections – this only happens in manual tests. An
|
||||
installed agent has its firewall rule and never asks.
|
||||
|
||||
### 4. First real synchronisation (mode `netbox`)
|
||||
|
||||
```powershell
|
||||
.\dist\win-x64\agent.exe `
|
||||
@@ -101,7 +153,7 @@ Dry-Run erfolgreich; keine Änderungen geschrieben.
|
||||
Expected output:
|
||||
|
||||
```text
|
||||
Synchronisiert: Device #123, Asset #456
|
||||
Synchronized: device #123, asset #456
|
||||
```
|
||||
|
||||
### 5. Install permanently
|
||||
@@ -119,9 +171,21 @@ powershell.exe -NoProfile -ExecutionPolicy Bypass `
|
||||
The script:
|
||||
|
||||
- copies the executable and configuration to `C:\Program Files\NetBox Windows Agent`,
|
||||
- restricts access to the API token to SYSTEM and local administrators,
|
||||
- creates the daily scheduled task `NetBox Windows Agent`,
|
||||
- starts the first synchronisation immediately.
|
||||
- restricts access to the API token and scan key to SYSTEM and local administrators,
|
||||
- mode `netbox`/`both`: creates the daily scheduled task `NetBox Windows Agent`
|
||||
and starts the first synchronisation immediately,
|
||||
- mode `listen`/`both`: adds the inbound firewall rule `NetBox Windows Agent`
|
||||
for `listen_port` (domain and private profile, limited to
|
||||
`allowed_networks`), then creates and starts the scheduled task
|
||||
`NetBox Windows Agent Listener` (runs as SYSTEM at startup, restarted after
|
||||
failures),
|
||||
- removes tasks and the firewall rule that a changed mode no longer needs,
|
||||
- can be run again at any time to update the agent or its configuration.
|
||||
|
||||
The installation state only depends on the installed executable, configuration
|
||||
and scheduled tasks. A temporary NetBox or network error during the first
|
||||
synchronisation does not undo the installation; the scheduled task retries the
|
||||
synchronisation later.
|
||||
|
||||
## Uninstall
|
||||
|
||||
@@ -132,12 +196,15 @@ powershell.exe -NoProfile -ExecutionPolicy Bypass `
|
||||
-File .\scripts\uninstall.ps1
|
||||
```
|
||||
|
||||
This removes both scheduled tasks, the firewall rule and the install folder.
|
||||
|
||||
## Configuration
|
||||
|
||||
Minimal example:
|
||||
### Mode `netbox`
|
||||
|
||||
```json
|
||||
{
|
||||
"mode": "netbox",
|
||||
"netbox_url": "https://netbox.example.com",
|
||||
"api_token": "YOUR_NETBOX_TOKEN",
|
||||
"region": "emea",
|
||||
@@ -155,9 +222,47 @@ Minimal example:
|
||||
}
|
||||
```
|
||||
|
||||
`site` must be the slug of an existing NetBox site, since NetBox requires a site
|
||||
for every device. `location` is optional and may be removed or set to `null`.
|
||||
`region` narrows the site lookup.
|
||||
`mode` may be omitted; `netbox` is the default. `site` must be the slug of an
|
||||
existing NetBox site, since NetBox requires a site for every device. `location`
|
||||
is optional and may be removed or set to `null`. `region` narrows the site
|
||||
lookup.
|
||||
|
||||
### Mode `listen`
|
||||
|
||||
```json
|
||||
{
|
||||
"mode": "listen",
|
||||
"listen_port": 8731,
|
||||
"scan_key": "the key from the NetBox Synchronizer",
|
||||
"allowed_networks": ["10.0.0.0/24"],
|
||||
"inventory_cache_seconds": 300,
|
||||
"collect_software": true,
|
||||
"max_software_entries": 250
|
||||
}
|
||||
```
|
||||
|
||||
| Setting | Meaning |
|
||||
|---|---|
|
||||
| `listen_port` | TCP port of the agent (default 8731) |
|
||||
| `scan_key` | Shared secret of all agents of one customer (at least 16 characters); only a NetBox Synchronizer with the same key can read the inventory |
|
||||
| `allowed_networks` | Optional networks in CIDR notation that may connect, e.g. the admin network. Empty = any address. Used for the firewall rule and checked by the agent |
|
||||
| `inventory_cache_seconds` | The inventory is collected on request and reused for this time |
|
||||
|
||||
For mode `both`, combine the settings of both modes.
|
||||
|
||||
### Security of the listen mode
|
||||
|
||||
- `GET /v1/info` answers without authentication, with the agent name and
|
||||
version only.
|
||||
- `GET /v1/inventory` needs an HMAC-SHA256 signature (key derived from
|
||||
`scan_key`) over a random nonce and the current time. Requests older than five
|
||||
minutes and repeated nonces are rejected.
|
||||
- The inventory is returned encrypted with AES-256-GCM (a separate key derived
|
||||
from `scan_key`), so serial numbers and software lists never cross the network
|
||||
in clear text – without needing TLS certificates.
|
||||
- The clocks of client and admin PC may differ by at most five minutes (domain
|
||||
time synchronisation is enough).
|
||||
- The agent only reads data; it accepts no commands.
|
||||
|
||||
### Self-signed certificate
|
||||
|
||||
@@ -200,6 +305,10 @@ Custom fields are not required by default. To use them, create them for
|
||||
|
||||
## Usage
|
||||
|
||||
Both distribution methods are fully unattended: the installer runs as SYSTEM,
|
||||
needs no user interaction and no administrator on the client, and the agent
|
||||
stays invisible to users.
|
||||
|
||||
### Distribution with Intune
|
||||
|
||||
Package these four files together as a Win32 app (`.intunewin`):
|
||||
@@ -223,23 +332,82 @@ powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\uninstall.ps1
|
||||
Install behavior:
|
||||
System
|
||||
|
||||
Device restart behavior:
|
||||
No specific action
|
||||
|
||||
Detection rule (rule type "File"):
|
||||
Path: C:\Program Files\NetBox Windows Agent
|
||||
File or folder: agent.exe
|
||||
Detection method: File or folder exists
|
||||
Detection method: String (version)
|
||||
Operator: Greater than or equal to
|
||||
Value: 0.2.0 (the version of agent.exe, see agent.exe --version)
|
||||
Associated with a 32-bit app on 64-bit clients: No
|
||||
```
|
||||
|
||||
Assign the app as **Required** to a device group so it installs without user
|
||||
action. The version rule lets Intune update clients with an older agent. After
|
||||
changes to `agent.exe`, `config.json` or the installation scripts, rebuild the
|
||||
`.intunewin` package and upload it again under
|
||||
**App > Properties > App package file** – a change in the local repository does
|
||||
not update a package that was already uploaded. A changed `config.json` alone
|
||||
(for example a new scan key) is not detected by the version rule; publish it as
|
||||
a new app that supersedes the old one, or use Group Policy.
|
||||
|
||||
### Distribution with Group Policy
|
||||
|
||||
1. Create a folder on a share that the group **Domain Computers** can read, for
|
||||
example `\\fileserver\NetBoxAgent$`, and copy these files into it:
|
||||
|
||||
```text
|
||||
agent.exe
|
||||
config.json
|
||||
install.ps1
|
||||
uninstall.ps1
|
||||
gpo-startup.ps1
|
||||
```
|
||||
|
||||
2. Create a GPO linked to the OU of the computers:
|
||||
**Computer Configuration > Policies > Windows Settings > Scripts
|
||||
(Startup/Shutdown) > Startup > PowerShell Scripts > Add** – script name
|
||||
`\\fileserver\NetBoxAgent$\gpo-startup.ps1`, no parameters.
|
||||
|
||||
3. Make sure the share is reachable at startup:
|
||||
**Computer Configuration > Policies > Administrative Templates > System >
|
||||
Logon > Always wait for the network at computer startup and logon** =
|
||||
*Enabled*.
|
||||
|
||||
At every startup the script compares `agent.exe` and `config.json` on the share
|
||||
with the installed version. If nothing changed, it does nothing; if a file
|
||||
changed or the agent is missing, it runs `install.ps1` from the share. To update
|
||||
all computers, replace the files on the share. The script logs to
|
||||
`C:\ProgramData\NetBox Windows Agent\gpo-startup.log`.
|
||||
|
||||
To remove the agent from all computers of the GPO, add the script parameter
|
||||
`-Uninstall`.
|
||||
|
||||
> `config.json` on the share is readable by all domain computers. In mode
|
||||
> `listen` it contains the scan key, in mode `netbox` the NetBox API token – use
|
||||
> a token with only the permissions listed above.
|
||||
|
||||
### Troubleshooting
|
||||
|
||||
**`agent.exe fehlt im Quellverzeichnis`** (agent.exe missing in source
|
||||
directory) — `SourceDirectory` must be the folder that contains both
|
||||
`agent.exe` and `config.json`:
|
||||
**`agent.exe is missing in the source directory`** — `SourceDirectory` must be
|
||||
the folder that contains both `agent.exe` and `config.json`:
|
||||
|
||||
```powershell
|
||||
-SourceDirectory .\dist\win-x64
|
||||
```
|
||||
|
||||
**The NetBox Synchronizer does not find an agent** — check that the task
|
||||
`NetBox Windows Agent Listener` is running, test the port from the admin PC with
|
||||
`Test-NetConnection <client> -Port 8731`, check firewalls between the networks
|
||||
and that the admin PC is inside `allowed_networks`. The firewall rule applies to
|
||||
the *Domain* and *Private* network profiles, not to *Public*.
|
||||
|
||||
**"Agent-Schlüssel stimmt nicht" in the NetBox Synchronizer** (wrong key) — the
|
||||
key in the app and `scan_key` on the client differ; distribute the
|
||||
configuration again.
|
||||
|
||||
**`RemoteCertificateNameMismatch` or `RemoteCertificateChainErrors`** — set
|
||||
`allow_insecure_tls` to `true` for testing. Permanently, install the correct
|
||||
internal CA and use a certificate name that matches the URL.
|
||||
@@ -265,9 +433,8 @@ Enter the slug of an existing site in `config.json`:
|
||||
detection rule, the `Path` field must contain only the folder. `agent.exe`
|
||||
belongs in the separate `File or folder` field.
|
||||
|
||||
**`400 Bad Request`** — the full response after `FEHLER:` (error) names the
|
||||
field NetBox rejected. Often the configured device role, site or location is
|
||||
missing.
|
||||
**`400 Bad Request`** — the full response after `ERROR:` names the field NetBox
|
||||
rejected. Often the configured device role, site or location is missing.
|
||||
|
||||
## Development
|
||||
|
||||
|
||||
Reference in new issue
Block a user