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 (read-only): Nautobot model the extracted value is matched against — dcim.location, extras.role, or tenancy.tenant. Derived from target_field rather than stored, so it cannot be set through the UI or the REST API.
  • match_field (string): Field on the matched Location, Role, or Tenant 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.
  • content_type always follows target_field: location → Location, role → Role, tenant → Tenant. It is computed on access, so changing target_field changes the model matched against; the two can never disagree.
  • 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).

REST API

content_type is returned on reads but ignored in POST/PUT/PATCH bodies — set target_field (location, role, or tenant) instead. Because it is no longer a database field, it also cannot be used to filter, sort, or query rules through the REST API or GraphQL; use target_field for those.