Skip to content

Commit

Permalink
Fix ttl Change time, Add probeTimeoutStatus to config
Browse files Browse the repository at this point in the history
  • Loading branch information
iobear committed May 29, 2024
1 parent 9c73520 commit cf42850
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 19 deletions.
19 changes: 13 additions & 6 deletions cmd/dashgoat/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ type (
LogFormat string `yaml:"logformat"`
UpdateKey string `yaml:"updatekey"`
CheckBuddyIntervalSec int `yaml:"checkBuddyIntervalSec"`
BuddyDownStatusMsg string `yaml:"buddyDownStatusMsg"`
BuddyDownStatus string `yaml:"buddyDownStatus"`
ProbeTimeoutStatus string `yaml:"probeTimeoutStatus"`
BuddyHosts []Buddy `yaml:"buddy"`
BuddyNsConfig string `yaml:"buddynsconfig"`
IgnorePrefix []string `yaml:"ignorePrefix"`
Expand Down Expand Up @@ -63,8 +64,8 @@ func (conf *Configer) ReadEnv() {
if os.Getenv("CHECKBUDDYINTERVALSEC") != "" {
conf.CheckBuddyIntervalSec = str2int(os.Getenv("CHECKBUDDYINTERVALSEC"))
}
if os.Getenv("BUDDYDOWNSTATUSMSG") != "" {
conf.BuddyDownStatusMsg = os.Getenv("BUDDYDOWNSTATUSMSG")
if os.Getenv("BUDDYDOWNSTATUS") != "" {
conf.BuddyDownStatus = os.Getenv("BUDDYDOWNSTATUS")
}
if os.Getenv("BUDDYNAME") != "" && os.Getenv("BUDDYURL") != "" {
tmp_buddy.Name = os.Getenv("BUDDYNAME")
Expand Down Expand Up @@ -135,13 +136,19 @@ func (conf *Configer) InitConfig(config_path string) error {
conf.DashName = strings.ToLower(conf.DashName)
}

if conf.ProbeTimeoutStatus == "" {
conf.ProbeTimeoutStatus = "error"
} else {
conf.ProbeTimeoutStatus = strings.ToLower(conf.ProbeTimeoutStatus)
}

// Buddy settings
if config_path == "" {
if buddy_cli.Url != "" && buddy_cli.Url != "0" {
conf.BuddyHosts = append(conf.BuddyHosts, buddy_cli)
}

conf.CheckBuddyIntervalSec = 11
conf.CheckBuddyIntervalSec = 3

if len(conf.BuddyHosts) > 0 {
err := validateBuddyConf()
Expand All @@ -153,8 +160,8 @@ func (conf *Configer) InitConfig(config_path string) error {
}

// Default status when Buddy is down
if conf.BuddyDownStatusMsg == "" {
conf.BuddyDownStatusMsg = "warning"
if conf.BuddyDownStatus == "" {
conf.BuddyDownStatus = "warning"
}

// Default TTL bahaviour
Expand Down
25 changes: 15 additions & 10 deletions cmd/dashgoat/timeoutprobe.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ func lostProbeTimer() {
count, check_slice := listProbeTimeout()

if count > 0 {
timeNow := time.Now().Unix()
time_now := time.Now().Unix()
for _, value := range check_slice {
if timeNow > value.TimeoutEpoch {
if time_now > value.TimeoutEpoch {
updateEventLostProbe(value.HostService)
}
}
Expand Down Expand Up @@ -64,23 +64,28 @@ func listProbeTimeout() (int, []TimerEpoch) {
}

// updateEventLostProbe - sets Message , Severity and Status accordingly
func updateEventLostProbe(hostService string) {
func updateEventLostProbe(host_service string) {
ss.mutex.Lock()
defer ss.mutex.Unlock()

tmpStruct := ss.serviceStateList[hostService]
tmpStruct.Message = "Lost probe heartbeat"
tmpStruct.Severity = "error"
tmpStruct.Status = "error"
tmp_struct := ss.serviceStateList[host_service]
tmp_struct.Message = "Lost probe heartbeat"
tmp_struct.Severity = config.ProbeTimeoutStatus
tmp_struct.Status = config.ProbeTimeoutStatus

iSnewState(tmpStruct)
change := iSnewState(tmp_struct) // Informs abount state change
if change {
tmp_struct.Change = time.Now().Unix()
} else {
tmp_struct.Change = ss.serviceStateList[host_service].Change
}

ss.serviceStateList[hostService] = tmpStruct
ss.serviceStateList[host_service] = tmp_struct
}

func findProbeInterval() int {
interval_max := 60
interval_min := 4
interval_min := 2
result := interval_min

result_slice := uniqList("nextupdatesec")
Expand Down
6 changes: 3 additions & 3 deletions dashgoat.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ ipport: :2000
# If a buddy goes down, on what level should this be reported in e.g., info, warning, error, or critical
# default warning

# buddyDownStatusMsg: warning
# buddyDownStatus: warning

# Time in sec between checking if your buddy is running
# default 11
# default 3

# checkBuddyIntervalSec: 11
# checkBuddyIntervalSec: 3

## PROMETHEUS ##

Expand Down

0 comments on commit cf42850

Please sign in to comment.