Skip to content

Commit

Permalink
Merge pull request #14 from heejin-github/patch
Browse files Browse the repository at this point in the history
Apply SDK changes for AlertTypes in sdk.CallResponse
  • Loading branch information
meetrick authored Oct 11, 2023
2 parents 6c8bf78 + 0ccd6a5 commit 25954ef
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 35 deletions.
18 changes: 8 additions & 10 deletions plugins/cpu_monitor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,10 @@ func pluginFeature(info, option map[string]*structpb.Value) (sdk.CallResponse, e
percent, err := cpu.Percent(defaultDuration*time.Second, false)
if err != nil {
ret := sdk.CallResponse{
FuncName: info["execute_method"].GetStringValue(),
Message: "failed to get cpu usage",
Severity: pluginpb.SEVERITY_CRITICAL,
State: pluginpb.STATE_FAILURE,
AlertTypes: []pluginpb.ALERT_TYPE{pluginpb.ALERT_TYPE_DISCORD},
FuncName: info["execute_method"].GetStringValue(),
Message: "failed to get cpu usage",
Severity: pluginpb.SEVERITY_CRITICAL,
State: pluginpb.STATE_FAILURE,
}

return ret, err
Expand All @@ -88,11 +87,10 @@ func pluginFeature(info, option map[string]*structpb.Value) (sdk.CallResponse, e
}

ret := sdk.CallResponse{
FuncName: info["execute_method"].GetStringValue(),
Message: message,
Severity: severity,
State: state,
AlertTypes: []pluginpb.ALERT_TYPE{pluginpb.ALERT_TYPE_DISCORD},
FuncName: info["execute_method"].GetStringValue(),
Message: message,
Severity: severity,
State: state,
}

return ret, nil
Expand Down
18 changes: 8 additions & 10 deletions plugins/disk_monitor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,10 @@ func pluginFeature(info, option map[string]*structpb.Value) (sdk.CallResponse, e
if err != nil {
message = fmt.Sprint("failed to get disk usage on ", path)
ret := sdk.CallResponse{
FuncName: info["execute_method"].GetStringValue(),
Message: message,
Severity: pluginpb.SEVERITY_CRITICAL,
State: pluginpb.STATE_FAILURE,
AlertTypes: []pluginpb.ALERT_TYPE{pluginpb.ALERT_TYPE_DISCORD},
FuncName: info["execute_method"].GetStringValue(),
Message: message,
Severity: pluginpb.SEVERITY_CRITICAL,
State: pluginpb.STATE_FAILURE,
}

return ret, err
Expand Down Expand Up @@ -133,11 +132,10 @@ func pluginFeature(info, option map[string]*structpb.Value) (sdk.CallResponse, e
log.Debug().Str("module", "plugin").Msgf("severity : %s, state : %s, message : %s", severity.String(), state.String(), message)

ret := sdk.CallResponse{
FuncName: info["execute_method"].GetStringValue(),
Message: message,
Severity: severity,
State: state,
AlertTypes: []pluginpb.ALERT_TYPE{pluginpb.ALERT_TYPE_DISCORD},
FuncName: info["execute_method"].GetStringValue(),
Message: message,
Severity: severity,
State: state,
}

return ret, nil
Expand Down
18 changes: 8 additions & 10 deletions plugins/mem_monitor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,10 @@ func pluginFeature(info, option map[string]*structpb.Value) (sdk.CallResponse, e
v, err := mem.VirtualMemory()
if err != nil {
ret := sdk.CallResponse{
FuncName: info["execute_method"].GetStringValue(),
Message: "failed to get memory usage",
Severity: pluginpb.SEVERITY_CRITICAL,
State: pluginpb.STATE_FAILURE,
AlertTypes: []pluginpb.ALERT_TYPE{pluginpb.ALERT_TYPE_DISCORD},
FuncName: info["execute_method"].GetStringValue(),
Message: "failed to get memory usage",
Severity: pluginpb.SEVERITY_CRITICAL,
State: pluginpb.STATE_FAILURE,
}

return ret, err
Expand All @@ -83,11 +82,10 @@ func pluginFeature(info, option map[string]*structpb.Value) (sdk.CallResponse, e
}

ret := sdk.CallResponse{
FuncName: info["execute_method"].GetStringValue(),
Message: message,
Severity: severity,
State: state,
AlertTypes: []pluginpb.ALERT_TYPE{pluginpb.ALERT_TYPE_DISCORD},
FuncName: info["execute_method"].GetStringValue(),
Message: message,
Severity: severity,
State: state,
}

return ret, nil
Expand Down
9 changes: 4 additions & 5 deletions plugins/net_monitor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,10 @@ func pluginFeature(info, option map[string]*structpb.Value) (sdk.CallResponse, e
}

ret := sdk.CallResponse{
FuncName: info["execute_method"].GetStringValue(),
Message: message,
Severity: severityToSend,
State: state,
AlertTypes: []pluginpb.ALERT_TYPE{pluginpb.ALERT_TYPE_DISCORD},
FuncName: info["execute_method"].GetStringValue(),
Message: message,
Severity: severityToSend,
State: state,
}

return ret, nil
Expand Down

0 comments on commit 25954ef

Please sign in to comment.