Giter Site home page Giter Site logo

Comments (3)

tuaris avatar tuaris commented on August 20, 2024

Here is how to add the email notifications:

lib/notify_email.py:

import smtplib
from email.mime.text import MIMEText

import lib.settings as settings

import lib.logger
log = lib.logger.get_logger('Notify_Email')

class NOTIFY_EMAIL():

    def notify_start(self):
    if settings.NOTIFY_EMAIL_TO != '':
        self.send_emails(settings.NOTIFY_EMAIL_TO,'Stratum Server Started','Stratum server has started!')

    def notify_found_block(self,worker_name):
    if settings.NOTIFY_EMAIL_TO != '':
        text = '%s on Stratum server found a block!' % worker_name
        self.send_emails(settings.NOTIFY_EMAIL_TO,'Stratum Server Found Block',text)

    def send_emails(self,to,subject,message):
    tos = to.split(";")
    for tov in tos:
        self.send_email(tov,subject,message)

    def send_email(self,to,subject,message):
    msg = MIMEText(message)
    msg['Subject'] = subject
    msg['From'] = settings.NOTIFY_EMAIL_FROM
    msg['To'] = to
    try:
        s = smtplib.SMTP(settings.NOTIFY_EMAIL_SERVER)
        if settings.NOTIFY_EMAIL_USERNAME != '':
        if settings.NOTIFY_EMAIL_USETLS:
            s.ehlo()
            s.starttls()
        s.ehlo()
        s.login(settings.NOTIFY_EMAIL_USERNAME, settings.NOTIFY_EMAIL_PASSWORD)
        s.sendmail(settings.NOTIFY_EMAIL_FROM,to,msg.as_string())
        s.quit()
    except smtplib.SMTPAuthenticationError as e:
        log.error('Error sending Email: %s' % e[1])
    except Exception as e:
        log.error('Error sending Email: %s' % e[0])

mining/interfaces.py:

...
import lib.notify_email
...
class ShareManagerInterface(object):
    def __init__(self):
        self.block_height = 0
        self.prev_hash = 0

        # Send out the e-mail saying we are starting.
        notify_email = lib.notify_email.NOTIFY_EMAIL()
        notify_email.notify_start()     
...
    def on_submit_block(self, is_accepted, worker_name, block_header, block_hash, timestamp, ip, share_diff):
        log.info("Block %s %s" % (block_hash, 'ACCEPTED' if is_accepted else 'REJECTED'))
        dbi.found_block([worker_name, block_header, block_hash, -1, timestamp, is_accepted, ip, self.block_height, self.prev_hash, share_diff ])

        # Send out the e-mail saying we found a block.
        if is_accepted:
            notify_email = lib.notify_email.NOTIFY_EMAIL()
            notify_email.notify_found_block(worker_name)    
...

Add to conf/config_sample.py:

NOTIFY_EMAIL_TO = ''        # Where to send Start/Found block notifications
NOTIFY_EMAIL_TO_DEADMINER = ''  # Where to send dead miner notifications
NOTIFY_EMAIL_FROM = 'root@localhost'    # Sender address
NOTIFY_EMAIL_SERVER = 'localhost'   # E-Mail Sender
NOTIFY_EMAIL_USERNAME = ''      # E-Mail server SMTP Logon
NOTIFY_EMAIL_PASSWORD = ''
NOTIFY_EMAIL_USETLS = True

from stratum-mining.

ahmedbodi avatar ahmedbodi commented on August 20, 2024

hmm, i can think about it, i wont be adding dead miner notifications im afraid. just block notifications and any severe error notifications

from stratum-mining.

ahmedbodi avatar ahmedbodi commented on August 20, 2024

added email notifications into the issue-4 branch

from stratum-mining.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.