From c816950bded20f6c5f41d77bb1a3c6ff7c9d6a49 Mon Sep 17 00:00:00 2001 From: Rodrigo Nascimento Date: Thu, 11 May 2017 14:25:23 -0300 Subject: [PATCH] [NEW] Show info about multiple instances at admin page --- packages/rocketchat-i18n/i18n/en.i18n.json | 7 ++- .../client/adminInfo.coffee | 11 ++++- .../rocketchat-ui-admin/client/adminInfo.html | 44 +++++++++++++++++++ server/stream/streamBroadcast.js | 15 +++++++ 4 files changed, 75 insertions(+), 2 deletions(-) diff --git a/packages/rocketchat-i18n/i18n/en.i18n.json b/packages/rocketchat-i18n/i18n/en.i18n.json index 1d18d31ef923..6500fda913b1 100644 --- a/packages/rocketchat-i18n/i18n/en.i18n.json +++ b/packages/rocketchat-i18n/i18n/en.i18n.json @@ -267,6 +267,7 @@ "BotHelpers_userFields": "User Fields", "BotHelpers_userFields_Description": "CSV of user fields that can be accessed by bots helper methods.", "Branch": "Branch", + "Broadcast_Connected_Instances": "Broadcast Connected Instances", "Bugsnag_api_key": "Bugsnag API Key", "busy": "busy", "Busy": "Busy", @@ -362,6 +363,7 @@ "CROWD_Reject_Unauthorized": "Reject Unauthorized", "CRM_Integration": "CRM Integration", "Current_Chats": "Current Chats", + "Current_Status": "Current Status", "Custom": "Custom", "Custom_Emoji": "Custom Emoji", "Custom_Emoji_Add": "Add New Emoji", @@ -706,6 +708,7 @@ "Install_FxOs_follow_instructions": "Please confirm the app installation on your device (press \"Install\" when prompted).", "Installation": "Installation", "Installed_at": "Installed at", + "Instance_Record": "Instance Record", "Instructions_to_your_visitor_fill_the_form_to_send_a_message": "Instructions to your visitor fill the form to send a message", "Impersonate_user": "Impersonate User", "Impersonate_user_description": "When enabled, integration posts as the user that triggered integration", @@ -1256,6 +1259,7 @@ "Reset_password": "Reset password", "Restart": "Restart", "Restart_the_server": "Restart the server", + "Retry_Count": "Retry Count", "Role": "Role", "Role_Editing": "Role Editing", "Role_removed": "Role removed", @@ -1560,6 +1564,7 @@ "Unread_Rooms": "Unread Rooms", "Unread_Rooms_Mode": "Unread Rooms Mode", "Unstar_Message": "Remove Star", + "Updated_at": "Updated at", "Upload_file_description": "File description", "Upload_file_name": "File name", "Upload_file_question": "Upload file?", @@ -1719,4 +1724,4 @@ "your_message_optional": "your message (optional)", "Your_password_is_wrong": "Your password is wrong!", "Your_push_was_sent_to_s_devices": "Your push was sent to %s devices" -} \ No newline at end of file +} diff --git a/packages/rocketchat-ui-admin/client/adminInfo.coffee b/packages/rocketchat-ui-admin/client/adminInfo.coffee index 51cea0151143..1bfaedf4c899 100644 --- a/packages/rocketchat-ui-admin/client/adminInfo.coffee +++ b/packages/rocketchat-ui-admin/client/adminInfo.coffee @@ -5,6 +5,8 @@ Template.adminInfo.helpers return Template.instance().ready.get() statistics: -> return Template.instance().statistics.get() + instances: -> + return Template.instance().instances.get() inGB: (size) -> if size > 1073741824 return _.numberFormat(size / 1024 / 1024 / 1024, 2) + ' GB' @@ -52,13 +54,20 @@ Template.adminInfo.onRendered -> Template.adminInfo.onCreated -> instance = @ @statistics = new ReactiveVar {} + @instances = new ReactiveVar [] @ready = new ReactiveVar false if RocketChat.authz.hasAllPermission('view-statistics') Meteor.call 'getStatistics', (error, statistics) -> - instance.ready.set true if error handleError(error) else instance.statistics.set statistics + Meteor.call 'instances/get', (error, instances) -> + instance.ready.set true + if error + handleError(error) + else + instance.instances.set instances + diff --git a/packages/rocketchat-ui-admin/client/adminInfo.html b/packages/rocketchat-ui-admin/client/adminInfo.html index e3d5358d08eb..c900a7c6dac6 100644 --- a/packages/rocketchat-ui-admin/client/adminInfo.html +++ b/packages/rocketchat-ui-admin/client/adminInfo.html @@ -226,6 +226,50 @@

{{_ "Usage"}}

+ {{#if instances}} +

{{_ "Broadcast_Connected_Instances"}}

+ {{#each instances}} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
{{_ "Address"}}{{address}}
{{_ "Auth"}}{{broadcastAuth}}
{{_ "Current_Status"}} > {{_ "Connected"}}{{currentStatus.connected}}
{{_ "Current_Status"}} > {{_ "Retry_Count"}}{{currentStatus.retryCount}}
{{_ "Current_Status"}} > {{_ "Status"}}{{currentStatus.status}}
{{_ "Instance_Record"}} > {{_ "ID"}}{{instanceRecord._id}}
{{_ "Instance_Record"}} > {{_ "PID"}}{{instanceRecord.pid}}
{{_ "Instance_Record"}} > {{_ "Created_at"}}{{formatDate instanceRecord._createdAt}}
{{_ "Instance_Record"}} > {{_ "Updated_at"}}{{formatDate instanceRecord._updatedAt}}
+ {{/each}} + {{/if}} + {{else}} {{_ "Loading..."}} diff --git a/server/stream/streamBroadcast.js b/server/stream/streamBroadcast.js index 6de334e34b95..b9b43639eae8 100644 --- a/server/stream/streamBroadcast.js +++ b/server/stream/streamBroadcast.js @@ -257,3 +257,18 @@ function startStreamBroadcast() { Meteor.startup(function() { return startStreamBroadcast(); }); + +Meteor.methods({ + 'instances/get'() { + if (!RocketChat.authz.hasPermission(Meteor.userId(), 'view-statistics')) { + throw new Meteor.Error('error-action-not-allowed', 'List instances is not allowed', { + method: 'instances/get' + }); + } + + return Object.keys(connections).map(address => { + const conn = connections[address]; + return Object.assign({ address, currentStatus: conn._stream.currentStatus }, _.pick(conn, 'instanceRecord', 'broadcastAuth')); + }); + } +});