Compare commits

..

No commits in common. "228ec269043290c1c8a8db0bfb768dd11bf91ba2" and "d82a83cca1897e0ecac3488f3743c7f16faf2997" have entirely different histories.

5 changed files with 18 additions and 16 deletions

View File

@ -35,12 +35,12 @@ func (h *Handler) HTTPClient(ctx context.Context, params map[string]string, _ ..
url := params["url"] url := params["url"]
if !strings.HasPrefix(url, "http") { if !strings.HasPrefix(url, "http") {
url = fmt.Sprintf("http://127.0.0.1:%d%s", config.Config.App.Port, url) url = fmt.Sprintf("http://localhost:%d/%s", config.Config.App.Port, url)
} }
body := params["body"] body := params["body"]
req, err := http.NewRequestWithContext(ctx, method, url, strings.NewReader(body)) // TODO: if empty use http.NoBody req, err := http.NewRequestWithContext(ctx, method, "https://api.imbytecat.com/ip", strings.NewReader(body)) // TODO: if empty use http.NoBody
if err != nil { if err != nil {
return nil, errs.Wrapf(err, "failed to create request") return nil, errs.Wrapf(err, "failed to create request")
} }
@ -57,7 +57,7 @@ func (h *Handler) HTTPClient(ctx context.Context, params map[string]string, _ ..
return nil, errs.Wrapf(err, "failed to read the response") return nil, errs.Wrapf(err, "failed to read the response")
} }
return method + url + body + string(data), nil return string(data), nil
} }
// NewHandler creates a new handler with initialized clients for system and tcp calls. // NewHandler creates a new handler with initialized clients for system and tcp calls.

View File

@ -84,9 +84,9 @@ func (p *zabbixAgentPlugin) registerMetrics() error {
), ),
handler: h.GetAppVersion, handler: h.GetAppVersion,
}, },
"onvif.httpclient": { "onvif.client": {
metric: metric.New( metric: metric.New(
"ONVIF HTTP client", "ONVIF client",
[]*metric.Param{ []*metric.Param{
metric.NewParam("method", "HTTP request method."), metric.NewParam("method", "HTTP request method."),
metric.NewParam("url", "HTTP request URL."), metric.NewParam("url", "HTTP request URL."),

18
main.go
View File

@ -62,14 +62,16 @@ func main() {
/** /**
* Zabbix agent * Zabbix agent
*/ */
go func() { //go func() {
err = zabbixagent.Launch() // zabbixagent.Run()
if err != nil { //}()
return //
} //select {}
panic(err) err = zabbixagent.Launch()
}() if err != nil {
return
}
select {} panic(err)
} }

View File

@ -4,8 +4,8 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
func Hello(c *gin.Context) { func Ping(c *gin.Context) {
c.JSON(200, gin.H{ c.JSON(200, gin.H{
"message": "Hello, World!", "message": "pong",
}) })
} }

View File

@ -7,7 +7,7 @@ import (
) )
func SetupRoutes(r *gin.Engine) { func SetupRoutes(r *gin.Engine) {
r.GET("/", handler.Hello) r.GET("/ping", handler.Ping)
userGroup := r.Group("/onvif") userGroup := r.Group("/onvif")
{ {