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

Way to be warned of failures between reports #20

Closed
dcurrey opened this issue Nov 5, 2017 · 2 comments
Closed

Way to be warned of failures between reports #20

dcurrey opened this issue Nov 5, 2017 · 2 comments

Comments

@dcurrey
Copy link

dcurrey commented Nov 5, 2017

My plan is to run the dupreport.py -r /etc/dupreport -c on a nightly basis. Only problem I see with this is I am not alerted to any errors in between the -c and when I run dupreport with the -t option. Having it run daily I would just end up ignoring the email altogether.

A way to parse the error and warning is needed. Given my limited skills I am testing the following

This very poorly done hack was attempted on the 2.0.3 issue 18 branch

On line 438 I added the following to def build_email_sql_statement

    # If errors found send backup warn email!
    if ('collect'in options) and ((sParts['warnings'] != '' or sParts['errors'] != '')):
         send_email_backup_warn( mParts['sourceComp'], mParts['destComp'], mParts['emailDate'], mParts['emailTime'], sParts['messages'], sParts['warnings'], sParts['errors'])

Then have the following code added. I am sure you can clean this up better than me if you decide to add something like this.

def send_email_backup_warn(source, destination, lastDate, lastTime, messages, warning, error):

    write_log_entry(2, 'Send_email()')
    msgText=''
    msgHtml='<html><head></head><body><table border={} cellpadding="{}">'.format(options['border'], options['padding'])
    msgHtml = msgHtml + '<tr>'  # New table row
    msgText = msgText + '{}@{}\n'.format(source,destination)
    msgHtml = msgHtml + '<td align="center" colspan = "11"><b>{}@{}</b></td>'.format(source,destination)
    if (warning != ''):
         msgText = msgText + '{}\n\n'.format(warning)
         msgHtml = msgHtml + '<tr><td><align="center" colspan = "11"><i>{}</i></td>'.format(warning)
    if (error != ''):
         msgText = msgText + '{}\n\n'.format(error)
         msgHtml = msgHtml + '<tr><td align="center" colspan = "11"><i>{}</i></td>'.format(error)
    msgText = msgText + '\n'
    msgHtml = msgHtml + '</tr></body><html>'

    # Build email message
    msg = MIMEMultipart('alternative')
    msg['Subject'] = "!!! Backup Warning for {}@{} !!!".format(source, destination)
    msg['From'] = options['outsender']
    msg['To'] = options['outreceiver']

    # Send the message via local SMTP server.
    server = smtplib.SMTP('{}:{}'.format(options['outserver'], options['outport']))
    write_log_entry(2, 'SMTP Server=[{}]'.format(server))
    if options['outencryption'] == 'tls':   # Do we need to use SSL/TLS?
        server.starttls()
    server.login(options['outaccount'], options['outpassword'])
    server.sendmail(options['outsender'], options['outreceiver'], msg.as_string())
    server.quit()

Sorry for my bad programming ability :(

Hopefully someone can test this. I didn't keep my bad backup emails from duplicati.

edit: fixed the output email to better match Handyguysoftware

@HandyGuySoftware
Copy link
Owner

dcurrey,

First, I've learned over the years that you should never apologize for your code. If it works, it's good code ;-)

Second, the -c & -t options are relics from the first bash/awk version of the program, where collecting and reporting were actually two separate programs. I stopped using them myself a couple of versions ago and was considering removing them altogether from the next version of the program. Now that I see there's a real life use case for them, I'll leave them in!

I like your idea but I'm not sure how to best implement it yet. I'm trying to lock down 2.0.4 so I don't want to make any more quick fixes to that code. I'm also starting to work on version 2.1 which will be an intensive restructuring of the code (it's getting too big and ungainly) and a rewrite of the reporting areas. Since this suggestion falls into that area, I will definitely put that on the to-do list for 2.1.

@HandyGuySoftware HandyGuySoftware changed the title Way to be warned of failers between reports Way to be warned of failures between reports Nov 27, 2017
@HandyGuySoftware
Copy link
Owner

Added to 2.1 code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants