1 Star 0 Fork 0

zhangjungang/beats

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
config.go 2.66 KB
一键复制 编辑 原始数据 按行查看 历史
package http
import (
"fmt"
"strings"
"time"
"github.com/elastic/beats/libbeat/outputs"
"github.com/elastic/beats/heartbeat/monitors"
)
type Config struct {
Name string `config:"name"`
URLs []string `config:"urls" validate:"required"`
ProxyURL string `config:"proxy_url"`
Timeout time.Duration `config:"timeout"`
MaxRedirects int `config:"max_redirects"`
Mode monitors.IPSettings `config:",inline"`
// authentication
Username string `config:"username"`
Password string `config:"password"`
// configure tls (if not configured HTTPS will use system defaults)
TLS *outputs.TLSConfig `config:"ssl"`
// http(s) ping validation
Check checkConfig `config:"check"`
}
type checkConfig struct {
Request requestParameters `config:"request"`
Response responseParameters `config:"response"`
}
type requestParameters struct {
// HTTP request configuration
Method string `config:"method"` // http request method
SendHeaders map[string]string `config:"headers"` // http request headers
SendBody string `config:"body"` // send body payload
Compression compressionConfig `config:"compression"` // optionally compress payload
// TODO:
// - add support for cookies
// - select HTTP version. golang lib will either use 1.1 or 2.0 if HTTPS is used, otherwise HTTP 1.1 . => implement/use specific http.RoundTripper implementation to change wire protocol/version being used
}
type responseParameters struct {
// expected HTTP response configuration
Status uint16 `config:"status" verify:"min=0, max=699"`
RecvHeaders map[string]string `config:"headers"`
RecvBody string `config:"body"`
}
type compressionConfig struct {
Type string `config:"type"`
Level int `config:"level"`
}
var defaultConfig = Config{
Name: "http",
Timeout: 16 * time.Second,
MaxRedirects: 10,
Mode: monitors.DefaultIPSettings,
Check: checkConfig{
Request: requestParameters{
Method: "GET",
SendHeaders: nil,
SendBody: "",
},
Response: responseParameters{
Status: 0,
RecvHeaders: nil,
RecvBody: "",
},
},
}
func (r *requestParameters) Validate() error {
switch strings.ToUpper(r.Method) {
case "HEAD", "GET", "POST":
default:
return fmt.Errorf("HTTP method '%v' not supported", r.Method)
}
return nil
}
func (c *compressionConfig) Validate() error {
t := strings.ToLower(c.Type)
if t != "" && t != "gzip" {
return fmt.Errorf("compression type '%v' not supported", c.Type)
}
if t == "" {
return nil
}
if !(0 <= c.Level && c.Level <= 9) {
return fmt.Errorf("compression level %v invalid", c.Level)
}
return nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhangjungang/beats.git
git@gitee.com:zhangjungang/beats.git
zhangjungang
beats
beats
v6.2.4

搜索帮助

0d507c66 1850385 C8b1a773 1850385