Skip to content

Commit

Permalink
Merge 1438f31 into 7f0cb13
Browse files Browse the repository at this point in the history
  • Loading branch information
llvieira committed Jan 11, 2018
2 parents 7f0cb13 + 1438f31 commit e7b37a8
Show file tree
Hide file tree
Showing 12 changed files with 164 additions and 26 deletions.
1 change: 1 addition & 0 deletions .travis.yml
@@ -1,5 +1,6 @@
sudo: true
dist: trusty
group: deprecated-2017Q4
language: node_js
node_js:
- '7'
Expand Down
21 changes: 19 additions & 2 deletions src/listener/utils/transforms/alert.js
Expand Up @@ -33,7 +33,7 @@ class Alert extends Resource {
}
}

buildPlainTextOutput() {
buildPlainTextHipchatOutput() {
let output = '';
for (const field in this) {
if (__isNonDisplayField__(field) || !this[field]) {
Expand All @@ -45,11 +45,28 @@ class Alert extends Resource {
output += '\t\u2022 ' + this.camelCaseToTitleCase(field) + ': ' + this[field] + '\n';
}
}
//Add status to output only for Flowdock and Hipchat

output += '\t\u2022 Severity: ' + this.severity + '\n';
return output;
}

buildPlainTextFlowdockOutput() {
let output = '>';
for (const field in this) {
if (__isNonDisplayField__(field) || !this[field]) {
continue;
}
if (field === 'associatedResource') {
output += '\t\u2022 **Resource**: ' + this[field].resourceName + '\n';
} else {
output += '\t\u2022 **' + this.camelCaseToTitleCase(field) + '**: ' + this[field] + '\n';
}
}

output += '\t\u2022 **Severity**: ' + this.severity + '\n';
return output;
}

buildSlackFields() {
let fields = [];
for (const field in this) {
Expand Down
13 changes: 12 additions & 1 deletion src/listener/utils/transforms/plain-text.js
Expand Up @@ -133,11 +133,22 @@ function __toOutput__(resource) {
let output = '';
if (title) {
output = title;

if (adapter === 'flowdock') {
output = '**[' + title + ']' + '(' + transformedRes.hyperlink + ')**\n';
}
}

if(transformedRes.pretext) {
output += transformedRes.pretext + '\n';
}
output += transformedRes.buildPlainTextOutput(host);

if (adapter === 'flowdock') {
output += transformedRes.buildPlainTextFlowdockOutput(host);
} else {
output += transformedRes.buildPlainTextHipchatOutput(host);
}

return output;
}

Expand Down
26 changes: 24 additions & 2 deletions src/listener/utils/transforms/server-hardware.js
Expand Up @@ -36,7 +36,7 @@ class ServerHardware extends Resource {
}
}

buildPlainTextOutput(host) {
buildPlainTextHipchatOutput(host) {
let output = '';
let hasProfile = false;
for (const field in this) {
Expand All @@ -52,12 +52,34 @@ class ServerHardware extends Resource {
if (!hasProfile) {
output += '\t\u2022 Profile: Available for deployment\n';
}
//Add status to output only for Flowdock and Hipchat

output += '\t\u2022 Status: ' + this.status + '\n';

return output;
}

buildPlainTextFlowdockOutput(host) {
let output = '>';
let hasProfile = false;
for (const field in this) {
if (__isNonDisplayField__(field) || !this[field]) {
continue;
}
output += '\t\u2022 **' + this.camelCaseToTitleCase(field) + '**: ' + this[field] + '\n';
}
if (this.serverProfileUri) {
output += '\t\u2022 **Profile**: ' + ov_brain.getDeviceNameAndHyperLink(host + this.serverProfileUri).deviceName + '\n';
hasProfile = true;
}
if (!hasProfile) {
output += '\t\u2022 **Profile**: Available for deployment\n';
}

output += '\t\u2022 **Status**: ' + this.status + '\n';

return output;
}

buildSlackFields(host) {
let fields = [];
let hasProfile = false;
Expand Down
Expand Up @@ -35,7 +35,7 @@ class ServerProfileCompliancePreview extends Resource {
}
}

buildPlainTextOutput() {
buildPlainTextHipchatOutput() {
let output = '';
for (const field in this) {
if (__isNonDisplayField__(field) || !this[field]) {
Expand All @@ -54,6 +54,25 @@ class ServerProfileCompliancePreview extends Resource {
return output;
}

buildPlainTextFlowdockOutput() {
let output = '';
for (const field in this) {
if (__isNonDisplayField__(field) || !this[field]) {
continue;
}
let value = '';
if (Array.isArray(this[field])) {
value = this[field].join("\n");
} else {
value = this[field];
}
if (value) {
output += '**' + this.camelCaseToTitleCase(field) + '**:\n' + value + '\n';
}
}
return output;
}

buildSlackFields() {
let fields = [];
for (const field in this) {
Expand Down
13 changes: 12 additions & 1 deletion src/listener/utils/transforms/server-profile-template.js
Expand Up @@ -31,7 +31,7 @@ class ServerProfileTemplate extends Resource {
}
}

buildPlainTextOutput() {
buildPlainTextHipchatOutput() {
let output = '';
for (const field in this) {
if (__isNonDisplayField__(field) || !this[field]) {
Expand All @@ -42,6 +42,17 @@ class ServerProfileTemplate extends Resource {
return output;
}

buildPlainTextFlowdockOutput() {
let output = '>';
for (const field in this) {
if (__isNonDisplayField__(field) || !this[field]) {
continue;
}
output += '\t\u2022 **' + this.camelCaseToTitleCase(field) + '**: ' + this[field] + '\n';
}
return output;
}

buildSlackFields() {
let fields = [];
for (const field in this) {
Expand Down
20 changes: 18 additions & 2 deletions src/listener/utils/transforms/server-profile.js
Expand Up @@ -36,7 +36,7 @@ class ServerProfile extends Resource {
}
}

buildPlainTextOutput(host) {
buildPlainTextHipchatOutput(host) {
let output = '';
for (const field in this) {
if (__isNonDisplayField__(field) || !this[field]) {
Expand All @@ -49,11 +49,27 @@ class ServerProfile extends Resource {
output += '\t\u2022 Hardware Model: ' + ov_brain.getHardwareModel(host + this.serverHardwareUri) + '\n';
}

//Add status to output only for Flowdock and Hipchat
output += '\t\u2022 Status: ' + this.status + '\n';
return output;
}

buildPlainTextFlowdockOutput(host) {
let output = '>';
for (const field in this) {
if (__isNonDisplayField__(field) || !this[field]) {
continue;
}
output += '\t\u2022 **' + this.camelCaseToTitleCase(field) + '**: ' + this[field] + '\n';
}
if (this.serverHardwareUri) {
output += '\t\u2022 **Server Hardware**: ' + ov_brain.getDeviceNameAndHyperLink(host + this.serverHardwareUri).deviceName + '\n';
output += '\t\u2022 **Hardware Model**: ' + ov_brain.getHardwareModel(host + this.serverHardwareUri) + '\n';
}

output += '\t\u2022 **Status**: ' + this.status + '\n';
return output;
}

buildSlackFields(host) {
let fields = [];
for (const field in this) {
Expand Down
13 changes: 11 additions & 2 deletions test/listener/utils/transforms/alert.js
Expand Up @@ -43,11 +43,20 @@ describe('Alert', () => {
hyperlink: "https://0.0.0.0/#/activity/r/rest/alerts/5483?s_sid=LTQ2OT",
};

it('buildPlainTextOutput', () => {
it('buildPlainTextHipchatOutput', () => {
let expected = "\t\u2022 Description: The server has been powered off.\n\t\u2022 Resource: 0000A66101, bay 3\n\t\u2022 Alert State: OK\n\t\u2022 Severity: OK\n"
const alert = new Alert(AlertResource);

let result = alert.buildPlainTextOutput();
let result = alert.buildPlainTextHipchatOutput();

expected.should.eql(result);
});

it('buildPlainTextFlowdockOutput', () => {
let expected = ">\t\u2022 **Description**: The server has been powered off.\n\t\u2022 **Resource**: 0000A66101, bay 3\n\t\u2022 **Alert State**: OK\n\t\u2022 **Severity**: OK\n"
const alert = new Alert(AlertResource);

let result = alert.buildPlainTextFlowdockOutput();

expected.should.eql(result);
});
Expand Down
14 changes: 7 additions & 7 deletions test/listener/utils/transforms/server-hardware.js
Expand Up @@ -79,20 +79,20 @@ describe('ServerHardware', () => {
const brain = new OneViewBrain(oVClient, robot, {});
sinon.stub(brain, 'getDeviceNameAndHyperLink').returns({deviceName: '0000A66103_b11 profile'});

it('buildPlainTextOutput with profile', () => {
let expected = "\t\u2022 State: ProfileApplied\n\t\u2022 Model: Synergy 480 Gen10\n\t\u2022 Power State: On\n\t\u2022 Profile: 0000A66103_b11 profile\n\t\u2022 Status: OK\n";
const sh = new ServerHardware(ServerHardwareResourceProfile, brain);
it('buildPlainTextHipchatOutput without profile', () => {
let expected = "\t\u2022 State: NoProfileApplied\n\t\u2022 Model: Synergy 480 Gen10\n\t\u2022 Power State: On\n\t\u2022 Profile: Available for deployment\n\t\u2022 Status: OK\n";
const sh = new ServerHardware(ServerHardwareResource, brain);

let result = sh.buildPlainTextOutput();
let result = sh.buildPlainTextHipchatOutput();

expected.should.eql(result);
});

it('buildPlainTextOutput without profile', () => {
let expected = "\t\u2022 State: NoProfileApplied\n\t\u2022 Model: Synergy 480 Gen10\n\t\u2022 Power State: On\n\t\u2022 Profile: Available for deployment\n\t\u2022 Status: OK\n";
it('buildPlainTextFlowdockOutput without profile', () => {
let expected = ">\t\u2022 **State**: NoProfileApplied\n\t\u2022 **Model**: Synergy 480 Gen10\n\t\u2022 **Power State**: On\n\t\u2022 **Profile**: Available for deployment\n\t\u2022 **Status**: OK\n";
const sh = new ServerHardware(ServerHardwareResource, brain);

let result = sh.buildPlainTextOutput();
let result = sh.buildPlainTextFlowdockOutput();

expected.should.eql(result);
});
Expand Down
12 changes: 10 additions & 2 deletions test/listener/utils/transforms/server-profile-compliance.js
Expand Up @@ -36,11 +36,19 @@ describe('ServerProfileCompliancePreview', () => {
manualUpdates: []
};

it('buildPlainTextOutput', () => {
it('buildPlainTextHipchatOutput', () => {
let expected = "Automatic Updates:\nCreate a connection to network {\"name\":\"eth\", \"uri\":\"/rest/ethernet-networks/95717f69\"} with id 2 on Mezzanine (Mezz) 3:2.\n";
const compliance = new ServerProfileCompliancePreview(ServerProfileCompliancePreviewResource);

let result = compliance.buildPlainTextOutput();
let result = compliance.buildPlainTextHipchatOutput();
expected.should.eql(result);
});

it('buildPlainTextFlowdockOutput', () => {
let expected = "**Automatic Updates**:\nCreate a connection to network {\"name\":\"eth\", \"uri\":\"/rest/ethernet-networks/95717f69\"} with id 2 on Mezzanine (Mezz) 3:2.\n";
const compliance = new ServerProfileCompliancePreview(ServerProfileCompliancePreviewResource);

let result = compliance.buildPlainTextFlowdockOutput();
expected.should.eql(result);
});

Expand Down
12 changes: 10 additions & 2 deletions test/listener/utils/transforms/server-profile-template.js
Expand Up @@ -44,11 +44,19 @@ describe('ServerProfileTemplate', () => {
enclosureGroupHyperlink: "https://0.0.0.0/#/enclosuregroups/show/interconectbayconfiguration/r/rest/enclosure-groups/84da6697?s_sid=LTc2"
};

it('buildPlainTextOutput', () => {
it('buildPlainTextHipchatOutput', () => {
let expected = '\t\u2022 Description: A server profile template\n';
const template = new ServerProfileTemplate(ServerProfileTemplateResource);

let result = template.buildPlainTextOutput();
let result = template.buildPlainTextHipchatOutput();
expected.should.eql(result);
});

it('buildPlainTextFlowdockOutput', () => {
let expected = '>\t\u2022 **Description**: A server profile template\n';
const template = new ServerProfileTemplate(ServerProfileTemplateResource);

let result = template.buildPlainTextFlowdockOutput();
expected.should.eql(result);
});

Expand Down
24 changes: 20 additions & 4 deletions test/listener/utils/transforms/server-profile.js
Expand Up @@ -89,19 +89,35 @@ describe('ServerProfile', () => {
sinon.stub(brain, 'getDeviceNameAndHyperLink').returns({deviceName: '0000A66101, bay 8'});
sinon.stub(brain, 'getHardwareModel').returns('HPE Synergy 480 Gen9 Compute Module');

it('buildPlainTextOutput with hardware', () => {
it('buildPlainTextHipchatOutput with hardware', () => {
let expected = "\t\u2022 Affinity: Bay\n\t\u2022 Serial Number: BCGLPVN00\n\t\u2022 Server Hardware: 0000A66101, bay 8\n\t\u2022 Hardware Model: HPE Synergy 480 Gen9 Compute Module\n\t\u2022 Status: OK\n";
const profile = new ServerProfile(ServerProfileResourceHardware, brain);

let result = profile.buildPlainTextOutput();
let result = profile.buildPlainTextHipchatOutput();
expected.should.eql(result);
});

it('buildPlainTextOutput without hardware', () => {
it('buildPlainTextHipchatOutput without hardware', () => {
let expected = "\t\u2022 Affinity: Bay\n\t\u2022 Serial Number: BCGLPVN00\n\t\u2022 Status: OK\n";
const profile = new ServerProfile(ServerProfileResource, brain);

let result = profile.buildPlainTextOutput();
let result = profile.buildPlainTextHipchatOutput();
expected.should.eql(result);
});

it('buildPlainTextFlowdockOutput with hardware', () => {
let expected = ">\t\u2022 **Affinity**: Bay\n\t\u2022 **Serial Number**: BCGLPVN00\n\t\u2022 **Server Hardware**: 0000A66101, bay 8\n\t\u2022 **Hardware Model**: HPE Synergy 480 Gen9 Compute Module\n\t\u2022 **Status**: OK\n";
const profile = new ServerProfile(ServerProfileResourceHardware, brain);

let result = profile.buildPlainTextFlowdockOutput();
expected.should.eql(result);
});

it('buildPlainTextFlowdockOutput without hardware', () => {
let expected = ">\t\u2022 **Affinity**: Bay\n\t\u2022 **Serial Number**: BCGLPVN00\n\t\u2022 **Status**: OK\n";
const profile = new ServerProfile(ServerProfileResource, brain);

let result = profile.buildPlainTextFlowdockOutput();
expected.should.eql(result);
});

Expand Down

0 comments on commit e7b37a8

Please sign in to comment.