コード例 #1
0
ファイル: api_endpoints.py プロジェクト: Denisfench/messaging
 def post(self):
     """
     Send notification to slack on latest heroku deployment
     """
     msg = latest_deployment()
     msgToSend = msg[0] + " was deployed at " + msg[1]
     send_slack_log(msgToSend)
     return msgToSend
コード例 #2
0
 def post(self):
     """
     Filter alerts in the system through a Slack message
     """
     send_slack_log('Entered /slack/filter_alerts')
     send_slack_log('Request info:')
     send_slack_log(str(request.form))
     trigger_id = request.form['trigger_id']
     channel_id = request.form['channel_id']
     response = open_form(channel_id, trigger_id,
                          config['slack_filter_form_path'])
     send_slack_log('Response info:')
     send_slack_log(str(response))
     return 'Please enter alerts filtering information in the form'
コード例 #3
0
 def post(self):
     """
     Update an alert in the system through a Slack message
     """
     send_slack_log('Entered /slack/update_alert')
     send_slack_log('Request info:')
     send_slack_log(str(request.form))
     trigger_id = request.form['trigger_id']
     channel_id = request.form['channel_id']
     response = open_form(channel_id, trigger_id,
                          config['slack_update_form_path'])
     send_slack_log('Response info:')
     send_slack_log(str(response))
     return 'Please enter the updated alert information in the form'
コード例 #4
0
ファイル: api_endpoints.py プロジェクト: Denisfench/messaging
 def post(self):
     """
     Post a new message into the system through a Slack message
     """
     send_slack_log('Entered /slack/post_msg')
     send_slack_log('Request info:')
     send_slack_log(str(request.form))
     # unknown request.form
     trigger_id = request.form['trigger_id']
     channel_id = request.form['channel_id']
     response = open_form(channel_id, trigger_id,
                          config['slack_post_form_path'])
     send_slack_log('Response info:')
     send_slack_log(str(response))
     return 'Please enter the new msg information in the form'
コード例 #5
0
 def post(self):
     """
     An API that handles all Slack submit events(interactions)
     """
     send_slack_log('Entered /slack/submit')
     send_slack_log('Request info:')
     send_slack_log(str(request.form))
     if request.form.get('payload') is None:
         send_slack_log('Invalid request: no payload')
         return
     else:
         return handle_interaction(json.loads(request.form['payload']))
コード例 #6
0
 def post(self):
     """
     Get a specific alert with the given alert id and send it to Slack
     """
     send_slack_log('Entered /slack/get_alert')
     send_slack_log('Request info:')
     send_slack_log(str(request.form))
     alert_id = request.form['text']
     channel_id = request.form['channel_id']
     try:
         id = int(alert_id)
     except ValueError:
         return "Invalid Alert ID: " + str(alert_id)
     text = read_alert(id)
     formated_alert = slack_format_alert(text)
     response = send_json_to_slack_channel(formated_alert, channel_id)
     send_slack_log('Response info:')
     send_slack_log(response)
     return "Alert " + str(id) + " fetched"
コード例 #7
0
ファイル: api_endpoints.py プロジェクト: Denisfench/messaging
 def post(self):
     """
     Get a specific message with the given message id and send it to Slack
     """
     send_slack_log('Entered /slack/get_msg')
     send_slack_log('Request info:')
     send_slack_log(str(request.form))
     msg_id = request.form['text']
     channel_id = request.form['channel_id']
     try:
         id = int(msg_id)
     except ValueError:
         return "Invalid Msg ID: " + str(msg_id)
     text = read_msg(id)
     formated_msg = slack_format_msg(text)
     response = send_json_to_slack_channel(formated_msg, channel_id)
     send_slack_log('Response info:')
     send_slack_log(response)
     return "Msg " + str(id) + " fetched"
コード例 #8
0
ファイル: test_slack.py プロジェクト: Denisfench/messaging
 def testLog(self):
     """
     Testing if send_slack_log works
     """
     responses.add(
         **{
             'method': responses.POST,
             'url': slack_config['Log_URL'],
             'body': 'ok',
             'status': 200,
             'content_type': 'application/json'
         })
     response = send_slack_log('Hello, Socnet')
     self.assertEqual('ok', response[200])
コード例 #9
0
 def post(self):
     """
     Delete an alert in the system through a Slack message
     """
     send_slack_log('Entered /slack/delete_alert')
     send_slack_log('Request info:')
     send_slack_log(str(request.form))
     alert_id = json.loads(request.form['text'])
     return delete_alert(int(alert_id))
コード例 #10
0
ファイル: operations.py プロジェクト: gcallah/socnet
def handle_interaction(payload_json):
    if payload_json['type'] == 'view_submission':
        send_slack_log('Payload type: view_submission')
        time = datetime.datetime.now() \
                       .strftime('%Y-%m-%d %H:%M:%S')
        if payload_json['view']['callback_id'] == 'post_alert':
            send_slack_log('callback_id: ' + 'post_alert')
            alert_json = create_alert_from_slack_message(payload_json, time)
            send_slack_log('New alert json: ' + str(alert_json))
            response = write_alert(alert_json)
            send_slack_log('Response info: ')
            send_slack_log(response)
            return get_confirmation_form('Success', response)
        elif payload_json['view']['callback_id'] == 'update_alert':
            send_slack_log('callback_id: ' + 'update_alert')
            alert_id = get_id_from_payload(payload_json)
            send_slack_log('Alert id: ' + str(alert_id))
            ret = read_alert(alert_id)
            if len(ret) == 0:
                send_slack_log('Invalid Alert ID')
                return {'response_action': 'clear'}
            alert_json = create_alert_json(ret[0])
            send_slack_log('Old alert json: ' + str(alert_json))
            alert_json = create_updated_alert_from_slack_message(
                payload_json, time, alert_json)
            send_slack_log('New alert json: ' + str(alert_json))
            response = update_alert(alert_json, alert_id)
            send_slack_log('Response info: ')
            send_slack_log(response)
            return get_confirmation_form('Success', response)
        elif payload_json['view']['callback_id'] == 'filter_alerts':
            send_slack_log('callback_id: ' + 'filter_alerts')
            params = get_filter_params_from_slack(payload_json)
            view = create_alerts_page_view(params)
            return get_alerts_page_form(view)
        else:
            send_slack_log('Unknown callback_id in view_submission')
            return
    elif payload_json['type'] == 'block_actions':
        send_slack_log('Payload type: block_actions')
        action = get_action_value(payload_json)
        params = get_filter_params_from_slack(payload_json)
        page = get_page_value(payload_json)
        alerts_count = get_alerts_count(payload_json)
        if action == 'next_page':
            if alerts_count == PAGE_LIMIT:
                page = page + 1
        elif action == 'prev_page':
            if page > 1:
                page = page - 1
        else:
            send_slack_log('Invalid action')
            return
        params['offset'] = PAGE_LIMIT * (page - 1)
        send_slack_log('Parameters: ' + str(params))
        view = create_alerts_page_view(params)
        view['blocks'][1]['text']['text'] = \
            "*Showing page " + str(page) + " (max " + \
            str(PAGE_LIMIT) + " alerts per page)*"
        view_id = payload_json['view']['id']
        hash_value = payload_json['view']['hash']
        return update_form(view_id, hash_value, view)
    else:
        send_slack_log('No action needed for this interaction')
        return