You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1.1 KiB
Python
34 lines
1.1 KiB
Python
import sys
|
|
import requests
|
|
|
|
from onioningestor.databases import PastieStorage
|
|
|
|
class Plugin(PastieStorage):
|
|
|
|
def __init__(self, logger, **kwargs):
|
|
# kwargs = {'name': 'telegram-notifer', 'chat_id': 111111, 'token': 'XXXX'}
|
|
self.name = kwargs.get('name')
|
|
self.logger = logger
|
|
self.token = kwargs.get('token')
|
|
self.chat_id = kwargs.get('chat_id')
|
|
|
|
def __save_pastie__(self, pastie):
|
|
message = '''
|
|
HiddenSite: {site}
|
|
Source : {url}
|
|
Monitor : {content}
|
|
Status : {status}
|
|
'''.format(
|
|
site=pastie.url,
|
|
url=pastie.source,
|
|
content=pastie.monitor,
|
|
status=pastie.status)
|
|
|
|
url = 'https://api.telegram.org/bot{0}/sendMessage'.format(self.token)
|
|
try:
|
|
self.logger.debug('Sending message to telegram {} for pastie_id {}'.format(url, pastie))
|
|
requests.post(url, data={'chat_id': self.chat_id, 'text':message})
|
|
except Exception as e:
|
|
self.logger.warning("Failed to alert through telegram: {0}".format(e))
|
|
|