Skip to content

Classification Rule

A Classification Rule defines how a discovered device is classified into a Nautobot Location, Role, or Tenant. Each rule extracts a value from a device attribute using a regex pattern and matches it against a field on a Nautobot model. Rules are evaluated in weight order; the first matching enabled rule in each target set wins.

Fields

  • name (string): Unique name for the rule.
  • description (string): Optional description.
  • enabled (boolean): Whether this rule is active (default: true).
  • weight (integer): Evaluation priority. Lower weight is evaluated first (default: 100).
  • target_field (string): Which device field this rule populates — location, role, or tenant.
  • source_field (string): Device attribute the Source Pattern is applied to (currently hostname).
  • source_pattern (string): Regex with a named capture group value. Example: ^(?P<value>[a-z]{2,4})-.
  • source_transform (string): Optional transformation applied to the extracted value before lookup (none, lowercase, uppercase, capitalize, title).
  • content_type (foreign key): Nautobot model the extracted value is matched against. Must be dcim.location, extras.role, or tenancy.tenant.
  • match_field (string): Field on the Match Against model used for comparison, e.g. name.
  • match_operator (string): Comparison operator (exact, iexact, contains, icontains, startswith, istartswith).
  • match_filters (JSON): Extra equality filters that narrow the lookup, e.g. {"status__name": "Active"}. Up to two foreign-key traversals are supported.
  • ip_scope (array): Optional list of IP prefixes. When set, the rule only applies to devices whose IP falls within one of these prefixes.

Behavior

  • Rules are only evaluated against devices with status Not Imported.
  • A rule fires only when the lookup returns exactly one candidate. Zero or multiple results are treated as no match.
  • target_field and content_type must be compatible: location ↔ Location, role ↔ Role, tenant ↔ Tenant. Mismatched combinations are rejected at save time.
  • source_pattern must include a named capture group value; validation rejects patterns that omit it.
  • match_filters keys are limited to two foreign-key traversal levels (e.g., parent__location_type__name is allowed; deeper paths are rejected at save time).