Reloading the API hostname when it has changed.

This commit is contained in:
Manuel 2017-05-24 19:15:55 +02:00
parent 05808fb803
commit fe46172d09
2 changed files with 28 additions and 1 deletions

View File

@ -152,7 +152,12 @@ app.controller('settingsController', function ($scope, $http, testConnection, ap
};
testConnection.check(tmpData).then(function (data) {
notify.info("Connection success");
tmpData.manager = data;
var index = $scope.apiEntries.indexOf(item);
$http.put("/api/wazuh-api/updateApiHostname/" + $scope.apiEntries[index]._id, tmpData).success(function (data) {
$scope.apiEntries[index]._source.manager = tmpData.manager;
});
notify.info("Connection success");
}, printError);
};

View File

@ -344,6 +344,17 @@ module.exports = function (server, options) {
reply({ 'statusCode': 500, 'error': 8, 'message': 'Could not save data in elasticsearch' }).code(500);
});
};
//Handlers - Update API Hostname
var updateApiHostname = function (req,reply) {
elasticRequest.callWithRequest(req, 'update', { index: '.kibana', type: 'wazuh-configuration', id:req.params.id, body: {doc: {"manager": req.payload.manager}} }).then(
function () {
reply({ 'statusCode': 200, 'message': 'ok' });
}, function (error) {
reply({ 'statusCode': 500, 'error': 8, 'message': 'Could not save data in elasticsearch' }).code(500);
});
};
//Handlers - Get API Settings
@ -535,4 +546,15 @@ module.exports = function (server, options) {
handler: fetchAgents
});
/*
* PUT /api/wazuh-api/updateApiHostname/apiId
* Update the API hostname
*
**/
server.route({
method: 'PUT',
path: '/api/wazuh-api/updateApiHostname/{id}',
handler: updateApiHostname
});
};