checker: Can call checker with a list of students to one-check

This commit is contained in:
nemunaire 2021-10-31 18:16:58 +01:00
parent a241aebcb4
commit 840d58e8b0
2 changed files with 243 additions and 222 deletions

View File

@ -559,26 +559,13 @@ func minTunnelVersion(std *adlin.Student, suffixip int) (int, error) {
return minversion, nil
}
func studentsChecker() {
students, err := adlin.GetStudents()
if err != nil {
log.Println("Unable to check students:", err)
return
}
check_matrix_for := (time.Now().Second()/30)*5 + time.Now().Minute()%5
log.Printf("Checking students... (std_matrix%%10=%d)\n", check_matrix_for)
for istd, s := range students {
time.Sleep(250 * time.Millisecond)
// Check ping
std := s
func studentChecker(std *adlin.Student, also_check_matrix bool) {
tuns, err := std.GetActivesTunnels()
if err != nil {
if verbose2 {
log.Printf("SKip %s due to error when getting active tunnels: %s", std.Login, err.Error())
}
continue
return
}
if verbose2 && len(tuns) == 0 {
log.Printf("%s has no active tunnels: %s", std.Login, err.Error())
@ -589,7 +576,8 @@ func studentsChecker() {
if verbose2 {
log.Printf("Tests %s on %s...", std.Login, stdIP)
}
go check_ping(stdIP, func(pkt *ping.Packet) {
// Check ping
check_ping(stdIP, func(pkt *ping.Packet) {
tunnel_version, err := minTunnelVersion(std, tun.SuffixIP)
if verbose {
log.Printf("%s PONG (on %x); version=%d (%v)\n", std.Login, tun.SuffixIP, tunnel_version, err)
@ -683,7 +671,7 @@ func studentsChecker() {
}
// Check Matrix (only if GLUE Ok and defer contraint)
if glueErr == nil && istd%10 == check_matrix_for {
if glueErr == nil && also_check_matrix {
// Check Matrix Federation first
if v, err := check_matrix_federation(std.MyDelegatedDomain()); err == nil {
if verbose {
@ -792,5 +780,21 @@ func studentsChecker() {
return
})
}
}
func studentsChecker() {
students, err := adlin.GetStudents()
if err != nil {
log.Println("Unable to check students:", err)
return
}
check_matrix_for := (time.Now().Second()/30)*5 + time.Now().Minute()%5
log.Printf("Checking students... (std_matrix%%10=%d)\n", check_matrix_for)
for istd, s := range students {
time.Sleep(250 * time.Millisecond)
go studentChecker(s, istd%10 == check_matrix_for)
}
}

View File

@ -33,6 +33,24 @@ func main() {
log.Fatal("Cannot create database: ", err)
}
if len(flag.Args()) >= 1 {
// Check one or more students and exit
for _, std_login := range flag.Args() {
if verbose {
log.Println("==============================\n")
}
if std, err := adlin.GetStudentByLogin(std_login); err != nil {
log.Printf("%s: %s", std_login, err.Error())
} else {
log.Printf("Checking %s...", std.Login)
studentChecker(std, true)
}
}
return
}
// Prepare graceful shutdown
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt, syscall.SIGTERM)
@ -51,5 +69,4 @@ loop:
studentsChecker()
}
}
}