Metadata-Version: 2.4
Name: nautobot-app-ssot-lantronix
Version: 0.8.0
Summary: Nautobot SSoT integration that syncs Lantronix console servers, console ports and attached devices from Percepxion.
License-Expression: Apache-2.0
Project-URL: Repository, https://github.com/Lantronix/nautobot-app-ssot-lantronix
Project-URL: Changelog, https://github.com/Lantronix/nautobot-app-ssot-lantronix/blob/main/CHANGELOG.md
Requires-Python: <3.15,>=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: nautobot<4.0,>=3.1
Requires-Dist: nautobot-ssot<5,>=4.8
Requires-Dist: requests>=2.31
Provides-Extra: dev
Requires-Dist: pytest>=8; extra == "dev"
Requires-Dist: ruff>=0.6; extra == "dev"
Requires-Dist: nornir-nautobot>=4; extra == "dev"
Provides-Extra: servicenow
Requires-Dist: nautobot-ssot[servicenow]<5,>=4.8; extra == "servicenow"
Dynamic: license-file

# nautobot-app-ssot-lantronix

A [Nautobot SSoT](https://github.com/nautobot/nautobot-app-ssot) integration that keeps Nautobot current with the Lantronix SLC 9000, SLC 8000 and EMG console servers managed by Percepxion. Nobody has to type console server inventory into Nautobot by hand.

The **Percepxion to Nautobot** job reads Percepxion and:

- creates each console server in Nautobot with the right device type, so its console server ports come from the device type
- labels each console server port with the name configured on the console server, and describes it with the hostname of the attached device
- records the port state and the attached device's type, model, OS version, serial, hostname and management IP in custom fields on the port, when the console server reports them
- adds an **Open console** link on each port that launches an SSH session through the console server (`ssh://<console server>:<the port's SSH port>`), kept in step with the console server's own settings

The job never writes to Percepxion or to a console server, and never deletes anything in Nautobot. Like every SSoT job, it can run as a dry run that shows the diff without writing.

The app also registers the **AOOB console coverage gate** job, and two optional modules build on the synced data:

- **ServiceNow console paths**: the stock nautobot-ssot ServiceNow job plus a "Connects to" relationship between each attached device and the console server port that reaches it.
- **Golden Config**: a Nornir dispatcher that backs up SLC configuration with every secret masked, for Nautobot Golden Config backup, intended and compliance jobs.

![The SSoT sync diff for a console server and its ports, read from Percepxion](https://raw.githubusercontent.com/Lantronix/nautobot-app-ssot-lantronix/main/docs/images/ssot-sync-diff.png)

![Console server ports labeled with the name set on the console server and described with the attached device's hostname](https://raw.githubusercontent.com/Lantronix/nautobot-app-ssot-lantronix/main/docs/images/console-server-ports.png)

![A console server port with the attached device's details in custom fields, and an Open console button](https://raw.githubusercontent.com/Lantronix/nautobot-app-ssot-lantronix/main/docs/images/port-attached-device.png)

## Requirements

| | |
|---|---|
| Nautobot | 3.1 or later, below 4.0 |
| nautobot-ssot | 4.8 or later, below 5 |
| Python | 3.11 to 3.14 |
| Percepxion | Percepxion cloud or on-premises, and a Percepxion user with the **tenant_user** role in the organization you sync. No administrator role is needed. |
| Device types | Lantronix SLC and EMG device types, imported before the first sync. The definitions are in [`docker/device-types`](docker/device-types). |

### Compatibility

| nautobot-app-ssot-lantronix | Nautobot | nautobot-ssot | Python |
|---|---|---|---|
| 0.3.0 and later | 3.1 and later 3.x | 4.8 and later 4.x | 3.11 to 3.14 |
| 0.1.0 to 0.2.0 | 3.1 and later 3.x | 4.8 and later 4.x | 3.10 to 3.14 |

CI runs the tests against Nautobot 3.1 and 3.2. Beyond nautobot-ssot, the core sync needs no other app or service. The optional ServiceNow module needs `nautobot-ssot[servicenow]`, and the optional Golden Config module needs Nautobot Golden Config and a Netmiko release that includes the `lantronix_itmgos` driver.

## Install

1. Install the package into the Nautobot environment:

   ```
   pip install nautobot-app-ssot-lantronix
   ```

   To pin a version, install `nautobot-app-ssot-lantronix==X.Y.Z` with a version from the [releases](https://github.com/Lantronix/nautobot-app-ssot-lantronix/releases). For the ServiceNow module, install `"nautobot-app-ssot-lantronix[servicenow]"`. For a Docker install, follow [Docker](#docker) instead of these steps.

2. Enable and configure the app in `nautobot_config.py` (see [Configuration](#configuration)).

3. Run `nautobot-server post_upgrade` and restart Nautobot and its Celery worker.

4. Import the device types for your hardware from [`docker/device-types`](docker/device-types) with **Devices > Device Types > Import**, and create the location set as `default_location`.

5. Run the job (see [First sync](#first-sync)).

On the first run the app creates the manufacturer `Lantronix`, the platform `Lantronix ITM OS` (network driver `lantronix_itmgos`), the device role you configure, the custom fields it writes and the **Lantronix: Open console** custom link, and reuses any that already exist.

## Docker

This runs Nautobot 3.2 with nautobot-ssot and the app in Docker, including its database and Redis. You need Docker with Compose and a Percepxion user with the **tenant_user** role.

1. Clone the repository and create your settings file:

   ```
   git clone https://github.com/Lantronix/nautobot-app-ssot-lantronix.git
   cd nautobot-app-ssot-lantronix/docker
   cp env.example .env
   ```

2. Fill in every value in `.env`. Generate the secret key and passwords with `openssl rand -hex 32`, and the API token with `openssl rand -hex 20`.

3. Build and start Nautobot. The first start runs the database migrations and can take several minutes.

   ```
   docker compose up -d --build
   ```

4. Import the device types and create the **Console Servers** location. Running this again changes nothing that already exists.

   ```
   docker compose exec nautobot nautobot-server nbshell --command "exec(open('/opt/nautobot-lantronix/setup.py').read())"
   ```

5. Open http://localhost:8080, sign in as `admin` with `NAUTOBOT_SUPERUSER_PASSWORD`, and follow [First sync](#first-sync).

To use another port, set `NAUTOBOT_PORT` in `.env`. The stack runs as Compose project `nautobot-lantronix`, so its containers and database stay separate from any other Nautobot on the host.

## First sync

1. Go to **Jobs > Jobs**, edit **Percepxion to Nautobot** and enable it.
2. Run it with **Dryrun** on to see the diff without writing anything.
3. Run it again with **Dryrun** off.

## Configuration

The Percepxion endpoint, organization and credentials come only from environment variables. They're never stored in the Nautobot database, job inputs or logs.

| Variable | |
|---|---|
| `PERCEPXION_URL` | API base, for example `https://api.percepxion.ai/api`. Must use `https://`. |
| `PERCEPXION_USERNAME`, `PERCEPXION_PASSWORD` | The Percepxion user the job signs in as |
| `PERCEPXION_ORG_ID` | The Percepxion organization to sync |
| `PERCEPXION_CA_BUNDLE` | Optional CA bundle for on-premises Percepxion |
| `PERCEPXION_VERIFY` | Optional. `false` turns TLS certificate checking off; the job log warns on every run. Prefer `PERCEPXION_CA_BUNDLE`. |
| `PERCEPXION_WEBHOOK_SECRETS` | Optional. Signing secrets for the events URL, comma-separated, each at least 32 characters. Two while rotating. See [Syncing on change](#syncing-on-change). |
| `PERCEPXION_SYNC_USER` | Optional. The Nautobot user that focused syncs started by events run as. Required for the events URL. |

```python
PLUGINS = ["nautobot_ssot", "nautobot_ssot_lantronix"]

PLUGINS_CONFIG = {
    "nautobot_ssot": {"hide_example_jobs": True},
    "nautobot_ssot_lantronix": {
        "default_location": "Main Site",   # location for new console servers (must exist)
        "default_role": "Console Server",
        "default_status": "Active",
        "ssh_base_port": 3000,             # used only for units whose port settings aren't read
        # "read_port_config": False,       # don't read each port's SSH port (see Open console)
        "model_rules": {},                 # see Device models
        # "adoption_locations": ["Main Site"],  # where existing devices may be adopted
        # "manage_cables": True,           # console cables follow the SLC (see Console cables)
        # "webhook_secrets": [...],        # or PERCEPXION_WEBHOOK_SECRETS (see Syncing on change)
        # "sync_user": "percepxion-sync",  # or PERCEPXION_SYNC_USER
    },
}
```

A missing setting stops the job with an error that names the setting, never its value.

Each run logs in to Percepxion, reads, then revokes its refresh token and closes the connection. Percepxion keeps the access token it issued valid until that token expires, which the app can't shorten.

### Device models

Percepxion reports an SLC 9000's model as its total number of serial ports and doesn't report the Ethernet switch module or the power supply type, so several SLC 9000 SKUs look the same in Percepxion. The job picks the device type from `show sysconfig` output stored in Percepxion (if anyone has run `show sysconfig` on the unit through Percepxion, in the console editor or a CLI job), then from `model_rules`, then from a single device type that matches the port counts. A rule maps `MODEL|RJ45|USB` to a device type, for fleets that buy one variant:

```python
"model_rules": {"SLC9016|16|0": "lantronix-slc9016-16e"}
```

A device the job can't resolve isn't created; the job log names it and the candidate types. EMG units resolve from Percepxion data alone.

### What the job changes in Nautobot

| Object | Job writes | Job never changes |
|---|---|---|
| Console server (device) | created with name, type, location, role, platform, serial and the Percepxion device ID; management IP in a custom field, never in IPAM | location, role or type of an existing device |
| Console server port | label (the port's name on the console server), description (attached device hostname), port state and attached-device custom fields | name, anything else |
| Console cable | only with `manage_cables` on, see [Console cables](#console-cables) | any cable that doesn't run between a synced console server port and a console port |

The console server is the source of truth for port labels and descriptions. A label edited by hand in Nautobot is overwritten on the next sync; rename the port on the console server instead. An existing Nautobot device is adopted only when it's a Lantronix device on the Lantronix platform (or none) whose serial matches, or that has no serial and the same name; anything else with the same name is reported and left alone. Adoption links the device and renames it to its Percepxion name, with no approval step, and the job log records the old name.

Adoption is limited to devices in `default_location` or a location under it. To adopt elsewhere, list the location names in `adoption_locations`, or set `["*"]` for any location. A matching device outside those locations is reported in the job log and left alone. Each name must match exactly one location; if two locations share a name, no device is adopted under that name until you rename one. Tenants aren't checked, so keep `adoption_locations` to locations whose devices this Percepxion organization should manage.

### Who can run the job

Anyone with permission to run **Percepxion to Nautobot** creates and updates console servers and their ports through it, whatever their own object permissions on devices. That is how Nautobot SSoT jobs work. Grant the run permission for this job only to people who should manage that inventory.

The job has a soft time limit of 2 hours and a hard limit 5 minutes later. Change either on the job's edit page under **Jobs > Jobs**.

## Console cables

With `"manage_cables": True` in the app's settings (or `PERCEPXION_MANAGE_CABLES=true` in the environment), each run makes the console cables on synced SLC ports match what the SLC reports, after it syncs devices and ports. Percepxion becomes the system of record for those cables: a cable drawn by hand on a synced SLC port is removed or replaced when the SLC reports something different. It's off by default.

The rules are narrow on purpose:

- A port's cable is removed only when the SLC reports the port **Disconnected**. A port that is Identifying, Unidentified or Authenticating keeps its cable.
- A cable is created only when the SLC reports an attached device whose serial matches exactly one Nautobot device in the SLCs' locations, narrowed by `adoption_locations` (or, with no serial match, whose name matches exactly one such device, ignoring case), and that device has one console port, or exactly one named Console. A name-only match fills free ports only.
- A device that turns up on a different SLC port moves once its old port reports Disconnected: its old cable goes and a new one is drawn. The serial and hostname are the attached device's own claim, so a report alone never pulls a cable off a port that still has something plugged in.
- Cables that end on anything other than a console port, such as a patch panel's front port, are never touched, on either end. The job log reports them.
- Ports the telemetry view didn't report this run are left as they are.

New cables have status Connected, the label "Observed by SLC discovery" and the tag `lantronix-discovered`. Each change adds a note to the attached device naming the SLC port and the reason, and the job log lists every change and every port it left alone with why. All cable changes in a run are written in one transaction and appear in Nautobot's change log under the job. A dry run logs the plan and writes nothing; because the devices aren't written either, a dry run plans only for SLCs already in Nautobot.

The job's **Manage console cables** input turns it on or off for one run. Leave it at **App setting** for scheduled and API runs, which send no input.

## Syncing on change

**Percepxion to Nautobot** reads every console server. Two jobs keep Nautobot current between its runs by syncing only the units that changed, usually within seconds of the change:

- **Percepxion focused sync** runs the same sync for just the requested console servers, so every other device, port and cable is left alone. Requests that arrive while one waits to start join it, so a burst of changes across a few units becomes one run. If another Percepxion sync is running, it waits for that one and runs after it. Events and the change watch start it; run on its own with nothing waiting, it does nothing. Enable it under **Jobs > Jobs**.
- **Percepxion change watch** reads each linked console server's port state and requests a focused sync for the ones whose ports changed since its last check. Enable it and schedule it with a custom crontab such as `*/5 * * * *`. It needs no inbound connection, at the cost of one port-state read per unit per check. With events flowing, schedule it rarely or not at all.

**Events.** With `webhook_secrets` and `sync_user` set and the focused sync job enabled, the app takes signed Percepxion events at:

```
POST /api/plugins/ssot-lantronix/events/
```

Events use webhook-payload v1: an HMAC-SHA256 signature over `<timestamp>.<body>`, sent in the `X-Percepxion-Timestamp` and `X-Percepxion-Signature: v1=<hex>` headers. The URL needs no Nautobot token, because the signature is the authentication. A port attach, port state or device status event for `PERCEPXION_ORG_ID` requests a focused sync of that console server and answers 202. Other event types and repeated event IDs answer 204. A bad signature, or a timestamp more than 5 minutes off, answers 401. A malformed body, or another organization's event, answers 400. Until events are fully set up, the URL answers 404, and the worker log's `nautobot_ssot_lantronix.events` line says what's missing. Nothing from the event body is logged or stored beyond the device ID. Nautobot has to be reachable from whatever sends the events.

Focused syncs run as `sync_user`, or as the user who scheduled the change watch. They write through the same SSoT job, so the change log and the job results show each one.

## Open console

The link opens `ssh://<address>:<SSH port>` with your SSH client, and you sign in to the console server as yourself. It appears only on the unit's numbered ports (`Port-01` and up). The app keeps the link's text and URL as shipped; its weight, group and button style are yours to change.

Console access is in three places:

- **The device you want to reach.** Any device whose console port is cabled in Nautobot to a synced console server port gets an **Open console** button on its own page, so you don't need to know which console server port it's on. The tooltip names the console server and port. With several console ports cabled, each gets a button labelled with its port name.
- **The console server port**, as the custom link described here.
- **The console server.** Its page lists the ports in use (cabled in Nautobot, or with a device attached according to Percepxion), each with its button.

A user sees a button only for a cable, console server port and console server they may view.

**Address.** The device's primary IP, or the IPv4 management address the console server reports to Percepxion.

**SSH port.** Each run reads every port's SSH port and whether SSH to the port is on from the console server's configuration in Percepxion (the Device Ports settings: **Starting SSH Port**, or `set deviceport port <n> sshport <tcp port>` for one port) into the port's **Console SSH port** custom field. When someone changes them on the console server, the link follows after the console server next uploads its configuration and the job next runs.

- A port with SSH turned off on the console server has `off` in the field and gets no link.
- A unit whose configuration Percepxion doesn't hold, or can't return, keeps the ports from the last run that read them. A port with nothing in the field uses `ssh_base_port` plus the port number, which is the factory numbering (3001 for port 1).

On the console server, direct SSH access is off by default on every port. Turn it on for the ports you want to reach, for example `set deviceport port 1-48 sshin enable` (answer `yes` to the confirmation).

### What the configuration read involves

Percepxion's port search doesn't report a port's SSH port, so the app reads it from the unit's stored configuration, one request per console server per run (`POST /v1/telemetry/config/edit`; despite the name it changes nothing, and the request that saves a configuration isn't on the app's list of allowed requests).

That response is the unit's whole settings tree. Percepxion masks its password fields, but SNMP community strings and similar detail are in it. The app reads two settings per port, the SSH port and whether SSH is on, and drops the rest before anything else sees it: nothing else is stored or logged. The account needs no extra rights for this; it can already read the configuration.

To turn the read off, set `"read_port_config": False` in the app's settings, or `PERCEPXION_READ_PORT_CONFIG=false` in the environment. Every link then uses `ssh_base_port` plus the port number.

## Console coverage gate

The **AOOB console coverage gate** job reports, for the devices you choose, which ones have a ready console path: a console cable in Nautobot to a port on a synced SLC, with that port in a ready state (Managed or Identified by default). Run it before a change, and stop the change when any device has no way back.

The `oob_coverage_gate` role in the [lantronix.oob](https://github.com/Lantronix/ansible-collection-oob) Ansible collection runs this job by name and fails the play when a device isn't covered.

The app registers the job; enable it under **Jobs** after you install or upgrade. It needs the console cables in Nautobot: each device's console port cabled to the SLC console server port that reaches it. The SSoT job doesn't create those cables.

The job is read only and reports only what the user running it may view; a cable whose SLC end the user can't see is reported as `peer_not_visible`, with no SLC details. It fails when any device in scope isn't covered, gives each one a reason (`no_console_port`, `no_console_cable`, `peer_not_visible`, `peer_not_console_server`, `slc_not_synced`, `port_name_unparsed`, `no_slc_host`, `port_state_unknown`, `port_state_not_ready` or `ssh_disabled`, meaning SSH to that console server port is turned off on the unit), and attaches the full report as `console-coverage.json` (schema `aoob.console-coverage/v1`).

## ServiceNow console paths (optional)

With nautobot-ssot's ServiceNow integration enabled (`"enable_servicenow": True` under `nautobot_ssot`, with its instance and credential settings), the app registers **Nautobot ⟹ ServiceNow (with console paths)**. It runs the stock device, interface, model and location sync, then adds a `cmdb_rel_ci` "Connects to::Connected by" relationship from each attached device to its console server, with the port number. Both CIs must already be in ServiceNow. The job never deletes records; links in ServiceNow with no Nautobot cable behind them are logged.

Set `"servicenow_console_link_parent": "console_server"` under `nautobot_ssot_lantronix` to make the console server the parent of each link instead.

## Golden Config (optional)

With Nautobot Golden Config installed, map the platform's network driver to the app's dispatcher:

```python
PLUGINS_CONFIG["nautobot_plugin_nornir"] = {
    "dispatcher_mapping": {
        "lantronix_itmgos": "nautobot_ssot_lantronix.golden_config.dispatcher.NetmikoLantronixItmgos",
    },
}
```

Backups use the console server's own configuration export and need a Netmiko release that includes the `lantronix_itmgos` driver. The dispatcher replaces the secrets it recognizes with `<secret hidden>`: prompted passwords, phrases and keys, SNMP communities, and local user password hashes. It then refuses to save the backup if anything still looks like a secret: a prompted secret that isn't masked, a value on the same line as a setting named like a secret, part of a value left behind, or key material. The error names the line and the setting, never the value. If a backup of yours is refused, open an issue with that error line so the format can be added.

## Troubleshooting

| Symptom | Check |
|---|---|
| Job isn't listed or can't run | **Jobs > Jobs**: enable **Percepxion to Nautobot** after installing or upgrading the app |
| Job stays pending | The Celery worker isn't running |
| Events URL answers 404 | Set `webhook_secrets` and `sync_user` (an existing, active user) and enable **Percepxion focused sync**. The worker log's `nautobot_ssot_lantronix.events` line names what's missing. |
| Job shows **Failed** and you need the reason | The **Sync failed** line in the job result's log, or the `nautobot_ssot_lantronix.sync` line in the worker log (`docker compose logs worker`). The job result's traceback has the full detail. |
| Job fails with a login error | `PERCEPXION_USERNAME` and `PERCEPXION_PASSWORD`. Fix them and restart Nautobot and the worker. |
| Job fails with "was redirected" | `PERCEPXION_URL` answers with a redirect. The job never follows redirects; use the final address. |
| Job is stopped partway on a large fleet | The job's time limit. Raise it on the job's edit page. |
| An existing device isn't adopted | It's outside `adoption_locations`, or the job log gives another reason |
| Job fails with "Percepxion read failed" and an HTTP status | The account needs the **tenant_user** role in `PERCEPXION_ORG_ID`. Check the organization ID matches the one in Percepxion. |
| Device missing after a sync | The job log names each skipped device and why: ambiguous model, device type not imported, a duplicate name, or a conflict with an existing Nautobot device. Devices outside the configured organization are counted, not named. |

## Support

- Bugs and feature requests: [GitHub Issues](https://github.com/Lantronix/nautobot-app-ssot-lantronix/issues). Include the app, Nautobot and nautobot-ssot versions, and the job log.
- Questions about Percepxion or Lantronix console servers: [Lantronix Technical Support](https://www.lantronix.com/technical-support/).

## License

Apache-2.0
