Documentation
¶
Overview ¶
Package escalation keeps the OTRS ticket escalation index (ticket.escalation_* columns) up to date and raises the OTRS escalation events.
Index ¶
- Constants
- Variables
- func DecayTime(db *sql.DB) (time.Duration, error)
- type Calendar
- type Calendars
- type Change
- type Event
- type Index
- type Indexer
- type Option
- type Preferences
- type Service
- func (s *Service) CheckEscalations(ctx context.Context, decay time.Duration) ([]Event, error)
- func (s *Service) LoadCalendars(ctx context.Context) error
- func (s *Service) RebuildAll(ctx context.Context, userID int) (int, error)
- func (s *Service) TicketEscalationIndexBuild(ctx context.Context, ticketID, userID int) error
- type State
Constants ¶
const ( FirstResponse = "FirstResponse" Update = "Update" Solution = "Solution" )
Escalation kinds, in the order OTRS evaluates them.
const DefaultDecayTime = 24 * time.Hour
DefaultDecayTime is OTRS's OTRSEscalationEvents::DecayTime default: an escalation event is raised again for the same ticket only after this long.
Variables ¶
var Kinds = []string{FirstResponse, Update, Solution}
Kinds lists the three escalation kinds.
Functions ¶
Types ¶
type Calendar ¶ added in v0.10.0
type Calendar struct {
// contains filtered or unexported fields
}
Calendar is one OTRS business calendar: the working hours of each weekday, the recurring and one-time vacation days, and the time zone in which they are read. It mirrors Kernel::System::DateTime's AsWorkingTime/ForWorkingTime arithmetic.
func ParseCalendar ¶ added in v0.10.0
func ParseCalendar(loc *time.Location, workingHours, vacationDays, vacationDaysOneTime string) (*Calendar, error)
ParseCalendar builds a calendar from the OTRS setting values: TimeWorkingHours ({Mon: ['8', '9', ...], ...}), TimeVacationDays ({'12': {'25': 'Christmas'}}) and TimeVacationDaysOneTime ({'2026': {'1': {'2': 'Bridge day'}}}). Empty strings mean "not set". A weekday missing from the working hours is not a working day.
func (*Calendar) AddWorkingTime ¶ added in v0.10.0
AddWorkingTime returns the moment at which seconds of working time have passed after start (OTRS DateTime->Add(AsWorkingTime => 1)). Without any configured working hour, or for seconds <= 0, start is returned unchanged, as in OTRS.
type Calendars ¶ added in v0.10.0
type Calendars struct {
// contains filtered or unexported fields
}
Calendars holds the default calendar and the named calendars "1".."9".
func LoadCalendars ¶ added in v0.10.0
LoadCalendars reads the OTRS calendar settings: TimeWorkingHours, TimeVacationDays and TimeVacationDaysOneTime for the default calendar, and their ::CalendarN variants with TimeZone::CalendarN for calendars 1-9. A numbered calendar is used when its working hours are set and its TimeZone::CalendarNName is not blanked out; otherwise its tickets use the default calendar. loc is the time zone of the default calendar and of numbered calendars without their own TimeZone::CalendarN.
type Change ¶ added in v0.10.0
Change describes the ticket change a rebuild follows: who made it and when. An escalation counts as stopped by the change when it had started by then and no longer has.
type Event ¶ added in v0.10.0
type Event struct {
TicketID int
Name string // ticket_history_type name, e.g. EscalationResponseTimeStart
}
Event is one escalation event raised by CheckEscalations.
type Index ¶ added in v0.10.0
type Index struct {
Escalation int64 // earliest of the three
Response int64
Update int64
Solution int64
}
Index is a ticket's escalation index: OTRS destination times in unix seconds, 0 where the kind does not escalate.
type Indexer ¶ added in v0.10.0
type Indexer struct {
// contains filtered or unexported fields
}
Indexer keeps the escalation index current: OTRS rebuilds it from the ticket event handler (Ticket::EventModulePost###9990-EscalationIndex); GoatFlow rebuilds it from RunOnce, which the scheduler calls every few seconds. The first run, and every run after an SLA, queue or calendar setting changed, rebuilds all tickets that can escalate.
func NewIndexer ¶ added in v0.10.0
NewIndexer returns an indexer that rebuilds through svc.
type Option ¶ added in v0.10.0
type Option func(*Service)
Option configures a Service.
func WithLocation ¶ added in v0.10.0
WithLocation sets the time zone of the default calendar (and of numbered calendars without TimeZone::CalendarN). Default UTC.
func WithLogger ¶ added in v0.10.0
WithLogger sets the logger.
type Preferences ¶ added in v0.10.0
type Preferences struct {
FirstResponseTime int
FirstResponseNotify int
UpdateTime int
UpdateNotify int
SolutionTime int
SolutionNotify int
Calendar string
}
Preferences are the escalation settings of a ticket: its SLA's when it has one, else its queue's (OTRS TicketEscalationPreferences). Times are in minutes, notify values in percent.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service computes the OTRS escalation index of tickets (Kernel::System::Ticket::TicketEscalationIndexBuild) and raises the escalation events (Maint::Ticket::EscalationCheck and Ticket::Event::TriggerEscalationStopEvents).
func NewService ¶
NewService returns a service on db. Calendars are loaded on first use and by LoadCalendars.
func (*Service) CheckEscalations ¶ added in v0.10.0
CheckEscalations is OTRS Maint::Ticket::EscalationCheck: for up to 1000 tickets escalating within five days it raises Escalation*TimeStart for every started escalation and Escalation*TimeNotifyBefore for every one past its notify percentage, by writing the ticket_history row of that type (webhooks and notification events read those). Tickets whose calendar had no working time in the last ten minutes are skipped, and an event is not repeated for a ticket within decay (0 = every run).
func (*Service) LoadCalendars ¶ added in v0.10.0
LoadCalendars (re)reads the calendar settings.
func (*Service) RebuildAll ¶ added in v0.10.0
RebuildAll rebuilds the escalation index of every ticket that can escalate or still has an index (OTRS Maint::Ticket::EscalationIndexRebuild). It returns how many tickets it rebuilt; a failing ticket is logged and skipped.
func (*Service) TicketEscalationIndexBuild ¶
TicketEscalationIndexBuild recomputes a ticket's escalation index and stores it in the ticket's escalation_* columns. When the change ends an escalation that had started, it records the OTRS Escalation*TimeStop history event on behalf of userID. Concurrent rebuilds of the same ticket are safe: only the one that moves the stored index records stop events.
type State ¶ added in v0.10.0
type State struct {
Kind string
Destination int64 // unix seconds
Escalated bool // the destination time has passed
Notify bool // the notify-before percentage of the working time is used up
WorkingTime int64 // working seconds left (negative: overdue)
}
State is a ticket's escalation state at one moment (OTRS TicketEscalationDateCalculation) for one kind.