escalation

package
v0.8.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 4, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package escalation provides SLA escalation calculation and management.

Package escalation provides SLA escalation calculation and management.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitGlobalEventHandler

func InitGlobalEventHandler(db *sql.DB, logger *log.Logger) error

InitGlobalEventHandler initializes the global event handler. Should be called during application startup.

func TriggerArticleCreate

func TriggerArticleCreate(ctx context.Context, ticketID, userID int)

TriggerArticleCreate triggers escalation index rebuild after article creation. Safe to call even if handler not initialized (will be a no-op).

func TriggerTicketCreate

func TriggerTicketCreate(ctx context.Context, ticketID, userID int)

TriggerTicketCreate triggers escalation index build for a new ticket. Safe to call even if handler not initialized (will be a no-op).

func TriggerTicketUpdate

func TriggerTicketUpdate(ctx context.Context, ticketID, userID int)

TriggerTicketUpdate triggers escalation index rebuild for an updated ticket. Safe to call even if handler not initialized (will be a no-op).

Types

type CalendarService

type CalendarService struct {
	// contains filtered or unexported fields
}

CalendarService manages business calendars, wrapping rickar/cal with OTRS sysconfig.

func NewCalendarService

func NewCalendarService(db *sql.DB) *CalendarService

NewCalendarService creates a new calendar service.

func (*CalendarService) AddWorkingTime

func (s *CalendarService) AddWorkingTime(calendarName string, start time.Time, minutes int) time.Time

AddWorkingTime adds working time (in minutes) to a start time and returns the destination time. This wraps rickar/cal's AddWorkHours for OTRS compatibility (minutes instead of Duration).

func (*CalendarService) GetCalendar

func (s *CalendarService) GetCalendar(name string) *cal.BusinessCalendar

GetCalendar returns a calendar by name. Name can be empty (default), "1"-"9", or "Calendar1"-"Calendar9".

func (*CalendarService) IsWorkingTime

func (s *CalendarService) IsWorkingTime(calendarName string, t time.Time) bool

IsWorkingTime checks if a given time is within working hours.

func (*CalendarService) LoadCalendars

func (s *CalendarService) LoadCalendars(ctx context.Context) error

LoadCalendars loads all calendars from sysconfig.

func (*CalendarService) WorkingTimeBetween

func (s *CalendarService) WorkingTimeBetween(calendarName string, start, end time.Time) int64

WorkingTimeBetween calculates working time in seconds between two times.

type CheckService

type CheckService struct {
	// contains filtered or unexported fields
}

CheckService handles escalation event triggering, matching OTRS EscalationCheck.

func NewCheckService

func NewCheckService(db *sql.DB, calendarService *CalendarService, logger *log.Logger) *CheckService

NewCheckService creates a new escalation check service.

func (*CheckService) CheckEscalations

func (s *CheckService) CheckEscalations(ctx context.Context) ([]EscalationEvent, error)

CheckEscalations finds tickets that are escalating and triggers events. This matches OTRS Maint::Ticket::EscalationCheck.

func (*CheckService) SetDecayTime

func (s *CheckService) SetDecayTime(minutes int)

SetDecayTime sets the decay time (minutes between repeat notifications).

type EscalatingTicket

type EscalatingTicket struct {
	ID           int
	TicketNumber string
}

EscalatingTicket holds basic ticket info for escalation check.

type EscalationEvent

type EscalationEvent struct {
	TicketID  int
	EventName string
}

EscalationEvent represents an escalation event to trigger.

type EscalationInfo

type EscalationInfo struct {
	FirstResponseTimeEscalation   bool
	FirstResponseTimeNotification bool
	UpdateTimeEscalation          bool
	UpdateTimeNotification        bool
	SolutionTimeEscalation        bool
	SolutionTimeNotification      bool
}

EscalationInfo holds ticket escalation state.

type EscalationPreferences

type EscalationPreferences struct {
	FirstResponseTime   int    // Minutes until first response required
	FirstResponseNotify int    // Percentage for warning notification
	UpdateTime          int    // Minutes between updates required
	UpdateNotify        int    // Percentage for warning notification
	SolutionTime        int    // Minutes until solution required
	SolutionNotify      int    // Percentage for warning notification
	Calendar            string // Calendar name (empty = default, "1"-"9" = named)
}

EscalationPreferences holds escalation settings from SLA or Queue.

type EventHandler

type EventHandler struct {
	// contains filtered or unexported fields
}

EventHandler handles ticket events that require escalation index updates. This matches OTRS Kernel::System::Ticket::Event::TicketEscalationIndex.

func GetEventHandler

func GetEventHandler() *EventHandler

GetEventHandler returns the global event handler. Returns nil if not initialized.

func NewEventHandler

func NewEventHandler(db *sql.DB, logger *log.Logger) *EventHandler

NewEventHandler creates a new escalation event handler.

func (*EventHandler) Initialize

func (h *EventHandler) Initialize(ctx context.Context) error

Initialize loads calendars and prepares the handler.

func (*EventHandler) OnArticleCreate

func (h *EventHandler) OnArticleCreate(ctx context.Context, ticketID, userID int)

OnArticleCreate handles new article events. Should be called when an article is added (may affect update escalation).

func (*EventHandler) OnTicketCreate

func (h *EventHandler) OnTicketCreate(ctx context.Context, ticketID, userID int)

OnTicketCreate handles ticket creation events. Should be called after a new ticket is created.

func (*EventHandler) OnTicketMerge

func (h *EventHandler) OnTicketMerge(ctx context.Context, ticketID, userID int)

OnTicketMerge handles ticket merge events. The merged ticket should have escalation cleared.

func (*EventHandler) OnTicketQueueUpdate

func (h *EventHandler) OnTicketQueueUpdate(ctx context.Context, ticketID, userID int)

OnTicketQueueUpdate handles queue change events. Should be called when ticket is moved to different queue (escalation settings may differ).

func (*EventHandler) OnTicketSLAUpdate

func (h *EventHandler) OnTicketSLAUpdate(ctx context.Context, ticketID, userID int)

OnTicketSLAUpdate handles SLA change events. Should be called when ticket SLA is changed.

func (*EventHandler) OnTicketServiceUpdate

func (h *EventHandler) OnTicketServiceUpdate(ctx context.Context, ticketID, userID int)

OnTicketServiceUpdate handles service change events.

func (*EventHandler) OnTicketStateUpdate

func (h *EventHandler) OnTicketStateUpdate(ctx context.Context, ticketID, userID int)

OnTicketStateUpdate handles ticket state change events. Should be called when ticket state changes (may clear escalation for closed tickets).

func (*EventHandler) OnTicketUpdate

func (h *EventHandler) OnTicketUpdate(ctx context.Context, ticketID, userID int)

OnTicketUpdate is a generic handler for any ticket update. Use this when you're not sure which specific event occurred.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service handles ticket escalation index calculation matching OTRS behavior.

func NewService

func NewService(db *sql.DB, logger *log.Logger) *Service

NewService creates a new escalation service.

func (*Service) Initialize

func (s *Service) Initialize(ctx context.Context) error

Initialize loads calendars from sysconfig.

func (*Service) RebuildAllTicketEscalations

func (s *Service) RebuildAllTicketEscalations(ctx context.Context, userID int) error

RebuildAllTicketEscalations rebuilds escalation index for all open tickets. This is useful for bulk updates after SLA/Queue changes.

func (*Service) TicketEscalationIndexBuild

func (s *Service) TicketEscalationIndexBuild(ctx context.Context, ticketID, userID int) error

TicketEscalationIndexBuild rebuilds escalation index for a ticket. This matches OTRS Kernel::System::Ticket::TicketEscalationIndexBuild.

type TicketInfo

type TicketInfo struct {
	ID        int
	QueueID   int
	SLAID     *int
	StateType string // new, open, closed, removed, pending, merged
	Created   time.Time
	UserID    int
}

TicketInfo holds ticket data needed for escalation calculation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL