Initial commit
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
package domaincheck
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"stat/common/log"
|
||||
"stat/common/tf"
|
||||
"stat/models/appInfoMod"
|
||||
"stat/models/landingPage"
|
||||
"stat/models/versionMod"
|
||||
"stat/statg"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func DomainCheck() error {
|
||||
ctx := context.Background()
|
||||
domainList, err := landingPage.FindAllLandingPage(ctx)
|
||||
if err != nil {
|
||||
log.Error("DomainCheck", log.E(err))
|
||||
return err
|
||||
}
|
||||
availableCountCheck(ctx, domainList)
|
||||
return nil
|
||||
}
|
||||
|
||||
func availableCountCheck(ctx context.Context, domainList []landingPage.LandingPage) {
|
||||
m := make(map[int32]int)
|
||||
for _, v := range domainList {
|
||||
m[v.AppId]++
|
||||
}
|
||||
var tips []string
|
||||
for appID, count := range m {
|
||||
log.Info("availableCountCheck", log.Any("appID", appID), log.Any("count", count))
|
||||
if count <= 2 {
|
||||
appinfo, _ := appInfoMod.GetAppInfoById(ctx, appID)
|
||||
tips = append(tips, fmt.Sprintf("[%s]可用域名还剩:%d个.", appinfo.Name, count))
|
||||
}
|
||||
}
|
||||
if len(tips) > 0 {
|
||||
txt := strings.Join(tips, "\n")
|
||||
statg.Bot.SendMonitorMessage(txt)
|
||||
}
|
||||
}
|
||||
|
||||
func TFCheck() error {
|
||||
ctx := context.Background()
|
||||
appIds, err := appInfoMod.GetAppIds(ctx)
|
||||
if err != nil {
|
||||
log.Error("daily RunStat GetAppIds failed!", log.E(err))
|
||||
return err
|
||||
}
|
||||
|
||||
versionList := make([]versionMod.VersionModel, 0)
|
||||
fmt.Println("TF域名检测 versionList", len(versionList))
|
||||
for _, appid := range appIds {
|
||||
version, err := versionMod.GetTfUrlList(ctx, appid)
|
||||
if err != nil {
|
||||
log.Error("TFCheck GetTfUrlList", log.E(err))
|
||||
return err
|
||||
}
|
||||
versionList = append(versionList, version)
|
||||
}
|
||||
|
||||
for _, version := range versionList {
|
||||
for _, url := range version.Link {
|
||||
fmt.Println("TF域名检测", url)
|
||||
result, err := tf.CheckTFValid(url)
|
||||
if err != nil {
|
||||
log.Error("runCheckUrl CheckTFValid", log.Any("url", url), log.E(err))
|
||||
continue
|
||||
}
|
||||
valid := result.Valid
|
||||
desc := result.Desc
|
||||
if !valid {
|
||||
appinfo, _ := appInfoMod.GetAppInfoById(ctx, version.AppId)
|
||||
text := fmt.Sprintf("[统计同学]:应用名称:%s\ntf域名异常\nURL:%s\nversion:%s\ndesc:%s", appinfo.Name, url, version.VersionNum, desc)
|
||||
statg.Bot.SendMonitorMessage(text)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user