Skip to content

Commit

Permalink
fix: various fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pgagnidze committed Dec 27, 2023
1 parent 5d8f59e commit 675f2a2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func main() {
defer ui.Close()

tuiManager := tui.NewManager()
tuiManager.InitializeWidgets()
tuiManager.InitializeWidgets(config.URL, config.RefreshInterval)

startMonitoring(config, tuiManager)
}
Expand Down
8 changes: 4 additions & 4 deletions net/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type WebsiteCheckResult struct {
TraceInfo *HttpTraceInfo
AssertionPassed bool
LastCheckTime time.Time
RefreshInterval time.Duration
AssertText string
}
type HttpTraceInfo struct {
Wait time.Duration
Expand All @@ -39,9 +39,8 @@ type NetworkConfig struct {

func CheckWebsite(url string, config NetworkConfig) WebsiteCheckResult {
result := WebsiteCheckResult{
URL: url,
LastCheckTime: time.Now(),
RefreshInterval: config.RefreshInterval,
URL: url,
LastCheckTime: time.Now(),
}

var start, connect, dnsStart, dnsDone, gotFirstByte time.Time
Expand Down Expand Up @@ -88,6 +87,7 @@ func CheckWebsite(url string, config NetworkConfig) WebsiteCheckResult {

bodyString := string(body)
result.AssertionPassed = true
result.AssertText = config.AssertText
if config.AssertText != "" {
result.AssertionPassed = strings.Contains(bodyString, config.AssertText)
if !result.AssertionPassed {
Expand Down
25 changes: 11 additions & 14 deletions tui/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ func NewManager() *Manager {
}
}

func (m *Manager) InitializeWidgets() {
func (m *Manager) InitializeWidgets(url string, refreshInterval time.Duration) {
m.QuitWidget = widgets.NewParagraph()
m.QuitWidget.Title = "Information"
m.QuitWidget.Text = "Press q or <C-c> to quit"
m.QuitWidget.BorderStyle.Fg = ui.ColorCyan
m.QuitWidget.BorderStyle.Fg = ui.ColorClear

m.UptimeWidget = widgets.NewParagraph()
m.UptimeWidget.Title = "Uptime"
Expand All @@ -54,7 +54,7 @@ func (m *Manager) InitializeWidgets() {
m.UpForWidget = widgets.NewParagraph()
m.UpForWidget.Title = "Duration"
m.UpForWidget.Text = "0s"
m.UpForWidget.BorderStyle.Fg = ui.ColorCyan
m.UpForWidget.BorderStyle.Fg = ui.ColorBlue

m.AvgResponseTimeWidget = widgets.NewParagraph()
m.AvgResponseTimeWidget.Title = "Average Response Time"
Expand Down Expand Up @@ -84,18 +84,18 @@ func (m *Manager) InitializeWidgets() {

m.URLWidget = widgets.NewParagraph()
m.URLWidget.Title = "Monitoring URL"
m.URLWidget.Text = "N/A"
m.URLWidget.Text = url
m.URLWidget.BorderStyle.Fg = ui.ColorBlue

m.RefreshWidget = widgets.NewParagraph()
m.RefreshWidget.Title = "Refresh Interval"
m.RefreshWidget.Text = "N/A"
m.RefreshWidget.Text = fmt.Sprintf("%v seconds", refreshInterval.Seconds())
m.RefreshWidget.BorderStyle.Fg = ui.ColorBlue

m.AssertionWidget = widgets.NewParagraph()
m.AssertionWidget.Title = "Assertion Result"
m.AssertionWidget.Text = "N/A"
m.AssertionWidget.BorderStyle.Fg = ui.ColorBlue
m.AssertionWidget.BorderStyle.Fg = ui.ColorCyan

m.TimingBreakdownWidget = uw.NewTimingBreakdown()
m.TimingBreakdownWidget.Title = "Timing Breakdown"
Expand All @@ -109,13 +109,13 @@ func (m *Manager) InitializeWidgets() {
ui.NewRow(1.0/7,
ui.NewCol(1.0/4, m.URLWidget),
ui.NewCol(1.0/4, m.RefreshWidget),
ui.NewCol(1.0/4, m.AssertionWidget),
ui.NewCol(1.0/4, m.UpForWidget),
ui.NewCol(1.0/4, m.QuitWidget),
),
ui.NewRow(1.0/7,
ui.NewCol(1.0/4, m.UptimeWidget),
ui.NewCol(1.0/4, m.UpForWidget),
ui.NewCol(1.0/4, m.AvgResponseTimeWidget),
ui.NewCol(1.0/4, m.AssertionWidget),
ui.NewCol(1.0/4, m.SSLOkWidget),
),
ui.NewRow(5.0/7,
Expand Down Expand Up @@ -144,12 +144,9 @@ func (m *Manager) UpdateWidgets(result net.WebsiteCheckResult, width int, height
sslExpiry := net.GetSSLCertExpiry(result.URL)
m.SSLOkWidget.Text = fmt.Sprintf("%d days remaining", sslExpiry)

m.URLWidget.Text = result.URL

refreshRate := fmt.Sprintf("%v seconds", result.RefreshInterval.Seconds())
m.RefreshWidget.Text = refreshRate

if result.AssertionPassed {
if result.AssertText == "" {
m.AssertionWidget.Text = "N/A"
} else if result.AssertionPassed {
m.AssertionWidget.Text = "Passing"
} else {
m.AssertionWidget.Text = "Failing"
Expand Down

0 comments on commit 675f2a2

Please sign in to comment.