Change Request: fas=>bugzilla sync script that does not email invalid users

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



We've had a few complaints about our bugzilla sync script sending out too
much email.  I'd like to apply this hotfix to the export-bugzilla script on
fas01 (where the cron job runs) and the associated config change to stop
sending out email to the invalid users.

Can I get two +1's?

-Toshio

diff --git a/scripts/export-bugzilla.py b/scripts/export-bugzilla.py
index 413cd27..2306b6f 100755
--- a/scripts/export-bugzilla.py
+++ b/scripts/export-bugzilla.py
@@ -14,7 +14,7 @@ from email.Message import Message
 import turbogears
 import bugzilla
 from turbogears import config
-turbogears.update_config(configfile="/etc/export-bugzilla.cfg")
+turbogears.update_config(configfile="./export-bugzilla.cfg")
 from turbogears.database import session
 from fas.model import BugzillaQueue
 
@@ -23,6 +23,7 @@ BZUSER = config.get('bugzilla.username')
 BZPASS = config.get('bugzilla.password')
 MAILSERVER = config.get('mail.server', 'localhost')
 ADMINEMAIL = config.get('mail.admin_email', 'admin@xxxxxxxxxxxxxxxxx')
+NOTIFYEMAIL = config.get('mail.notify_email', ['admin@xxxxxxxxxxxxxxxxx'])
 
 if __name__ == '__main__':
     opts, args = getopt.getopt(sys.argv[1:], '', ('usage', 'help'))
@@ -77,39 +78,66 @@ if __name__ == '__main__':
         session.delete(entry)
         session.flush()
 
-    # Mail the people without bugzilla accounts
-    for person in no_bz_account:
-        smtplib.SMTP(MAILSERVER)
-        msg = Message()
-        message = '''Hello %(name)s,
+# Mail the people without bugzilla accounts
+    if '$USER' in NOTIFYEMAIL:
+        for person in no_bz_account:
+            smtplib.SMTP(MAILSERVER)
+            msg = Message()
+            message = '''Hello %(name)s,
+
+    As a Fedora packager, we grant you permissions to make changes to bugs in
+    bugzilla to all Fedora bugs.  This lets you work together with other Fedora
+    developers in an easier fashion.  However, to enable this functionality, we
+    need to have your bugzilla email address stored in the Fedora Account System.
+    At the moment you have:
 
-As a Fedora packager, we grant you permissions to make changes to bugs in
-bugzilla to all Fedora bugs.  This lets you work together with other Fedora
-developers in an easier fashion.  However, to enable this functionality, we
-need to have your bugzilla email address stored in the Fedora Account System.
-At the moment you have:
+        %(email)s
 
-    %(email)s
+    which bugzilla is telling us is not an account in bugzilla.  If you could
+    please set up an account in bugzilla with this address or change your email
+    address on your Fedora Account to match an existing bugzilla account this would
+    let us go forward.
 
-which bugzilla is telling us is not an account in bugzilla.  If you could
-please set up an account in bugzilla with this address or change your email
-address on your Fedora Account to match an existing bugzilla account this would
-let us go forward.
+    Note: this message is being generated by an automated script.  You'll continue
+    getting this message until the problem is resolved.  Sorry for the
+    inconvenience.
 
-Note: this message is being generated by an automated script.  You'll continue
-getting this message until the problem is resolved.  Sorry for the
-inconvenience.
+    Thank you,
+    The Fedora Account System
+    %(admin_email)s
+    ''' % {'name': person.person.human_name, 'email': person.email,
+            'admin_email': ADMINEMAIL}
+
+            msg.add_header('To', person.email)
+            msg.add_header('From', ADMINEMAIL)
+            msg.add_header('Subject', 'Fedora Account System and Bugzilla Mismatch')
+            msg.set_payload(message)
+            smtp = smtplib.SMTP(MAILSERVER)
+            smtp.sendmail(ADMINEMAIL, [person.email], msg.as_string())
+            smtp.quit()
+            #print 'Message to %s: %s' % (person.email, message,)
+    recipients = ', '.join([e for e in NOTIFYEMAIL if e != '$USER'])
+    if recipients and no_bz_account:
+        smtplib.SMTP(MAILSERVER)
+        msg = Message()
+        people = []
+        for person in no_bz_account:
+            people.append('  %(user)s  --  %(name)s  --  %(email)s' %
+                    {'name': person.person.human_name, 'email': person.email,
+                     'user': person.person.username})
+        people = '\n'.join(people)
+        message = '''
+The following people are in the packager group but do not have email addresses
+that are valid in bugzilla:
+%s
 
-Thank you,
-The Fedora Account System
-%(admin_email)s
-''' % {'name': person.person.human_name, 'email': person.email,
-        'admin_email': ADMINEMAIL}
+''' % people
 
-        msg.add_header('To', person.email)
         msg.add_header('From', ADMINEMAIL)
+        msg.add_header('To', recipients)
         msg.add_header('Subject', 'Fedora Account System and Bugzilla Mismatch')
         msg.set_payload(message)

diff --git a/scripts/export-bugzilla.cfg b/scripts/export-bugzilla.cfg
index ead23f6..89d1945 100644
--- a/scripts/export-bugzilla.cfg
+++ b/scripts/export-bugzilla.cfg
@@ -1,14 +1,19 @@
 [global]
 # bugzilla.url = https://bugdev.devel.redhat.com/bugzilla-cvs/xmlrpc.cgi
-# bugzilla.url = https://bugzilla.redhat.com/xmlrpc.cgi
-bugzilla.url = "https://bzprx.vip.phx.redhat.com/xmlrpc.cgi";
-bugzilla.username = "<%= bugzillaUser %>"
-bugzilla.password = "<%= bugzillaPassword %>"
+bugzilla.url = "https://bugzilla.redhat.com/xmlrpc.cgi";
+#bugzilla.url = "https://bzprx.vip.phx.redhat.com/xmlrpc.cgi";
+bugzilla.username = "fedora-admin-xmlrpc@xxxxxxxxxx"
+bugzilla.password = "MOLPiNsy2c"
 
 # Mail server for sending invalid bugzilla account messages
-mail.server = 'localhost'
+mail.server = 'bastion'
 mail.admin_email = 'admin@xxxxxxxxxxxxxxxxx'
 
+# This is a list (*must* have a comma) of email addresses to send messages about
+# invalid bugzilla accounts to.  The strin '$USER' is special.  If present in the
+# list, it will send an email to the user whose email address is not in bugzilla.
+mail.notify_email = '$USER', 'admin@xxxxxxxxxxxxxxxxx'
+
 # At the moment, we have to extract this information directly from the fas2
 # database.  We can build a json interface for it at a later date.
-sqlalchemy.dburi = "postgres://fedora:bunbunbun@localhost/fas2"
+sqlalchemy.dburi = "postgres://fas:DsjBks9dn3Sakz9Gsnd55@db02/fas2"

Attachment: pgpN3VoLd8MAn.pgp
Description: PGP signature

_______________________________________________
infrastructure mailing list
infrastructure@xxxxxxxxxxxxxxxxxxxxxxx
https://admin.fedoraproject.org/mailman/listinfo/infrastructure

[Index of Archives]     [Fedora Development]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [KDE Users]

  Powered by Linux