You've already forked prometheus-fail2ban-exporter
							
							move code into new function
This commit is contained in:
		@@ -20,17 +20,7 @@ type Collector struct {
 | 
			
		||||
 | 
			
		||||
func NewExporter(appSettings *cfg.AppSettings, exporterVersion string) *Collector {
 | 
			
		||||
	log.Printf("reading fail2ban metrics socket file: %s", appSettings.Fail2BanSocketPath)
 | 
			
		||||
	s, err := socket.ConnectToSocket(appSettings.Fail2BanSocketPath)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.Printf("error connecting to socket: %v", err)
 | 
			
		||||
	} else {
 | 
			
		||||
		version, err := s.GetServerVersion()
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			log.Printf("error interacting with socket: %v", err)
 | 
			
		||||
		} else {
 | 
			
		||||
			log.Printf("successfully connected to fail2ban socket! fail2ban version: %s", version)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	printFail2BanServerVersion(appSettings.Fail2BanSocketPath)
 | 
			
		||||
	return &Collector{
 | 
			
		||||
		socketPath:                 appSettings.Fail2BanSocketPath,
 | 
			
		||||
		exporterVersion:            exporterVersion,
 | 
			
		||||
@@ -70,3 +60,17 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) {
 | 
			
		||||
	}
 | 
			
		||||
	c.collectErrorCountMetric(ch)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func printFail2BanServerVersion(socketPath string) {
 | 
			
		||||
	s, err := socket.ConnectToSocket(socketPath)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.Printf("error connecting to socket: %v", err)
 | 
			
		||||
	} else {
 | 
			
		||||
		version, err := s.GetServerVersion()
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			log.Printf("error interacting with socket: %v", err)
 | 
			
		||||
		} else {
 | 
			
		||||
			log.Printf("successfully connected to fail2ban socket! fail2ban version: %s", version)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user