source: people/peter.buschman/backup_monitoring/backmon/commands/mail/subcommands/test.py@ 1273

Last change on this file since 1273 was 976, checked in by peter, on Dec 6, 2011 at 10:19:33 AM

Raw checkin of current NetBackup / TSM parsing code.

File size: 2.8 KB
Line 
1#!/usr/bin/python26
2###
3### backmon.commands.mail.test
4###
5
6import sys
7import os
8import os.path
9import glob
10import re
11import email
12import StringIO
13import io
14import mimetypes
15import socket
16
17from optparse import OptionParser
18from guppy import hpy
19
20from email import encoders
21from email.message import Message
22from email.mime.audio import MIMEAudio
23from email.mime.base import MIMEBase
24from email.mime.image import MIMEImage
25from email.mime.multipart import MIMEMultipart
26from email.mime.text import MIMEText
27
28from ....lib import *
29
30from backup_monitoring.debug import *
31from backup_monitoring.math import *
32
33from backup_monitoring.parsing.parsers import bpstulist
34from backup_monitoring.parsing.parsers import df
35from backup_monitoring.parsing.parsers import dsu_ls_l
36from backup_monitoring.parsing.parsers import nbstlutil
37from backup_monitoring.parsing.parsers import nbdevquery
38from backup_monitoring.parsing.parsers import bpdbjobs
39
40usage = 'usage: %prog mail test'
41parser = OptionParser(usage=usage)
42
43def 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
Note: See TracBrowser for help on using the repository browser.