Skip to content

Commit

Permalink
Merge pull request #8 from GrupaPracuj/test-config-option
Browse files Browse the repository at this point in the history
Test config option added
  • Loading branch information
mateusz-jablonski94 authored Oct 22, 2018
2 parents 2e13fee + 6a8a719 commit 1e71663
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 8 deletions.
15 changes: 15 additions & 0 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ type daemonCommand struct {
logger *log.Logger
}

type checkConfigCommand struct{}

func (c *versionCommand) Run(_ []string) int {
fmt.Printf("%v\r\n", c.version)
return 0
Expand Down Expand Up @@ -101,3 +103,16 @@ func (c *daemonCommand) Help() string {
func (c *daemonCommand) Synopsis() string {
return "Run IISLogExporter as daemon"
}

func (c *checkConfigCommand) Run(_ []string) int {
fmt.Printf("Configuration file is valid")
return 0
}

func (c *checkConfigCommand) Help() string {
return "Check if configuration file is valid"
}

func (c *checkConfigCommand) Synopsis() string {
return "Check if configuration file is valid"
}
3 changes: 2 additions & 1 deletion config/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package config

import (
"io/ioutil"
"log"
"os"
"path/filepath"
"strings"
"log"

"github.com/hashicorp/hcl"
)

const configFile string = "config.hcl"

func LoadConfig() (*Config, error) {
Expand Down
10 changes: 9 additions & 1 deletion lib/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"log"
"net/http"
"os"

"github.com/GrupaPracuj/iislog-prometheus-exporter/config"
"github.com/GrupaPracuj/iislog-prometheus-exporter/logging"
Expand All @@ -26,5 +27,12 @@ func ExportLogs(cfg *config.Config, logger *log.Logger) {
logging.Info(logger, fmt.Sprintf("Running HTTP server on address %s", listenAddr))

http.Handle("/metrics", prometheus.Handler())
go http.ListenAndServe(listenAddr, nil)

go func() {
err := http.ListenAndServe(listenAddr, nil)
if err != nil {
logging.Error(logger, "Error starting service", err)
os.Exit(-1)
}
}()
}
4 changes: 0 additions & 4 deletions lib/help_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,4 @@ func handler(w http.ResponseWriter, r *http.Request) {

func enableHelpPage(appConfig *config.Config) {
http.HandleFunc("/", handler)

listenAddr := fmt.Sprintf("%s:%d", appConfig.Listen.Address, appConfig.Listen.Port)

go http.ListenAndServe(listenAddr, nil)
}
5 changes: 3 additions & 2 deletions lib/site_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ func processOneFile(filename string, grokParser *grok.Grok, metrics *Metrics, si
ReOpen: true,
Poll: true,
})

if err != nil {
logging.Error(logger, "", err)
panic(err)
logging.Error(logger, fmt.Sprintf("Error tailing file %s", filename), err)
}

//Set labels and metrics
go func(siteCfg config.SiteConfig, metricCfg config.MetricConfig) {
metricsCount := len(metricCfg.Labels)
Expand Down
7 changes: 7 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ func main() {
version: version.Version,
}, nil
},
"check-config": func() (cli.Command, error) {
_, confErr := config.LoadConfig()
if confErr != nil {
panic(confErr)
}
return &checkConfigCommand{}, nil
},
"debug": func() (cli.Command, error) {
cfg, confErr := config.LoadConfig()
if confErr != nil {
Expand Down

0 comments on commit 1e71663

Please sign in to comment.