nsmcp::LogErrorSummaryTool method options (protected)

 <instance of nsmcp::LogErrorSummaryTool[i]> options arguments

Defined in /usr/local/ns/tcl/nsmcp/log-summary.tcl

Parameters:
arguments (required)

Testcases:
No testcase defined.
Source code:
if {[lindex $arguments 1] ne "object"} {
    error "Expected an arguments object"
}
set values {timezone UTC maxGroups 20 severities {Error Fatal Bug}}
set seen {}
foreach {key type value} [lindex $arguments 2] {
    if {$key ni {period timezone lastMinutes from to maxGroups severities literal} || $key in $seen} {
        error "Unknown or duplicate summary argument"
    }
    lappend seen $key
    if {$key eq "literal"} {
        if {$type ne "string" || $value eq {} || [string length [encoding convertto utf-8 $value]]>1024
            || [regexp {[\x00\r\n]} $value]} {
            error "literal must be a nonempty single-line string of at most 1024 UTF-8 bytes"
        }
        dict set values literal $value
        continue
    }
    if {$key eq "severities"} {
        if {$type ne "array" || [llength $value]%3 || [llength $value]<3 || [llength $value]>12} {
            error "Invalid severities array"
        }
        set selected {}
        foreach {index itemType severity} $value {
            if {$itemType ne "string" || $severity ni {Warning Error Fatal Bug} || $severity in $selected} {
                error "Invalid or duplicate severity"
            }
            lappend selected $severity
        }
        dict set values severities $selected
        continue
    }
    set expected [expr {$key in {period timezone} ? "string" : "number"}]
    if {$type ne $expected || ($type eq "number" && ![string is entier -strict $value])} {
        error "Invalid summary argument type"
    }
    dict set values $key $value
}
set timezone [dict get $values timezone]
if {[string length $timezone]>128 || ![regexp {^[A-Za-z][A-Za-z0-9_+-]*(/[A-Za-z][A-Za-z0-9_+-]*)*$} $timezone] || [catch {
    clock format [clock seconds] -timezone $timezone
}]} {
    error "Invalid timezone"
}
set selectors [expr {[dict exists $values period]+[dict exists $values lastMinutes]+([dict exists $values from] || [dict exists $values to])}]
if {$selectors>1} {
    error "Use one time selector: period, lastMinutes or from/to"
}
set now [clock seconds]
if {[dict exists $values from] || [dict exists $values to]} {
    if {![dict exists $values from] || ![dict exists $values to]} {
        error "Supply both from and to"
    }
} elseif {[dict exists $values lastMinutes]} {
    set minutes [dict get $values lastMinutes]
    if {$minutes<1 || $minutes>10080} {
        error "lastMinutes must be 1..10080"
    }
    dict set values from [expr {$now-60*$minutes}]
    dict set values to $now
} else {
    set period [:dict getdef $values period "today"]
    if {$period ni {today yesterday}} {
        error "Invalid period"
    }
    set midnight [clock scan [clock format $now -timezone $timezone -format %Y-%m-%d] -timezone $timezone -format %Y-%m-%d]
    dict set values from [expr {$period eq "today" ? $midnight : [clock add $midnight -1 day -timezone $timezone]}]
    dict set values to [expr {$period eq "today" ? $now : $midnight}]
}
if {[dict get $values from]<0 || [dict get $values from]>=[dict get $values to]} {
    error "Expected 0 <= from < to"
}
if {[dict get $values maxGroups]<1 || [dict get $values maxGroups]>50} {
    error "maxGroups must be 1..50"
}
return $values
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: