@@ -31,6 +31,14 @@ import (
3131 "golang.org/x/term"
3232)
3333
34+ type config struct {
35+ listenAddress string
36+ telemetryPath string
37+ puppetReportFile string
38+ puppetConfigFile string
39+ puppetConfigSection string
40+ }
41+
3442func setupLogger () func () {
3543 var logger * zap.Logger
3644 var err error
@@ -78,22 +86,25 @@ var rootTemplate = template.Must(template.New("/").Parse(`<html>
7886</html>
7987` ))
8088
81- func run (ctx context.Context , listenAddress , telemetryPath string ) (ok bool ) {
89+ func run (ctx context.Context , cfg * config ) (ok bool ) {
8290 lgr := zap .S ()
8391
8492 prometheus .DefaultRegisterer .MustRegister (puppetconfig.Collector {
85- Logger : lgr ,
93+ Logger : lgr ,
94+ ConfigPath : cfg .puppetConfigFile ,
95+ ConfigSection : cfg .puppetConfigSection ,
8696 })
8797 prometheus .DefaultRegisterer .MustRegister (puppetreport.Collector {
88- Logger : lgr ,
98+ Logger : lgr ,
99+ ReportPath : cfg .puppetReportFile ,
89100 })
90101
91102 mux := http .NewServeMux ()
92- mux .Handle (telemetryPath , promhttp .Handler ())
103+ mux .Handle (cfg . telemetryPath , promhttp .Handler ())
93104 mux .HandleFunc ("/" , func (writer http.ResponseWriter , request * http.Request ) {
94- _ = rootTemplate .Execute (writer , telemetryPath )
105+ _ = rootTemplate .Execute (writer , cfg . telemetryPath )
95106 })
96- server := & http.Server {Addr : listenAddress , Handler : mux }
107+ server := & http.Server {Addr : cfg . listenAddress , Handler : mux }
97108
98109 resultCh := make (chan bool )
99110 go func () {
@@ -125,10 +136,18 @@ func run(ctx context.Context, listenAddress, telemetryPath string) (ok bool) {
125136
126137func main () {
127138 // Flag definitions copied from github.com/prometheus/node_exporter
128- var (
129- listenAddress = kingpin .Flag ("web.listen-address" , "Address on which to expose metrics and web interface." ).Default (":9819" ).String ()
130- telemetryPath = kingpin .Flag ("web.telemetry-path" , "Path under which to expose metrics." ).Default ("/metrics" ).String ()
131- )
139+ var cfg config
140+
141+ kingpin .Flag ("web.listen-address" , "Address on which to expose metrics and web interface." ).
142+ Default (":9819" ).StringVar (& cfg .listenAddress )
143+ kingpin .Flag ("web.telemetry-path" , "Path under which to expose metrics." ).
144+ Default ("/metrics" ).StringVar (& cfg .telemetryPath )
145+ kingpin .Flag ("puppet.report-file" , "Path to the Puppet run report." ).
146+ Default ("/opt/puppetlabs/puppet/cache/state/last_run_report.yaml" ).StringVar (& cfg .puppetReportFile )
147+ kingpin .Flag ("puppet.config-file" , "Path to the Puppet configuration." ).
148+ Default ("/etc/puppetlabs/puppet/puppet.conf" ).StringVar (& cfg .puppetConfigFile )
149+ kingpin .Flag ("puppet.config-section" , "Stanza to consider in the Puppet configuration." ).
150+ Default ("main" ).StringVar (& cfg .puppetConfigSection )
132151 kingpin .HelpFlag .Short ('h' )
133152 kingpin .Parse ()
134153
@@ -138,7 +157,7 @@ func main() {
138157 ctx , onExit := setupInterruptContext ()
139158 defer onExit ()
140159
141- if ok := run (ctx , * listenAddress , * telemetryPath ); ! ok {
160+ if ok := run (ctx , & cfg ); ! ok {
142161 os .Exit (1 )
143162 }
144163}
0 commit comments