github.com/choria-io/go-choria@v0.28.1-0.20240416190746-b3bf9c7d5a45/aagent/watchers/nagioswatcher/state_notification.go (about) 1 // Copyright (c) 2020-2021, R.I. Pienaar and the Choria Project contributors 2 // 3 // SPDX-License-Identifier: Apache-2.0 4 5 package nagioswatcher 6 7 import ( 8 "encoding/json" 9 "fmt" 10 11 cloudevents "github.com/cloudevents/sdk-go/v2" 12 13 "github.com/choria-io/go-choria/aagent/util" 14 "github.com/choria-io/go-choria/aagent/watchers/event" 15 ) 16 17 type StateNotification struct { 18 event.Event 19 20 Plugin string `json:"plugin"` 21 Status string `json:"status"` 22 StatusCode int `json:"status_code"` 23 Output string `json:"output"` 24 CheckTime int64 `json:"check_time"` 25 PerfData []util.PerfData `json:"perfdata"` 26 RunTime float64 `json:"runtime"` 27 History []*Execution `json:"history"` 28 Annotations map[string]string `json:"annotations"` 29 } 30 31 // JSON creates a JSON representation of the notification 32 func (s *StateNotification) JSON() ([]byte, error) { 33 return json.Marshal(s.CloudEvent()) 34 } 35 36 // CloudEvent creates a CloudEvent from the state notification 37 func (s *StateNotification) CloudEvent() cloudevents.Event { 38 return s.Event.CloudEvent(s) 39 } 40 41 // String is a string representation of the notification suitable for printing 42 func (s *StateNotification) String() string { 43 return fmt.Sprintf("%s %s#%s %s: %s", s.Identity, s.Machine, s.Name, s.Status, s.Output) 44 }