Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[apps] add a slack streamalert app #764

Merged
merged 13 commits into from Jun 13, 2018
Merged

Conversation

@GarretReece
Copy link
Contributor

@GarretReece GarretReece commented Jun 11, 2018

to: @airbnb/streamalert-maintainers
cc: @jacknagz
size: medium

Background

StreamAlert currently doesn't have an app that collects Slack logs.

Changes

  • Adds an app that will collect logs from Slack. Supported log types are access logs and integrations logs.
  • Schema definitions for the two new logs types are included.
  • Unit tests for the app as well as schema validation tests are included.
  • Documentation for authorizing the app is included in the README in the apps directory.

Testing

Unit tests and schema validation tests included. App has been deployed to my test environment and works.

@coveralls
Copy link

@coveralls coveralls commented Jun 11, 2018

Coverage Status

Coverage increased (+0.05%) to 97.648% when pulling da8ccf9 on trailofbits:garret/slack-app into a6062e0 on airbnb:master.

@jacknagz jacknagz requested review from austinbyers and ryandeivert Jun 12, 2018
@jacknagz
Copy link
Contributor

@jacknagz jacknagz commented Jun 12, 2018

Hey @GarretReece, we'll review soon 😄

@ryandeivert
Copy link
Contributor

@ryandeivert ryandeivert commented Jun 12, 2018

hey @GarretReece sorry for the delay - going to be looking at this very soon!!

Copy link
Contributor

@austinbyers austinbyers left a comment

I'll let @ryandeivert , the app expert, give the final approval, but this looks great to me. Nice work!

3. Scroll to the ``Scopes`` section, click on the dropdown box under ``Select Permission Scopes``, and type ``admin`` to bring up the administrator scope (labeled ``Administer the workspace``). Select it, then click ``Save changes``.
4. Scroll to the top of that same page and click on ``Install App to Workspace``. Click ``Authorize`` on the next dialog. You should be returned to the ``OAuth & Permissions`` page.
5. The bearer token is the string labeled with ``OAuth Access Token`` and beginning with ``xoxp-``. It's what's needed to authorize the Slack StreamAlert app.

This comment has been minimized.

@austinbyers

austinbyers Jun 13, 2018
Contributor

Thanks for the explicit instructions here!

Copy link
Contributor

@ryandeivert ryandeivert left a comment

hey @GarretReece nice work!! I just did a first pass and this is largely looking awesome. a few nit-picky comments for you :)

@@ -1,3 +1,19 @@
How to set up the slack app

This comment has been minimized.

@ryandeivert

ryandeivert Jun 13, 2018
Contributor

this information is great to have here, but could this also be added to a section in the docs/ so it lands on streamalert.io?

LOGGER.exception('Received bad response from slack')
return False

if not u'ok' in response.keys() or not response[u'ok']:

This comment has been minimized.

@ryandeivert

ryandeivert Jun 13, 2018
Contributor

can you omit the unicode u prefix here (and elsewhere). technically it's fine, just overly verbose.

also, to be more consistent with elsewhere, the can this please be changed to:

if 'ok' not in response or not response['ok']...

or: if not response.get('ok') would even do

results = self._filter_response_entries(response)

if not self._more_to_poll:
self._last_timestamp = int(time.time())

This comment has been minimized.

@ryandeivert

ryandeivert Jun 13, 2018
Contributor

This value can be updated even if there the _more_to_poll prop is true. Updating it here will make sure it gets updated in the saved stated, and will prevent missing or duplicative data in the event of a function timeout.

def _sleep_seconds(cls):
"""Return the number of seconds this polling function should sleep for
between requests to avoid failed requests. The Slack team.integrationLog API
has Tier 2 limiting, which is 20 requests per minute.

This comment has been minimized.

@ryandeivert

ryandeivert Jun 13, 2018
Contributor

good find!!

self._next_page += 1
return response['paging']['pages'] > response['paging']['page']


This comment has been minimized.

@ryandeivert

ryandeivert Jun 13, 2018
Contributor

nitpick- there's an extra line here

return False

def _check_for_more_to_poll(self, response):
'''if we hit the maximum possible number of returned entries, there may still be more

This comment has been minimized.

@ryandeivert

ryandeivert Jun 13, 2018
Contributor

Please use double-quotes (""") to surround docstrings

raise NotImplementedError("Subclasses must implement the _filter_response_entries method")

def _get_request_data(self):
'''The Slack API takes additional parameters to its endpoints in the body of the request.

This comment has been minimized.

@ryandeivert

ryandeivert Jun 13, 2018
Contributor

Please use double-quotes (""") to surround docstrings

response['paging']['pages'] == response['paging']['page'])

def _filter_response_entries(self, response):
"""The slack endpoints don't provide a programatic way to filter for new results,

This comment has been minimized.

@ryandeivert

ryandeivert Jun 13, 2018
Contributor

spelling: programatic --> programmatic

return 'slack'

@classmethod
def date_formatter(cls):

This comment has been minimized.

@ryandeivert

ryandeivert Jun 13, 2018
Contributor

If not special formatting is needed, you should be able to omit this method altogether (it's not an abstractmethod that is required to be implemented)

@staticmethod
def _get_sample_access_logs():
"""Sample logs collected from the slack api documentation"""
return {

This comment has been minimized.

@ryandeivert

ryandeivert Jun 13, 2018
Contributor

a bit of a nit, but to be consistent with the codebase: can you ensure all string literals use single quotes (') not double quotes? and omit the leading u prefix. there are a few other instances within this file as well.

Copy link
Contributor

@ryandeivert ryandeivert left a comment

LGTM!! Awesome work @GarretReece. Thanks for doing a test deploy as well 👍

@ryandeivert ryandeivert merged commit 7d16fb9 into airbnb:master Jun 13, 2018
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage increased (+0.05%) to 97.648%
Details
@ryandeivert ryandeivert added the apps label Jun 13, 2018
@ryandeivert ryandeivert added this to the 2.0.0 milestone Jun 13, 2018
@ryandeivert ryandeivert changed the title Add a slack streamalert app [apps] add a slack streamalert app Jul 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants
You can’t perform that action at this time.