Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/pkg/integrations/snmp_exporter/common/common.go
5371 views
1
package common
2
3
import (
4
"bytes"
5
"compress/gzip"
6
_ "embed" // enables the go:embed directive
7
"io"
8
9
snmp_config "github.com/prometheus/snmp_exporter/config"
10
"gopkg.in/yaml.v2"
11
)
12
13
//go:generate curl https://raw.githubusercontent.com/prometheus/snmp_exporter/v0.20.0/snmp.yml --output snmp.yml
14
//go:generate gzip -9 snmp.yml
15
//go:embed snmp.yml.gz
16
var content []byte
17
18
// LoadEmbeddedConfig loads the SNMP config via a file using the go:embed directive.
19
func LoadEmbeddedConfig() (*snmp_config.Config, error) {
20
gzipReader, err := gzip.NewReader(bytes.NewReader(content))
21
if err != nil {
22
return nil, err
23
}
24
25
b, err := io.ReadAll(gzipReader)
26
if err != nil {
27
return nil, err
28
}
29
30
cfg := &snmp_config.Config{}
31
err = yaml.UnmarshalStrict(b, cfg)
32
if err != nil {
33
return nil, err
34
}
35
return cfg, nil
36
}
37
38