1
0
mirror of https://github.com/Chipazawra/v8-1c-cluster-pde.git synced 2024-11-21 16:46:33 +02:00

fix cluster auth

This commit is contained in:
Chipazawra 2022-05-11 00:16:03 +03:00
parent 67b12641b4
commit fcbba2e36b
3 changed files with 51 additions and 4 deletions

View File

@ -30,6 +30,10 @@ var (
PUSH_INTERVAL int
PUSH_HOST string
PUSH_PORT string
AGNT_PASS string
AGNT_USER string
CLS_USER string
CLS_PASS string
)
func init() {
@ -47,6 +51,10 @@ func init() {
flag.IntVar(&PUSH_INTERVAL, "push-interval", 0, "mode push or pull")
flag.StringVar(&PUSH_HOST, "push-host", "", "pushgateway host")
flag.StringVar(&PUSH_PORT, "push-port", "", "pushgateway port")
flag.StringVar(&AGNT_USER, "agnt-user", "", "agent user")
flag.StringVar(&AGNT_PASS, "agnt-pass", "", "agent password")
flag.StringVar(&CLS_USER, "cls-user", "", "cluster user")
flag.StringVar(&CLS_PASS, "cls-pass", "", "cluster password")
flag.Parse()
if RAS_HOST != "" {
@ -77,20 +85,39 @@ func init() {
conf.PUSH_PORT = PUSH_PORT
}
if AGNT_USER != "" {
conf.AGNT_USER = AGNT_USER
}
if AGNT_PASS != "" {
conf.AGNT_PASS = AGNT_PASS
}
if CLS_USER != "" {
conf.CLS_USER = CLS_USER
}
if CLS_PASS != "" {
conf.CLS_PASS = CLS_PASS
}
log.Printf("v8-1c-cluster-pde: overrided config from stdin:\n%#v", conf)
}
func Run() error {
rcli := rascli.NewClient(fmt.Sprintf("%s:%s", conf.RAS_HOST, conf.RAS_PORT))
rcli.AuthenticateAgent(conf.CLS_USER, conf.CLS_PASS)
rcli.AuthenticateAgent(conf.AGNT_USER, conf.AGNT_USER)
defer rcli.Close()
log.Printf("v8-1c-cluster-pde: connected to RAS %v",
fmt.Sprintf("%s:%s", conf.RAS_HOST, conf.RAS_PORT),
)
rhc := rpHostsCollector.New(rcli)
rhc := rpHostsCollector.New(rcli,
rpHostsCollector.WithCredentionals(conf.CLS_USER, conf.CLS_PASS),
)
ctx, cancel := context.WithCancel(context.Background())

View File

@ -5,6 +5,8 @@ type AppConfig struct {
RAS_PORT string `env:"RAS_PORT" envDefault:"1545"`
CLS_USER string `env:"CLS_USER"`
CLS_PASS string `env:"CLS_PASS"`
AGNT_USER string `env:"AGNT_USER"`
AGNT_PASS string `env:"AGNT_PASS"`
MODE string `env:"MODE" envDefault:"pull"`
PUSH_INTERVAL int `env:"PUSH_INTERVAL" envDefault:"500"`
PUSH_HOST string `env:"PUSH_HOST" envDefault:"localhost"`

View File

@ -14,6 +14,8 @@ import (
type rpHostsCollector struct {
ctx context.Context
clsuser string
clspass string
wg sync.WaitGroup
rasapi rascli.Api
rpHosts *prometheus.Desc
@ -34,11 +36,20 @@ type rpHostsCollector struct {
Enable *prometheus.Desc
}
func New(rasapi rascli.Api) prometheus.Collector {
type opt func(*rpHostsCollector)
func WithCredentionals(clsuser, clspass string) opt {
return func(c *rpHostsCollector) {
c.clsuser = clsuser
c.clspass = clspass
}
}
func New(rasapi rascli.Api, opts ...opt) prometheus.Collector {
proccesLabels := []string{"cluster", "pid", "host", "port", "startedAt"}
return &rpHostsCollector{
rpc := rpHostsCollector{
ctx: context.Background(),
rasapi: rasapi,
rpHosts: prometheus.NewDesc(
@ -106,6 +117,12 @@ func New(rasapi rascli.Api) prometheus.Collector {
"host enable",
proccesLabels, nil),
}
for _, opt := range opts {
opt(&rpc)
}
return &rpc
}
func (c *rpHostsCollector) Describe(ch chan<- *prometheus.Desc) {
@ -123,6 +140,7 @@ func (c *rpHostsCollector) Collect(ch chan<- prometheus.Metric) {
for _, сluster := range сlusters {
c.wg.Add(1)
c.rasapi.AuthenticateCluster(сluster.UUID, c.clsuser, c.clspass)
go c.funInCollect(ch, *сluster)
}
c.wg.Wait()