health: done

This commit is contained in:
nemunaire 2020-01-29 11:35:01 +01:00
parent a0b19f6184
commit 007efc6118
4 changed files with 58 additions and 15 deletions

View File

@ -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

View File

@ -16,6 +16,10 @@ func GetCertificateAssociation(serial uint64) string {
return fmt.Sprintf(SymlinkPrefix + "%0[2]*[1]X", serial, int(math.Ceil(math.Log2(float64(serial))/8)*2))
}
func GetAssociation(dirname string) (assocs string, err error) {
return os.Readlink(dirname)
}
func GetAssociations(dirname string) (assocs []string, err error) {
if ds, errr := ioutil.ReadDir(dirname); errr != nil {
return nil, errr

View File

@ -136,6 +136,9 @@ angular.module("FICApp")
.factory("Timestamp", function($resource) {
return $resource("/api/timestamps.json")
})
.factory("Health", function($resource) {
return $resource("/api/health.json")
})
.factory("Monitor", function($resource) {
return $resource("/api/monitor/:machineId", { machineId: '@id' })
})
@ -416,6 +419,15 @@ angular.module("FICApp")
$scope.$on('$destroy', function () { $interval.cancel(myinterval); });
})
.controller("HealthController", function($scope, $interval, Health) {
var refresh = function() {
$scope.health = Health.query();
}
refresh();
var myinterval = $interval(refresh, 2500);
$scope.$on('$destroy', function () { $interval.cancel(myinterval); });
})
.controller("MonitorController", function($scope, Monitor) {
$scope.monitor = Monitor.get();
})

View File

@ -1,14 +1,24 @@
<div class="jumbotron text-light bg-dark">
<h1 class="display-4">Interface d'administration du challenge</h1>
<p class="lead">
Sélectionnez une action dans le menu ci-dessus.
</p>
<hr class="my-4">
<p ng-controller="VersionController">
Version de l'API : {{ v.version }}
</p>
<p ng-controller="TimestampController">
Latence frontend-backend : <ng-pluralize count="t.diffFB / 1000000000" when="{'one': '{}&nbsp;seconde', 'other': '{}&nbsp;secondes'}"></ng-pluralize><br>
Dernière synchronisation du frontend : {{ t.frontend | date:"mediumTime" }}
</p>
<div class="row">
<div class="col">
<p ng-controller="VersionController">
Version de l'API : {{ v.version }}
</p>
<p ng-controller="TimestampController">
Latence frontend-backend : <ng-pluralize count="t.diffFB / 1000000000" when="{'one': '{}&nbsp;seconde', 'other': '{}&nbsp;secondes'}"></ng-pluralize><br>
Dernière synchronisation du frontend : {{ t.frontend | date:"mediumTime" }}
</p>
</div>
<div class="col">
<ul ng-controller="HealthController">
<li ng-repeat="heal in health">
<a ng-href="teams/{{ heal.id_team }}" ng-if="heal.id_team">{{ heal.path }}</a>
<span ng-if="!heal.id_team">{{ heal.path }}</span>
: {{ heal.error }}
</li>
</ul>
</div>
</div>
</div>