Ejemplo n.º 1
0
    def cmd_created_in_last(self, params, team_id=None, channel=None):
        elk_to_slack = ELK_to_Slack()
        if len(params) < 2:
            text = ":exclamation: you must provide an start date. You can use `1d`,`1w`,`1y` (d=day, w=week, y=year"
            return {"text": text, "attachments": []}

        from_date = params.pop()
        issues = API_Issues().issues_created_in_last(from_date)

        issues_text = elk_to_slack.get_text_with_issues_key_and_summary(issues)
        graph_name = elk_to_slack.save_issues_as_new_graph(issues)
        text = elk_to_slack.get_slack_message(issues, graph_name)

        max_table = 100
        if len(issues) < max_table:
            text += "\n (Since there are less than {0} results also showing table with data)".format(
                max_table)
            self.cmd_table(["table", graph_name], team_id, channel)
        return {
            "text": text,
            "attachments": [{
                'text': issues_text,
                'color': 'good'
            }]
        }
Ejemplo n.º 2
0
    def cmd_created_between(self, params, team_id=None, channel=None):
        elk_to_slack = ELK_to_Slack()
        if len(params) < 3:
            text = ":exclamation: you must provide an start and end date. You can use `1d`,`1w`,`1y` (d=day, w=week, y=year"
            text += "\nTry `now-1d` and `now`"
            return {"text": text, "attachments": []}
        to_date = params.pop()
        from_date = params.pop()
        try:
            issues = API_Issues().elastic().get_data_between_dates(
                "Created", from_date, to_date)

            issues_text = elk_to_slack.get_text_with_issues_key_and_summary(
                issues)
            graph_name = elk_to_slack.save_issues_as_new_graph(issues)
            text = elk_to_slack.get_slack_message(issues, graph_name)

            min_table = 100
            max_table = 100
            if min_table < len(issues) < max_table:
                text += "\n (Since there are less than {0} (and more than {1}) results also showing table with data)".format(
                    max_table, min_table)
                self.cmd_table(["table", graph_name], team_id, channel)
            return {
                "text": text,
                "attachments": [{
                    'text': issues_text,
                    'color': 'good'
                }]
            }
        except Exception as error:
            text = "Error in cmd_created_between: {0}".format(error)
            return {"text": text, "attachments": []}
Ejemplo n.º 3
0
    def return_search_results(self, query):
        query = query.replace('+', ' ')
        max_show = 100
        issues = ELK_to_Slack().cmd_search(query.split(' '))

        count = len(issues)
        options = []
        if count > max_show:
            options.append({
                'text':
                '[{0} matches, showing first {1}]'.format(count, max_show),
                'value':
                'NA'
            })
        else:
            options.append({
                'text': '[{0} matches]'.format(count),
                'value': 'NA'
            })
        options.append({
            'text': '------------------------------',
            'value': 'NA'
        })

        issues = issues[0:max_show]
        items = {}
        for issue in issues:
            text = "{1}: {0}".format(issue.get('Summary'),
                                     issue.get('Issue Type'))
            items[text] = issue.get('Key')
        for text in sorted(items.keys()):
            options.append({'text': text, 'value': items[text]})

        return {"options": options}
Ejemplo n.º 4
0
 def __init__(self):
     self.lambda_graph = Lambda('osbot_jira.lambdas.graph')
     self.api_issues = API_Issues()
     self.gs_bot_jira = GS_Bot_Jira()
     self.graph_commands = Lambda_Graph_Commands()
     self.elk_to_slack = ELK_to_Slack()
Ejemplo n.º 5
0
class Jp_Graph_Data:
    def __init__(self):
        self.lambda_graph = Lambda('osbot_jira.lambdas.graph')
        self.api_issues = API_Issues()
        self.gs_bot_jira = GS_Bot_Jira()
        self.graph_commands = Lambda_Graph_Commands()
        self.elk_to_slack = ELK_to_Slack()

    def lambda_invoke(self, params):
        result = self.lambda_graph.invoke({'params': params, 'data': {}})
        return json_loads(result)

    def issue(self, issue_id):
        return self.api_issues.issue(issue_id)

    def issues(self, issue_id):
        return self.api_issues.issues(issue_id)

    def jira_links(self, source, depth=1):
        params = ['links', source, depth]
        return self.gs_bot_jira.cmd_links(params, save_graph=False)

    def jira_search(self, query):
        params = query.split(' ')
        query = self.elk_to_slack.get_search_query(params)
        return self.api_issues.search_using_lucene(query)

    def graph_expand(self, source, depth, link_types):
        params = [source, depth, link_types]
        return self.graph_commands.expand(params=params, save_graph=False)

        #data = json..invoke(params))
        #nodes = data.get('nodes')
        #edges = data.get('edges')

    def draw_graph(self, graph):
        nodes = graph.nodes
        edges = graph.edges
        import networkx as nx
        import matplotlib.pyplot as plt

        size = 40
        plt.figure(figsize=(size, size))
        G = nx.DiGraph()

        for node in nodes:
            G.add_node(node)

        for edge in edges:
            G.add_edge(edge[0], edge[2], label=edge[1])

        edge_labels = nx.get_edge_attributes(G, 'label')

        # pos = nx.spring_layout(G)
        # pos=nx.nx_pydot.graphviz_layout(G,prog='dot')
        pos = nx.nx_pydot.graphviz_layout(G)

        nx.draw_networkx_nodes(G, pos, node_shape='', node_size=100)
        nx.draw_networkx_labels(G, pos, font_size=16)
        nx.draw_networkx_edges(G, pos)
        nx.draw_networkx_edge_labels(G,
                                     pos=pos,
                                     edge_labels=edge_labels,
                                     font_size=10)
Ejemplo n.º 6
0
 def setUp(self):
     self.elk_to_slack = ELK_to_Slack()
     self._lambda = Lambda("osbot_jira.lambdas.elk_to_slack")
Ejemplo n.º 7
0
class Test_ELK_to_Slack(TestCase):
    def setUp(self):
        self.elk_to_slack = ELK_to_Slack()
        self._lambda = Lambda("osbot_jira.lambdas.elk_to_slack")

    # def test_update_lambda(self):
    #     Lambda("lambdas.gs.elk_to_slack").update_with_src()
    #     #Lambda('osbot_jira.lambdas.jira').update_with_src()

    def test_cmd_search(self):
        params = ['Issue\ Type:"Security Controls"']
        user = '******'
        channel = 'DDKUZTK6X'
        assert len(self.elk_to_slack.cmd_search(params, user, channel)) > 10

    def test_cmd_search___people(self):
        params = ['people', 'dinis']
        assert self.elk_to_slack.cmd_search(params)[0].get('Key') == 'GSP-95'

    def test_cmd_search__no_params(self):
        params = []
        response = self.elk_to_slack.cmd_search(params)
        #Dev.print(response)

    def test_cmd_search__view_handle_lambda_event(self):
        params = {
            'params': ['search', '"GSOKR-924"'],
            'user': '******',
            'channel': 'DDKUZTK6X'
        }
        #Dev.pprint(self.elk_to_slack.handle_lambda_event(params))

    def test_get_search_query(self):
        assert self.elk_to_slack.get_search_query([]) == ''
        assert self.elk_to_slack.get_search_query(
            ['people', '123']) == 'Issue\\ Type:People AND Summary:123'
        assert self.elk_to_slack.get_search_query(['aaa', '123']) == 'aaa 123'

    def test__lambda_update_invoke(self):
        params = {
            'params': ['search', 'project:RISK', 'and', 'Status=Open'],
            'user': '******',
            'channel': 'DDKUZTK6X'
        }
        result = self._lambda.invoke(params)
        #Dev.pprint(result)

    def test__cmd_search__via_lambda(self):
        query = ['Project:RISK', 'AND', 'Status:Open']
        payload = {"params": ["search"] + query, "channel": "DDKUZTK6X"}

        result = self._lambda.invoke(payload)
        assert len(result) > 12

    def test__cmd_search__via_lambda___Epic_issue(self):
        query = ['"GSOKR-924"']
        payload = {"params": ["search"] + query, "channel": "DDKUZTK6X"}

        result = self._lambda.invoke(payload)
        assert len(result) > 12

    # def test__cmd_search_graph__via_lambda(self):
    #
    #     query =  ['Labels:R1']
    #     payload = {"params": ["search-graph"] + query, "channel": "DDKUZTK6X"}
    #
    #     result = self._lambda.invoke(payload)
    #     Dev.pprint(result)
    #     #assert result is None

    def test___cmd_search_graph__send_results_to_Lambda(self):
        slack_cmd = 'links RISK-1534,RISK-1496,RISK-1498,RISK-1494,RISK-1592,RISK-1495 down 1'
        params = slack_cmd.split(' ')
        user_id = None
        channel = 'DDKUZTK6X'
        result = Lambda('osbot_jira.lambdas.jira').invoke({
            "params": params,
            "user": user_id,
            "channel": channel
        })
        ##Dev.pprint(result)
        slack_message(result.get('text'), result.get('attachments'), channel)

    def test_bug_in_search(self):
        query = ['"Epic Link":“SEC-9700”']
        payload = {"params": ["search"] + query}

        result = self._lambda.invoke(payload)