Skip to content

Commit 0f16c70

Browse files
committed
fix nil pointer in soc ai
1 parent eb5018e commit 0f16c70

5 files changed

Lines changed: 19 additions & 39 deletions

File tree

installer/updater/window.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ func UpdateWindowConfig() {
2727

2828
func IsInMaintenanceWindow() bool {
2929
if windowConfig == "" {
30-
config.Logger().Info("Maintenance window config not set in backend, presuming 24/7 maintenance window")
3130
return true
3231
}
3332

plugins/soc-ai/alert.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,20 @@ func cleanAlerts(alert schema.AlertFields) schema.AlertFields {
3535

3636
if alert.LastEvent.Log != nil {
3737
for key, val := range alert.LastEvent.Log {
38-
if val == nil || val.GetKind() == nil || val.GetKind().(*structpb.Value_StringValue) == nil {
38+
switch v := val.Kind.(type) {
39+
case *structpb.Value_StringValue:
40+
original := v.StringValue
41+
cleaned := original
42+
for _, pattern := range configurations.SensitivePatterns {
43+
re := regexp.MustCompile(pattern.Regexp)
44+
cleaned = re.ReplaceAllString(cleaned, pattern.FakeValue)
45+
}
46+
if cleaned != original {
47+
alert.LastEvent.Log[key] = structpb.NewStringValue(cleaned)
48+
}
49+
default:
3950
continue
4051
}
41-
original := val.GetStringValue()
42-
cleaned := original
43-
for _, pattern := range configurations.SensitivePatterns {
44-
re := regexp.MustCompile(pattern.Regexp)
45-
cleaned = re.ReplaceAllString(cleaned, pattern.FakeValue)
46-
}
47-
if cleaned != original {
48-
alert.LastEvent.Log[key] = structpb.NewStringValue(cleaned)
49-
}
5052
}
5153
}
5254
}

plugins/soc-ai/configurations/config.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ var (
2020
type Config struct {
2121
Backend string
2222
InternalKey string
23+
Openseach string
2324
APIKey string
2425
ChangeAlertStatus bool
2526
AutomaticIncidentCreation bool
@@ -51,12 +52,11 @@ func UpdateGPTConfigurations() {
5152
os.Exit(1)
5253
}
5354

54-
internalKey := pluginConfig.Get("internalKey").String()
55-
backendUrl := pluginConfig.Get("backend").String()
56-
config.Backend = backendUrl
57-
config.InternalKey = internalKey
55+
config.Backend = pluginConfig.Get("internalKey").String()
56+
config.InternalKey = pluginConfig.Get("backend").String()
57+
config.Openseach = pluginConfig.Get("opensearch").String()
5858

59-
client := moduleConf.NewUTMClient(internalKey, backendUrl)
59+
client := moduleConf.NewUTMClient(config.InternalKey, config.Backend)
6060

6161
for {
6262
if err := utils.ConnectionChecker(GPT_API_ENDPOINT); err != nil {

plugins/soc-ai/configurations/const.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
package configurations
22

3-
import (
4-
"path/filepath"
5-
6-
"github.com/utmstack/UTMStack/plugins/soc-ai/utils"
7-
)
8-
93
const (
10-
SOC_AI_SERVER_PORT = "8080"
11-
SOC_AI_SERVER_ENDPOINT = "/process"
124
API_ALERT_ENDPOINT = "/api/elasticsearch/search"
135
API_ALERT_STATUS_ENDPOINT = "/api/utm-alerts/status"
146
API_INCIDENT_ENDPOINT = "/api/utm-incidents"
@@ -65,16 +57,3 @@ var (
6557
GPT_FALSE_POSITIVE = "This alert is categorized as a potential false positive due to two key factors. Firstly, it originates from an automated system, which may occasionally produce alerts without direct human validation. Additionally, the absence of any correlated logs further raises suspicion, as a genuine incident typically leaves a trail of relevant log entries. Hence, the combination of its system-generated nature and the lack of associated logs suggests a likelihood of being a false positive rather than a genuine security incident."
6658
CORRELATION_CONTEXT = "\n\nThe current alert has historical correlation with previous alerts:\n%s"
6759
)
68-
69-
func GetOpenSearchHost() string {
70-
return "http://" + utils.Getenv("OPENSEARCH_HOST", true)
71-
}
72-
73-
func GetOpenSearchPort() string {
74-
return utils.Getenv("OPENSEARCH_PORT", true)
75-
}
76-
77-
func GetAlertsDBPath() string {
78-
path, _ := utils.GetMyPath()
79-
return filepath.Join(path, "database", "alerts.sqlite3")
80-
}

plugins/soc-ai/elastic/index.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func ElasticQuery(index string, query interface{}, op string) error {
1919
case "update":
2020
endp = configurations.ELASTIC_UPDATE_BY_QUERY_ENDPOINT
2121
}
22-
url := configurations.GetOpenSearchHost() + ":" + configurations.GetOpenSearchPort() + "/" + index + endp
22+
url := fmt.Sprintf("%s/%s%s", configurations.GetConfig().Openseach, index, endp)
2323
headers := map[string]string{
2424
"Content-Type": "application/json",
2525
}
@@ -78,7 +78,7 @@ func IndexStatus(id, status, op string) error {
7878
}
7979

8080
func CreateIndexIfNotExist(index string) error {
81-
url := configurations.GetOpenSearchHost() + ":" + configurations.GetOpenSearchPort() + "/" + index
81+
url := fmt.Sprintf("%s/%s", configurations.GetConfig().Openseach, index)
8282
headers := map[string]string{
8383
"Content-Type": "application/json",
8484
}

0 commit comments

Comments
 (0)