コード例 #1
0
def run(event, context):
    load_dependency('pydot')
    channel = event.get('channel')
    data = event.get('dot')

    #slack_message("in dot to svg: {0}".format(event), [], channel)
    log_to_elk("in dot to svg: {0}".format(event))

    import dot_parser

    try:
        (fd, tmp_file) = tempfile.mkstemp('dot)')
        dot_static = '/tmp/lambdas-dependencies/pydot/dot_static'
        Process.run("chmod", ['+x', dot_static])
        data = data.replace('&lt;', '<').replace(
            '&gt;', '>'
        )  # this solved a really nasty bug caused by the fact that Slack will html encode the < and >

        # graph          = pydot.graph_from_dot_data(data).pop()
        # <from pydot>  use code below (instead of above) to get a better error message from dot parser
        graphparser = dot_parser.graph_definition()
        graphparser.parseWithTabs()
        tokens = graphparser.parseString(data)
        graph = list(tokens).pop()
        # </from pydot>
        graph.write_svg(tmp_file, prog=dot_static)
        svg_raw = Files.contents(tmp_file)
        return base64.b64encode(svg_raw.encode()).decode()
    except Exception as error:
        slack_message("[dot_to_svg] Error: {0} ".format(error), [], channel)
        return None
コード例 #2
0
    def default(team_id=None, channel=None, params=None, no_render=False):

        load_dependencies(['syncer', 'requests']);
        from view_helpers.VivaGraph_Js import VivaGraph_Js

        graph_name = params.pop(0)
        vivagraph_js = VivaGraph_Js(headless=False)  # will start browser

        graph_data = vivagraph_js.get_graph_data(graph_name)
        #
        vivagraph_js.load_page(False)
        if graph_data:
            edges = graph_data.get('edges')
            nodes = []
            for key,issue in graph_data.get('nodes').items():
                node = {
                            'key'   : key ,
                            'label' : key,
                            'img'   : vivagraph_js.resolve_icon_from_issue_type(issue, key)
                        }
                nodes.append(node)
            slack_message(":point_right: Rendering `{0}` using VivaGraph JS engine (`{1}` nodes and `{2}` edges)"
                          .format(graph_name, len(nodes), len(edges)), [], channel,team_id)



            if no_render is True:
                return graph_name, nodes, edges, graph_data, vivagraph_js

            options = {}
            vivagraph_js.create_graph_and_send_screenshot_to_slack(nodes, edges, options, team_id, channel)
コード例 #3
0
 def invoke(self, team_id=None, channel=None, params=None):
     if params is None: params = []
     attachments = []
     if len(params) == 0:
         (text, attachments) = self.help()
     else:
         original_params = list(params)
         command = params.pop(0)  # extract first element from the array
         if command in self.available_methods():
             method = getattr(self.target, command)
             try:
                 start = time()
                 result = method(team_id, channel, params)
                 if type(result).__name__ == 'tuple':
                     text, attachments = result
                 else:
                     text, attachments = result, []
                 if text is None and self._show_duration:
                     duration = time() - start
                     text = 'completed execution in `{0:.0f}` secs'.format(
                         duration)
             except Exception as error:
                 text = ':red_circle: Error processing params `{0}`: _{1}_'.format(
                     original_params, pprint.pformat(error))
                 log_to_elk(
                     "Error in Lambda_Graph.handle_lambda_event :{0}".
                     format(text),
                     level='error')
         else:
             (text, attachments) = self.help(
                 ':red_circle: command not found `{0}`\n\n'.format(command))
     if channel and text is not None:  # if there is a text value, then send it as a slack message
         slack_message(text, attachments, channel, team_id)
     return text, attachments
コード例 #4
0
    def test__create_button_to_test_dialog(self):
        Lambdas('gs.jira_dialog').update()

        self.api_attach.set_text       ('Click on button below to test dialog'    ) \
                       .set_callback_id("button-dialog-test"                      ) \
                       .add_button     ("button", "open dialog", "open", "primary")
        attachments = self.api_attach.render()
        slack_message("", attachments, 'DDKUZTK6X')
コード例 #5
0
 def test_render(self):
     self.api.set_text       ('this is the attachment text'            ) \
             .set_callback_id("button-test")                      \
             .add_button     ("name 1", "text 1", "type 3", "primary") \
             .add_button     ("name 2", "text 2", "type 3", "danger" )
     attachments = self.api.render()
     text = None  # 'main text'
     slack_message(text, attachments, 'DDKUZTK6X')
コード例 #6
0
 def test_add_select_user_data_source(self):
     (self.api.set_text('here are the multiple data sources'     )
          .set_callback_id         ("issue-suggestion"           )
          .add_select_users        ("user", "pick a user"        )
          .add_select_channels     ("user", "pick a channel"     )
          .add_select_conversations("user", "pick a conversation")
          .add_select_external     ("key", "pick an Key"        ))   
     slack_message("", self.api.render(), 'DDKUZTK6X')
コード例 #7
0
    def test_select(self):
        text          =  "...testing select attachment"
        (self.api.set_text('this is the attachment text')
             .set_callback_id ("button-test")
             .set_color       ("#0055AA")
             .add_button      ("name 1", "text 1", "type 3", "primary")
             .add_button      ("name 2", "text 2", "type 3", "danger")
             .add_select      ("name", "pick a value",[("text 1", "value-1"), ("text 2", "value-2")])
             .add_select_users("user", "pick a user")  )

        attachments = self.api.render()
        slack_message(text, attachments, 'DDKUZTK6X')
コード例 #8
0
 def screenshot(team_id=None, channel=None, params=[]):
     url = params.pop(0).replace('<', '').replace(
         '>', '')  # fix extra chars added by Slack
     delay = Misc.to_int(Misc.array_pop(params, 0))
     slack_message(
         ":point_right: taking screenshot of url: {0}".format(url), [],
         channel, team_id)
     browser_helper = Browser_Lamdba_Helper().setup()
     png_data = browser_helper.get_screenshot_png(url,
                                                  full_page=True,
                                                  delay=delay)
     return browser_helper.send_png_data_to_slack(team_id, channel, url,
                                                  png_data)
コード例 #9
0
def run(event, context):
    channel = event.get('channel')
    try:
        dot_to_svg = Lambdas('utils.dot_to_svg').invoke
        svg_to_png = Lambdas('utils.svg_to_png').invoke
        svg        = dot_to_svg(event)
        result     = svg_to_png({"svg": svg , "width": event.get("width")})
        if result.get('image'):
            return  result['image']
        return { 'error' : result}
    except Exception as error:
        slack_message(":red_circle: Error in dot_to_png: {0}".format(error), [], channel)
        return { 'error': error }
コード例 #10
0
def run(event, context):
    team_id = 'T7F3AUXGV'
    channel = 'DDKUZTK6X'
    text = "in API Gateway test..."
    attachments = [ {'text': "{0}".format(Misc.json_format(event)) , 'color':'good'}]
    #attachments = [{'text': "{0}".format(event), 'color': 'good'}]

    slack_message(text, attachments, channel,team_id)

    result = Misc.json_format({'text': text})
    return {
                'headers'        : {'Content-Type': 'application/json'},
                "statusCode"     : 209,
                "body"           : result
            }
コード例 #11
0
 def mindmap(slack_event, params=None):
     channel = slack_event.get('channel')
     team_id = slack_event.get('team_id')
     if len(params) < 1:
         text = ':red_circle: Hi, for the `mindmap` command, you need to provide an `graph_name`'
         slack_message(text, [], channel, team_id)
         return None, None
     graph_name = params.pop(0)
     graph_params = ['go_js', graph_name, 'mindmap']
     graph_params.extend(params)
     Lambdas('browser.lambda_browser').invoke_async({
         "params": graph_params,
         'data': {
             'team_id': team_id,
             'channel': channel
         }
     })
     return None, None
コード例 #12
0
def run(event, context):
    team_id = 'T7F3AUXGV'
    channel = 'DDKUZTK6X'
    querystring = event.get('queryStringParameters')
    if querystring and querystring.get('file_id'):
        file_id = querystring.get('file_id')
        if querystring.get('action') == 'diff':
            payload = {
                "params": ["diff_sheet", file_id],
                "channel": "DDKUZTK6X",
                'team_id': 'T7F3AUXGV'
            }
        elif querystring.get('action') == 'sync':
            payload = {
                "params": ["sync_sheet", file_id],
                "channel": "DDKUZTK6X",
                'team_id': 'T7F3AUXGV'
            }
        else:
            payload = {
                "params": ["load_sheet", file_id],
                "channel": "DDKUZTK6X",
                'team_id': 'T7F3AUXGV'
            }
        Lambdas('gs.elastic_jira').invoke(payload)
        text = ":point_right: [trigger_sync_jira_sheets] completed workflow for file_id: {0} , see channel {1} for more details".format(
            file_id, channel)
        status_code = 201
    else:
        text = "Error: file_id value not provided"
        status_code = 501

    slack_message(text, [], channel, team_id)

    return {
        'headers': {
            'Content-Type': 'application/json'
        },
        "statusCode": status_code,
        "body": Misc.json_format({'text': text})
    }
コード例 #13
0
def run(event, context):
    team_id = 'T7F3AUXGV'
    channel = 'DDKUZTK6X'
    text = ":robot_face: In trigger_server_reload lambda function \n"

    payload = {
        "params": ["server", "reload"],
        "channel": channel,
        'team_id': team_id
    }
    result = Lambdas('gs.elastic_jira').invoke(payload)

    attachments = [{'text': result, 'color': 'good'}]

    slack_message(text, attachments, channel, team_id)

    result = Misc.json_format({'text': text})
    return {
        'headers': {
            'Content-Type': 'application/json'
        },
        "statusCode": 209,
        "body": result
    }
コード例 #14
0
    def render(team_id, channel, params):

        if params:
            target = params.pop(0)
            delay = Misc.to_int(Misc.array_pop(params, 0))
            if len(params) == 4:
                clip = {
                    'x': int(params[0]),
                    'y': int(params[1]),
                    'width': int(params[2]),
                    'height': int(params[3])
                }
            else:
                clip = None
        else:
            return None

        slack_message(":point_right: rendering file `{0}`".format(target), [],
                      channel, team_id)
        return Browser_Lamdba_Helper().setup().render_file(team_id,
                                                           channel,
                                                           target,
                                                           clip=clip,
                                                           delay=delay)
コード例 #15
0
 def log_status(self, message):
     if self.team_id and self.channel:
         slack_message(message, [], self.channel, self.team_id)
コード例 #16
0
 def send_graph_name_to_slack(self, team_id, channel):
     from utils.Lambdas_Helpers import slack_message
     slack_message(
         ":point_right: Created graph `{0}` from jira key `{1}`".format(
             self.graph_name, self.jira_key), [], channel, team_id)
     return self