nsmcp::AccessDiagnosticTool method classify (public)

 <instance of nsmcp::AccessDiagnosticTool[i]> classify record maps \
    target

Defined in /usr/local/ns/tcl/nsmcp/traffic-tools.tcl

Classify a request using the available fallback routing rules. Evaluate supported map forms in order and retain unknown conditions instead of claiming an exact match.

Parameters:
record (required)
Recorded request fields or routing-evidence dictionary.
maps (required)
Ordered routing map entries to evaluate.
target (required)
Target connection pool used for the diagnostic comparison.
Returns:
The fallback classification dictionary.

Testcases:
No testcase defined.
Source code:
set matches {}
set unknown 0
set index 0
foreach map $maps {
    set id $index
    incr index
    if {[llength $map] ni {4 5}} {
        incr unknown
        continue
    }
    lassign $map method base glob inherit condition
    if {$method ne [dict get $record method]} {
        continue
    }
    if {$base ne "/" || $glob ne "*" || $inherit ne "inherit" || [llength $map]!=5} {
        incr unknown
        continue
    }
    if {[llength $condition]!=2 || ![string equal -nocase [lindex $condition 0] user-agent]} {
        incr unknown
        continue
    }
    if {![dict exists $record userAgent]} {
        incr unknown
        continue
    }
    if {[string match [lindex $condition 1] [dict get $record userAgent]]} {
        lappend matches $id
    }
}
if {[dict get $record pool] eq "unknown"} {
    set category unknown
} elseif {[llength $matches]} {
    set category [expr {[dict get $record pool] eq $target ? "matching-rule-in-target" : "matching-rule-other-pool-candidate"}]
} elseif {$unknown || ![dict exists $record userAgent]} {
    set category unknown
} elseif {[regexp -nocase {bot|crawl|spider|baidu|knowledge} [dict get $record userAgent]] && [dict get $record pool] ne $target} {
    set category bot-like-unmatched-heuristic
} else {
    set category no-target-rule-match
}
return [dict create category $category matchingRuleIndexes $matches unknownRules $unknown]
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: