Documentation
¶
Overview ¶
Package utils provides utility functions for the application
Package utils provides utility functions for the application
Index ¶
- Constants
- func ContainsMarkdownSyntax(text string) bool
- func ConvertMarkdownToPlainText(markdown string) string
- func ConvertToTeamsPayload(powerAutomateURL, messageText string, incident *m.Incident) ([]byte, error)
- func CreateHTTPClient(proxyConfig config.ProxyConfig, useProxy bool) *http.Client
- func ExtractJSONObject(s string) string
- func GetIncludeFunc(tmplName string) func(string, interface{}) (string, error)
- func GetTemplateFuncMaps() template.FuncMap
- func IsAgentIncident(content map[string]interface{}) bool
- func NormalizeSeverity(s string) string
- func OneLine(s string, maxLen int) string
- func RegisterTemplate(name string, tmpl *template.Template)
- func SeverityRank(s string) int
- func StripMarkdown(text string) string
- type AdaptiveCard
- type LarkCard
- type LarkCardElement
- type LarkCardHeader
- type LarkCardTitle
- type LarkMessage
- type MSTeamsMessage
- type TemplateDict
Constants ¶
const ( AgentSlackTemplatePath = "config/agent_slack.tmpl" AgentTelegramTemplatePath = "config/agent_telegram.tmpl" AgentMSTeamsTemplatePath = "config/agent_msteams.tmpl" AgentLarkTemplatePath = "config/agent_lark.tmpl" AgentViberTemplatePath = "config/agent_viber.tmpl" AgentEmailTemplatePath = "config/agent_email.tmpl" )
Hardcoded per-channel template paths used for incidents emitted by the AI SRE Agent (detect mode). Each channel has its own file because the markup syntax differs per channel (mrkdwn, HTML, Markdown, plain text). Providers render agent-emitted incidents through these files instead of their per-channel default templates.
Variables ¶
This section is empty.
Functions ¶
func ContainsMarkdownSyntax ¶
ContainsMarkdownSyntax checks if the message contains any Markdown formatting
func ConvertMarkdownToPlainText ¶
ConvertMarkdownToPlainText converts markdown to plain text for fallback
func ConvertToTeamsPayload ¶
func ConvertToTeamsPayload(powerAutomateURL, messageText string, incident *m.Incident) ([]byte, error)
ConvertToTeamsPayload takes the rendered template message and converts it to the appropriate payload format for Power Automate.
func CreateHTTPClient ¶ added in v1.3.7
func CreateHTTPClient(proxyConfig config.ProxyConfig, useProxy bool) *http.Client
CreateHTTPClient creates an HTTP client with optional proxy support
func ExtractJSONObject ¶ added in v1.4.0
ExtractJSONObject pulls the first balanced {...} block out of s. Returns "" when no balanced object is present.
This is intentionally simpler than a full JSON tokenizer — it is designed for tolerating LLM-style output that may wrap a single JSON object in code fences or preamble. A depth counter with string-escape handling is enough for the degraded-output cases we care about; nested objects inside string literals do not throw it off.
func GetIncludeFunc ¶ added in v1.3.2
GetIncludeFunc returns an include function that uses the specified template
func GetTemplateFuncMaps ¶
GetTemplateFuncMaps returns a map of template functions that can be used in templates
func IsAgentIncident ¶ added in v1.4.0
IsAgentIncident returns true when the incident content map was built by services.CreateIncidentFromFinding, i.e. originated from the AI SRE Agent. Detection is based on stable fields stamped by the agent path: a non-empty PatternID OR a Source that begins with "agent:".
func NormalizeSeverity ¶ added in v1.4.0
NormalizeSeverity coerces a free-form severity string into one of the canonical alert severities (`critical`, `high`, `medium`, `low`). Unknown / empty values fall back to "medium".
func OneLine ¶ added in v1.4.0
OneLine collapses newlines into spaces and truncates to maxLen runes (well, bytes — callers pass log lines that are ASCII-dominant). A trailing ellipsis "…" is appended on truncation. maxLen <= 0 disables truncation.
func RegisterTemplate ¶ added in v1.3.2
RegisterTemplate registers a template for use with the include function
func SeverityRank ¶ added in v1.4.4
SeverityRank maps a canonical severity to an orderable rank (critical highest). Unknown / empty severities rank lowest (0) so they never act as a floor over a real AI-assigned severity.
func StripMarkdown ¶
StripMarkdown removes common markdown syntax from text
Types ¶
type AdaptiveCard ¶
type AdaptiveCard struct {
Type string `json:"type"`
Body []interface{} `json:"body"`
Schema string `json:"$schema"`
Version string `json:"version"`
// Required MS Teams fields
Text string `json:"text,omitempty"` // Fallback text for clients that don't support cards
Summary string `json:"summary,omitempty"` // Required by MS Teams for notification
}
AdaptiveCard represents a basic Adaptive Card structure for MS Teams
func ConvertMarkdownToAdaptiveCard ¶
func ConvertMarkdownToAdaptiveCard(markdown string) AdaptiveCard
ConvertMarkdownToAdaptiveCard converts Markdown-like text to an Adaptive Card
type LarkCard ¶ added in v1.3.1
type LarkCard struct {
Header LarkCardHeader `json:"header"`
Elements []LarkCardElement `json:"elements"`
}
LarkCard represents an interactive card in Lark
type LarkCardElement ¶ added in v1.3.1
LarkCardElement represents an element in a Lark card
type LarkCardHeader ¶ added in v1.3.1
type LarkCardHeader struct {
Title LarkCardTitle `json:"title"`
}
LarkCardHeader represents the header of a Lark card
type LarkCardTitle ¶ added in v1.3.1
LarkCardTitle represents the title component of a Lark card header
type LarkMessage ¶ added in v1.3.1
LarkMessage represents the structure of a Lark message
func CreateLarkMessage ¶ added in v1.3.1
func CreateLarkMessage(content string, isResolved bool) *LarkMessage
CreateLarkMessage creates a Lark message with interactive card format This format uses "msg_type": "interactive" with a card structure
type MSTeamsMessage ¶
type MSTeamsMessage struct {
Text string `json:"text"`
}
MSTeamsMessage represents a basic message for MS Teams
type TemplateDict ¶ added in v1.3.2
type TemplateDict map[string]interface{}
TemplateDict is a custom dictionary type that supports the Set method
func (TemplateDict) Set ¶ added in v1.3.2
func (d TemplateDict) Set(key string, value interface{}) TemplateDict
Set adds or updates a key-value pair in the dictionary