add 'Kill All Existing Monkeys' button

This commit is contained in:
itsikkes 2016-07-26 22:32:46 +03:00
parent d474008526
commit f8ca808ad5
3 changed files with 61 additions and 1 deletions

View File

@ -193,10 +193,14 @@
<div class="col-lg-3 col-md-6 col-sm-6">
<div class="panel panel-default">
<div class="panel-heading">
<a href="#reset" data-toggle="collapse">Reset Database</a>
<a href="#reset" data-toggle="collapse">Stop Test</a>
</div>
<div id="reset" style="overflow: visible" class="panel-body panel-collapse collapse" aria-expanded="true">
<span class="input-group-btn">
<button id="btnKillAll" class="btn btn-default" type="button"
onclick="killAll()" style="margin-top:-4px">
Kill All Monkeys
</button>
<button id="btnResetDB" class="btn btn-default" type="button"
onclick="resetDB()" style="margin-top:-4px">
Reset Database

View File

@ -791,6 +791,57 @@ function selectNode(hostname, zoom) {
}
function killAll() {
BootstrapDialog.show({
title: 'Kill All Monkeys',
message: 'This action will mark all existing monkeys to die.<br/>As some of the monkyes might be in the middle of exploitation, new monkeys might still apear, and you will need to perform this kill again.<br/>Perform kill all?',
type: BootstrapDialog.TYPE_DANGER,
buttons: [{
label: 'Kill All',
cssClass: 'btn-danger',
action: function(dialogItself){
dialogItself.close();
$.ajax({
headers : {
'Accept' : 'application/json',
},
url : '/api?action=killall',
type : 'GET',
success : function(response, textStatus, jqXhr) {
console.log(response);
if (response.status != 'OK') {
BootstrapDialog.show({
title: 'Kill All Monkeys',
message: "The following error occured: " + response.reason
});
}
else {
console.log("All monkeys marked to die");
BootstrapDialog.show({
title: 'Kill All Monkeys',
message: "All existing monkeys marked to die"
});
}
},
error : function(jqXHR, textStatus, errorThrown) {
console.log("The following error occured: " + textStatus, errorThrown);
BootstrapDialog.show({
title: 'Kill All Monkeys',
message: "The following error occured: " + textStatus
});
}
});
}
}, {
label: 'Cancel',
action: function(dialogItself){
dialogItself.close();
}
}]
});
}
function resetDB() {
if (confirm('Are you sure you want to empty the database?')) {
$.ajax({

View File

@ -238,6 +238,11 @@ class Root(restful.Resource):
return {
'status': 'OK',
}
elif action=="killall":
mongo.db.monkey.update({}, {'$set': {'config.alive': False, 'modifytime': datetime.now()}}, upsert=False, multi=True)
return {
'status': 'OK',
}
else:
return {'status': 'BAD',
'reason': 'unknown action'}