3737
3838-p -- specify a supervisor process_name. Send mail when this process
3939 transitions to the EXITED state unexpectedly. If this process is
40- part of a group, it can be specified using the
40+ part of a group, it must be specified using the
4141 'process_name:group_name' syntax.
4242
4343-a -- Send mail when any child of the supervisord transitions
6666"""
6767
6868import os
69+ import re
6970import sys
7071
7172from supervisor import childutils
@@ -124,10 +125,25 @@ def runforever(self, test=False):
124125 if self .optionalheader :
125126 subject = self .optionalheader + ':' + subject
126127
127- self .stderr .write ('unexpected exit, mailing\n ' )
128- self .stderr .flush ()
129128
130- self .mail (self .email , subject , msg )
129+ ident = pheaders ['processname' ]
130+ if pheaders ['groupname' ] != ident :
131+ ident = pheaders ['groupname' ] + ":" + ident
132+
133+ if self .any or \
134+ not self .programs or \
135+ any (prog .match (ident ) for prog in self .programs ):
136+
137+ self .stderr .write ('\n unexpected exit, mailing\n ' )
138+ self .stderr .flush ()
139+
140+ self .mail (self .email , subject , msg )
141+
142+ else :
143+
144+ self .stderr .write ('\n ignoring %s\n ' % subject )
145+ self .stderr .flush ()
146+
131147
132148 childutils .listener .ok (self .stdout )
133149 if test :
@@ -140,7 +156,7 @@ def mail(self, email, subject, msg):
140156 body += msg
141157 with os .popen (self .sendmail , 'w' ) as m :
142158 m .write (body )
143- self .stderr .write ('Mailed:\n \n %s' % body )
159+ self .stderr .write ('Mailed:\n \n %s\n ' % body )
144160 self .mailed = body
145161
146162
@@ -167,13 +183,19 @@ def main(argv=sys.argv):
167183 email = None
168184 optionalheader = None
169185
186+ progGroupRE = re .compile (r"(\w+):\*" )
187+
170188 for option , value in opts :
171189
172190 if option in ('-h' , '--help' ):
173191 usage ()
174192
175193 if option in ('-p' , '--program' ):
176- programs .append (value )
194+ pg = progGroupRE .match (value )
195+ if pg :
196+ programs .append (re .compile (pg .group (1 )+ ":.*" ))
197+ else :
198+ programs .append (re .compile (re .escape (value )))
177199
178200 if option in ('-a' , '--any' ):
179201 any = True
0 commit comments