示例#1
0
func (messageRouter *messageRouter) manageDrains(activeSinks *groupedsinks.GroupedSinks, appId string, drainUrls []string, sourceName string) {
	if sourceName != "App" {
		return
	}
	//delete all drains for app
	if len(drainUrls) == 0 {
		for _, sink := range activeSinks.DrainsFor(appId) {
			messageRouter.unregisterSink(sink, activeSinks)
		}
		return
	}

	//delete all drains that were not sent
	for _, sink := range activeSinks.DrainsFor(appId) {
		if contains(sink.Identifier(), drainUrls) {
			continue
		}
		messageRouter.unregisterSink(sink, activeSinks)
	}

	//add all drains that didn't exist
	for _, drainUrl := range drainUrls {
		if activeSinks.DrainFor(appId, drainUrl) == nil && !messageRouter.urlIsBlackListed(drainUrl) {
			dl, err := url.Parse(drainUrl)
			if err != nil {
				messageRouter.blacklistedURLS = append(messageRouter.blacklistedURLS, drainUrl)
				errorMessage := fmt.Sprintf("MessageRouter: Error when trying to parse syslog url %v. Requesting close. Err: %v", drainUrl, err)
				messageRouter.sendLoggregatorErrorMessage(errorMessage, appId)
				continue
			}
			ipNotBlacklisted, err := iprange.IpOutsideOfRanges(*dl, messageRouter.blackListIPs)
			if err != nil {
				messageRouter.blacklistedURLS = append(messageRouter.blacklistedURLS, drainUrl)
				errorMessage := fmt.Sprintf("MessageRouter: Error when trying to check syslog url %v against blacklist ip ranges. Requesting close. Err: %v", drainUrl, err)
				messageRouter.sendLoggregatorErrorMessage(errorMessage, appId)
				continue
			}
			if ipNotBlacklisted {
				sysLogger := sinks.NewSyslogWriter(dl.Scheme, dl.Host, appId, messageRouter.skipCertVerify)
				s := sinks.NewSyslogSink(appId, drainUrl, messageRouter.logger, sysLogger, messageRouter.errorChannel)
				ok := messageRouter.registerSink(s, activeSinks)
				if ok {
					go s.Run()
				}
			} else {
				messageRouter.blacklistedURLS = append(messageRouter.blacklistedURLS, drainUrl)
				errorMsg := fmt.Sprintf("MessageRouter: Syslog drain url is blacklisted: %s", drainUrl)
				messageRouter.sendLoggregatorErrorMessage(errorMsg, appId)
			}
		}
	}
}
示例#2
0
func (messageRouter *messageRouter) manageDrains(activeSinks *groupedsinks.GroupedSinks, appId string, drainUrls []string, sourceType logmessage.LogMessage_SourceType) {
	if sourceType != logmessage.LogMessage_WARDEN_CONTAINER {
		return
	}
	//delete all drains for app
	if len(drainUrls) == 0 {
		for _, sink := range activeSinks.DrainsFor(appId) {
			messageRouter.unregisterSink(sink, activeSinks)
		}
		return
	}

	//delete all drains that were not sent
	for _, sink := range activeSinks.DrainsFor(appId) {
		if contains(sink.Identifier(), drainUrls) {
			continue
		}
		messageRouter.unregisterSink(sink, activeSinks)
	}

	//add all drains that didn't exist
	for _, drainUrl := range drainUrls {
		if activeSinks.DrainFor(appId, drainUrl) == nil {
			dl, err := url.Parse(drainUrl)
			if err != nil {
				messageRouter.logger.Warnf("MessageRouter: Error when trying to parse syslog url %v. Requesting close. Err: %v", drainUrl, err)
				continue
			}
			sysLogger := sinks.NewSyslogWriter("tcp", dl.Host, appId)
			s := sinks.NewSyslogSink(appId, drainUrl, messageRouter.logger, sysLogger)
			ok := messageRouter.registerSink(s, activeSinks)
			if ok {
				go s.Run()
			}
		}
	}
}
示例#3
0
func init() {
	syslogWriter = sinks.NewSyslogWriter("syslog", "localhost:24631", "appId", false)
}
func init() {
	syslogWriter = sinks.NewSyslogWriter("tcp", "localhost:24631", "appId")
}