Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Alert handing changes: #168

Merged
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
59 changes: 49 additions & 10 deletions public-interface/admin/createDB.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,35 +28,74 @@ CreateDB.prototype.create = function(){
host: config.postgres.options.replication.write.host,
database: 'postgres',
password: config.postgres.su_password,
port: config.postgres.options.replication.write.port,
port: config.postgres.options.port,
});
const query = {text: 'CREATE DATABASE ' +
config.postgres.database + ';'
};
client.connect()
client.connect(
)
.then(() => console.log("Connected"))
.catch(function(err) {
console.log("Cannot connect: " + err);
process.exit(1);
})
.then(function() {
console.log("Executing query: ", query.text);
return client.query(query);
})
/*.catch(function(err) {
console.log("Cannot create db: " + err);
console.log("OK to continue!");
})*/
.then(function() {
console.log("Connected to postgres");
query.text = 'CREATE USER ' + config.postgres.su_username +
' WITH PASSWORD \'' + config.postgres.su_password + '\';';
console.log("Trying to create PG user. Executing query: ", query.text);
return client.query(query);
})
.catch(function(err) {
console.log("Cannot create user: " + err);
console.log("OK to continue ");
})
.then(function() {
query.text = 'CREATE USER ' + config.postgres.username +
' WITH PASSWORD ' + config.postgres.password + ';' +
' GRANT CONNECT ON DATABASE ' + config.postgres.database +
query.text = ' GRANT CONNECT ON DATABASE ' + config.postgres.database +
' TO ' + config.postgres.username + ';';
return client.query();
console.log("Trying grant rights to PG user. Executing query: ", query.text);
return client.query(query);
})
.catch(function(err) {
console.log("Cannot create user: " + err);
console.log("OK to continue ");
})
.then(function() {
query.text = 'CREATE DATABASE test; ' +
'GRANT ALL PRIVILEGES ON DATABASE test TO ' +
query.text = 'CREATE DATABASE test;';
console.log("Trying to create test database. Executing query: ", query.text);
return client.query(query);
})
.then(function() {
query.text = 'GRANT ALL PRIVILEGES ON DATABASE test TO ' +
config.postgres.su_username + '; ' +
'GRANT CONNECT ON DATABASE test TO ' +
config.postgres.username + ';';
return client.query();
console.log("Trying to create test database. Executing query: ", query.text);
return client.query(query);
})
.catch(function(err) {
console.log("Cannot create db test: " + err);
console.log("OK to continue ");
})
.then(() => {
console.log("Trying to create DB models ...");
return models.createDatabase();

})
.catch(function(err) {
console.log("Cannot create models: " + err);
console.log("OK to continue ");
})
.then(function() {
console.log("Trying to create system users.");
return systemUsers.create();
})
.then(function() {
Expand Down
14 changes: 14 additions & 0 deletions public-interface/admin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ var addUser = require('./addUser');
var RemoveTestUser = require('./removeTestUser');
var ResetDB = require('./resetDB');
var CreateDB = require('./createDB');
var UpdateDB = require('./updateDB');
var command = process.argv[2];
var arg = process.argv[3];

switch (command) {
case 'addUser':
Expand All @@ -44,6 +46,18 @@ case 'createDB':
var databaseCreater = new CreateDB();
databaseCreater.create();
break;
case 'updateDB':
var databaseUpdater = new UpdateDB();
databaseUpdater.update(arg);
break;
case 'revertDB':
var databaseUpdater = new UpdateDB();
databaseUpdater.revertOne(arg);
break;
case 'revertAllDB':
var databaseUpdater = new UpdateDB();
databaseUpdater.revertAll(arg);
break;
default:
console.log ("Command : ", command , " not supported ");
}
77 changes: 77 additions & 0 deletions public-interface/admin/updateDB.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
const config = require('../config');
const { exec } = require('child_process');

var UpdateDB = function(){};
var cdCommand = "cd /app/iot-entities/postgresql/migrations;";


UpdateDB.prototype.update = function(test) {
var database = config.postgres.database;
if (test === "test") {
database = "test";
}

var dbupdateCommand = "npx sequelize-cli db:migrate --url postgres://" +
config.postgres.su_username +
":" + config.postgres.su_password +
"@" + config.postgres.options.replication.write.host +
"/" + database;
console.log("Executing " + cdCommand + dbupdateCommand);
exec(cdCommand + dbupdateCommand, (err, stdout, stderr) => {
if (err) {
console.log("Error: ", err);
process.exit(1);
}
console.log(`stdout: ${stdout}`);
console.log(`stderr: ${stderr}`);
process.exit(0);
});
};

UpdateDB.prototype.revertOne = function(test) {
var database = config.postgres.database;
if (test === "test") {
database = "test";
}

var dbupdateCommand = "npx sequelize-cli db:migrate:undo --url postgres://" +
config.postgres.su_username +
":" + config.postgres.su_password +
"@" + config.postgres.options.replication.write.host +
"/" + database;
console.log("Executing " + cdCommand + dbupdateCommand);
exec(cdCommand + dbupdateCommand, (err, stdout, stderr) => {
if (err) {
console.log("Error: ", err);
process.exit(1);
}
console.log(`stdout: ${stdout}`);
console.log(`stderr: ${stderr}`);
process.exit(0);
});
};

UpdateDB.prototype.revertAll = function(test) {
var database = config.postgres.database;
if (test === "test") {
database = "test";
}

var dbupdateCommand = "npx sequelize-cli db:migrate:undo:all --url postgres://" +
config.postgres.su_username +
":" + config.postgres.su_password +
"@" + config.postgres.options.replication.write.host +
"/" + database;
console.log("Executing " + cdCommand + dbupdateCommand);
exec(cdCommand + dbupdateCommand, (err, stdout, stderr) => {
if (err) {
console.log("Error: ", err);
process.exit(1);
}
console.log(`stdout: ${stdout}`);
console.log(`stderr: ${stderr}`);
process.exit(0);
});
};

module.exports = UpdateDB;
14 changes: 10 additions & 4 deletions public-interface/dashboard/public/js/services/alerts_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ iotServices.factory('alertsService', ['$http', 'utilityService','sessionService'
method: 'GET',
url: url,
params: {
"_" : utilityService.timeStamp()
"_" : utilityService.timeStamp(),
"active": true
}
}).success(function(data){
summary.unread = data;
Expand All @@ -56,7 +57,8 @@ iotServices.factory('alertsService', ['$http', 'utilityService','sessionService'
method: 'GET',
url: url,
params: {
"_" : utilityService.timeStamp()
"_" : utilityService.timeStamp(),
"active": true
}
}).success(function(data) {
summary.unread = removeReadAlerts(data);
Expand All @@ -71,7 +73,8 @@ iotServices.factory('alertsService', ['$http', 'utilityService','sessionService'
method: 'GET',
url: url,
params: {
"_" : utilityService.timeStamp()
"_" : utilityService.timeStamp(),
"active": true
}
}).success(successCallback).error(errorCallback);
});
Expand All @@ -87,7 +90,10 @@ iotServices.factory('alertsService', ['$http', 'utilityService','sessionService'
.then(function(url){
var requestOptions = {
method: 'PUT',
url: url
url: url,
params:{
"active": true
}
};
$http(requestOptions).success(function(data, status){
fireStatusUpdatedEvent(ngScope, {alert: alert, newStatus: newStatus});
Expand Down
6 changes: 6 additions & 0 deletions public-interface/doc/api/alerts.raml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ get:
example: 75
get:
is: [ authorization-header, response-errors-alerts, response-errors-generic ]
queryParameters:
active:
description: If true, ignore suppressed events
type: boolean
required: false
example: true
description: |
**Get Alert information**

Expand Down
Loading