Fix match check

This commit is contained in:
Magnus Root 2026-06-09 17:12:18 +03:00
parent 33eb27f892
commit 8e2544b431
20 changed files with 25 additions and 29 deletions

0
.gitignore vendored Normal file → Executable file
View file

0
ARCHITECTURE.md Normal file → Executable file
View file

0
DATABASE_SCHEMA.md Normal file → Executable file
View file

0
LICENSE Normal file → Executable file
View file

0
README.md Normal file → Executable file
View file

0
certcheck.go Normal file → Executable file
View file

0
config.go Normal file → Executable file
View file

0
dockercheck.go Normal file → Executable file
View file

0
email.go Normal file → Executable file
View file

0
go.mod Normal file → Executable file
View file

0
go.sum Normal file → Executable file
View file

0
logcheck.go Normal file → Executable file
View file

0
main.go Normal file → Executable file
View file

54
matchcheck.go Normal file → Executable file
View file

@ -366,18 +366,23 @@ func mcIsValidJSON(filePath string) bool {
return json.Unmarshal(data, &js) == nil
}
// mcBuildContainerName строит имя Docker-контейнера по новому формату:
// {ClientTitle}_{AZN}_{prefix}{nodeN}_a{agentN}
// mcBuildContainerName строит имя Docker-контейнера в зависимости от формата hostname.
//
// Пример:
// Продакшн (hostname содержит "node"):
//
// hostname: PTAF-TB-docker-AZ3-HW-node01, client: PSB_CFA, agent: 1
// → PSB_CFA_AZ3_hn01_a001
// PTAF-TB-docker-AZ3-HW-node01 → {client}_AZ3_hn01_a{NNN}
// PTAF-TB-docker-AZ1-node04 → {client}_AZ1_n04_a{NNN}
//
// hostname: PTAF-TB-docker-AZ1-node04, client: ITAR-TASS, agent: 1
// → ITAR-TASS_AZ1_n04_a001
// Тест (hostname не содержит "node"):
//
// PTAF-TB-docker-AZ1-test01 → ptaf_{client}_{NNN}
func mcBuildContainerName(client, hostname string, agentNum int) string {
// Извлекаем AZN: ищем AZ + цифры в hostname
// Тестовый хост — старый формат
if !strings.Contains(strings.ToLower(hostname), "node") {
return fmt.Sprintf("ptaf_%s_%03d", client, agentNum)
}
// Продакшн — новый формат с AZ и номером ноды
azRe := regexp.MustCompile(`AZ(\d+)`)
azMatch := azRe.FindStringSubmatch(hostname)
azPart := "AZ0"
@ -385,18 +390,15 @@ func mcBuildContainerName(client, hostname string, agentNum int) string {
azPart = "AZ" + azMatch[1]
}
// Определяем префикс ноды: HW → hn, иначе n
nodePrefix := "n"
if strings.Contains(hostname, "-HW-") {
nodePrefix = "hn"
}
// Извлекаем номер ноды: цифры после "node"
nodeRe := regexp.MustCompile(`node(\d+)`)
nodeMatch := nodeRe.FindStringSubmatch(hostname)
nodePart := "00"
if len(nodeMatch) > 1 {
// Берём последние 2 цифры с ведущим нулём
num := nodeMatch[1]
if len(num) >= 2 {
nodePart = num[len(num)-2:]
@ -515,18 +517,18 @@ func mcPrintError(msg string) { fmt.Printf("%s✗ %s%s\n", cRed, msg, cReset) }
func mcSendAlerts(hostname string, stats *mcStatistics, alertList []mcAlert) {
var sb strings.Builder
sb.WriteString("🚨 <b>PTAF Docker Ports Check Alert</b>\n\n")
sb.WriteString(fmt.Sprintf("🖥 <b>Хост:</b> <code>%s</code>\n", hostname))
sb.WriteString(fmt.Sprintf("📊 <b>Проверено клиентов:</b> %d\n", stats.TotalClients))
sb.WriteString(fmt.Sprintf("✅ <b>Без проблем:</b> %d\n", stats.ClientsOK))
sb.WriteString("🔴 <b>PTAF Docker Ports Check Alert</b>\n\n")
sb.WriteString(fmt.Sprintf("Хост: <code>%s</code>\n", hostname))
sb.WriteString(fmt.Sprintf("Проверено клиентов: %d\n", stats.TotalClients))
sb.WriteString(fmt.Sprintf("Без проблем: %d\n", stats.ClientsOK))
if stats.ClientsWarning > 0 {
sb.WriteString(fmt.Sprintf("⚠️ <b>С предупреждениями:</b> %d\n", stats.ClientsWarning))
sb.WriteString(fmt.Sprintf("С предупреждениями: %d\n", stats.ClientsWarning))
}
if stats.ClientsError > 0 {
sb.WriteString(fmt.Sprintf("❌ <b>С ошибками:</b> %d\n", stats.ClientsError))
sb.WriteString(fmt.Sprintf("С ошибками: %d\n", stats.ClientsError))
}
sb.WriteString("\n<b>📋 Детали проблем:</b>\n\n")
sb.WriteString("\n<b>Детали проблем:</b>\n\n")
clientAlerts := make(map[string][]mcAlert)
for _, a := range alertList {
@ -550,27 +552,21 @@ func mcSendAlerts(hostname string, stats *mcStatistics, alertList []mcAlert) {
}
}
if crit > 0 {
sb.WriteString(fmt.Sprintf("<b>%s</b> (%d ошибок", client, crit))
sb.WriteString(fmt.Sprintf("<b>%s</b> (%d ошибок", client, crit))
if warn > 0 {
sb.WriteString(fmt.Sprintf(", %d предупреждений", warn))
}
sb.WriteString(")\n")
} else {
sb.WriteString(fmt.Sprintf("⚠️ <b>%s</b> (%d предупреждений)\n", client, warn))
sb.WriteString(fmt.Sprintf("<b>%s</b> (%d предупреждений)\n", client, warn))
}
for _, a := range cas {
icon := "⚠️"
if a.IsCritical {
icon = "❌"
sb.WriteString(fmt.Sprintf("<code>%s</code>: %s - %s\n", a.Container, a.ErrorType, a.Description))
}
sb.WriteString(fmt.Sprintf("%s <code>%s</code>: %s - %s\n", icon, a.Container, a.ErrorType, a.Description))
}
sb.WriteString("\n")
}
sb.WriteString("━━━━━━━━━━━━━━━━━━━━━\n")
sb.WriteString("🔍 Проверьте должны ли быть данные ресурсы на этом хосте.\n")
sb.WriteString(" Если нет, то удалите все старые контейнеры и конфиги для Angie.\n")
sb.WriteString("Проверьте должны ли быть данные ресурсы на этом хосте.\n")
sb.WriteString("Если нет, то удалите все старые контейнеры и конфиги для Angie.\n")
if err := telegramSendHTML(sb.String()); err != nil {
fmt.Printf("%s[Telegram] ✗ Ошибка отправки: %v%s\n", cRed, err, cReset)

0
mattermost.go Normal file → Executable file
View file

0
portcheck.go Normal file → Executable file
View file

0
portsview.go Normal file → Executable file
View file

0
servicecheck.go Normal file → Executable file
View file

0
telegram.go Normal file → Executable file
View file

0
webcheck.go Normal file → Executable file
View file