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

Integrated Slack Action #88

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion pastepwn/actions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,15 @@
from .genericaction import GenericAction
from .databaseaction import DatabaseAction
from .savejsonaction import SaveJSONAction
from .slackaction import SlackAction

__all__ = ('BasicAction', 'SaveFileAction', 'TelegramAction', 'LogAction', 'GenericAction', 'DatabaseAction', 'SaveJSONAction')
__all__ = (
'BasicAction',
'SaveFileAction',
'TelegramAction',
'LogAction',
'GenericAction',
'DatabaseAction',
'SaveJSONAction',
'SlackAction'
)
44 changes: 44 additions & 0 deletions pastepwn/actions/slackaction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import logging
import os

import slack

from string import Template

from pastepwn.util import DictWrapper
from .basicaction import BasicAction



class SlackAction(BasicAction):
"""Action to send a Slack message to a channel"""

name="SlackAction"

def __init__(self, token, client, channel_name, template=None):
super().__init__()
self.logger = logging.getLogger(__name__)

if token is None or channel_name is None:
raise ValueError("Token or Channel Name is either missing or None!")

self.channel_name=channel_name
self.client=slack.WebClient(token=token)
# self.client=slac.WebClient(token=os.environ['SLACK_API_TOKEN'])
d-Rickyy-b marked this conversation as resolved.
Show resolved Hide resolved

if template is not None:
self.template = Template(template)
else:
self.template = None

def perform(self, paste, analyzer_name="None"):
"""Send a message to a specified Slack channel without post-assertion"""

if self.template is None:
text = "New paste matched by analyzer '{0}' - Link: {1}".format(analyzer_name, paste.full_url)
else:
paste_dict = paste.to_dict()
paste_dict["analyzer_name"] = analyzer_name
text = self.template.safe_substitute(DictWrapper(paste_dict))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Big plus for the templating :) thank you very much,


self.client.chat_postMessage(channel=self.channel_name, text=text)
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pymongo
mysql-connector-python
requests
slackclient