Files
kopia/notification/notifydata/error_info.go
Jarek Kowalski afb85cbb34 feat(cli): send error notifications and snapshot reports (#4233)
* feat(cli): send error notifications and snapshot reports

Notifications will be sent to all configured notification profiles
according to their severity levels.

The following events will trigger notifications:

- Snapshot is created (CLI only, severity >= report)
- Server Maintenance error occurs (CLI, server and UI, severity >= error)
- Any other CLI error occurs (CLI only, severity >= error).

A flag `--no-error-notifications` can be used to disable error notifications.

* added template tests

* improved time formatting in templates

* plumb through notifytemplate.Options

* more testing for formatting options

* fixed default date format to RFC1123
2024-11-11 17:53:50 -08:00

44 lines
1.3 KiB
Go

package notifydata
import (
"fmt"
"time"
)
// ErrorInfo represents information about errors.
type ErrorInfo struct {
Operation string `json:"operation"`
OperationDetails string `json:"operationDetails"`
StartTime time.Time `json:"start"`
EndTime time.Time `json:"end"`
ErrorMessage string `json:"error"`
ErrorDetails string `json:"errorDetails"`
}
// StartTimestamp returns the start time of the operation that caused the error.
func (e *ErrorInfo) StartTimestamp() time.Time {
return e.StartTime.Truncate(time.Second)
}
// EndTimestamp returns the end time of the operation that caused the error.
func (e *ErrorInfo) EndTimestamp() time.Time {
return e.EndTime.Truncate(time.Second)
}
// Duration returns the duration of the operation.
func (e *ErrorInfo) Duration() time.Duration {
return e.EndTimestamp().Sub(e.StartTimestamp())
}
// NewErrorInfo creates a new ErrorInfo.
func NewErrorInfo(operation, operationDetails string, startTime, endTime time.Time, err error) *ErrorInfo {
return &ErrorInfo{
Operation: operation,
OperationDetails: operationDetails,
StartTime: startTime,
EndTime: endTime,
ErrorMessage: fmt.Sprintf("%v", err),
ErrorDetails: fmt.Sprintf("%+v", err),
}
}