Skip to content

Commit

Permalink
Fix logged duration when errors are resolved (closes: #17).
Browse files Browse the repository at this point in the history
  • Loading branch information
a-bali committed Mar 12, 2024
1 parent 84432ba commit c20915a
Showing 1 changed file with 30 additions and 24 deletions.
54 changes: 30 additions & 24 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,22 +128,24 @@ type MQTTMonitorData struct {
}

type PingMonitorData struct {
Name string
LastOK time.Time
LastError time.Time
Status int32
TotalOK int64
TotalError int64
Errors int
Timestamp time.Time
Interval int
Threshold int
Name string
LastOK time.Time
LastError time.Time
LastErrorStart time.Time
Status int32
TotalOK int64
TotalError int64
Errors int
Timestamp time.Time
Interval int
Threshold int
}

type HTTPMonitorData struct {
Name string
LastOK time.Time
LastError time.Time
LastErrorStart time.Time
Value string
LastValue string
LastErrorValue string
Expand All @@ -158,17 +160,18 @@ type HTTPMonitorData struct {
}

type ExecMonitorData struct {
Name string
LastOK time.Time
LastError time.Time
Status int32
TotalOK int64
TotalError int64
Errors int
Timestamp time.Time
Interval int
Timeout int
Threshold int
Name string
LastOK time.Time
LastError time.Time
LastErrorStart time.Time
Status int32
TotalOK int64
TotalError int64
Errors int
Timestamp time.Time
Interval int
Timeout int
Threshold int
}

// MonitorData stores the actual status data of the monitoring process.
Expand Down Expand Up @@ -775,7 +778,7 @@ func checkPing() {
e.LastOK = time.Now()
e.Errors = 0
if e.Status == STATUS_ERROR {
alert("Ping", e.Name, STATUS_OK, e.LastError, "")
alert("Ping", e.Name, STATUS_OK, e.LastErrorStart, "")
}
e.Status = STATUS_OK
} else {
Expand All @@ -789,6 +792,7 @@ func checkPing() {
if e.Status == STATUS_WARN && e.Errors >= e.Threshold {
alert("Ping", e.Name, STATUS_ERROR, e.LastOK, "")
e.Status = STATUS_ERROR
e.LastErrorStart = time.Now()
}
}
monitorData.Unlock()
Expand Down Expand Up @@ -820,7 +824,7 @@ func checkHTTP() {
e.LastValue = val
e.Errors = 0
if e.Status == STATUS_ERROR {
alert("HTTP", e.Name, STATUS_OK, e.LastError, "")
alert("HTTP", e.Name, STATUS_OK, e.LastErrorStart, "")
}
e.Status = STATUS_OK
} else {
Expand All @@ -835,6 +839,7 @@ func checkHTTP() {
if e.Status == STATUS_WARN && e.Errors >= e.Threshold {
alert("HTTP", e.Name, STATUS_ERROR, e.LastOK, err)
e.Status = STATUS_ERROR
e.LastErrorStart = time.Now()
}

}
Expand Down Expand Up @@ -865,7 +870,7 @@ func checkExec() {

e.Errors = 0
if e.Status == STATUS_ERROR {
alert("Exec", e.Name, STATUS_OK, e.LastError, "")
alert("Exec", e.Name, STATUS_OK, e.LastErrorStart, "")
}
e.Status = STATUS_OK
} else {
Expand All @@ -880,6 +885,7 @@ func checkExec() {
if e.Status == STATUS_WARN && e.Errors >= e.Threshold {
alert("Exec", e.Name, STATUS_ERROR, e.LastOK, "")
e.Status = STATUS_ERROR
e.LastErrorStart = time.Now()
}

}
Expand Down

0 comments on commit c20915a

Please sign in to comment.