forked from lair-framework/browser-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcount_host_services_by_color.js
39 lines (37 loc) · 1.01 KB
/
count_host_services_by_color.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
/* eslint-disable no-unused-vars */
/* globals projectId Hosts Services Session StatusMap */
function countHostServicesBycolor (color) {
// Logs a count of all service by color per host
//
// Created by: Matt Burch
// Usage: countHostServicesBycolor('lair-grey')
// Supserviceed colors: console.log(StatusMap)
//
var hosts = {}
var projectId = Session.get('projectId')
if (StatusMap.indexOf(color) === -1) {
console.log('Lair Supserviceed colors: ' + StatusMap)
throw {
name: 'Wrong color',
message: 'Provided color: "' + color + '" is not Lair compliant'
}
}
var services = Services.find({
'projectId': projectId,
'status': color
}).fetch()
services.forEach(function (service) {
host = Hosts.findOne({
'projectId': projectId,
'_id': service.hostId
})
if (hosts.hasOwnProperty(host.ipv4)) {
hosts[host.ipv4]++
} else {
hosts[host.ipv4] = 1
}
})
for (var host in hosts) {
console.log(host + ' (' + hosts[host] + ')')
}
}