예제 #1
0
func (sinkManager *SinkManager) registerNewSyslogSink(appId string, syslogSinkUrl string) {
	parsedSyslogDrainUrl, err := sinkManager.urlBlacklistManager.CheckUrl(syslogSinkUrl)
	if err != nil {
		errorMsg := fmt.Sprintf("SinkManager: Invalid syslog drain URL: %s. Err: %v", syslogSinkUrl, err)
		sinkManager.SendSyslogErrorToLoggregator(errorMsg, appId)
	} else {
		syslogWriter := syslogwriter.NewSyslogWriter(parsedSyslogDrainUrl, appId, sinkManager.skipCertVerify)
		syslogSink := syslog.NewSyslogSink(appId, syslogSinkUrl, sinkManager.logger, syslogWriter, sinkManager.errorChannel)
		sinkManager.RegisterSink(syslogSink)
	}

}
예제 #2
0
func (sinkManager *SinkManager) registerNewSyslogSinks(appId string, syslogSinkUrls []string) {
	for _, syslogSinkUrl := range syslogSinkUrls {
		if sinkManager.sinks.DrainFor(appId, syslogSinkUrl) == nil && !sinkManager.urlBlacklistManager.IsBlacklisted(syslogSinkUrl) {
			parsedSyslogDrainUrl, err := sinkManager.urlBlacklistManager.CheckUrl(syslogSinkUrl)
			if err != nil {
				sinkManager.urlBlacklistManager.BlacklistUrl(syslogSinkUrl)
				errorMsg := fmt.Sprintf("SinkManager: Invalid syslog drain URL: %s. Err: %v", syslogSinkUrl, err)
				sinkManager.sendSyslogErrorToLoggregator(errorMsg, appId)
			} else {
				syslogWriter := syslogwriter.NewSyslogWriter(parsedSyslogDrainUrl.Scheme, parsedSyslogDrainUrl.Host, appId, sinkManager.skipCertVerify)
				syslogSink := sinks.NewSyslogSink(appId, syslogSinkUrl, sinkManager.logger, syslogWriter, sinkManager.errorChannel)
				if sinkManager.RegisterSink(syslogSink) {
					go syslogSink.Run()
				}
			}
		}
	}
}
	"strings"
	"time"
)

var _ = Describe("SyslogWriter", func() {
	Context("With syslog Connection", func() {

		var dataChan <-chan []byte
		var serverStoppedChan <-chan bool
		var shutdownChan chan bool
		var sysLogWriter syslogwriter.SyslogWriter

		BeforeEach(func() {
			shutdownChan = make(chan bool)
			dataChan, serverStoppedChan = startSyslogServer(shutdownChan)
			sysLogWriter = syslogwriter.NewSyslogWriter("syslog", "localhost:9999", "appId", false)
			sysLogWriter.Connect()
		})

		AfterEach(func() {
			close(shutdownChan)
			sysLogWriter.Close()
			<-serverStoppedChan
		})

		Context("Message Format", func() {
			It("should send messages from stdout with INFO priority", func(done Done) {
				sysLogWriter.WriteStdout([]byte("just a test"), "test", "", time.Now().UnixNano())

				data := <-dataChan
				Expect(string(data)).To(MatchRegexp(`\d <14>\d `))
예제 #4
0
	"time"
)

var _ = Describe("SyslogWriter", func() {
	Context("With syslog Connection", func() {

		var dataChan <-chan []byte
		var serverStoppedChan <-chan bool
		var shutdownChan chan bool
		var sysLogWriter syslogwriter.SyslogWriter

		BeforeEach(func() {
			shutdownChan = make(chan bool)
			dataChan, serverStoppedChan = startSyslogServer(shutdownChan)
			outputUrl, _ := url.Parse("syslog://localhost:9999")
			sysLogWriter = syslogwriter.NewSyslogWriter(outputUrl, "appId", false)
			sysLogWriter.Connect()
		})

		AfterEach(func() {
			close(shutdownChan)
			sysLogWriter.Close()
			<-serverStoppedChan
		})

		Context("Message Format", func() {
			It("should send messages from stdout with INFO priority", func(done Done) {
				sysLogWriter.WriteStdout([]byte("just a test"), "test", "", time.Now().UnixNano())

				data := <-dataChan
				Expect(string(data)).To(MatchRegexp(`\d <14>\d `))
예제 #5
0
				sinkManager.UnregisterSink(dumpSink)

				Eventually(func() []*logmessage.Message {
					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", true)
				errorChan := make(chan *logmessage.Message)
				syslogSink = syslog.NewSyslogSink("appId", "localhost:9999", loggertesthelper.Logger(), writer, errorChan)

				sinkManager.RegisterSink(syslogSink)
			})

			It("removes the sink", func() {
				Expect(sinkManager.Metrics.SyslogSinks).To(Equal(1))

				sinkManager.UnregisterSink(syslogSink)

				Expect(sinkManager.Metrics.SyslogSinks).To(Equal(0))
			})
		})