本文整理汇总了Golang中github.com/skydive-project/skydive/config.GetConfig函数的典型用法代码示例。如果您正苦于以下问题:Golang GetConfig函数的具体用法?Golang GetConfig怎么用?Golang GetConfig使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetConfig函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewOrientDBBackendFromConfig
func NewOrientDBBackendFromConfig() (*OrientDBBackend, error) {
addr := config.GetConfig().GetString("storage.orientdb.addr")
database := config.GetConfig().GetString("storage.orientdb.database")
username := config.GetConfig().GetString("storage.orientdb.username")
password := config.GetConfig().GetString("storage.orientdb.password")
return NewOrientDBBackend(addr, database, username, password)
}
示例2: init
func init() {
Analyzer.Flags().String("listen", "127.0.0.1:8082", "address and port for the analyzer API")
config.GetConfig().BindPFlag("analyzer.listen", Analyzer.Flags().Lookup("listen"))
Analyzer.Flags().Int("flowtable-expire", 600, "expiration time for flowtable entries")
config.GetConfig().BindPFlag("analyzer.flowtable_expire", Analyzer.Flags().Lookup("flowtable-expire"))
Analyzer.Flags().Int("flowtable-update", 60, "send updated flows to storage every time (second)")
config.GetConfig().BindPFlag("analyzer.flowtable_update", Analyzer.Flags().Lookup("flowtable-update"))
Analyzer.Flags().String("elasticsearch", "127.0.0.1:9200", "elasticsearch server")
config.GetConfig().BindPFlag("storage.elasticsearch", Analyzer.Flags().Lookup("elasticsearch"))
Analyzer.Flags().Bool("embed-etcd", true, "embed etcd")
config.GetConfig().BindPFlag("etcd.embedded", Analyzer.Flags().Lookup("embed-etcd"))
Analyzer.Flags().Int("etcd-port", 2379, "embedded etcd port")
config.GetConfig().BindPFlag("etcd.port", Analyzer.Flags().Lookup("etcd-port"))
Analyzer.Flags().String("etcd-datadir", "/tmp/skydive-etcd", "embedded etcd data folder")
config.GetConfig().BindPFlag("etcd.data_dir", Analyzer.Flags().Lookup("etcd-datadir"))
Analyzer.Flags().String("graph-backend", "memory", "graph backend")
config.GetConfig().BindPFlag("graph.backend", Analyzer.Flags().Lookup("graph-backend"))
Analyzer.Flags().String("gremlin", "ws://127.0.0.1:8182", "gremlin server")
config.GetConfig().BindPFlag("graph.gremlin", Analyzer.Flags().Lookup("gremlin"))
}
示例3: NewAgentAnalyzerServerConn
func NewAgentAnalyzerServerConn(addr *net.UDPAddr) (a *AgentAnalyzerServerConn, err error) {
a = &AgentAnalyzerServerConn{mode: UDP}
certPEM := config.GetConfig().GetString("analyzer.X509_cert")
keyPEM := config.GetConfig().GetString("analyzer.X509_key")
clientCertPEM := config.GetConfig().GetString("agent.X509_cert")
if len(certPEM) > 0 && len(keyPEM) > 0 {
cert, err := tls.LoadX509KeyPair(certPEM, keyPEM)
if err != nil {
logging.GetLogger().Fatalf("Can't read X509 key pair set in config : cert '%s' key '%s'", certPEM, keyPEM)
}
rootPEM, err := ioutil.ReadFile(clientCertPEM)
if err != nil {
logging.GetLogger().Fatalf("Failed to open root certificate '%s' : %s", certPEM, err.Error())
}
roots := x509.NewCertPool()
ok := roots.AppendCertsFromPEM([]byte(rootPEM))
if !ok {
logging.GetLogger().Fatal("Failed to parse root certificate " + certPEM)
}
cfgTLS := &tls.Config{
ClientCAs: roots,
ClientAuth: tls.RequireAndVerifyClientCert,
Certificates: []tls.Certificate{cert},
MinVersion: tls.VersionTLS12,
PreferServerCipherSuites: true,
CipherSuites: []uint16{
tls.TLS_RSA_WITH_AES_128_CBC_SHA,
tls.TLS_RSA_WITH_AES_256_CBC_SHA,
tls.TLS_RSA_WITH_AES_128_GCM_SHA256,
tls.TLS_RSA_WITH_AES_256_GCM_SHA384,
tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA,
tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
},
}
cfgTLS.BuildNameToCertificate()
a.tlsListen, err = tls.Listen("tcp", fmt.Sprintf("%s:%d", common.IPToString(addr.IP), addr.Port+1), cfgTLS)
if err != nil {
return nil, err
}
a.mode = TLS
logging.GetLogger().Info("Analyzer listen agents on TLS socket")
return a, nil
}
a.udpConn, err = net.ListenUDP("udp", addr)
logging.GetLogger().Info("Analyzer listen agents on UDP socket")
return a, err
}
示例4: NewElasticSearchClientFromConfig
func NewElasticSearchClientFromConfig() (*ElasticSearchClient, error) {
elasticonfig := strings.Split(config.GetConfig().GetString("storage.elasticsearch.host"), ":")
if len(elasticonfig) != 2 {
return nil, ErrBadConfig
}
maxConns := config.GetConfig().GetInt("storage.elasticsearch.maxconns")
retrySeconds := config.GetConfig().GetInt("storage.elasticsearch.retry")
bulkMaxDocs := config.GetConfig().GetInt("storage.elasticsearch.bulk_maxdocs")
return NewElasticSearchClient(elasticonfig[0], elasticonfig[1], maxConns, retrySeconds, bulkMaxDocs)
}
示例5: NewElasticSearchBackendFromConfig
func NewElasticSearchBackendFromConfig() (*ElasticSearchBackend, error) {
addr := config.GetConfig().GetString("storage.elasticsearch.host")
c := strings.Split(addr, ":")
if len(c) != 2 {
return nil, ErrBadConfig
}
maxConns := config.GetConfig().GetInt("storage.elasticsearch.maxconns")
retrySeconds := config.GetConfig().GetInt("storage.elasticsearch.retry")
bulkMaxDocs := config.GetConfig().GetInt("storage.elasticsearch.bulk_maxdocs")
return NewElasticSearchBackend(c[0], c[1], maxConns, retrySeconds, bulkMaxDocs)
}
示例6: NewOpenContrailMapper
func NewOpenContrailMapper(g *graph.Graph, r *graph.Node) *OpenContrailMapper {
host := config.GetConfig().GetString("opencontrail.host")
port := config.GetConfig().GetInt("opencontrail.port")
if host == "" {
host = "localhost"
}
if port == 0 {
port = 8085
}
mapper := &OpenContrailMapper{graph: g, root: r, agentHost: host, agentPort: port}
mapper.nodeUpdaterChan = make(chan graph.Identifier, 500)
g.AddEventListener(mapper)
return mapper
}
示例7: init
func init() {
host, err := os.Hostname()
if err != nil {
panic(err)
}
Agent.Flags().String("host-id", host, "ID used to reference the agent, defaults to hostname")
config.GetConfig().BindPFlag("host_id", Agent.Flags().Lookup("host-id"))
Agent.Flags().String("listen", "127.0.0.1:8081", "address and port for the agent API")
config.GetConfig().BindPFlag("agent.listen", Agent.Flags().Lookup("listen"))
Agent.Flags().String("ovsdb", "unix:///var/run/openvswitch/db.sock", "ovsdb connection")
config.GetConfig().BindPFlag("ovs.ovsdb", Agent.Flags().Lookup("ovsdb"))
}
示例8: CreateRootNode
func CreateRootNode(g *graph.Graph) *graph.Node {
hostID := config.GetConfig().GetString("host_id")
m := graph.Metadata{"Name": hostID, "Type": "host"}
if config.GetConfig().IsSet("agent.metadata") {
subtree := config.GetConfig().Sub("agent.metadata")
for key, value := range subtree.AllSettings() {
m[key] = value
}
}
buffer, err := ioutil.ReadFile("/var/lib/cloud/data/instance-id")
if err == nil {
m["InstanceID"] = strings.TrimSpace(string(buffer))
}
u, _ := uuid.NewV5(uuid.NamespaceOID, []byte(hostID))
return g.NewNode(graph.Identifier(u.String()), m)
}
示例9: NewOvsdbProbeFromConfig
func NewOvsdbProbeFromConfig(g *graph.Graph, n *graph.Node) *OvsdbProbe {
address := config.GetConfig().GetString("ovs.ovsdb")
var protocol string
var target string
if strings.HasPrefix(address, "unix://") {
target = strings.TrimPrefix(address, "unix://")
protocol = "unix"
} else if strings.HasPrefix(address, "tcp://") {
target = strings.TrimPrefix(address, "tcp://")
protocol = "tcp"
} else {
// fallback to the original address format addr:port
addr, port, err := config.GetHostPortAttributes("ovs", "ovsdb")
if err != nil {
logging.GetLogger().Errorf("Configuration error: %s", err.Error())
return nil
}
protocol = "tcp"
target = fmt.Sprintf("%s:%d", addr, port)
}
return NewOvsdbProbe(g, n, protocol, target)
}
示例10: SetStorageFromConfig
func (s *Server) SetStorageFromConfig() {
if t := config.GetConfig().GetString("analyzer.storage"); t != "" {
var (
err error
storage storage.Storage
)
switch t {
case "elasticsearch":
storage, err = elasticsearch.New()
if err != nil {
logging.GetLogger().Fatalf("Can't connect to ElasticSearch server: %v", err)
}
case "orientdb":
storage, err = orientdb.New()
if err != nil {
logging.GetLogger().Fatalf("Can't connect to OrientDB server: %v", err)
}
default:
logging.GetLogger().Fatalf("Storage type unknown: %s", t)
os.Exit(1)
}
s.SetStorage(storage)
logging.GetLogger().Infof("Using %s as storage", t)
}
}
示例11: NewAgentAnalyzerClientConn
func NewAgentAnalyzerClientConn(addr *net.UDPAddr) (a *AgentAnalyzerClientConn, err error) {
a = &AgentAnalyzerClientConn{}
certPEM := config.GetConfig().GetString("agent.X509_cert")
keyPEM := config.GetConfig().GetString("agent.X509_key")
serverCertPEM := config.GetConfig().GetString("analyzer.X509_cert")
if len(certPEM) > 0 && len(keyPEM) > 0 {
cert, err := tls.LoadX509KeyPair(certPEM, keyPEM)
if err != nil {
logging.GetLogger().Fatalf("Can't read X509 key pair set in config : cert '%s' key '%s'", certPEM, keyPEM)
return nil, err
}
rootPEM, err := ioutil.ReadFile(serverCertPEM)
if err != nil {
logging.GetLogger().Fatalf("Failed to open root certificate '%s' : %s", certPEM, err.Error())
}
roots := x509.NewCertPool()
ok := roots.AppendCertsFromPEM(rootPEM)
if !ok {
logging.GetLogger().Fatal("Failed to parse root certificate " + certPEM)
}
cfgTLS := &tls.Config{
Certificates: []tls.Certificate{cert},
RootCAs: roots,
}
cfgTLS.BuildNameToCertificate()
logging.GetLogger().Debugf("TLS client connection ... Dial %s:%d", common.IPToString(addr.IP), addr.Port+1)
a.tlsConnClient, err = tls.Dial("tcp", fmt.Sprintf("%s:%d", common.IPToString(addr.IP), addr.Port+1), cfgTLS)
if err != nil {
logging.GetLogger().Errorf("TLS error %s:%d : %s", common.IPToString(addr.IP), addr.Port+1, err.Error())
return nil, err
}
state := a.tlsConnClient.ConnectionState()
if state.HandshakeComplete == false {
logging.GetLogger().Debugf("TLS Handshake is not complete %s:%d : %+v", common.IPToString(addr.IP), addr.Port+1, state)
return nil, errors.New("TLS Handshake is not complete")
}
logging.GetLogger().Debugf("TLS v%d Handshake is complete on %s:%d", state.Version, common.IPToString(addr.IP), addr.Port+1)
return a, nil
}
a.udpConn, err = net.DialUDP("udp", nil, addr)
if err != nil {
return nil, err
}
logging.GetLogger().Debug("UDP client dialup done")
return a, nil
}
示例12: NewFlowProbeBundleFromConfig
func NewFlowProbeBundleFromConfig(tb *probes.TopologyProbeBundle, g *graph.Graph, fta *flow.TableAllocator) *FlowProbeBundle {
list := config.GetConfig().GetStringSlice("agent.flow.probes")
logging.GetLogger().Infof("Flow probes: %v", list)
gfe := mappings.NewGraphFlowEnhancer(g)
var aclient *analyzer.Client
addr, port, err := config.GetAnalyzerClientAddr()
if err != nil {
logging.GetLogger().Errorf("Unable to parse analyzer client: %s", err.Error())
return nil
}
if addr != "" {
aclient, err = analyzer.NewClient(addr, port)
if err != nil {
logging.GetLogger().Errorf("Analyzer client error %s:%d : %s", addr, port, err.Error())
return nil
}
}
probes := make(map[string]probe.Probe)
for _, t := range list {
if _, ok := probes[t]; ok {
continue
}
switch t {
case "ovssflow":
o := NewOvsSFlowProbesHandler(tb, g)
if o != nil {
ofe := mappings.NewOvsFlowEnhancer(g)
pipeline := mappings.NewFlowMappingPipeline(gfe, ofe)
probes[t] = FlowProbe{fpi: o, pipeline: pipeline, client: aclient}
}
case "gopacket":
o := NewGoPacketProbesHandler(g)
if o != nil {
pipeline := mappings.NewFlowMappingPipeline(gfe)
gopacket := FlowProbe{fpi: o, pipeline: pipeline, client: aclient}
probes["afpacket"] = gopacket
probes["pcap"] = gopacket
}
default:
logging.GetLogger().Errorf("unknown probe type %s", t)
}
}
p := probe.NewProbeBundle(probes)
return &FlowProbeBundle{
ProbeBundle: *p,
Graph: g,
FlowTableAllocator: fta,
}
}
示例13: initSkydiveLogger
func initSkydiveLogger() {
id := config.GetConfig().GetString("host_id") + ":" + skydiveLoggingID
skydiveLogger = SkydiveLogger{
id: id,
loggers: make(map[string]*logging.Logger),
format: "%{color}%{time} " + id + " %{shortfile} %{shortpkg} %{longfunc} > %{level:.4s} %{id:03x}%{color:reset} %{message}",
formatDebug: "%{color}%{time} " + id + " %{shortfile} %{shortpkg} %{callpath:5} %{longfunc} > %{level:.4s} %{id:03x}%{color:reset} %{message}",
}
newLogger("default", "INFO")
}
示例14: Alloc
func (a *SFlowAgentAllocator) Alloc(uuid string, p flow.FlowProbeNodeSetter, ft *flow.Table) (*SFlowAgent, error) {
address := config.GetConfig().GetString("sflow.bind_address")
if address == "" {
address = "127.0.0.1"
}
min := config.GetConfig().GetInt("sflow.port_min")
if min == 0 {
min = 6345
}
max := config.GetConfig().GetInt("sflow.port_max")
if max == 0 {
max = 6355
}
a.Lock()
defer a.Unlock()
// check if there is an already allocated agent for this uuid
for _, agent := range a.allocated {
if uuid == agent.UUID {
return agent, AgentAlreadyAllocated
}
}
for i := min; i != max+1; i++ {
if _, ok := a.allocated[i]; !ok {
s := NewSFlowAgent(uuid, address, i, ft)
s.SetFlowProbeNodeSetter(p)
a.allocated[i] = s
s.Start()
return s, nil
}
}
return nil, errors.New("sflow port exhausted")
}
示例15: NewSession
func NewSession() (*Session, error) {
s := &Session{
analyzerAddr: "localhost:8082",
authenticationOpts: shttp.AuthenticationOpts{
Username: "admin",
Password: "password",
},
}
config.GetConfig().Set("agent.analyzers", s.analyzerAddr)
return s, nil
}