forked from aquasecurity/saas-integrations
-
Notifications
You must be signed in to change notification settings - Fork 0
/
email.js
68 lines (63 loc) · 3.21 KB
/
email.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
var email = require(__dirname + '/../email.js');
var alert = function(settings, callback) {
if (!settings) return callback('No settings object provided');
if (!settings.endpoints) return callback('No settings endpoints provided');
if (!settings.account_name) return callback('No settings account_name provided');
if (!settings.test_name) return callback('No settings test_name provided');
if (!settings.test_description) return callback('No settings test_description provided');
if (!settings.scan_id) return callback('No settings scan_id provided');
if (settings.result !== 1 && settings.result !== 2) return callback('Settings result is not a valid number');
email.sendAlert(settings.endpoints, settings.account_name, settings.test_name, settings.test_description, settings.result, settings.scan_id, settings.resources, function(err) {
callback(err);
});
};
/*
* remediation_notification - called to send a remediation notification
* arguments:
* settings: an object containing the following properties:
* - endpoints
* - cloud
* - account_id
* - account_name
* - remediated_resources
* - remediation_type
* - permissions
* - remediation_id
* - esult
* - caller
* - region
* - action
* - ip_address
* - message
* - created
* callback
*/
var remediation_notification = function(settings, callback) {
if (!settings) return callback('No settings object provided');
if (!settings.endpoints) return callback('No settings endpoints provided');
if (!settings.names) return callback('No settings names provided');
if (!settings.cloud) return callback('No settings cloud provided');
if (!settings.account_id) return callback('No settings account_id provided');
if (!settings.account_name) return callback('No settings account_name provided');
if (!settings.remediated_resources) return callback('No settings remediated resources provided');
if (!settings.remediation_type) return callback('No settings remediation type provided');
if (!settings.permissions) return callback('No settings permissions provided');
if (!settings.remediation_id) return callback('No settings remediation_id provided');
if (settings.result !== 0 && settings.result !== 1) return callback('Settings result is not a valid number');
if (settings.event_id) {
if (!settings.region) return callback('No settings region provided');
if (!settings.action) return callback('No settings action provided');
if (!settings.caller) return callback('No settings caller provided');
if (!settings.ip_address) return callback('No settings ip_address provided');
if (!settings.message) return callback('No settings message provided');
if (!settings.created) return callback('No settings created provided');
}
email.sendRemediationNotification(settings, function(err) {
settings.remediation_file['integrations'].push({integration:settings.names, status:(err ? 2 : 0), host:'SMTP', err:(err ? err : '')});
callback(err);
});
};
module.exports = {
alert: alert,
remediation_notification: remediation_notification
};