Exemple #1
0
func (t *HTTPProvider) Init(i interface{}) error {
	conf := i.(*HTTPConfig)

	// make sure the port is open
	l, err := net.Listen("tcp", conf.Listen)
	if err != nil {
		logrus.Error(err)

		// check to see if the busy port is due to another provider
		resp, err := std_http.Get("http://" + conf.Listen + ENDPOINT + "?init_check=true")
		if err != nil {
			return err
		}

		buff, _ := ioutil.ReadAll(resp.Body)
		if string(buff) != START_HANDSHAKE {
			return err

		}
	}

	// stop the test
	err = l.Close()
	if err != nil {
		logrus.Error(err)
		return err
	}

	// update the providers litening address
	t.listen = conf.Listen
	t.pool = event.NewEncodingPool(event.EncoderFactories[conf.Encoding], event.DecoderFactories[conf.Encoding], conf.MaxEncoders)

	return nil
}
Exemple #2
0
func (t *TCPProvider) Init(i interface{}) error {
	c := i.(*TCPConfig)

	// make sure we have a valid address
	addr, err := net.ResolveTCPAddr("tcp4", c.Listen)
	if err != nil {
		return err
	}

	t.laddr = addr

	// build an encoding pool
	t.pool = event.NewEncodingPool(event.EncoderFactories[c.Encoding], event.DecoderFactories[c.Encoding], c.MaxDecoders)
	return nil
}
Exemple #3
0
// NewPipeline
func NewPipeline(conf *config.AppConfig) *Pipeline {
	p := &Pipeline{
		encodingPool:       event.NewEncodingPool(event.EncoderFactories[conf.Encoding], event.DecoderFactories[conf.Encoding], runtime.NumCPU()),
		keepAliveAge:       conf.KeepAliveAge,
		keepAliveCheckTime: 10 * time.Second,
		in:                 make(chan *event.Event),
		unpauseChan:        make(chan struct{}),
		pauseChan:          make(chan struct{}),
		tracker:            NewTracker(),
		escalations:        &alarm.Collection{},
		index:              event.NewIndex(),
	}
	p.Start()

	p.Refresh(conf)

	logrus.Debug("Starting expiration checker")
	go p.checkExpired()

	return p
}
Exemple #4
0
func testPipeline(p map[string]*alarm.Policy) (*Pipeline, *test.TestAlert) {
	tests_ran += 1
	ta := test.NewTest().(*test.TestAlert)
	pipe := &Pipeline{
		policies:     p,
		index:        event.NewIndex(),
		pauseChan:    make(chan struct{}),
		unpauseChan:  make(chan struct{}),
		encodingPool: event.NewEncodingPool(event.EncoderFactories["json"], event.DecoderFactories["json"], runtime.NumCPU()),
		escalations: &alarm.Collection{
			Coll: map[string][]alarm.Alarm{
				"test": []alarm.Alarm{ta},
			},
		},
		tracker: NewTracker(),
		in:      make(chan *event.Event),
	}

	go pipe.tracker.Start()
	pipe.Start()
	return pipe, ta
}