Beispiel #1
0
func main() {

	flag.Parse()
	config, err := config.Configuration(*configFilePath)
	if err != nil {
		panic(err)
	}
	logging.SetLogLevel(config.LogLevel)

	alertChan := make(chan *event.Event, 100)
	mqttBroker := broker.NewMQTTBroker("wff_notification", config.BrokerUrl)
	subscriber := subscribe.New(mqttBroker, alertChan)
	// Subscribe to all available sensor keys
	go subscriber.Start()

	// Set up the Twilio notifier
	notifier := notifiers.NewTwilio(config.TwilioAccountSid, config.TwilioAuthToken, config.TwilioFromPhone, config.To)

	service := notification.New(notifier, alertChan, time.Duration(config.NotificationIntervalMinutes)*time.Minute)
	service.Start()
}
Beispiel #2
0
	BeforeEach(func() {
		mockNotifier = &MockNotifier{}
		inputChan = make(chan *event.Event)
		sensorEvent = &event.Event{
			Name: "touchsensor1",
			Data: "test message",
		}
	})

	Context("Start", func() {
		AfterEach(func() {
			ns.Stop()
		})

		It("reads from inputChan and notifies", func() {
			ns = notification.New(mockNotifier, inputChan, time.Second)

			go ns.Start()

			Expect(mockNotifier.NotifyCallCount()).To(BeZero())
			inputChan <- sensorEvent
			Eventually(mockNotifier.NotifyCallCount).Should(Equal(1))
			Expect(mockNotifier.lastNotification).To(Equal("test message"))
		})

		It("doesn't notify again if new notification is received within notification period", func() {

			ns = notification.New(mockNotifier, inputChan, time.Second)
			go ns.Start()

			Expect(mockNotifier.NotifyCallCount()).To(BeZero())