health: done
This commit is contained in:
parent
a0b19f6184
commit
007efc6118
@ -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
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
})
|
||||
|
@ -1,9 +1,7 @@
|
||||
<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">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<p ng-controller="VersionController">
|
||||
Version de l'API : {{ v.version }}
|
||||
</p>
|
||||
@ -11,4 +9,16 @@
|
||||
Latence frontend-backend : <ng-pluralize count="t.diffFB / 1000000000" when="{'one': '{} seconde', 'other': '{} 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>
|
||||
|
Loading…
Reference in New Issue
Block a user