health: done
This commit is contained in:
parent
a0b19f6184
commit
007efc6118
4 changed files with 58 additions and 15 deletions
|
|
@ -8,6 +8,8 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"srs.epita.fr/fic-server/admin/pki"
|
||||
|
||||
"github.com/julienschmidt/httprouter"
|
||||
)
|
||||
|
||||
|
|
@ -30,17 +32,32 @@ func init() {
|
|||
router.GET("/api/health.json", apiHandler(GetHealth))
|
||||
}
|
||||
|
||||
func getHealth(pathname string) (ret []string) {
|
||||
type healthFileReport struct {
|
||||
IdTeam string `json:"id_team,omitempty"`
|
||||
Path string `json:"path"`
|
||||
Error string `json:"error"`
|
||||
}
|
||||
|
||||
func getHealth(pathname string) (ret []healthFileReport) {
|
||||
if ds, err := ioutil.ReadDir(pathname); err != nil {
|
||||
ret = append(ret, fmt.Sprintf("%s: unable to ReadDir: %s", strings.TrimPrefix(pathname, TimestampCheck), err))
|
||||
ret = append(ret, healthFileReport{
|
||||
Path: strings.TrimPrefix(pathname, TimestampCheck),
|
||||
Error: fmt.Sprintf("unable to ReadDir: %s", err),
|
||||
})
|
||||
return
|
||||
} else {
|
||||
for _, d := range ds {
|
||||
p := path.Join(pathname, d.Name())
|
||||
if d.IsDir() && d.Name() != ".tmp" && d.Mode()&os.ModeSymlink == 0 {
|
||||
ret = append(ret, getHealth(p)...)
|
||||
} else if !d.IsDir() && d.Mode()&os.ModeSymlink == 0 {
|
||||
ret = append(ret, fmt.Sprintf("%s/%s: existing untreated file.", strings.TrimPrefix(pathname, TimestampCheck), d.Name()))
|
||||
} else if !d.IsDir() && d.Mode()&os.ModeSymlink == 0 && time.Since(d.ModTime()) > 2 * time.Second {
|
||||
teamDir := strings.TrimPrefix(pathname, TimestampCheck)
|
||||
idteam, _ := pki.GetAssociation(path.Join(TeamsDir, teamDir))
|
||||
ret = append(ret, healthFileReport{
|
||||
IdTeam: idteam,
|
||||
Path: path.Join(teamDir, d.Name()),
|
||||
Error: "existing untreated file",
|
||||
})
|
||||
}
|
||||
}
|
||||
return
|
||||
|
|
|
|||
Reference in a new issue