health: done
This commit is contained in:
parent
a0b19f6184
commit
007efc6118
@ -8,6 +8,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"srs.epita.fr/fic-server/admin/pki"
|
||||||
|
|
||||||
"github.com/julienschmidt/httprouter"
|
"github.com/julienschmidt/httprouter"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -30,17 +32,32 @@ func init() {
|
|||||||
router.GET("/api/health.json", apiHandler(GetHealth))
|
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 {
|
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
|
return
|
||||||
} else {
|
} else {
|
||||||
for _, d := range ds {
|
for _, d := range ds {
|
||||||
p := path.Join(pathname, d.Name())
|
p := path.Join(pathname, d.Name())
|
||||||
if d.IsDir() && d.Name() != ".tmp" && d.Mode()&os.ModeSymlink == 0 {
|
if d.IsDir() && d.Name() != ".tmp" && d.Mode()&os.ModeSymlink == 0 {
|
||||||
ret = append(ret, getHealth(p)...)
|
ret = append(ret, getHealth(p)...)
|
||||||
} else if !d.IsDir() && d.Mode()&os.ModeSymlink == 0 {
|
} else if !d.IsDir() && d.Mode()&os.ModeSymlink == 0 && time.Since(d.ModTime()) > 2 * time.Second {
|
||||||
ret = append(ret, fmt.Sprintf("%s/%s: existing untreated file.", strings.TrimPrefix(pathname, TimestampCheck), d.Name()))
|
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
|
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))
|
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) {
|
func GetAssociations(dirname string) (assocs []string, err error) {
|
||||||
if ds, errr := ioutil.ReadDir(dirname); errr != nil {
|
if ds, errr := ioutil.ReadDir(dirname); errr != nil {
|
||||||
return nil, errr
|
return nil, errr
|
||||||
|
@ -136,6 +136,9 @@ angular.module("FICApp")
|
|||||||
.factory("Timestamp", function($resource) {
|
.factory("Timestamp", function($resource) {
|
||||||
return $resource("/api/timestamps.json")
|
return $resource("/api/timestamps.json")
|
||||||
})
|
})
|
||||||
|
.factory("Health", function($resource) {
|
||||||
|
return $resource("/api/health.json")
|
||||||
|
})
|
||||||
.factory("Monitor", function($resource) {
|
.factory("Monitor", function($resource) {
|
||||||
return $resource("/api/monitor/:machineId", { machineId: '@id' })
|
return $resource("/api/monitor/:machineId", { machineId: '@id' })
|
||||||
})
|
})
|
||||||
@ -416,6 +419,15 @@ angular.module("FICApp")
|
|||||||
$scope.$on('$destroy', function () { $interval.cancel(myinterval); });
|
$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) {
|
.controller("MonitorController", function($scope, Monitor) {
|
||||||
$scope.monitor = Monitor.get();
|
$scope.monitor = Monitor.get();
|
||||||
})
|
})
|
||||||
|
@ -1,14 +1,24 @@
|
|||||||
<div class="jumbotron text-light bg-dark">
|
<div class="jumbotron text-light bg-dark">
|
||||||
<h1 class="display-4">Interface d'administration du challenge</h1>
|
<h1 class="display-4">Interface d'administration du challenge</h1>
|
||||||
<p class="lead">
|
<div class="row">
|
||||||
Sélectionnez une action dans le menu ci-dessus.
|
<div class="col">
|
||||||
</p>
|
<p ng-controller="VersionController">
|
||||||
<hr class="my-4">
|
Version de l'API : {{ v.version }}
|
||||||
<p ng-controller="VersionController">
|
</p>
|
||||||
Version de l'API : {{ v.version }}
|
<p ng-controller="TimestampController">
|
||||||
</p>
|
Latence frontend-backend : <ng-pluralize count="t.diffFB / 1000000000" when="{'one': '{} seconde', 'other': '{} secondes'}"></ng-pluralize><br>
|
||||||
<p ng-controller="TimestampController">
|
Dernière synchronisation du frontend : {{ t.frontend | date:"mediumTime" }}
|
||||||
Latence frontend-backend : <ng-pluralize count="t.diffFB / 1000000000" when="{'one': '{} seconde', 'other': '{} secondes'}"></ng-pluralize><br>
|
</p>
|
||||||
Dernière synchronisation du frontend : {{ t.frontend | date:"mediumTime" }}
|
</div>
|
||||||
</p>
|
|
||||||
|
<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>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user