refactor(zabbix): 使 zabbix agent 插件集成独立化
This commit is contained in:
@ -7,6 +7,7 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"onvif-agent/config"
|
||||
"onvif-agent/constant"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@ -22,8 +23,8 @@ type Handler struct {
|
||||
client *http.Client
|
||||
}
|
||||
|
||||
func (h *Handler) GetPluginVersion(_ context.Context, _ map[string]string, _ ...string) (any, error) {
|
||||
return config.Conf.Integrations.ZabbixAgent.Plugin.Version, nil
|
||||
func (h *Handler) GetAppVersion(_ context.Context, _ map[string]string, _ ...string) (any, error) {
|
||||
return constant.AppVersion, nil
|
||||
}
|
||||
|
||||
func (h *Handler) HTTPClient(ctx context.Context, params map[string]string, _ ...string) (any, error) {
|
||||
@ -34,13 +35,12 @@ func (h *Handler) HTTPClient(ctx context.Context, params map[string]string, _ ..
|
||||
|
||||
url := params["url"]
|
||||
if !strings.HasPrefix(url, "http") {
|
||||
url = fmt.Sprintf("http://localhost:%d/%s", config.Conf.Server.Port, url)
|
||||
url = fmt.Sprintf("http://localhost:%d/%s", config.Config.App.Port, url)
|
||||
}
|
||||
|
||||
body := params["body"]
|
||||
|
||||
//req, err := http.NewRequestWithContext(ctx, method, "https://api.imbytecat.com/ip", http.NoBody)
|
||||
req, err := http.NewRequestWithContext(ctx, method, "https://api.imbytecat.com/ip", strings.NewReader(body))
|
||||
req, err := http.NewRequestWithContext(ctx, method, "https://api.imbytecat.com/ip", strings.NewReader(body)) // TODO: if empty use http.NoBody
|
||||
if err != nil {
|
||||
return nil, errs.Wrapf(err, "failed to create request")
|
||||
}
|
||||
|
Reference in New Issue
Block a user