1 Star 0 Fork 0

zhangjungang/beats

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
provider_google_gce.go 1.07 KB
一键复制 编辑 原始数据 按行查看 历史
package add_cloud_metadata
import (
"github.com/elastic/beats/libbeat/common"
s "github.com/elastic/beats/libbeat/common/schema"
c "github.com/elastic/beats/libbeat/common/schema/mapstriface"
)
// Google GCE Metadata Service
func newGceMetadataFetcher(config *common.Config) (*metadataFetcher, error) {
gceMetadataURI := "/computeMetadata/v1/?recursive=true&alt=json"
gceHeaders := map[string]string{"Metadata-Flavor": "Google"}
gceSchema := func(m map[string]interface{}) common.MapStr {
out := common.MapStr{}
if instance, ok := m["instance"].(map[string]interface{}); ok {
s.Schema{
"instance_id": c.StrFromNum("id"),
"instance_name": c.Str("name"),
"machine_type": c.Str("machineType"),
"availability_zone": c.Str("zone"),
}.ApplyTo(out, instance)
}
if project, ok := m["project"].(map[string]interface{}); ok {
s.Schema{
"project_id": c.Str("projectId"),
}.ApplyTo(out, project)
}
return out
}
fetcher, err := newMetadataFetcher(config, "gce", gceHeaders, metadataHost, gceSchema, gceMetadataURI)
return fetcher, err
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhangjungang/beats.git
git@gitee.com:zhangjungang/beats.git
zhangjungang
beats
beats
v6.2.3

搜索帮助