Skip to content

Commit

Permalink
Bug fix (http error)
Browse files Browse the repository at this point in the history
  • Loading branch information
leech001 committed Sep 3, 2022
1 parent cf8f90a commit ce1f594
Showing 1 changed file with 29 additions and 31 deletions.
60 changes: 29 additions & 31 deletions app/httpCheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,46 +28,44 @@ func httpCheck(update uint16, bot *tgbotapi.BotAPI, group int64, site struct {
elapsed := time.Since(start).Seconds()

if err != nil {
msg := tgbotapi.NewMessage(group, "Site "+site.Url+" HTTP get error")
bot.Send(msg)
break
}

if elapsed >= delay {
msg := tgbotapi.NewMessage(group, "Site "+site.Url+" HTTP delay "+strconv.FormatFloat(elapsed, 'f', 3, 32)+" sec.")
bot.Send(msg)
break
}

bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
msg := tgbotapi.NewMessage(group, "Site "+site.Url+" HTTP get error")
bot.Send(msg)
break
}
body := string(bodyBytes)

if resp.StatusCode != 200 {
msg := tgbotapi.NewMessage(group, "Site "+site.Url+" HTTP error. Code "+strconv.Itoa(resp.StatusCode))
bot.Send(msg)
break
}
errorHTML++
} else {
if resp.StatusCode != 200 {
msg := tgbotapi.NewMessage(group, "Site "+site.Url+" HTTP error. Code "+strconv.Itoa(resp.StatusCode))
bot.Send(msg)
break
}

for _, element := range site.Elements {
if !strings.Contains(body, element) {
msg := tgbotapi.NewMessage(group, "Site "+site.Url+" defaced. Element '"+element+"' not found.")
if elapsed >= delay {
msg := tgbotapi.NewMessage(group, "Site "+site.Url+" HTTP delay "+strconv.FormatFloat(elapsed, 'f', 3, 32)+" sec.")
bot.Send(msg)
deface = true
break
}
}
if deface {
break

bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
errorHTML++
} else {
body := string(bodyBytes)

for _, element := range site.Elements {
if !strings.Contains(body, element) {
msg := tgbotapi.NewMessage(group, "Site "+site.Url+" defaced. Element '"+element+"' not found.")
bot.Send(msg)
deface = true
break
}
}
if deface {
break
}
}
}
}
if errorHTML >= int(repeat-1) {
msg := tgbotapi.NewMessage(group, "Site "+site.Url+" HTTP get error")
bot.Send(msg)
errorHTML = 0
}
time.Sleep(time.Duration(update) * time.Second)
}
Expand Down

0 comments on commit ce1f594

Please sign in to comment.