forked from lair-framework/browser-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_os_to_hosts_by_os_regex.js
41 lines (37 loc) · 1.27 KB
/
add_os_to_hosts_by_os_regex.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
var addOsToHostsByOsRegex = function (os_regex, new_os, weight) {
// Loops through each host from the selected project
// and adds a new Operating System value if the host's primary
// OS matches the provided regex. Assigns the provided weight as well.
//
// Usage: addOsToHostsByOsRegex(/.*Linux.*/, 'Linux', 100);
// Created by: Dan Kottmann
// Requires client-side updates: false
var PROJECT_ID = Session.get('projectId');
var query = {
'project_id': PROJECT_ID,
'os.fingerprint': {
$regex: os_regex
}
};
var hosts = [];
Hosts.find(query).fetch().forEach(function (host) {
host.os = host.os.sort(sortWeight)[0];
hosts.push(host);
});
if (hosts.length < 1) {
console.log('No hosts found');
return;
}
hosts.forEach(function (host) {
var os = host.os.fingerprint;
if (os.match(os_regex)) {
Meteor.call('addHostOs', PROJECT_ID, host._id, 'Manual', new_os, weight, function (err) {
if (err) {
console.log('Unable to update host ' + host.string_addr);
} else {
console.log('Updated host ' + host.string_addr);
}
});
}
});
};