Skip to content

Commit

Permalink
[rocketchat] Patch for PR chaoss#882
Browse files Browse the repository at this point in the history
  • Loading branch information
obaroikoh committed Jun 11, 2020
1 parent 43d10d9 commit 4106d06
Show file tree
Hide file tree
Showing 4 changed files with 1,473 additions and 11 deletions.
34 changes: 23 additions & 11 deletions grimoire_elk/enriched/rocketchat.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#
# Authors:
# Animesh Kumar<[email protected]>
# Obaro Ikoh <[email protected]>
#

import logging
Expand Down Expand Up @@ -56,11 +57,6 @@ def get_elastic_mappings(es_major):
class RocketChatEnrich(Enrich):
mapping = Mapping

def __init__(self, db_sortinghat=None, db_projects_map=None, json_projects_map=None,
db_user='', db_password='', db_host=''):
super().__init__(db_sortinghat, db_projects_map, json_projects_map,
db_user, db_password, db_host)

def get_field_author(self):
return "u"

Expand Down Expand Up @@ -105,6 +101,8 @@ def get_rich_item(self, item):
eitem['id'] = message['_id']
# parent exists in case message is a reply
eitem['parent'] = message.get('parent', None)
# set default value for is_edited
eitem['is_edited'] = 0

if 'u' in message and message['u']:
author = message['u']
Expand All @@ -117,17 +115,24 @@ def get_rich_item(self, item):
editor = message['editedBy']
eitem['edited_by_username'] = editor.get('username', None)
eitem['edited_by_user_id'] = editor.get('_id', None)
eitem['is_edited'] = 1

if 'file' in message and message['file']:
eitem['file_id'] = message['file'].get('_id', None)
eitem['file_name'] = message['file'].get('name', None)
eitem['file_type'] = message['file'].get('type', None)

if 'replies' in message and message['replies']:
eitem['replies'] = message['replies']
eitem['replies'] = len(message['replies'])

if 'reactions' in message and message['reactions']:
eitem.update(self.__get_reactions(message))
reactions = self.__get_reactions(message)
eitem.update(reactions)
# Calculate total reaction count
count = 0
for key, value in reactions.items():
count += value['properties']['count']
eitem['total_number_of_reactions'] = count

if 'mentions' in message and message['mentions']:
eitem['mentions'] = self.__get_mentions(message['mentions'])
Expand All @@ -144,6 +149,8 @@ def get_rich_item(self, item):
if self.prjs_map:
eitem.update(self.get_item_project(eitem))

eitem.update(self.get_grimoire_fields(item["metadata__updated_on"], "message"))

self.add_repository_labels(eitem)
self.add_metadata_filter_raw(eitem)
return eitem
Expand All @@ -154,9 +161,14 @@ def __get_reactions(self, item):
reactions = {}

item_reactions = item.get('reactions', {})
for reaction in item_reactions:
reactions['reaction_{}'.format(reaction)] = item_reactions[reaction]

for key, reaction in item_reactions.items():
reactions[key] = {"properties": {
"name": reaction['names'],
"usernames": reaction['usernames'],
"count": len(reaction['usernames']),
"type": key
}
}
return reactions

def __get_mentions(self, mentioned):
Expand All @@ -165,7 +177,7 @@ def __get_mentions(self, mentioned):
rich_mentions = []

for usr in mentioned:
if '_id' in usr.keys():
if '_id' in usr.keys() and 'name' in usr.keys():
rich_mentions.append({'username': usr['username'], 'id': usr['_id'],
'name': usr['name']})

Expand Down
49 changes: 49 additions & 0 deletions schema/rocketchat.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name,type,aggregatable,description
author_bot,boolean,true,"True if the given author is identified as a bot."
author_domain,keyword,true,"Domain associated to the author in SortingHat profile."
author_gender,keyword,true,"Author gender."
author_gender_acc,keyword,true,"Accuracy to assess author gender."
author_id,keyword,true,"Author Id from SortingHat."
author_multi_org_names,keyword,true,"List of the author organizations from SortingHat profile."
author_name,keyword,true,"Author name."
author_org_name,keyword,true,"Author organization name from SortingHat profile."
author_user_name,keyword,true,"Author username from Sortinghat profile."
author_uuid,keyword,true,"Author UUID from SortingHat."
channel_updated_at,date,true,"Date when channel was created in UNIX timestamp format."
channel_id,keyword,long,true,"Channel Id of a Slack channel."
channel_num_users,long,true,"Number of members in a Rocketchat channel."
channel_num_messages,long,true,"Number of messages in a Rocketchat channel."
channel_name,keyword,true,"Channel Name."
grimoire_creation_date,date,true,"Message creation date."
is_rocketchat_message,long,true,"1 indicating the item is a message."
is_edited,long,true,"1 indicating the message has been edited"
metadata__enriched_on,date,true,"Date when the item was enriched."
metadata__gelk_backend_name,keyword,true,"Name of the backend used to enrich information."
metadata__gelk_version,keyword,true,"Version of the backend used to enrich information."
metadata__timestamp,date,true,"Date when the item was stored in RAW index."
metadata__updated_on,date,true,"Date when the item was updated on its original data source."
metadata__filter_raw,keyword,true,"Raw filter"
origin,keyword,true,"Original URL where the channel was retrieved from."
profile_title,keyword,true,"Title in a user profile."
project,keyword,true,"Project."
project_1,keyword,true,"Project (if more than one level is allowed in project hierarchy)."
reaction_count,long,true,"Number of reactions on a message."
reactions,keyword,true,"Reactions on a message."
replies,long,true,"Number of replies on a message."
repository_labels,keyword,true,"Custom repository labels defined by the user."
tag,keyword,true,"Perceval tag."
total_number_of_reactions,long,true,"Number of reactions in a message"
msg,keyword,true,"Message text."
text_analyzed,keyword,true,"Message body in plain text."
user_username,keyword,true,"Rocketchat user."
u_bot,long,true,"1 if the given user is identified as a bot."
u_domain,keyword,true,"Domain associated to the user in SortingHat profile."
u_gender,keyword,true,"User gender, based on her name (disabled by default)."
u_gender_acc,long,true,"User gender accuracy (disabled by default)."
u_id,keyword,true,"User Id from SortingHat."
u_multi_org_names,keyword,true,"List of the user organizations from SortingHat profile."
u_name,keyword,true,"User's name from SortingHat profile"
u_org_name,keyword,true,"User's organization name from SortingHat profile."
u_user_name,keyword,true,"User's username from SortingHat profile."
u_uuid,keyword,true,"User's UUID from SortingHat profile."
uuid,keyword,true,"Perceval UUID."
Loading

0 comments on commit 4106d06

Please sign in to comment.