> For the complete documentation index, see [llms.txt](https://docs.octoxlabs.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.octoxlabs.com/adapters/l/lansweeper.md).

# Lansweeper

|                               |                                                   |
| ----------------------------- | ------------------------------------------------- |
| Category                      | IT asset management                               |
| Asset types                   | Devices, Users, Services                          |
| Authentication                | SQL Server login (SQL authentication or Kerberos) |
| Direction                     | OctoXLabs → Lansweeper (read only)                |
| Supported Lansweeper versions | Not specified                                     |
| Available since               | Not specified                                     |

Lansweeper is an IT asset discovery and inventory tool. This adapter reads the Lansweeper database on Microsoft SQL Server directly. OctoXLabs adds the assets, their installed software, the Active Directory users seen on those assets and, optionally, Windows services to its inventories.

## Use cases

* **Find Lansweeper assets that no EDR covers.** List Lansweeper devices that CrowdStrike does not report.

```
Adapters = lansweeper AND NOT Adapters = falcon-crowdstrike
```

* **Find assets that Lansweeper has not scanned recently.** Last seen comes from the `Lastseen` column.

```
Adapters = lansweeper AND NOT LastSeen last now-30d/d
```

* **List Windows servers in Lansweeper.** Combine the category and OS type.

```
Adapters = lansweeper AND Category = Server AND OS.Type = Windows
```

## Before you begin

### Network

| Source              | Destination                                | Port                | Protocol         |
| ------------------- | ------------------------------------------ | ------------------- | ---------------- |
| OctoXLabs connector | SQL Server host of the Lansweeper database | 1433 (configurable) | TCP (SQL Server) |

With Kerberos, the connector must also reach the KDC (typically the domain controller). The Kerberos port is not set in the code.

### Required permissions

| Scope or role                                                                    | Permission | Needed for                                                                                         |
| -------------------------------------------------------------------------------- | ---------- | -------------------------------------------------------------------------------------------------- |
| Select and List on the Lansweeper database (for example the db\_datareader role) | Read       | Devices, software, users, services                                                                 |
| tblADusers                                                                       | Select     | Active Directory details of users. Without it users are still collected but AD details stay empty. |
| tblADMembership and tblADGroups                                                  | Select     | Group membership (MembersOf). Without them only AD groups stay empty.                              |

The baseline says the account needs read permission on devices and the SQL Server. If you grant permissions per table, include tblADusers, tblADMembership and tblADGroups as well.

## Create credentials in Lansweeper

{% stepper %}
{% step %}

### Open SQL Server Management Studio

Connect to the SQL Server that hosts the Lansweeper database.
{% endstep %}

{% step %}

### Create a login

In the **Security** folder, right-click **Login** and click **New Login**.
{% endstep %}

{% step %}

### Fill in the details

Select the authentication used in the server. Fill in the details and select your Lansweeper database in **Default Database**.
{% endstep %}

{% step %}

### Grant read access

Give the user **Select** and **List** privileges on the database, for example the **db\_datareader** role.
{% endstep %}

{% step %}

### Save and sign in once

Save the user. Log in to the database with this user once to avoid an error.
{% endstep %}
{% endstepper %}

{% hint style="info" %}
**Kerberos (optional).** Set Auth Type to Kerberos to use Active Directory credentials instead of SQL authentication. In password mode the connector uses the username and password to get a ticket. In keytab mode you upload a keytab generated with `ktpass` on a domain controller and no password is needed. The realm can be left empty when the username is in UPN format (`user@REALM`). After connecting, query `sys.dm_exec_connections` for your session and confirm `auth_scheme` is `KERBEROS`.
{% endhint %}

{% hint style="info" %}
With **Use PyODBC Driver** (or Kerberos), ODBC Driver 17 or 18 for SQL Server must be installed on the connector machine. For SQL authentication the connector tries Driver 17 first, then Driver 18. For Kerberos it tries Driver 18 first.
{% endhint %}

## Connection parameters

| Parameter                | Required    | Type    | Default  | Description                                                                                                 |
| ------------------------ | ----------- | ------- | -------- | ----------------------------------------------------------------------------------------------------------- |
| IP                       | Yes         | String  | None     | IP address of the SQL Server host.                                                                          |
| Port                     | No          | Integer | 1433     | SQL Server port.                                                                                            |
| Domain                   | No          | String  | None     | Domain FQDN. When set, the login is sent as `domain\username`.                                              |
| Database                 | Yes         | String  | None     | Name of the Lansweeper database.                                                                            |
| Username                 | Yes         | String  | None     | Login with read permission on the database.                                                                 |
| Password                 | Conditional | String  | None     | Required for SQL authentication and for Kerberos Mode password. May be empty for Kerberos Mode keytab.      |
| Use PyODBC Driver        | No          | Boolean | False    | Use pyodbc instead of pymssql. Needed for some SQL Server configurations.                                   |
| Batch Size               | No          | Integer | 300      | Rows fetched per batch.                                                                                     |
| Fetch Services           | No          | Boolean | False    | Collect the Windows service inventory of each asset.                                                        |
| Query Timeout            | No          | Integer | 60       | Query timeout in seconds.                                                                                   |
| Auth Type                | No          | String  | SQL      | `SQL` or `Kerberos`.                                                                                        |
| Kerberos Mode            | No          | String  | password | `password` or `keytab`.                                                                                     |
| Kerberos Realm           | No          | String  | None     | Active Directory realm in uppercase, for example `CORP.LOCAL`. Optional when the username is in UPN format. |
| KDC IP                   | No          | String  | None     | Host name or IP of the KDC, typically a domain controller. Optional when the host already resolves it.      |
| Kerberos SPN             | No          | String  | None     | Service principal name override, for example `MSSQLSvc/sqlserver.corp.local:1433`.                          |
| Keytab                   | Conditional | File    | None     | Required when Kerberos Mode is keytab.                                                                      |
| Encrypt                  | No          | Boolean | True     | TLS between client and SQL Server. Applied only with Kerberos.                                              |
| Trust Server Certificate | No          | Boolean | True     | Skip certificate chain validation. Applied only with Kerberos.                                              |

## What the connection test does

The test opens a connection to the database. With Kerberos it also checks that SQL Server reports `auth_scheme` as `KERBEROS`, and fails if it does not.

## API endpoints called

| Method | Path                                                                              | Purpose                                                                                                                                                                           |
| ------ | --------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| SQL    | tblAssets joined with tsysAssetTypes and tsysOS                                   | Reads assets with asset type and OS name. If the joined query fails before returning rows, the connector retries `SELECT * FROM tblAssets` and Category and OS fields stay empty. |
| SQL    | tblSoftware, tblLinuxSoftware, tblSoftwareUni                                     | Reads installed software of the assets in each batch.                                                                                                                             |
| SQL    | tblServices, tblServicesUni, tblServiceStartMode, tblServiceState, tblAssetCustom | Reads Windows services. Only with Fetch Services.                                                                                                                                 |
| SQL    | tblUsersInGroup, tblADusers                                                       | Reads users seen on assets. Falls back to a query without tblADusers.                                                                                                             |
| SQL    | tblADMembership, tblADGroups                                                      | Reads AD group membership of users.                                                                                                                                               |

Lansweeper is read through SQL, not an HTTP API.

## Fields fetched

### Devices

| Lansweeper field                    | OctoXLabs field               |
| ----------------------------------- | ----------------------------- |
| AssetName                           | Hostname (primary identifier) |
| Lastseen                            | Last seen                     |
| IPAddress                           | IpAddresses (valid IPv4 only) |
| Mac                                 | MacAddresses                  |
| Software rows                       | InstalledSoftware             |
| Domain (lowercase)                  | Domain                        |
| AssetTypename (mapped), else OSname | Category                      |
| OSname                              | OS.FullOsString and OS.Type   |

### Users

| Lansweeper field         | OctoXLabs field                                       |
| ------------------------ | ----------------------------------------------------- |
| Username with Domainname | Primary key (username\@domain, domain without suffix) |
| Domainname               | Domain                                                |
| email                    | Email                                                 |
| Firstname                | FirstName                                             |
| Lastname                 | LastName                                              |
| Displayname              | DisplayName                                           |
| Office                   | Location                                              |
| whenCreated              | CreatedTime                                           |
| AD groups                | MembersOf                                             |

### Services (Fetch Services)

| Lansweeper field                    | OctoXLabs field  |
| ----------------------------------- | ---------------- |
| Service Name with a hash of AssetID | PrimaryKey       |
| Service Name                        | Name             |
| windows\_service                    | ServiceType      |
| State                               | DeploymentStatus |

## Troubleshooting

| Error message                                                                                                             | Cause                                                                                                                                                                                                                                            | Fix                                                                                                                                                                     |
| ------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| MSSQL query failed \[{label}]: {cause}; {n} row(s) read before failure. Detail: {detail}                                  | A SQL query failed. The cause is one of: query or connection timeout (DB-Lib 20003), connection dropped (DB-Lib 20047), no result set, read from server failed (DB-Lib 20004), login or authentication failure, or an unexpected database error. | Use the cause text in the message. Check network and firewall for dropped connections, raise Query Timeout for timeouts, and verify the credentials for login failures. |
| No ODBC Driver found. Install 'ODBC Driver 17' or 'ODBC Driver 18' for SQL Server.                                        | Use PyODBC Driver is on but neither driver is installed on the connector host.                                                                                                                                                                   | Install ODBC Driver 17 or 18 for SQL Server, or turn the option off.                                                                                                    |
| Password is required for SQL Server Authentication.                                                                       | Auth Type is SQL and the password is empty.                                                                                                                                                                                                      | Enter the password.                                                                                                                                                     |
| Keytab is required when kerberos\_mode is 'keytab'.                                                                       | Kerberos Mode is keytab and no keytab was uploaded.                                                                                                                                                                                              | Upload the keytab file.                                                                                                                                                 |
| Password is required when kerberos\_mode is 'password'.                                                                   | Kerberos Mode is password and the password is empty.                                                                                                                                                                                             | Enter the password.                                                                                                                                                     |
| Kerberos config failed: SQL Server reports auth\_scheme='{scheme}'. Check SPN registration in AD and the Encrypt setting. | The connection works but SQL Server did not use Kerberos, for example because of a wrong SPN.                                                                                                                                                    | Check the SPN registration in Active Directory and the Encrypt setting.                                                                                                 |
| Kerberos authentication failed: wrong password or pre-authentication rejected.                                            | The KDC rejected the credentials.                                                                                                                                                                                                                | Check the username and password.                                                                                                                                        |
| Cannot reach KDC. Check the kdc\_ip value and network/firewall.                                                           | The KDC is not reachable.                                                                                                                                                                                                                        | Check KDC IP and the firewall.                                                                                                                                          |
| Clock skew between client and KDC is too large. Sync the system clock.                                                    | Time differs too much between the connector and the KDC.                                                                                                                                                                                         | Synchronize the clock.                                                                                                                                                  |
| Principal not found in Active Directory. Check the realm and username.                                                    | The Kerberos principal does not exist.                                                                                                                                                                                                           | Check the realm and username.                                                                                                                                           |
| Keytab does not contain a matching key for the principal.                                                                 | The keytab does not match the account.                                                                                                                                                                                                           | Generate the keytab again for this principal.                                                                                                                           |
| Encryption type mismatch between client/keytab and KDC.                                                                   | No common encryption type.                                                                                                                                                                                                                       | Check the encryption types of the account and keytab.                                                                                                                   |
| {query\_name} failed before returning any row ({error}); retrying {fallback}.                                             | A join table is missing or unreadable. The connector retries with a simpler query and some fields stay empty.                                                                                                                                    | Grant Select on the tables named in the baseline.                                                                                                                       |
| AD group membership could not be read ({error}); MembersOf stays empty for this run.                                      | tblADMembership or tblADGroups is not readable.                                                                                                                                                                                                  | Grant Select on both tables.                                                                                                                                            |

## Change history
