forked from RackHD/on-tasks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode-discovered-alert-job.js
executable file
·100 lines (89 loc) · 2.81 KB
/
node-discovered-alert-job.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Copyright 2016, EMC, Inc.
'use strict';
var di = require('di');
module.exports = nodeAlertJobFactory;
di.annotate(nodeAlertJobFactory, new di.Provide('Job.Alert.Node.Discovered'));
di.annotate(nodeAlertJobFactory, new di.Inject(
'Protocol.Events',
'Job.Base',
'Logger',
'Util',
'Services.Waterline',
'Services.Lookup',
'Assert'
));
function nodeAlertJobFactory(
eventsProtocol,
BaseJob,
Logger,
util,
waterline,
lookup,
assert
) {
var logger = Logger.initialize(nodeAlertJobFactory);
/**
* @param {Object} options
* @param {Object} context
* @param {String} taskId
* @constructor
*/
function NodeAlertJob(options, context, taskId) {
NodeAlertJob.super_.call(this, logger, options, context, taskId);
this.logger = logger;
this.nodeId = context.target;
}
util.inherits(NodeAlertJob, BaseJob);
/**
* @memberOf NodeAlertJob
*/
NodeAlertJob.prototype._run = function run() {
var self = this;
return waterline.nodes.needByIdentifier(self.nodeId)
.then(function(node) {
assert.string(node.type);
return lookup.findIpMacAddresses(self.nodeId)
.then(function(ipMacPairs) {
var nodeInfo = {};
nodeInfo.ipMacAddresses = ipMacPairs;
nodeInfo.nodeId = self.nodeId;
if(self.context.data){
nodeInfo = _.defaults(
nodeInfo,
self.context.data
);
}
return self._getDmiSystemInformation()
.then(function(systemInformation) {
if (systemInformation) {
nodeInfo.serial = systemInformation['Serial Number'];
nodeInfo.product = systemInformation['Product Name'];
nodeInfo.vendor = systemInformation['Manufacturer'];
}
return eventsProtocol.publishNodeEvent(node, 'discovered', nodeInfo);
});
});
})
.then(function() {
self._done();
})
.catch(function(err) {
self._done(err);
});
};
NodeAlertJob.prototype._getDmiSystemInformation = function () {
var self = this;
return waterline.catalogs.findMostRecent({
node: self.nodeId,
source: 'dmi'
}).then(function (catalog) {
if (!catalog || !catalog.data || !catalog.data['System Information']) {
logger.info("DMI catalog not found for node " + self.nodeId);
return false;
} else {
return catalog.data['System Information'];
}
});
};
return NodeAlertJob;
}