Skip to content
This repository has been archived by the owner on Dec 30, 2024. It is now read-only.

Commit

Permalink
updates for #185
Browse files Browse the repository at this point in the history
  • Loading branch information
morjoan committed Dec 15, 2021
1 parent d7d23e9 commit 9bd5e8c
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 26 deletions.
18 changes: 12 additions & 6 deletions source/html/js/app/mappers/nodes/ec2.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ define(["jquery", "app/server", "app/connections", "app/regions", "app/model", "
const id = cache_entry.arn;
const nodes = model.nodes;
const rgb = "#D5DBDB";
let node_type = "EC2 Instance";
const generic_node_type = "EC2 Instance";
let node_type = generic_node_type;
if ('Tags' in config) {
if ('MSAM-NodeType' in config.Tags) {
node_type = config.Tags['MSAM-NodeType'];
Expand All @@ -55,33 +56,37 @@ define(["jquery", "app/server", "app/connections", "app/regions", "app/model", "
let local_name = name;
let local_rgb = rgb;
let local_id = id;
let local_generic_node_type = generic_node_type;
return function() {
return svg_node.unselected(local_node_type, local_name, local_rgb, local_id);
return svg_node.unselected(local_node_type, local_name, local_rgb, local_id, config, local_generic_node_type);
};
})(),
normal_selected: (function() {
let local_node_type = node_type;
let local_name = name;
let local_rgb = rgb;
let local_id = id;
let local_generic_node_type = generic_node_type;
return function() {
return svg_node.selected(local_node_type, local_name, local_rgb, local_id);
return svg_node.selected(local_node_type, local_name, local_rgb, local_id, config, local_generic_node_type);
};
})(),
alert_unselected: (function() {
let local_node_type = node_type;
let local_name = name;
let local_id = id;
var local_generic_node_type = generic_node_type;
return function() {
return svg_node.unselected(local_node_type, local_name, "#ff0000", local_id);
return svg_node.unselected(local_node_type, local_name, "#ff0000", local_id, config, local_generic_node_type);
};
})(),
alert_selected: (function() {
let local_node_type = node_type;
let local_name = name;
let local_id = id;
var local_generic_node_type = generic_node_type;
return function() {
return svg_node.selected(local_node_type, local_name, "#ff0000", local_id);
return svg_node.selected(local_node_type, local_name, "#ff0000", local_id, config, local_generic_node_type);
};
})()
},
Expand All @@ -98,7 +103,8 @@ define(["jquery", "app/server", "app/connections", "app/regions", "app/model", "
let html = `https://console.aws.amazon.com/cloudwatch/home?region=${region}#metricsV2:graph=~();query=~'*7bAWS*2fEC2*2cInstanceId*7d*20InstanceId*3d*22${name}*22`;
return html;
};
})()
})(),
"generic_node_type": generic_node_type
};
node_data.image.selected = node_data.render.normal_selected();
node_data.image.unselected = node_data.render.normal_unselected();
Expand Down
28 changes: 17 additions & 11 deletions source/html/js/app/mappers/nodes/ssm_managed_instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ define(["jquery", "app/server", "app/connections", "app/regions", "app/model", "
};

var map_config = function(cache_entry) {
var config = JSON.parse(cache_entry.data);
var name = config.Id;
var id = cache_entry.arn;
var nodes = model.nodes;
var rgb = "#D5DBDB";
var node_type = "SSM Managed Instance";
const config = JSON.parse(cache_entry.data);
const name = config.Id;
const id = cache_entry.arn;
const nodes = model.nodes;
const rgb = "#D5DBDB";
const generic_node_type = "SSM Managed Instance";
var node_type = generic_node_type;
if ('Tags' in config) {
if ('MSAM-NodeType' in config.Tags) {
node_type = config.Tags['MSAM-NodeType'];
Expand All @@ -55,33 +56,37 @@ define(["jquery", "app/server", "app/connections", "app/regions", "app/model", "
var local_name = name;
var local_rgb = rgb;
var local_id = id;
var local_generic_node_type = generic_node_type;
return function() {
return svg_node.unselected(local_node_type, local_name, local_rgb, local_id);
return svg_node.unselected(local_node_type, local_name, local_rgb, local_id, config, local_generic_node_type);
};
})(),
normal_selected: (function() {
var local_node_type = node_type;
var local_name = name;
var local_rgb = rgb;
var local_id = id;
var local_generic_node_type = generic_node_type;
return function() {
return svg_node.selected(local_node_type, local_name, local_rgb, local_id);
return svg_node.selected(local_node_type, local_name, local_rgb, local_id, config, local_generic_node_type);
};
})(),
alert_unselected: (function() {
var local_node_type = node_type;
var local_name = name;
var local_id = id;
var local_generic_node_type = generic_node_type;
return function() {
return svg_node.unselected(local_node_type, local_name, "#ff0000", local_id);
return svg_node.unselected(local_node_type, local_name, "#ff0000", local_id, config, local_generic_node_type);
};
})(),
alert_selected: (function() {
var local_node_type = node_type;
var local_name = name;
var local_id = id;
var local_generic_node_type = generic_node_type;
return function() {
return svg_node.selected(local_node_type, local_name, "#ff0000", local_id);
return svg_node.selected(local_node_type, local_name, "#ff0000", local_id, config, local_generic_node_type);
};
})()
},
Expand All @@ -98,7 +103,8 @@ define(["jquery", "app/server", "app/connections", "app/regions", "app/model", "
var html = `https://console.aws.amazon.com/cloudwatch/home?region=${region}#metricsV2:graph=~();query=~'*7bMSAM*2fSSMRunCommand*2c*22Instance*20ID*22*7d*20${name}`;
return html;
};
})()
})(),
"generic_node_type": generic_node_type
};
node_data.image.selected = node_data.render.normal_selected();
node_data.image.unselected = node_data.render.normal_unselected();
Expand Down
2 changes: 2 additions & 0 deletions source/html/js/app/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ define({
"app/ui/overlays/mediaconnect_flow",
"app/ui/overlays/medialive_channel",
"app/ui/overlays/medialive_multiplex",
"app/ui/overlays/ssm_managed_instance",
"app/ui/overlays/ec2_instance"
],
"default-overlay": "app/ui/overlays/alarms_only"
});
2 changes: 1 addition & 1 deletion source/html/js/app/ui/informational_overlays.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
if (ov.informational == true) {
const nodes = model.nodes.get({
filter: function(item) {
return ov.match_type == item.title;
return ov.match_type == (item.generic_node_type || item.title);
}
});

Expand Down
35 changes: 35 additions & 0 deletions source/html/js/app/ui/overlays/ec2_instance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*! Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0 */

define(["jquery", "lodash", "app/events", "app/alarms", "app/ui/overlays/overlay_tools", "app/model"],
function($, _, alert_events, alarms, tools, model) {

var match_type = "EC2 Instance";

var decorate_alarms = function(drawing, font_size, width, height, id) {
var alarm_count = 0;
for (let item of alarms.get_subscribers_with_alarms().current) {
if (item.ResourceArn == id) {
alarm_count += item.AlarmCount;
}
}
tools.set_alarm_text(alarm_count, drawing, font_size, width);
};

var decorate_information = function(drawing, font_size, width, height, id) {
var node = model.nodes.get(id);
if (node) {
if (node.data.Tags.Name) {
computer_name = node.data.Tags.Name;
tools.set_info_text(computer_name, drawing, font_size, width, "Name");
}
}
};

var decorate = function(drawing, font_size, width, height, id) {
decorate_alarms(drawing, font_size, width, height, id);
decorate_information(drawing, font_size, width, height, id);
};

return { match_type, decorate, informational: true };
});
4 changes: 2 additions & 2 deletions source/html/js/app/ui/overlays/overlay_tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ define(['jquery', 'lodash', 'app/events', 'app/alarms'], function($, _, alert_ev
draw_font_set_position(typeLabel, font_size, width);
};

const set_info_text = function(data, drawing, font_size, width) {
const typeLabel = drawing.text(generateText('Type', data)).y(info_y);
const set_info_text = function(data, drawing, font_size, width, label = "Type") {
const typeLabel = drawing.text(generateText(label, data)).y(info_y);
draw_font_set_position(typeLabel, font_size, width);
};

Expand Down
35 changes: 35 additions & 0 deletions source/html/js/app/ui/overlays/ssm_managed_instance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*! Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0 */

define(["jquery", "lodash", "app/events", "app/alarms", "app/ui/overlays/overlay_tools", "app/model"],
function($, _, alert_events, alarms, tools, model) {

var match_type = "SSM Managed Instance";

var decorate_alarms = function(drawing, font_size, width, height, id) {
var alarm_count = 0;
for (let item of alarms.get_subscribers_with_alarms().current) {
if (item.ResourceArn == id) {
alarm_count += item.AlarmCount;
}
}
tools.set_alarm_text(alarm_count, drawing, font_size, width);
};

var decorate_information = function(drawing, font_size, width, height, id) {
var node = model.nodes.get(id);
if (node) {
if (node["data"]["Data"]["AWS:InstanceInformation"]["Content"][0]["ComputerName"]) {
computer_name = node["data"]["Data"]["AWS:InstanceInformation"]["Content"][0]["ComputerName"];
tools.set_info_text(computer_name, drawing, font_size, width, "Name");
}
}
};

var decorate = function(drawing, font_size, width, height, id) {
decorate_alarms(drawing, font_size, width, height, id);
decorate_information(drawing, font_size, width, height, id);
};

return { match_type, decorate, informational: true };
});
12 changes: 6 additions & 6 deletions source/html/js/app/ui/svg_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ define(["jquery", "lodash", "app/window", "app/ui/util", "app/plugins"], functio

const wordWrap = (str, max) => str.length > max ? [`${str.substring(0, max - 1)} [...]`] : [str];

const create = (type_name, node_name, node_rgb, selected, id, data) => {
const create = (type_name, node_name, node_rgb, selected, id, data, generic_type_name) => {
const inc_y = 35;
const radius = 20;
const width = 400;
Expand Down Expand Up @@ -50,7 +50,7 @@ define(["jquery", "lodash", "app/window", "app/ui/util", "app/plugins"], functio

for (let module of overlays) {
let overlay = require(module);
if (overlay.match_type == type_name) {
if (overlay.match_type == (generic_type_name || type_name)) {
// console.log("applying overlay " + overlay.name);
overlay.decorate(drawing, font_size, width, height, id, data);
found = true;
Expand All @@ -77,10 +77,10 @@ define(["jquery", "lodash", "app/window", "app/ui/util", "app/plugins"], functio
$("body").append(work_div_html);

return {
selected: (type_name, node_name, node_rgb, id, data) =>
create(type_name, node_name, node_rgb, true, id, data),
unselected: (type_name, node_name, node_rgb, id, data) =>
create(type_name, node_name, node_rgb, false, id, data),
selected: (type_name, node_name, node_rgb, id, data, generic_type_name) =>
create(type_name, node_name, node_rgb, true, id, data, generic_type_name),
unselected: (type_name, node_name, node_rgb, id, data, generic_type_name) =>
create(type_name, node_name, node_rgb, false, id, data, generic_type_name),
getDegradedRgb: () => degraded_rgb
};
});

0 comments on commit 9bd5e8c

Please sign in to comment.