Exemplo n.º 1
0
func (sinkManager *SinkManager) registerNewSyslogSink(appId string, syslogSinkURL string) {
	parsedSyslogDrainURL, err := sinkManager.urlBlacklistManager.CheckUrl(syslogSinkURL)
	if err != nil {
		sinkManager.SendSyslogErrorToLoggregator(invalidSyslogURLErrorMsg(appId, syslogSinkURL, err), appId)
		return
	}

	syslogWriter, err := syslogwriter.NewWriter(parsedSyslogDrainURL, appId, sinkManager.skipCertVerify, sinkManager.dialTimeout, sinkManager.sinkIOTimeout)
	if err != nil {
		logURL := fmt.Sprintf("%s://%s%s", parsedSyslogDrainURL.Scheme, parsedSyslogDrainURL.Host, parsedSyslogDrainURL.Path)
		sinkManager.SendSyslogErrorToLoggregator(invalidSyslogURLErrorMsg(appId, logURL, err), appId)
		return
	}

	syslogSink := syslog.NewSyslogSink(
		appId,
		parsedSyslogDrainURL,
		sinkManager.logger,
		sinkManager.messageDrainBufferSize,
		syslogWriter,
		sinkManager.SendSyslogErrorToLoggregator,
		sinkManager.dropsondeOrigin,
	)

	sinkManager.RegisterSink(syslogSink)

}
Exemplo n.º 2
0
func (sinkManager *SinkManager) registerNewSyslogSink(appId string, syslogSinkUrl string) {
	parsedSyslogDrainUrl, err := sinkManager.urlBlacklistManager.CheckUrl(syslogSinkUrl)
	if err != nil {
		sinkManager.SendSyslogErrorToLoggregator(invalidSyslogUrlErrorMsg(appId, syslogSinkUrl, err), appId, syslogSinkUrl)
		return
	}

	syslogWriter, err := syslogwriter.NewWriter(parsedSyslogDrainUrl, appId, sinkManager.skipCertVerify)
	if err != nil {
		sinkManager.SendSyslogErrorToLoggregator(invalidSyslogUrlErrorMsg(appId, syslogSinkUrl, err), appId, syslogSinkUrl)
		return
	}

	syslogSink := syslog.NewSyslogSink(
		appId,
		syslogSinkUrl,
		sinkManager.logger,
		syslogWriter,
		sinkManager.SendSyslogErrorToLoggregator,
		sinkManager.dropsondeOrigin,
		sinkManager.sinkDropUpdateChannel,
	)

	sinkManager.RegisterSink(syslogSink)

}
Exemplo n.º 3
0
				sinkManager.UnregisterSink(dumpSink)

				Eventually(func() []*events.Envelope {
					return sinkManager.RecentLogsFor("appId")
				}).Should(HaveLen(0))
			})
		})

		Context("with a SyslogSink", func() {
			var syslogSink sinks.Sink

			BeforeEach(func() {
				url := &url.URL{Scheme: "syslog", Host: "localhost:9998"}
				writer, _ := syslogwriter.NewSyslogWriter(url, "appId", &net.Dialer{Timeout: 500 * time.Millisecond}, 0)
				syslogSink = syslog.NewSyslogSink("appId", url, loggertesthelper.Logger(), 100, writer, func(string, string) {}, "dropsonde-origin")

				sinkManager.RegisterSink(syslogSink)
			})

			It("removes the sink", func() {
				Expect(fakeMetricSender.GetValue("messageRouter.numberOfSyslogSinks").Value).To(Equal(float64(1)))

				sinkManager.UnregisterSink(syslogSink)

				Expect(fakeMetricSender.GetValue("messageRouter.numberOfSyslogSinks").Value).To(Equal(float64(0)))
			})
		})

		Context("when called twice", func() {
			var dumpSink *dump.DumpSink
Exemplo n.º 4
0
		errorHandler = func(errorMsg string, appId string, drainUrl string) {
			logMessage := factories.NewLogMessage(events.LogMessage_ERR, errorMsg, appId, "LGR")
			envelope, _ := emitter.Wrap(logMessage, "dropsonde-origin")

			select {
			case errorChannel <- envelope:
			default:
			}
		}

		bufferSize = 100
	})

	JustBeforeEach(func() {
		syslogSink = syslog.NewSyslogSink("appId", "syslog://using-fake", loggertesthelper.Logger(), bufferSize, sysLogger, errorHandler, "dropsonde-origin")
	})

	Context("when remote syslog server is down", func() {
		JustBeforeEach(func() {
			sysLogger.SetDown(true)
			go func() {
				syslogSink.Run(inputChan)
				close(syslogSinkRunFinished)
			}()
		})

		AfterEach(func() {
			syslogSink.Disconnect()
			Eventually(syslogSinkRunFinished).Should(BeClosed())
		})
Exemplo n.º 5
0
				sinkManager.UnregisterSink(dumpSink)

				Eventually(func() []*events.Envelope {
					return sinkManager.RecentLogsFor("appId")
				}).Should(HaveLen(0))
			})
		})

		Context("with a SyslogSink", func() {
			var syslogSink sinks.Sink

			BeforeEach(func() {
				url, err := url.Parse("syslog://localhost:9998")
				Expect(err).To(BeNil())
				writer, _ := syslogwriter.NewSyslogWriter(url, "appId")
				syslogSink = syslog.NewSyslogSink("appId", "localhost:9999", loggertesthelper.Logger(), writer, func(string, string, string) {}, "dropsonde-origin", make(chan int64))

				sinkManager.RegisterSink(syslogSink)
			})

			It("removes the sink", func() {
				Expect(fakeMetricSender.GetValue("messageRouter.numberOfSyslogSinks").Value).To(Equal(float64(1)))

				sinkManager.UnregisterSink(syslogSink)

				Expect(fakeMetricSender.GetValue("messageRouter.numberOfSyslogSinks").Value).To(Equal(float64(0)))
			})
		})

		Context("when called twice", func() {
			var dumpSink *dump.DumpSink
				var requests int64

				server := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
					w.WriteHeader(400)
					timestampsInMillis = append(timestampsInMillis, time.Now().UnixNano()/1e6)
					atomic.AddInt64(&requests, 1)
				}))
				url, _ := url.Parse(server.URL)

				dialer := &net.Dialer{}
				httpsWriter, err := syslogwriter.NewHttpsWriter(url, appId, true, dialer, 0)
				Expect(err).ToNot(HaveOccurred())

				errorHandler := func(errorMsg string, appId string, drainUrl string) {}

				syslogSink := syslog.NewSyslogSink(appId, server.URL, loggertesthelper.Logger(), bufferSize, httpsWriter, errorHandler, "dropsonde-origin")
				inputChan := make(chan *events.Envelope)

				defer syslogSink.Disconnect()
				go syslogSink.Run(inputChan)

				for i := 0; i < int(bufferSize); i++ {
					msg := fmt.Sprintf("message number %v", i)
					logMessage, _ := emitter.Wrap(factories.NewLogMessage(events.LogMessage_OUT, msg, appId, "App"), "origin")

					inputChan <- logMessage
				}
				close(inputChan)

				Eventually(func() int64 {
					return atomic.LoadInt64(&requests)
Exemplo n.º 7
0
			logMessage := factories.NewLogMessage(events.LogMessage_ERR, errorMsg, appId, "LGR")
			envelope, _ := emitter.Wrap(logMessage, "dropsonde-origin")

			select {
			case errorChannel <- envelope:
			default:
			}
		}

		bufferSize = 100
	})

	JustBeforeEach(func() {
		drainURL, err := url.Parse(drainURL)
		Expect(err).ToNot(HaveOccurred())
		syslogSink = syslog.NewSyslogSink("appId", drainURL, logger, bufferSize, sysLogger, errorHandler, "dropsonde-origin")
	})

	Describe("Identifier", func() {
		Context("with an empty drain URL", func() {
			BeforeEach(func() {
				drainURL = ""
			})

			It("returns an empty string", func() {
				Expect(syslogSink.Identifier()).To(BeEmpty())
			})
		})
	})

	Context("hides sensitive info", func() {
Exemplo n.º 8
0
		sysLogger = NewSyslogWriterRecorder()
		errorChannel = make(chan *events.Envelope, 10)
		inputChan = make(chan *events.Envelope)

		errorHandler = func(errorMsg string, appId string, drainUrl string) {
			logMessage := factories.NewLogMessage(events.LogMessage_ERR, errorMsg, appId, "LGR")
			envelope, _ := emitter.Wrap(logMessage, "dropsonde-origin")

			select {
			case errorChannel <- envelope:
			default:
			}
		}

		updateMetricChan = make(chan int64, 1)
		syslogSink = syslog.NewSyslogSink("appId", "syslog://using-fake", loggertesthelper.Logger(), sysLogger, errorHandler, "dropsonde-origin", updateMetricChan)
	})

	Context("when remote syslog server is down", func() {
		BeforeEach(func() {
			sysLogger.SetDown(true)
			go func() {
				syslogSink.Run(inputChan)
				close(syslogSinkRunFinished)
			}()
		})

		AfterEach(func() {
			syslogSink.Disconnect()
			Eventually(syslogSinkRunFinished).Should(BeClosed())
		})