Skip to content

Commit

Permalink
Improving coverage, bug fixes
Browse files Browse the repository at this point in the history
Improving coverage a little and fixing bug in creating network
utilization chart. Renaming some listeners so the names are more
consistent.
  • Loading branch information
Daniel Reed committed Nov 22, 2017
1 parent f998ac0 commit 7f0558f
Show file tree
Hide file tree
Showing 20 changed files with 892 additions and 64 deletions.
18 changes: 8 additions & 10 deletions src/charting/chart.js
Expand Up @@ -199,16 +199,14 @@ function buildD3Chart(robot, room, metricName, metricList, sampleInterval) {
svg.append("g").call(d3.axisLeft(y).ticks(4, "s"));

let buf = Buffer.from(document.d3.select("body").html());

return svg2png(buf).then((buffer) => {
try {
fs.writeFileSync(metricName + "-chart.png", buffer);
resolve();
} catch (err) {
robot.logger.error('Error creating chart on the filesytem', err);
reject(err);
}
});
const outputBuffer = svg2png.sync(buf, {});
try {
fs.writeFileSync(metricName + "-chart.png", outputBuffer);
resolve();
} catch (err) {
robot.logger.error('Error creating chart on the filesytem', err);
reject(err);
}

}).then((res) => {
return __uploadPNG__(robot, room, metricName + "-chart.png");
Expand Down
23 changes: 10 additions & 13 deletions src/charting/dashboard.js
Expand Up @@ -529,7 +529,6 @@ function buildDashboard(robot, room, aggregatedAlerts, aggregatedServerProfiles,
});
}


let middle4 = g4.append("text")
.attr("text-anchor", "middle")
.style("font-size", "4.0em")
Expand All @@ -544,19 +543,17 @@ function buildDashboard(robot, room, aggregatedAlerts, aggregatedServerProfiles,
.attr("dy", "1em")
.text("Total");

// convert the final svg to png
let buf = Buffer.from(document.d3.select("body").html());
const outputBuffer = svg2png.sync(buf, {});
try {
fs.writeFileSync('dashboard.png', outputBuffer);
resolve();
} catch (err) {
robot.logger.error('Error creating dashboard on the filesytem', err);
reject(err);
}

//convert the final svg to png
let buf = Buffer.from(document.d3.select("body").html());

return svg2png(buf).then((buffer) => {
try {
fs.writeFileSync('dashboard.png', buffer);
resolve();
} catch (err) {
robot.logger.error('Error creating Dashboard on the filesytem', err);
reject(err);
}
});
}).then((res) => {
return __uploadPNG__(robot, room, 'dashboard.png');
});
Expand Down
2 changes: 1 addition & 1 deletion src/listener/alerts-listener.js → src/listener/alerts.js 100755 → 100644
Expand Up @@ -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 Listener = require('./base-listener');
const Listener = require('./base');
const Conversation = require("hubot-conversation");

class AlertsListener extends Listener {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/listener/bot.js
Expand Up @@ -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 Listener = require('./base-listener');
const Listener = require('./base');

class BotListener extends Listener {
constructor(robot, client, transform, developer,
Expand Down
Expand Up @@ -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 Listener = require('./base-listener');
const Listener = require('./base');
const buildDashboard = require('../charting/dashboard');

class DashboardListener extends Listener {
Expand Down
2 changes: 1 addition & 1 deletion src/listener/default-listener.js → src/listener/default.js 100755 → 100644
Expand Up @@ -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 Listener = require('./base-listener');
const Listener = require('./base');

class DefaultListener extends Listener {
constructor(robot, transform) {
Expand Down
2 changes: 1 addition & 1 deletion src/listener/developer.js
Expand Up @@ -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 Listener = require('./base-listener');
const Listener = require('./base');

class DeveloperListener extends Listener {
constructor(robot, client, transform) {
Expand Down
6 changes: 3 additions & 3 deletions src/listener/ov-listener.js → src/listener/oneview.js
Expand Up @@ -25,9 +25,9 @@ const DeveloperListener = require('./developer');
const ServerHardwareListener = require('./server-hardware');
const ServerProfilesListener = require('./server-profiles');
const ServerProfileTemplateListener = require('./server-profile-templates');
const DashboardListener = require('./dashboard-listener');
const AlertsListener = require('./alerts-listener');
const DefaultListener = require('./default-listener');
const DashboardListener = require('./dashboard');
const AlertsListener = require('./alerts');
const DefaultListener = require('./default');
const BotListener = require('./bot');
const NotificationsFilter = require('./notifications-filter');
const url = require('url');
Expand Down
50 changes: 30 additions & 20 deletions src/listener/server-hardware.js
Expand Up @@ -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 Listener = require('./base-listener');
const Listener = require('./base');
const buildD3Chart = require('../charting/chart');
const Conversation = require('hubot-conversation');

Expand All @@ -29,31 +29,42 @@ class ServerHardwareListener extends Listener {
constructor(robot, client, transform, brain) {
super(robot, client, transform);

this.switchBoard = new Conversation(robot);
this.room = client.chatRoom;
this.brain = brain;
this.title = "Server hardware";
this.capabilities = [];
this.respond(/(?:turn|power) on (:<host>.*?)(?:\/rest\/server-hardware\/)(:<serverId>[a-zA-Z0-9_-]*?)\.$/i, this.PowerOn.bind(this));
this.respond(/(?:turn|power) off (:<host>.*?)(?:\/rest\/server-hardware\/)(:<serverId>[a-zA-Z0-9_-]*?)\.$/i, this.PowerOff.bind(this));

this.POWER_ON=/(?:turn|power) on (:<host>.*?)(?:\/rest\/server-hardware\/)(:<serverId>[a-zA-Z0-9_-]*?)\.$/i;
this.POWER_OFF=/(?:turn|power) off (:<host>.*?)(?:\/rest\/server-hardware\/)(:<serverId>[a-zA-Z0-9_-]*?)\.$/i;
this.LIST_ALL=/(?:get|list|show) all (?:server ){0,1}hardware\.$/i;
this.LIST_UTILIZATION=/(?:get|list|show) (:<host>.*?)(?:\/rest\/server-hardware\/)(:<serverId>[a-zA-Z0-9_-]*?) utilization\.$/i;
this.LIST_ALL_UTILIZATION=/(?:get|list|show) (:<host>.*?)(?:\/rest\/server-hardware\/)(:<serverId>[a-zA-Z0-9_-]*?) all utilization\.$/i;
this.LIST=/(?:get|list|show) (?!\/rest\/server-profiles\/)(:<host>.*?)(?:\/rest\/server-hardware\/)(:<serverId>[a-zA-Z0-9_-]*?)\.$/i;
this.LIST_STATUS=/(?:get|list|show) (?:all ){0,1}(:<status>critical|ok|disabled|warning*?) (?:server ){0,1}hardware\.$/i;
this.LIST_POWER=/(?:get|list|show) (?:all ){0,1}(:<powerState>powered on|powered off*?) (?:server ){0,1}hardware\.$/i;

this.switchBoard = new Conversation(robot);

this.respond(this.POWER_ON, this.PowerOn.bind(this));
this.respond(this.POWER_OFF, this.PowerOff.bind(this));
this.capabilities.push(this.BULLET + "Power on/off a specific (server) hardware (e.g. turn on Encl1, bay 1).");

this.respond(/(?:get|list|show) all (?:server ){0,1}hardware\.$/i, this.ListServerHardware.bind(this));
this.respond(this.LIST_ALL, this.ListServerHardware.bind(this));
this.capabilities.push(this.BULLET + "List all (server) hardware (e.g. list all hardware).");

this.respond(/(?:get|list|show) (:<host>.*?)(?:\/rest\/server-hardware\/)(:<serverId>[a-zA-Z0-9_-]*?) utilization\.$/i, this.ListServerHardwareUtilization.bind(this));
this.respond(this.LIST_UTILIZATION, this.ListServerHardwareUtilization.bind(this));
this.capabilities.push(this.BULLET + "List server hardware utilization (e.g. list Encl1, bay 1 utilization).");

this.respond(/(?:get|list|show) (:<host>.*?)(?:\/rest\/server-hardware\/)(:<serverId>[a-zA-Z0-9_-]*?) all utilization\.$/i, this.ListAllServerHardwareUtilization.bind(this));
this.respond(this.LIST_ALL_UTILIZATION, this.ListAllServerHardwareUtilization.bind(this));
this.capabilities.push(this.BULLET + "List server hardware utilization (e.g. list Encl1, bay 1 utilization).");

this.respond(/(?:get|list|show) (?!\/rest\/server-profiles\/)(:<host>.*?)(?:\/rest\/server-hardware\/)(:<serverId>[a-zA-Z0-9_-]*?)\.$/i, this.ListServerHardwareById.bind(this));
this.respond(this.LIST, this.ListServerHardwareById.bind(this));
this.capabilities.push(this.BULLET + "List server hardware by name (e.g. list Encl1, bay 1).");

this.respond(/(?:get|list|show) (?:all ){0,1}(:<status>critical|ok|disabled|warning*?) (?:server ){0,1}hardware\.$/i, this.ListHardwareByStatus.bind(this));
this.respond(this.LIST_STATUS, this.ListHardwareByStatus.bind(this));
this.capabilities.push(this.BULLET + "List all critical/warning/ok/disabled (server) hardware (e.g. list all critical hardware).");

this.respond(/(?:get|list|show) (?:all ){0,1}(:<powerState>powered on|powered off*?) (?:server ){0,1}hardware\.$/i, this.ListHardwareByPowerState.bind(this));
this.respond(this.LIST_POWER, this.ListHardwareByPowerState.bind(this));
this.capabilities.push(this.BULLET + "List all powered on/off (server) hardware.");
}

Expand Down Expand Up @@ -159,7 +170,6 @@ class ServerHardwareListener extends Listener {
else {
if (status.toLowerCase() === "ok") {
return this.pagination(msg, res, "Okay " + msg.message.user.name + ", the following blades have an " + status.toUpperCase() + " status.");
return;
} else {
return this.pagination(msg, res, "Okay " + msg.message.user.name + ", the following blades have an " + status.toUpperCase() + " status.");
}
Expand All @@ -170,13 +180,13 @@ class ServerHardwareListener extends Listener {
}

ListHardwareByPowerState(msg) {
let status = msg.powerState.substring(8, msg.powerState.length);
status = status.charAt(0).toUpperCase() + status.slice(1);
this.client.ServerHardware.getHardwareByPowerState(status).then((res) => {
let state = msg.powerState.substring(8, msg.powerState.length);
state = state.charAt(0).toUpperCase() + state.slice(1);
this.client.ServerHardware.getHardwareByPowerState(state).then((res) => {
if (res.members.length === 0) {
return this.transform.text(msg, msg.message.user.name + ", I didn't find any blades that are powered " + status.toLowerCase() + ".");
return this.transform.text(msg, msg.message.user.name + ", I didn't find any blades that are powered " + state.toLowerCase() + ".");
} else {
return this.pagination(msg, res, "Okay, " + msg.message.user.name + ", the following blades are powered " + status.toLowerCase() + ".");
return this.pagination(msg, res, "Okay, " + msg.message.user.name + ", the following blades are powered " + state.toLowerCase() + ".");
}
}).catch((err) => {
return this.transform.error(msg, err);
Expand All @@ -196,9 +206,9 @@ class ServerHardwareListener extends Listener {
let promises = [];
for (let serverInterconnectPortLink of res.serverInterconnectPortLinks) {
let shInterconnectUri = serverInterconnectPortLink.replace(rtrim, ''); //remove statistics port to make lookup key
let shLogicalInterconnectUri = icMap.get(shInterconnectUri);
let shLogicalInterconnectUri = icMap.get(msg.host + '' + shInterconnectUri);
if(shLogicalInterconnectUri) { //don't query if the interconnect is not part of a logical interconnect
promises.push(this.client.ServerHardware.getServerNetworkUtilization(serverInterconnectPortLink, shLogicalInterconnectUri));
promises.push(this.client.ServerHardware.getServerNetworkUtilization(msg.host, serverInterconnectPortLink, shLogicalInterconnectUri));
}
}
return Promise.all(promises);
Expand Down Expand Up @@ -244,9 +254,9 @@ class ServerHardwareListener extends Listener {
let promises = [];
for (let serverInterconnectPortLink of res.serverInterconnectPortLinks) {
let shInterconnectUri = serverInterconnectPortLink.replace(rtrim, ''); //remove statistics port to make lookup key
let shLogicalInterconnectUri = icMap.get(shInterconnectUri);
let shLogicalInterconnectUri = icMap.get(msg.host + '' + shInterconnectUri);
if(shLogicalInterconnectUri) { //don't query if the interconnect is not part of a logical interconnect
promises.push(this.client.ServerHardware.getServerNetworkUtilization(serverInterconnectPortLink, shLogicalInterconnectUri));
promises.push(this.client.ServerHardware.getServerNetworkUtilization(msg.host, serverInterconnectPortLink, shLogicalInterconnectUri));
}
}
return Promise.all(promises);
Expand Down
2 changes: 1 addition & 1 deletion src/listener/server-profile-templates.js
Expand Up @@ -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 Listener = require('./base-listener');
const Listener = require('./base');
const UserException = require('../oneview-sdk/user-exception');
const Conversation = require('hubot-conversation');

Expand Down
4 changes: 2 additions & 2 deletions src/listener/server-profiles.js
Expand Up @@ -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 Listener = require('./base-listener');
const Listener = require('./base');
const Conversation = require("hubot-conversation");

class ServerProfilesListener extends Listener {
Expand All @@ -30,7 +30,7 @@ class ServerProfilesListener extends Listener {
this.brain = brain;
this.title = "Server Profile";
this.capabilities = [];

this.LIST_ALL = /(?:get|list|show) all (?:server ){0,1}profiles\.$/i;
this.LIST = /(?:get|list|show) (:<host>.*?)(?:\/rest\/server-profiles\/)(:<profileId>[a-zA-Z0-9_-]*?)\.$/i;
this.LIST_COMPLIANCE = /(?:get|list|show) (:<host>.*?)(?:\/rest\/server-profiles\/)(:<profileId>[a-zA-Z0-9_-]*?) compliance(?: preview){0,1}\.$/i;
Expand Down
10 changes: 6 additions & 4 deletions src/oneview-sdk/server-hardware.js
Expand Up @@ -19,8 +19,8 @@ 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 uri = '/rest/server-hardware/';
const url = require('url');

class ServerHardware {
constructor (ov_client) {
Expand Down Expand Up @@ -107,9 +107,11 @@ class ServerHardware {
@param server hardware interconnect port statistics uri
@param server hardware logical interconnect uri
*/
getServerNetworkUtilization(shInterconnectPortStatisticsUri, shLogicalInterconnectUri) {
return this.ov_client.connection.get(shInterconnectPortStatisticsUri).then((res) => {
return Promise.all([res, this.ov_client.LogicalInterconnects.getLogicalInterconnectTelemetryConfiguration(shLogicalInterconnectUri)]);
getServerNetworkUtilization(host, shInterconnectPortStatisticsUri, shLogicalInterconnectUri) {
const connection = this.connections.get(host);
return connection.get(shInterconnectPortStatisticsUri).then((res) => {
let uri = url.parse('https://' + shLogicalInterconnectUri);
return Promise.all([res, this.ov_client.LogicalInterconnects.getLogicalInterconnectTelemetryConfiguration(host, uri.pathname)]);
});
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/oneview.js
Expand Up @@ -21,7 +21,7 @@ THE SOFTWARE.
*/

const nlp = require('./middleware/nlp-middleware').nlp;
const ovListener = require('./listener/ov-listener');
const ovListener = require('./listener/oneview');
const ovClient = require('./oneview-sdk/ov-client');
const ovBrain = require('./middleware/ov-brain');

Expand Down
Expand Up @@ -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 AlertsListener = require('../../src/listener/alerts-listener');
const AlertsListener = require('../../src/listener/alerts');
const OneViewBrain = require('../../src/middleware/ov-brain');
const OVClient = require('../../src/oneview-sdk/ov-client');
const ResourceTransforms = require('../../src/listener/utils/resource-transforms');
Expand Down
Expand Up @@ -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 DashboardListener = require('../../src/listener/dashboard-listener');
const DashboardListener = require('../../src/listener/dashboard');
const OneViewBrain = require('../../src/middleware/ov-brain');
const OVClient = require('../../src/oneview-sdk/ov-client');
const ResourceTransforms = require('../../src/listener/utils/resource-transforms');
Expand Down
Expand Up @@ -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 DefaultListener = require('../../src/listener/default-listener');
const DefaultListener = require('../../src/listener/default');
const OneViewBrain = require('../../src/middleware/ov-brain');
const OVClient = require('../../src/oneview-sdk/ov-client');
const ResourceTransforms = require('../../src/listener/utils/resource-transforms');
Expand Down
2 changes: 1 addition & 1 deletion test/listener/ov-listener.js → test/listener/oneview.js
Expand Up @@ -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 listener = require('../../src/listener/ov-listener');
const listener = require('../../src/listener/oneview');
const OneViewBrain = require('../../src/middleware/ov-brain');
const OVClient = require('../../src/oneview-sdk/ov-client');

Expand Down

0 comments on commit 7f0558f

Please sign in to comment.