コード例 #1
0
ファイル: main.go プロジェクト: Cepave/lvs-metrics
func main() {
	flag.Parse()

	ctx := ipc.NewTrustedContext(seesaw.SCLocalCLI)

	var err error
	seesawConn, err = conn.NewSeesawIPC(ctx)
	if err != nil {
		fatalf("Failed to connect to engine: %v", err)
	}
	if err := seesawConn.Dial(*engineSocket); err != nil {
		fatalf("Failed to connect to engine: %v", err)
	}
	defer seesawConn.Close()
	seesawCLI = cli.NewSeesawCLI(seesawConn, exit)

	if *command == "" {
		interactive()
		exit()
	}

	if err := seesawCLI.Execute(*command); err != nil {
		fatalf("%v", err)
	}
}
コード例 #2
0
ファイル: core.go プロジェクト: Cepave/lvs-metrics
// sendBatch sends a batch of notifications to the Seesaw Engine.
func (s *Server) sendBatch(batch []*Notification) error {
	engineConn, err := net.DialTimeout("unix", s.config.EngineSocket, engineTimeout)
	if err != nil {
		return err
	}
	engineConn.SetDeadline(time.Now().Add(engineTimeout))
	engine := rpc.NewClient(engineConn)
	defer engine.Close()

	var reply int
	ctx := ipc.NewTrustedContext(seesaw.SCHealthcheck)
	return engine.Call("SeesawEngine.HealthState", &HealthState{ctx, batch}, &reply)
}
コード例 #3
0
ファイル: engine_client.go プロジェクト: Cepave/lvs-metrics
// HAUpdate informs the Seesaw Engine of the current HAStatus.
// The Seesaw Engine may request a failover in response.
func (e *EngineClient) HAUpdate(status seesaw.HAStatus) (bool, error) {
	engineConn, err := net.DialTimeout("unix", e.Socket, engineTimeout)
	if err != nil {
		return false, fmt.Errorf("HAUpdate: Dial failed: %v", err)
	}
	engineConn.SetDeadline(time.Now().Add(engineTimeout))
	engine := rpc.NewClient(engineConn)
	defer engine.Close()

	var failover bool
	ctx := ipc.NewTrustedContext(seesaw.SCHA)
	if err := engine.Call("SeesawEngine.HAUpdate", &ipc.HAStatus{ctx, status}, &failover); err != nil {
		return false, fmt.Errorf("HAUpdate: SeesawEngine.HAUpdate failed: %v", err)
	}
	return failover, nil
}
コード例 #4
0
ファイル: engine_client.go プロジェクト: Cepave/lvs-metrics
// HAState informs the Seesaw Engine of the current HAState.
func (e *EngineClient) HAState(state seesaw.HAState) error {
	engineConn, err := net.DialTimeout("unix", e.Socket, engineTimeout)
	if err != nil {
		return fmt.Errorf("HAState: Dial failed: %v", err)
	}
	engineConn.SetDeadline(time.Now().Add(engineTimeout))
	engine := rpc.NewClient(engineConn)
	defer engine.Close()

	var reply int
	ctx := ipc.NewTrustedContext(seesaw.SCHA)
	if err := engine.Call("SeesawEngine.HAState", &ipc.HAState{ctx, state}, &reply); err != nil {
		return fmt.Errorf("HAState: SeesawEngine.HAState failed: %v", err)
	}
	return nil
}
コード例 #5
0
ファイル: engine_client.go プロジェクト: Cepave/lvs-metrics
// HAConfig requests the HAConfig from the Seesaw Engine.
func (e *EngineClient) HAConfig() (*seesaw.HAConfig, error) {
	engineConn, err := net.DialTimeout("unix", e.Socket, engineTimeout)
	if err != nil {
		return nil, fmt.Errorf("HAConfig: Dial failed: %v", err)
	}
	engineConn.SetDeadline(time.Now().Add(engineTimeout))
	engine := rpc.NewClient(engineConn)
	defer engine.Close()

	var config seesaw.HAConfig
	ctx := ipc.NewTrustedContext(seesaw.SCHA)
	if err := engine.Call("SeesawEngine.HAConfig", ctx, &config); err != nil {
		return nil, fmt.Errorf("HAConfig: SeesawEngine.HAConfig failed: %v", err)
	}
	return &config, nil
}
コード例 #6
0
ファイル: core.go プロジェクト: Cepave/lvs-metrics
// getHealthchecks attempts to get the current healthcheck configurations from
// the Seesaw Engine.
func (s *Server) getHealthchecks() (*Checks, error) {
	engineConn, err := net.DialTimeout("unix", s.config.EngineSocket, engineTimeout)
	if err != nil {
		return nil, fmt.Errorf("Dial failed: %v", err)
	}
	engineConn.SetDeadline(time.Now().Add(engineTimeout))
	engine := rpc.NewClient(engineConn)
	defer engine.Close()

	var checks Checks
	ctx := ipc.NewTrustedContext(seesaw.SCHealthcheck)
	if err := engine.Call("SeesawEngine.Healthchecks", ctx, &checks); err != nil {
		return nil, fmt.Errorf("SeesawEngine.Healthchecks failed: %v", err)
	}

	return &checks, nil
}
コード例 #7
0
ファイル: stats.go プロジェクト: Cepave/lvs-metrics
// update attempts to update the cached statistics from the Seesaw Engine.
func (e *ecuStats) update() error {
	// TODO(jsing): Make this untrusted.
	ctx := ipc.NewTrustedContext(seesaw.SCECU)
	seesawConn, err := conn.NewSeesawIPC(ctx)
	if err != nil {
		return fmt.Errorf("Failed to connect to engine: %v", err)
	}
	if err := seesawConn.Dial(e.ecu.cfg.EngineSocket); err != nil {
		return fmt.Errorf("Failed to connect to engine: %v", err)
	}
	defer seesawConn.Close()

	clusterStatus, err := seesawConn.ClusterStatus()
	if err != nil {
		return fmt.Errorf("Failed to get cluster status: %v", err)
	}
	e.stats.lock.Lock()
	e.stats.ClusterStatus = *clusterStatus
	e.stats.lock.Unlock()

	configStatus, err := seesawConn.ConfigStatus()
	if err != nil {
		return fmt.Errorf("Failed to get config status: %v", err)
	}
	e.stats.lock.Lock()
	e.stats.ConfigStatus = *configStatus
	e.stats.lock.Unlock()

	ha, err := seesawConn.HAStatus()
	if err != nil {
		return fmt.Errorf("Failed to get HA status: %v", err)
	}
	e.stats.lock.Lock()
	e.stats.HAStatus = *ha
	e.stats.lock.Unlock()

	neighbors, err := seesawConn.BGPNeighbors()
	if err != nil {
		return fmt.Errorf("Failed to get BGP neighbors: %v", err)
	}
	e.stats.lock.Lock()
	e.stats.neighbors = neighbors
	e.stats.lock.Unlock()

	vlans, err := seesawConn.VLANs()
	if err != nil {
		return fmt.Errorf("Failed to get VLANs: %v", err)
	}
	e.stats.lock.Lock()
	e.stats.vlans = vlans.VLANs
	e.stats.lock.Unlock()

	vservers, err := seesawConn.Vservers()
	if err != nil {
		return fmt.Errorf("Failed to get vservers: %v", err)
	}
	e.stats.lock.Lock()
	e.stats.vservers = vservers
	e.stats.lock.Unlock()

	return nil
}