[976] | 1 | #!/usr/bin/python26
|
---|
| 2 | ###
|
---|
| 3 | ### backmon.commands.mail.test
|
---|
| 4 | ###
|
---|
| 5 |
|
---|
| 6 | import sys
|
---|
| 7 | import os
|
---|
| 8 | import os.path
|
---|
| 9 | import glob
|
---|
| 10 | import re
|
---|
| 11 | import email
|
---|
| 12 | import StringIO
|
---|
| 13 | import io
|
---|
| 14 | import mimetypes
|
---|
| 15 | import socket
|
---|
| 16 |
|
---|
| 17 | from optparse import OptionParser
|
---|
| 18 | from guppy import hpy
|
---|
| 19 |
|
---|
| 20 | from email import encoders
|
---|
| 21 | from email.message import Message
|
---|
| 22 | from email.mime.audio import MIMEAudio
|
---|
| 23 | from email.mime.base import MIMEBase
|
---|
| 24 | from email.mime.image import MIMEImage
|
---|
| 25 | from email.mime.multipart import MIMEMultipart
|
---|
| 26 | from email.mime.text import MIMEText
|
---|
| 27 |
|
---|
| 28 | from ....lib import *
|
---|
| 29 |
|
---|
| 30 | from backup_monitoring.debug import *
|
---|
| 31 | from backup_monitoring.math import *
|
---|
| 32 |
|
---|
| 33 | from backup_monitoring.parsing.parsers import bpstulist
|
---|
| 34 | from backup_monitoring.parsing.parsers import df
|
---|
| 35 | from backup_monitoring.parsing.parsers import dsu_ls_l
|
---|
| 36 | from backup_monitoring.parsing.parsers import nbstlutil
|
---|
| 37 | from backup_monitoring.parsing.parsers import nbdevquery
|
---|
| 38 | from backup_monitoring.parsing.parsers import bpdbjobs
|
---|
| 39 |
|
---|
| 40 | usage = 'usage: %prog mail test'
|
---|
| 41 | parser = OptionParser(usage=usage)
|
---|
| 42 |
|
---|
| 43 | def run(args, kwargs):
|
---|
| 44 |
|
---|
| 45 | #
|
---|
| 46 | # add kwargs to local namespace
|
---|
| 47 | #
|
---|
| 48 | for key in kwargs.keys():
|
---|
| 49 |
|
---|
| 50 | if re.compile('^[A-Z][A-Z_]+$').match(key):
|
---|
| 51 | exec(key + ' = kwargs[\'' + key + '\']')
|
---|
| 52 |
|
---|
| 53 | (options, args) = parser.parse_args(args)
|
---|
| 54 |
|
---|
| 55 | body = StringIO.StringIO()
|
---|
| 56 |
|
---|
| 57 | msg = MIMEMultipart('alternative')
|
---|
| 58 |
|
---|
| 59 | msg['To'] = TO
|
---|
| 60 | msg['From'] = FROM
|
---|
| 61 | msg['Subject'] = 'Test'
|
---|
| 62 |
|
---|
| 63 | text = 'This message requires an email client that understands HTML.'
|
---|
| 64 |
|
---|
| 65 | html = """
|
---|
| 66 | <style type="text/css">
|
---|
| 67 |
|
---|
| 68 | h1
|
---|
| 69 | {
|
---|
| 70 | font-size: 12px;
|
---|
| 71 |
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | table
|
---|
| 75 | {
|
---|
| 76 | table-layout: auto;
|
---|
| 77 | border: 1px solid #005AB0;
|
---|
| 78 | font-family: arial,sans-serif;
|
---|
| 79 | font-size: 12px;
|
---|
| 80 | font-weight: normal;
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 |
|
---|
| 84 | </style>
|
---|
| 85 |
|
---|
| 86 | <html>
|
---|
| 87 | <head></head>
|
---|
| 88 | <body>
|
---|
| 89 | <table width="480">
|
---|
| 90 | <thead>
|
---|
| 91 | <tr>
|
---|
| 92 | <th colspan="3"><center><h1 align="center">Data Backup Central</h1></center></th>
|
---|
| 93 | </tr>
|
---|
| 94 | </thead>
|
---|
| 95 | <tbody>
|
---|
| 96 | <tr>
|
---|
| 97 | <td>DABEX</td>
|
---|
| 98 | </tr>
|
---|
| 99 | <tr>
|
---|
| 100 | <td>SQL-BU</td>
|
---|
| 101 | </tr>
|
---|
| 102 | <tr>
|
---|
| 103 | <td>COSIBA</td>
|
---|
| 104 | </tr>
|
---|
| 105 | </tbody>
|
---|
| 106 | <tfoot>
|
---|
| 107 | <tr>
|
---|
| 108 | </tr>
|
---|
| 109 | </tfoot>
|
---|
| 110 | </table>
|
---|
| 111 | </body>
|
---|
| 112 | </html>
|
---|
| 113 | """
|
---|
| 114 |
|
---|
| 115 | msg.attach(MIMEText(text, 'plain'))
|
---|
| 116 | msg.attach(MIMEText(html, 'html'))
|
---|
| 117 |
|
---|
| 118 | print msg
|
---|
| 119 |
|
---|
| 120 | msmtp = os.popen('/usr/bin/msmtp --read-envelope-from --read-recipients', 'w')
|
---|
| 121 | msmtp.write(msg.as_string())
|
---|
| 122 | msmtp.close()
|
---|
| 123 |
|
---|