Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Markdown in Flowdock responses #143

Merged
merged 4 commits into from
Jan 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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