Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Add pause monitoring feature #87 #99

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/sentinel.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ var FIELDS_WHICH_MODIFICATION_TRIGGER_SERVICE_RESTART = [
'alertTo',
'pingServiceName',
'pingServiceOptions',
'warningThreshold'
'warningThreshold',
'isPaused'
];
var timeoutId = null;

Expand All @@ -34,7 +35,7 @@ Sentinel.prototype._findAdded = function (databaseServices, runningServices) {
databaseServices.forEach(function (s) {
if (!_.find(runningServices, function (rs) {
return rs.id == s.id;
})) {
}) && !s.isPaused) {
added.push(s);
}
});
Expand Down Expand Up @@ -112,7 +113,9 @@ Sentinel.prototype._tick = function () {
if (modifiedServices.length) {
modifiedServices.forEach(function (s) {
self.watchmen.removeService(s.id);
self.watchmen.addService(s);
if (!s.isPaused) {
self.watchmen.addService(s);
}
console.log('changes detected in service: ', s.name, '. Restarting...');
});
}
Expand Down
2 changes: 1 addition & 1 deletion lib/watchmen.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ WatchMen.prototype.startAll = function (options) {
}

this.services.forEach(function (service) {
if (!service.running) {
if (!service.running && !service.isPaused) {
setTimeout(function(){
self._launch(service);
service.running = true;
Expand Down
20 changes: 20 additions & 0 deletions webserver/public/js/controllers/services-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,26 @@
}
};

$scope.pause = function (id) {
if (confirm('Are you sure you want to pause this service?')) {
Service.pause({id: id}, function () {
reload(function () {
}, function () {
$scope.errorLoadingServices = "Error loading data from remote server";
});
});
}
};

$scope.resume = function (id) {
Service.resume({id: id}, function () {
reload(function () {
}, function () {
$scope.errorLoadingServices = "Error loading data from remote server";
});
});
};

reload(scheduleNextTick, loadServicesErrHandler);

});
Expand Down
16 changes: 16 additions & 0 deletions webserver/public/js/factories.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,22 @@
reset: {
method: 'POST',
url: '/api/services/:id/reset'
},

/**
* Pause service
*/
pause: {
method: 'POST',
url: '/api/services/:id/pause'
},

/**
* Resume service
*/
resume: {
method: 'POST',
url: '/api/services/:id/resume'
}

});
Expand Down
2 changes: 1 addition & 1 deletion webserver/public/less/service-list.less
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

.dropdown-menu{
padding:10px;
width:250px;
width:370px;
text-align: center;

.btn {
Expand Down
58 changes: 58 additions & 0 deletions webserver/routes/api-service-route.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,5 +168,63 @@ module.exports.getRoutes = function (storage) {
});
});

/**
* Pause service
*/

router.post('/services/:id/pause', requireAdmin, function (req, res) {
var id = req.params.id;
if (!id) {
return res.status(404).json({error: 'ID parameter not found'});
}
storage.getService(id, function (err, service) {
if (err) {
return res.status(500).json({error: err});
}

if (!service) {
return res.status(404).json({error: 'service not found'});
}

service.isPaused = 1;

storage.updateService(service, function (err, service) {
if (err) {
return res.status(500).json({error: err});
}
return res.json(service);
});
});
});

/**
* Resume service
*/

router.post('/services/:id/resume', requireAdmin, function (req, res) {
var id = req.params.id;
if (!id) {
return res.status(404).json({error: 'ID parameter not found'});
}
storage.getService(id, function (err, service) {
if (err) {
return res.status(500).json({error: err});
}

if (!service) {
return res.status(404).json({error: 'service not found'});
}

service.isPaused = 0;

storage.updateService(service, function (err, service) {
if (err) {
return res.status(500).json({error: err});
}
return res.json(service);
});
});
});

return router;
};
14 changes: 11 additions & 3 deletions webserver/views/service-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<tbody>

<tr ng-class={'result-disabled':row.service.enabled===false,'result-success':!row.status.currentOutage,'result-error':row.status.currentOutage}
ng-repeat="row in $data | filter:serviceFilter">
ng-repeat="row in $data | filter:serviceFilter track by row.service.id">

<% if ((user && user.isAdmin) || no_auth) { %>
<td class="admin-operations" data-title="'Admin'">
Expand All @@ -41,6 +41,13 @@
<a class="edit btn btn-default btn-xs" href="services/{{row.service.id}}/edit">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> edit
</a>
<button class="btn btn-warning btn-xs" ng-click="pause(row.service.id)" ng-if="!row.service.isPaused" >
<span class="glyphicon glyphicon-pause" aria-hidden="true"></span> Pause
</button>

<button class="btn btn-warning btn-xs" ng-click="resume(row.service.id)" ng-if="row.service.isPaused" >
<span class="glyphicon glyphicon-play" aria-hidden="true"></span> Resume
</button>
<button class="btn btn-danger btn-xs" ng-click="reset(row.service.id)">
<span class="glyphicon glyphicon-fire" aria-hidden="true"></span> reset
</button>
Expand All @@ -53,8 +60,9 @@
<% } %>

<td class="status" data-title="'Status'" sortable="'status.currentOutage'">
<span ng-if="row.status.currentOutage" class="label label-danger">offline</span>
<span ng-if="!row.status.currentOutage" class="label label-success">online</span>
<span ng-if="(!row.service.isPaused && row.status.currentOutage)" class="label label-danger">offline</span>
<span ng-if="(!row.service.isPaused && !row.status.currentOutage)" class="label label-success">online</span>
<span ng-if="row.service.isPaused" class="label label-info">Paused</span>
</td>

<td class="result-uptime" data-title="'last 24h'" sortable="'status.last24Hours.uptime'">
Expand Down