Skip to content

Commit 77ca5cb

Browse files
authored
Merge pull request #27 from NextronSystems/feat/no-summary
feat: remove summary
2 parents 69e056d + 9b5430a commit 77ca5cb

31 files changed

Lines changed: 56 additions & 128 deletions

object.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package jsonlog
22

33
// Object is the interface that all log objects must implement.
4-
// Each log object has a `type` and `summary` field in its JSON representation.
5-
// The type field is used to identify the object type, and the summary field is
6-
// a human-readable summary of the object's contents.
4+
// Each log object has a `type` field in its JSON representation
5+
// that is used to identify the object type.
76
type Object interface {
87
// EmbeddedHeader returns the header of the log object.
98
EmbeddedHeader() ObjectHeader
@@ -13,8 +12,6 @@ type Object interface {
1312

1413
// ObjectHeader is the header of a log object. It must be embedded in all log objects.
1514
type ObjectHeader struct {
16-
// Summary is a human-readable summary of the object's contents.
17-
Summary string `json:"summary"`
1815
// Type is the type of the object. It should be unique across all log objects
1916
// and can be used to identify the object type that has embedded this header.
2017
Type string `json:"type"`

textlog_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ type SimpleSubstruct struct {
3030
func TestToDetails(t *testing.T) {
3131
var test = TestObject{
3232
ObjectHeader: ObjectHeader{
33-
Summary: "TestObject",
34-
Type: "testobject",
33+
Type: "testobject",
3534
},
3635
Element1: "element1",
3736
Element2: "element2",

thorlog/jsonschema/generateschema.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ func makeObjectSchema() (mainEntry string, defs map[string]*jsonschema.Schema) {
6767
var logObjectSchema = &jsonschema.Schema{
6868
Properties: orderedmap.New[string, *jsonschema.Schema](),
6969
}
70-
logObjectSchema.Properties.Set("summary", &jsonschema.Schema{Type: "string"})
7170
logObjectSchema.Properties.Set("type", &jsonschema.Schema{
7271
Type: "string",
7372
Enum: logObjectTypes,

thorlog/v3/antivirus.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ func init() { AddLogObjectType(typeAntiVirusProduct, &AntiVirusProduct{}) }
2222
func NewAntiVirusProduct(name string) *AntiVirusProduct {
2323
return &AntiVirusProduct{
2424
LogObjectHeader: jsonlog.ObjectHeader{
25-
Type: typeAntiVirusProduct,
26-
Summary: name,
25+
Type: typeAntiVirusProduct,
2726
},
2827
Name: name,
2928
}
@@ -45,8 +44,7 @@ func init() { AddLogObjectType(typeAntiVirusExclude, &AntiVirusExclude{}) }
4544
func NewAntiVirusExclude(exclusionType string, exclusion string) *AntiVirusExclude {
4645
return &AntiVirusExclude{
4746
LogObjectHeader: jsonlog.ObjectHeader{
48-
Type: typeAntiVirusExclude,
49-
Summary: exclusionType + " " + exclusion,
47+
Type: typeAntiVirusExclude,
5048
},
5149
Type: exclusionType,
5250
Exclusion: exclusion,

thorlog/v3/beaconwatcher.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package thorlog
22

33
import (
4-
"fmt"
54
"time"
65

76
"github.com/NextronSystems/jsonlog"
@@ -26,8 +25,7 @@ func (NetworkConnectingThread) reportable() {}
2625
func NewNetworkConnectingThread(threadId uint32, process *Process) *NetworkConnectingThread {
2726
return &NetworkConnectingThread{
2827
ObjectHeader: jsonlog.ObjectHeader{
29-
Summary: fmt.Sprintf("Thread %d connected to remote servers regularly", threadId),
30-
Type: typeNetworkConnectingThread,
28+
Type: typeNetworkConnectingThread,
3129
},
3230
ThreadId: threadId,
3331
Process: process,

thorlog/v3/dnscache.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ func init() { AddLogObjectType(typeDnsCacheEntry, &DnsCacheEntry{}) }
1515
func NewDnsCacheEntry(host string, ip string) *DnsCacheEntry {
1616
return &DnsCacheEntry{
1717
LogObjectHeader: LogObjectHeader{
18-
Type: typeDnsCacheEntry,
19-
Summary: host,
18+
Type: typeDnsCacheEntry,
2019
},
2120
Host: host,
2221
IP: ip,

thorlog/v3/doublepulsar.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
package thorlog
22

3-
import (
4-
"fmt"
5-
)
6-
73
type DoublePulsarHandshake struct {
84
LogObjectHeader
95

@@ -20,8 +16,7 @@ func init() { AddLogObjectType(typeDoublePulsarHandshake, &DoublePulsarHandshake
2016
func NewDoublePulsarHandshake(handshakeType string, key uint64) *DoublePulsarHandshake {
2117
return &DoublePulsarHandshake{
2218
LogObjectHeader: LogObjectHeader{
23-
Type: typeDoublePulsarHandshake,
24-
Summary: fmt.Sprintf("DoublePulsar Handshake via %s succeeded", handshakeType),
19+
Type: typeDoublePulsarHandshake,
2520
},
2621
Key: HexNumber(key),
2722
Type: handshakeType,

thorlog/v3/envvar.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ func init() { AddLogObjectType(typeEnvironmentVariable, &EnvironmentVariable{})
1919
func NewEnvironmentVariable(variable string, value string) *EnvironmentVariable {
2020
return &EnvironmentVariable{
2121
LogObjectHeader: LogObjectHeader{
22-
Type: typeEnvironmentVariable,
23-
Summary: variable + "=" + value,
22+
Type: typeEnvironmentVariable,
2423
},
2524
Variable: variable,
2625
Value: value,

thorlog/v3/event.go

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
type Finding struct {
1717
jsonlog.ObjectHeader
1818
Meta LogEventMetadata `json:"meta" textlog:",expand"`
19+
Text string `json:"message" textlog:"-"`
1920
Subject ReportableObject `json:"subject" textlog:",expand"`
2021
Score int64 `json:"score" textlog:"score"`
2122
Reasons []Reason `json:"reasons" textlog:",expand"`
@@ -31,7 +32,7 @@ type ReportableObject interface {
3132
}
3233

3334
func (f *Finding) Message() string {
34-
return f.Summary
35+
return f.Text
3536
}
3637

3738
func (f *Finding) Version() common.Version {
@@ -43,29 +44,20 @@ func (f *Finding) Metadata() *LogEventMetadata {
4344
}
4445

4546
func (f *Finding) UnmarshalJSON(data []byte) error {
47+
type plainFinding Finding
4648
var rawFinding struct {
47-
jsonlog.ObjectHeader
48-
Meta LogEventMetadata `json:"meta"`
49-
Subject EmbeddedObject `json:"subject"`
50-
Score int64 `json:"score"`
51-
Reasons []Reason `json:"reasons"`
52-
EventContext Context `json:"context"`
53-
LogVersion common.Version `json:"log_version"`
49+
plainFinding // Embed without unmarshal method to avoid infinite recursion
50+
Subject EmbeddedObject `json:"subject"` // EmbeddedObject is used to allow unmarshalling of the subject as a ReportableObject
5451
}
5552
if err := json.Unmarshal(data, &rawFinding); err != nil {
5653
return err
5754
}
58-
f.ObjectHeader = rawFinding.ObjectHeader
59-
f.Meta = rawFinding.Meta
6055
subject, ok := rawFinding.Subject.Object.(ReportableObject)
6156
if !ok {
6257
return fmt.Errorf("subject must implement the reportable interface")
6358
}
59+
*f = Finding(rawFinding.plainFinding) // Copy the fields from rawFinding to f
6460
f.Subject = subject
65-
f.Score = rawFinding.Score
66-
f.Reasons = rawFinding.Reasons
67-
f.EventContext = rawFinding.EventContext
68-
f.LogVersion = rawFinding.LogVersion
6961

7062
// Resolve all references
7163
// When the event is unmarshalled, the references are not resolved yet and only contain the JSON pointers.
@@ -163,9 +155,9 @@ func init() { AddLogObjectType(typeFinding, &Finding{}) }
163155
func NewFinding(subject ReportableObject, message string) *Finding {
164156
return &Finding{
165157
ObjectHeader: LogObjectHeader{
166-
Type: typeFinding,
167-
Summary: message,
158+
Type: typeFinding,
168159
},
160+
Text: message,
169161
Subject: subject,
170162
LogVersion: currentVersion,
171163
}
@@ -174,12 +166,13 @@ func NewFinding(subject ReportableObject, message string) *Finding {
174166
type Message struct {
175167
jsonlog.ObjectHeader
176168
Meta LogEventMetadata `json:"meta" textlog:",expand"`
169+
Text string `json:"message" textlog:"-"`
177170
Fields MessageFields `json:"fields" textlog:",expand" jsonschema:"nullable"`
178171
LogVersion common.Version `json:"log_version"`
179172
}
180173

181174
func (m *Message) Message() string {
182-
return m.Summary
175+
return m.Text
183176
}
184177

185178
func (m *Message) Version() common.Version {
@@ -199,9 +192,9 @@ func init() { AddLogObjectType(typeMessage, &Message{}) }
199192
func NewMessage(meta LogEventMetadata, message string, kvs ...any) *Message {
200193
msg := &Message{
201194
ObjectHeader: LogObjectHeader{
202-
Type: typeMessage,
203-
Summary: message,
195+
Type: typeMessage,
204196
},
197+
Text: message,
205198
Meta: meta,
206199
LogVersion: currentVersion,
207200
}

thorlog/v3/event_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,15 @@ func concatEntry(entry jsonlog.TextlogEntry) string {
9292
func TestFinding_UnmarshalJSON(t *testing.T) {
9393
for i, finding := range []*Finding{
9494
{
95-
ObjectHeader: LogObjectHeader{Type: typeFinding, Summary: "message"},
95+
ObjectHeader: LogObjectHeader{Type: typeFinding},
9696
Meta: LogEventMetadata{
9797
Lvl: common.Alert,
9898
Mod: "Test",
9999
ScanID: "abdc",
100100
GenID: "abdas",
101101
Source: "aserarsd",
102102
},
103+
Text: "This is a test finding",
103104
Subject: NewFile("path/to/file"),
104105
EventContext: Context{
105106
{

0 commit comments

Comments
 (0)