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, ortenant.source_field(string): Device attribute the Source Pattern is applied to (currentlyhostname).source_pattern(string): Regex with a named capture groupvalue. 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 bedcim.location,extras.role, ortenancy.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_fieldandcontent_typemust be compatible:location↔ Location,role↔ Role,tenant↔ Tenant. Mismatched combinations are rejected at save time.source_patternmust include a named capture groupvalue; validation rejects patterns that omit it.match_filterskeys are limited to two foreign-key traversal levels (e.g.,parent__location_type__nameis allowed; deeper paths are rejected at save time).