satellite/nodeevents: add method Name to Type
Add method Name to Type for a more human-readable format Change-Id: I10050b9ef3691922d9dfccdbb6f046769a649321
This commit is contained in:
parent
57be07f60a
commit
705dfa0875
@ -7,7 +7,6 @@ import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"github.com/zeebo/errs"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@ -34,34 +33,10 @@ func (m *MockNotifier) Notify(ctx context.Context, satellite string, events []No
|
||||
}
|
||||
nodeIDs = strings.TrimSuffix(nodeIDs, ",")
|
||||
|
||||
eventString, err := typeToString(events[0].Event)
|
||||
name, err := events[0].Event.Name()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
m.log.Info("node operator notified", zap.String("email", events[0].Email), zap.String("event", eventString), zap.String("node IDs", nodeIDs))
|
||||
m.log.Info("node operator notified", zap.String("email", events[0].Email), zap.String("event", name), zap.String("node IDs", nodeIDs))
|
||||
return nil
|
||||
}
|
||||
|
||||
func typeToString(event Type) (desc string, err error) {
|
||||
switch event {
|
||||
case Online:
|
||||
desc = "online"
|
||||
case Offline:
|
||||
desc = "offline"
|
||||
case Disqualified:
|
||||
desc = "disqualified"
|
||||
case UnknownAuditSuspended:
|
||||
desc = "unknown audit suspended"
|
||||
case UnknownAuditUnsuspended:
|
||||
desc = "unknown audit unsuspended"
|
||||
case OfflineSuspended:
|
||||
desc = "offline suspended"
|
||||
case OfflineUnsuspended:
|
||||
desc = "offline unsuspended"
|
||||
case BelowMinVersion:
|
||||
desc = "below minimum version"
|
||||
default:
|
||||
err = errs.New("event type has no description")
|
||||
}
|
||||
return desc, err
|
||||
}
|
||||
|
@ -3,6 +3,8 @@
|
||||
|
||||
package nodeevents
|
||||
|
||||
import "github.com/zeebo/errs"
|
||||
|
||||
// Type is a type of node event.
|
||||
type Type int
|
||||
|
||||
@ -23,4 +25,38 @@ const (
|
||||
OfflineUnsuspended
|
||||
// BelowMinVersion indicates that the node's software is below the minimum version.
|
||||
BelowMinVersion
|
||||
|
||||
onlineName = "online"
|
||||
offlineName = "offline"
|
||||
disqualifiedName = "disqualified"
|
||||
unknownAuditSuspendedName = "unknown audit suspended"
|
||||
unknownAuditUnsuspendedName = "unknown audit unsuspended"
|
||||
offlineSuspendedName = "offline suspended"
|
||||
offlineUnsuspendedName = "offline unsuspended"
|
||||
belowMinVersionName = "below minimum version"
|
||||
)
|
||||
|
||||
// Name returns the name of the node event Type.
|
||||
func (t Type) Name() (name string, err error) {
|
||||
switch t {
|
||||
case Online:
|
||||
name = onlineName
|
||||
case Offline:
|
||||
name = offlineName
|
||||
case Disqualified:
|
||||
name = disqualifiedName
|
||||
case UnknownAuditSuspended:
|
||||
name = unknownAuditSuspendedName
|
||||
case UnknownAuditUnsuspended:
|
||||
name = unknownAuditUnsuspendedName
|
||||
case OfflineSuspended:
|
||||
name = offlineSuspendedName
|
||||
case OfflineUnsuspended:
|
||||
name = offlineUnsuspendedName
|
||||
case BelowMinVersion:
|
||||
name = belowMinVersionName
|
||||
default:
|
||||
err = errs.New("invalid Type")
|
||||
}
|
||||
return name, err
|
||||
}
|
||||
|
@ -31,12 +31,16 @@ func (ne *nodeEvents) Insert(ctx context.Context, email string, nodeID storj.Nod
|
||||
if err != nil {
|
||||
return nodeEvent, err
|
||||
}
|
||||
name, err := eventType.Name()
|
||||
if err != nil {
|
||||
return nodeEvent, err
|
||||
}
|
||||
entry, err := ne.db.Create_NodeEvent(ctx, dbx.NodeEvent_Id(id.Bytes()), dbx.NodeEvent_Email(email), dbx.NodeEvent_NodeId(nodeID.Bytes()), dbx.NodeEvent_Event(int(eventType)), dbx.NodeEvent_Create_Fields{})
|
||||
if err != nil {
|
||||
return nodeEvent, err
|
||||
}
|
||||
|
||||
ne.db.log.Info("node event inserted", zap.Int("type", int(eventType)), zap.String("email", email), zap.String("node ID", nodeID.String()))
|
||||
ne.db.log.Info("node event inserted", zap.String("name", name), zap.String("email", email), zap.String("node ID", nodeID.String()))
|
||||
|
||||
return fromDBX(entry)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user