forked from utmstack/UTMStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsamples.go
More file actions
94 lines (79 loc) · 1.87 KB
/
samples.go
File metadata and controls
94 lines (79 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package main
import (
"bytes"
"crypto/tls"
"encoding/json"
"net/http"
"time"
)
func generateSample(severity string, seq int) Log {
return Log{
Timestamp: time.Now().UTC().Format(time.RFC3339Nano),
DataSource: "sample-host",
DataType: "sample-data",
Log: map[string]interface{}{
"logType": "Example data",
"vendor": "UTMStack",
"severity": severity,
"description": "This is an example log used for automatic UTMStack test alert generation",
"src_user": "user-1",
"dest_user": "user-2",
"src_host": "dns.google",
"dest_host": "host-2.utmstack.com",
"src_port": 24300,
"dest_port": 8080,
"src_ip": "8.8.8.8",
"dest_ip": "10.10.10.10",
"proto": "tcp",
"sequence": seq,
},
}
}
func SendSampleData() error {
severities := []string{
"High",
"Medium",
"Low",
}
const baseURL = "http://127.0.0.1:10000"
transCfg := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
for i := 0; i <= 1000; i++ {
for _, s := range severities {
log := generateSample(s, i)
jLog, err := json.Marshal(log)
if err != nil {
return err
}
req, err := http.NewRequest("POST", baseURL+"/v1/newlog", bytes.NewBuffer(jLog))
if err != nil {
return err
}
client := &http.Client{Transport: transCfg}
var resp *http.Response
for intent := 0; intent <= 10; intent++ {
resp, err = client.Do(req)
if err != nil {
if intent >= 10 {
return err
}
time.Sleep(1 * time.Minute)
} else {
break
}
}
err = resp.Body.Close()
if err != nil {
return err
}
}
}
return nil
}
type Log struct {
Timestamp string `json:"@timestamp"`
DataSource string `json:"dataSource"`
DataType string `json:"dataType"`
Log map[string]interface{} `json:"logx"`
}