-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']) | ||
|
||
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)) | ||
|
||
self.client.chat_postMessage(channel=self.channel_name, text=text) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pymongo | ||
mysql-connector-python | ||
requests | ||
slackclient |