Documentation
¶
Overview ¶
Package customlogs provides log processing for user-defined logs
Index ¶
Examples ¶
Constants ¶
View Source
const LogTypePrefix = "Custom"
Variables ¶
This section is empty.
Functions ¶
func Build ¶
Build validates the schema and metadata and builds a logtypes.Entry
Example ¶
package main
import (
"fmt"
jsoniter "github.com/json-iterator/go"
"github.com/tidwall/gjson"
"github.com/panther-labs/panther/internal/log_analysis/log_processor/customlogs"
logschema "github.com/panther-labs/panther/internal/log_analysis/log_processor/logschema"
"github.com/panther-labs/panther/internal/log_analysis/log_processor/logtypes"
"github.com/panther-labs/panther/internal/log_analysis/log_processor/pantherlog"
)
func main() {
logSample := `{
"method": "GET",
"path": "/-/metrics",
"format": "html",
"controller": "MetricsController",
"action": "index",
"status": 200,
"params": [],
"remote_ip": "1.1.1.1",
"user_id": null,
"username": null,
"ua": null,
"queue_duration_s": null,
"correlation_id": "c01ce2c1-d9e3-4e69-bfa3-b27e50af0268",
"cpu_s": 0.05,
"db_duration_s": 0,
"view_duration_s": 0.00039,
"duration_s": 0.0459,
"tag": "test",
"time": "2019-11-14T13:12:46.156Z"
}`
logSchemaJSON := `{
"schema": "SampleAPI",
"version": 0,
"fields": [
{ "name": "remote_ip", "type": "string", "indicators": ["ip"] , "description": "remote ip address" },
{ "name": "path", "type": "string", "description": "request URI path" },
{ "name": "time", "type": "timestamp", "timeFormat": "rfc3339", "isEventTime": true, "description": "event timestamp" },
{ "name": "method", "type":"string", "description": "request method" },
{ "name": "duration_s", "type": "float", "description": "duration of the request in seconds" }
]
}`
logSchema := logschema.Schema{}
fmt.Println("load schema JSON", jsoniter.UnmarshalFromString(logSchemaJSON, &logSchema))
desc := logtypes.Desc{
Name: "API",
Description: "API log type",
ReferenceURL: "-",
}
config, err := customlogs.Build(desc, &logSchema)
if err != nil {
fmt.Println(err)
panic(err)
}
parser, err := config.NewParser(nil)
if err != nil {
fmt.Println(err)
panic(err)
}
fmt.Println("generated parser", err)
results, err := parser.ParseLog(logSample)
fmt.Println("parse sample log", err)
result := results[0]
fmt.Println("result log type", result.PantherLogType)
jsonAPI := pantherlog.ConfigJSON()
data, err := jsonAPI.Marshal(result)
if err != nil {
panic(err)
}
// Panther log type field set in JSON
fmt.Println("p_log_type", gjson.Get(string(data), "p_log_type").Raw)
// Panther event_time set in JSON in the appropriate format
fmt.Println("p_event_time", gjson.Get(string(data), "p_event_time").Raw)
// Duration is proper number
fmt.Println("duration_s", gjson.Get(string(data), "duration_s").Raw)
// Panther fields collected
fmt.Println("p_any_ip_addresses", gjson.Get(string(data), "p_any_ip_addresses").Raw)
}
Output: load schema JSON <nil> generated parser <nil> parse sample log <nil> result log type Custom.API p_log_type "Custom.API" p_event_time "2019-11-14T13:12:46.156Z" duration_s 0.0459 p_any_ip_addresses ["1.1.1.1"]
func CheckSchemaChange ¶
Types ¶
This section is empty.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package customparser provides a log parser that uses reflection
|
Package customparser provides a log parser that uses reflection |
Click to show internal directories.
Click to hide internal directories.