Skip to content

Commit

Permalink
Updating project dependencies and fixing related issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Reed committed Aug 8, 2019
1 parent 86faa4e commit 0151343
Show file tree
Hide file tree
Showing 14 changed files with 117 additions and 108 deletions.
28 changes: 15 additions & 13 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
const gulp = require('gulp');
const tasks = require('gulp-task-listing');
const util = require('gulp-util');
const log = require('fancy-log');
const del = require('del');

// Add a task to render registered tasks when user types 'gulp help'
gulp.task('help', tasks);
gulp.task('default', ['help']);

function output() {
var fs = require('fs');
if (fs.existsSync('../hubot')) {
Expand All @@ -22,24 +18,30 @@ function output() {

function templates() {
const dir = output();
util.log('Copying templates to', dir);
log('Copying templates to', dir);
return gulp.src('src/**/*.html').pipe(gulp.dest(dir))
}

function build() {
const dir = output();
util.log('Copying javascript to', dir);
log('Copying javascript to', dir);
return gulp.src('src/**/*.js').pipe(gulp.dest(dir));
}

function watchFiles() {
gulp.watch("src/**/*.js", build);
}

gulp.task('clean', function() {
const dir = output();
util.log('Removing destination', dir);
log('Removing destination', dir);
return del([dir], {force:true});
});

gulp.task('templates', ['clean'], templates);
gulp.task('build', ['templates'], function() { return build(); });
gulp.task('watch', ['build'], function () {
gulp.watch('src/**/*.js', ['build']);
});
gulp.task('templates', gulp.series('clean', function() { return templates(); }));

gulp.task('build', gulp.series('templates', function() { return build(); }));

gulp.task('watch', gulp.series('build', function () { return watchFiles(); }));

gulp.task('help', tasks);
53 changes: 30 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "0.0.0",
"author": "Hewlett Packard Enterprise <>",
"license": "MIT",
"keywords": "hubot, hubot-scripts, oneview, hewlett packard enterprise",
"keywords": ["hubot", "hubot-scripts", "oneview", "hewlett packard enterprise"],
"repository": {
"type": "git",
"url": "git://github.com/HewlettPackard/hpe-oneview-hubot.git"
Expand All @@ -13,40 +13,47 @@
"url": "https://github.com/HewlettPackard/hpe-oneview-hubot/issues"
},
"dependencies": {
"amqp": "^0.2.6",
"d3": "^4.2.7",
"fuzzyset.js": "0.0.1",
"amqp": "^0.2.7",
"core-util-is": "^1.0.2",
"d3": "^5.9.7",
"fuzzyset.js": "0.0.8",
"https": "^1.0.0",
"hubot-conversation": "^1.1.1",
"hubot-flowdock": ">= 0.0.1",
"jsdom": "^9.8.0",
"nlp_compromise": "^6.5.0",
"request": "^2.75.0",
"request-promise": "^4.1.1",
"svg2png": "^4.0.0"
"jsdom": "^15.1.1",
"compromise": "^11.14.2",
"request": "^2.88.0",
"request-promise": "^4.2.4",
"svg2png": "^4.1.1"
},
"peerDependencies": {
"hubot": "2.x"
"hubot": "3.x"
},
"devDependencies": {
"chai": "^3.5.0",
"coveralls": "^2.13.0",
"del": "^2.2.2",
"gulp": "^3.9.1",
"gulp-task-listing": "^1.0.1",
"gulp-util": "^3.0.7",
"hubot": "2.x",
"chai": "^4.2.0",
"coveralls": "^3.0.5",
"del": "^5.0.0",
"fancy-log": "^1.3.3",
"gulp": "^4.0.2",
"gulp-task-listing": "^1.1.0",
"hubot": "3.x",
"istanbul": "^0.4.5",
"mocha": "^3.5.3",
"nock": "^9.0.8",
"nyc": "^11.3.0",
"sinon": "^1.17.7"
"mocha": "^6.2.0",
"nock": "^10.0.6",
"nyc": "^14.1.1",
"sinon": "^7.3.2"
},
"main": "dist/oneview.js",
"scripts": {
"prepublish": "gulp build",
"test": "nyc --all mocha --recursive test",
"test": "nyc --all mocha --recursive test --exit",
"coverage": "nyc report --reporter=text-lcov | coveralls && rm -rf ./coverage"
},
"nyc": { "exclude": [ "dist", "gulpfile.js", "test" ] }
"nyc": {
"exclude": [
"dist",
"gulpfile.js",
"test"
]
}
}
36 changes: 19 additions & 17 deletions src/charting/chart.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
(c) Copyright 2016-2017 Hewlett Packard Enterprise Development LP
(c) Copyright 2016-2019 Hewlett Packard Enterprise Development LP
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -19,9 +19,9 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

const d3 = require('d3');
const jsdom = require('jsdom');
const { JSDOM } = jsdom;
const fs = require("fs");
const svg2png = require("svg2png");

Expand Down Expand Up @@ -109,13 +109,15 @@ function buildD3Chart(robot, room, metricName, metricList, sampleInterval) {

return new Promise((resolve, reject) => {

const document = jsdom.jsdom("<html><body></body></html>");
document.d3 = d3.select(document);
let svg = document.d3.select("body").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
const doc = new JSDOM('<!DOCTYPE html><html><body></body></html>');
let body = d3.select(doc.window.document).select('body');

let svg = body.append('div').attr('class', 'container')
.append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");

let data = [];
if (sampleInterval) {
Expand Down Expand Up @@ -164,10 +166,10 @@ function buildD3Chart(robot, room, metricName, metricList, sampleInterval) {

// Add the Legend
svg.append("text")
.attr("x", (legendSpace/2)+i*legendSpace)
.attr("x", (legendSpace/3)+i*legendSpace)
.attr("y", height + (margin.bottom/2)+ 5)
.style("font-family", "sans-serif")
.style("font-size", "12px")
.style("font-family", "'Arial'")
.style("font-size", ".8em")
.style("fill", function() {return d.color = color(i); })
.text(d.key);
});
Expand All @@ -182,23 +184,23 @@ function buildD3Chart(robot, room, metricName, metricList, sampleInterval) {
.attr("x", (width / 2))
.attr("y", 0 - (margin.top / 2))
.attr("text-anchor", "middle")
.style("font-family", "sans-serif")
.style("font-size", "14px")
.style("font-family", "'Arial'")
.style("font-size", "1.0em")
.text(metricName);

// Add axis label
svg.append("text")
.attr("x", 0 - 35)
.attr("y", (height / 2))
.attr("text-anchor", "middle")
.style("font-family", "sans-serif")
.style("font-size", "10px")
.style("font-family", "'Arial'")
.style("font-size", ".8em")
.text(__chooseLabel__(metricName));

// Add the Y Axis
svg.append("g").call(d3.axisLeft(y).ticks(4, "s"));

let buf = Buffer.from(document.d3.select("body").html());
let buf = Buffer.from(body.select('.container').html());
const outputBuffer = svg2png.sync(buf, {});
try {
fs.writeFileSync(metricName + "-chart.png", outputBuffer);
Expand Down
14 changes: 7 additions & 7 deletions src/charting/dashboard.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
(c) Copyright 2016-2017 Hewlett Packard Enterprise Development LP
(c) Copyright 2016-2019 Hewlett Packard Enterprise Development LP
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -19,9 +19,9 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

const d3 = require('d3');
const jsdom = require('jsdom');
const { JSDOM } = jsdom;
const fs = require("fs");
const svg2png = require("svg2png");

Expand Down Expand Up @@ -249,8 +249,8 @@ function buildDashboard(robot, room, aggregatedAlerts, aggregatedServerProfiles,
let dataset4 = hardwareWithProfiles.dataset;

//generate the document to write the svg
const document = jsdom.jsdom("<html><body></body></html>");
document.d3 = d3.select(document);
const doc = new JSDOM('<!DOCTYPE html><html><body></body></html>');
let body = d3.select(doc.window.document).select('body');

//set the radius of the donut (the center part)
let radius = 200;
Expand Down Expand Up @@ -278,7 +278,8 @@ function buildDashboard(robot, room, aggregatedAlerts, aggregatedServerProfiles,
let height = radius * 6;

//generate the svg on the document with the given dimensions
let svg = document.d3.select("body").append("svg")
let svg = body.append('div').attr('class', 'container')
.append("svg")
.attr("width", width)
.attr("height", height);
//sets the background to white so the image shows up on mobile
Expand Down Expand Up @@ -414,7 +415,6 @@ function buildDashboard(robot, room, aggregatedAlerts, aggregatedServerProfiles,
});
}


let middle2 = g2.append("text")
.attr("text-anchor", "middle")
.style("font-size", "4.0em")
Expand Down Expand Up @@ -544,7 +544,7 @@ function buildDashboard(robot, room, aggregatedAlerts, aggregatedServerProfiles,
.text("Total");

// convert the final svg to png
let buf = Buffer.from(document.d3.select("body").html());
let buf = Buffer.from(body.select('.container').html());
const outputBuffer = svg2png.sync(buf, {});
try {
fs.writeFileSync('dashboard.png', outputBuffer);
Expand Down
4 changes: 2 additions & 2 deletions src/listener/server-hardware.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
(c) Copyright 2016-2017 Hewlett Packard Enterprise Development LP
(c) Copyright 2016-2019 Hewlett Packard Enterprise Development LP
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -267,7 +267,7 @@ class ServerHardwareListener extends Listener {
if (response[0].advancedStatistics) {
let receiveKilobytesPerSec = {metricName: 'receiveKilobytesPerSec', metricSamples: response[0].advancedStatistics.receiveKilobytesPerSec.split(':')};
let transmitKilobytesPerSec = {metricName: 'transmitKilobytesPerSec', metricSamples: response[0].advancedStatistics.transmitKilobytesPerSec.split(':')};
promises.push(buildD3Chart(this.robot, this.room, 'Network Utilization Port ' + response[0].portNumber, [receiveKilobytesPerSec, transmitKilobytesPerSec], response[1].sampleInterval));
promises.push(buildD3Chart(this.robot, this.room, 'Network Utilization Port ' + response[0].advancedStatistics.portNumber, [receiveKilobytesPerSec, transmitKilobytesPerSec], response[1].sampleInterval));
}
}
return Promise.all(promises);
Expand Down
18 changes: 11 additions & 7 deletions src/middleware/nlp-middleware.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
(c) Copyright 2016-2017 Hewlett Packard Enterprise Development LP
(c) Copyright 2016-2019 Hewlett Packard Enterprise Development LP
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -19,7 +19,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
const nlp_compromise = require('nlp_compromise');
const nlp_compromise = require('compromise');
const SpellCheck = require('./utils/spell-check');
const Lexer = require('./utils/lexer');

Expand Down Expand Up @@ -68,20 +68,24 @@ const toNormal = {
nlp_compromise.plugin(toNormal);

function runNLP(message, logger, lex) {
if (typeof message.text === 'undefined') {
return;
}
const cleaned = message.text.replace(wordSpacer, ' ').replace(sentenceSpacer, "$1$2 ").trim();

let cleanSentences = null;
// If text contains IP address don't run through nlp_compromise
if (/(?:[0-9]{1,3}\.){3}[0-9]{1,3}/.test(cleaned)) {
cleanSentences = cleaned;
} else {
let normalized = nlp_compromise.text(cleaned)/*.to_present().toAmerican()*/.toNormal();
let normalized = nlp_compromise(cleaned).normalize().out();

if (normalized.contractions && normalized.contractions.expand) {
normalized = normalized.contractions.expand();
}
// Ensure that all sentences end with '.' a note, this will replace ! and ? with .
cleanSentences = nlp_compromise.text(normalized.text()).sentences.map((s) => {
return s.str.trim().replace(sentenceTerminal, '.');
cleanSentences = nlp_compromise(normalized).sentences().data().map((s) => {
return s.text.trim().replace(sentenceTerminal, '.');
}).join(' ');
}

Expand All @@ -91,7 +95,7 @@ function runNLP(message, logger, lex) {

message.original_text = message.text;
message.text = resolved;
message.nlp = nlp_compromise.text(message.text);
message.nlp = nlp_compromise(message.text);
};
module.exports.runNLP = runNLP; //export for testing

Expand All @@ -101,7 +105,7 @@ const nlp = (robot) => {
const message = context.response.message.message || context.response.message;
runNLP(message, robot.logger, lex);

if (!message.text.includes('@' + robot.name)) {
if (typeof message.text === 'undefined' || !message.text.includes('@' + robot.name)) {
context.response.message.done = true;
}

Expand Down
17 changes: 8 additions & 9 deletions src/middleware/utils/lexer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
(c) Copyright 2016-2017 Hewlett Packard Enterprise Development LP
(c) Copyright 2016-2019 Hewlett Packard Enterprise Development LP
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -33,7 +33,7 @@ let lookupset = {};
class Lexer {
constructor(nlp) {
this.nlp = nlp;
this.lex = nlp.lexicon();
// this.lex = nlp.lexicon();
this.largestDevice = 1;

//TODO: BUG - This should really be part of a spelling error correction task, we should use an independent fuzzy set that operates on individual words.
Expand All @@ -45,8 +45,7 @@ class Lexer {
}

addNamedDevice(search, replacement) {
const tSearch = search.trim();

const tSearch = this.nlp(search.trim()).normalize().out();
__addNamedDevice__(tSearch, replacement);

if (bladeName.test(tSearch)) {//We know blades conform to a specific naming pattern so we can get really accurate fuzzy search results by mapping some explicit typographic errors to the correct value
Expand All @@ -69,18 +68,18 @@ class Lexer {
}

updateNamedDevice(robot, search, replacement) {
const tSearch = search.trim();
const tSearch = this.nlp(search.trim()).normalize().out();
namedDevices.forEach((namedDevice) => {
if (namedDevice.replacement === replacement) {
robot.logger.debug('Updating named device: ' + namedDevice.search + ' from: ' + namedDevice.search + ' to: ' + search + ' with uri: ' + namedDevice.replacement);
namedDevice.search = new RegExp('\\b' + search + '\\b', 'ig');
robot.logger.debug('Updating named device: ' + namedDevice.search + ' from: ' + namedDevice.search + ' to: ' + tSearch + ' with uri: ' + namedDevice.replacement);
namedDevice.search = new RegExp('\\b' + tSearch + '\\b', 'ig');
}
});
}

resolveDevices(text) {
text = this.nlp.text(text).sentences.map((sentence) => { //Split the message into sentences so our window is applied on each sentence.
let text = sentence.str.trim();
text = this.nlp(text).sentences().data().map((sentence) => { //Split the message into sentences so our window is applied on each sentence.
let text = this.nlp(sentence.text.trim()).normalize().out();
if (text.endsWith('.')) {
text = text.slice(0, -1);
}
Expand Down
Loading

0 comments on commit 0151343

Please sign in to comment.