-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
62 lines (39 loc) · 1.55 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"flag"
"os"
"net/http"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/sumeshkanayi/prometheus_ad_exporter/vars"
"github.com/sumeshkanayi/prometheus_ad_exporter/exporter"
"github.com/prometheus/client_golang/prometheus"
"log"
"time"
)
func init(){
}
func main(){
ldapServer:=flag.String("server","ad","LDAP Server Hostname or port")
ldapServerPort:=flag.String("port","389","LDAP Server port")
serviceAccountName:=flag.String("user","user@domainFQDN","User account to be monitored")
exporterPort:=flag.String("exporterPort","2134","Port on which the exporter should listen")
serviceAccountPassword:=os.Getenv("BIND_PASSWORD")
ldapBindTimeOut:=flag.Duration("timeout",5*time.Second,"How long should the exporter wait before exporter times out")
flag.Parse()
log.Printf("Parsing input variables completed")
log.Printf("Waiting for prometheus to start scrapping")
if serviceAccountPassword==""{
log.Printf("Empty password detected .Exiting for now.Please set the BIND_PASSWORD environment variable")
return
}
vars.Inputs.UserName=*serviceAccountName
vars.Inputs.LdapBindPassword=serviceAccountPassword
vars.Inputs.LdapServer=*ldapServer
vars.Inputs.LdapServerPort=*ldapServerPort
vars.Inputs.LdapFullPath=vars.Inputs.LdapServer+":"+vars.Inputs.LdapServerPort
vars.Inputs.LdapConnectionTimeOut=*ldapBindTimeOut
exporterCollector:=exporter.ADmetricsCollector()
prometheus.MustRegister(exporterCollector)
http.Handle("/metrics", promhttp.Handler())
http.ListenAndServe(":"+*exporterPort, nil)
}