mirror of
https://github.com/kopia/kopia.git
synced 2025-12-23 22:57:50 -05:00
* 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
44 lines
1.3 KiB
Go
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),
|
|
}
|
|
}
|