/[qa]/trunk/mia/mia-tracker
ViewVC logotype

Contents of /trunk/mia/mia-tracker

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2738 - (hide annotations) (download)
Mon Apr 16 16:41:41 2012 UTC (13 months ago) by geissert
File size: 4647 byte(s)
/org -> /srv
1 luk 1752 #!/usr/bin/perl
2    
3     # Tracker tool for MIA people
4     # Copyright (C) 2007 Mario Iseli <mario@debian.org>
5     #
6     # This program is free software; you can redistribute it and/or modify
7     # it under the terms of the GNU General Public License as published by
8     # the Free Software Foundation; either version 2 of the License, or
9     # (at your option) any later version.
10     #
11     # This program is distributed in the hope that it will be useful,
12     # but WITHOUT ANY WARRANTY; without even the implied warranty of
13     # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     # GNU General Public License for more details.
15     #
16     # You should have received a copy of the GNU General Public License
17     # along with this program; if not, write to the Free Software
18     # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19    
20     use DBI;
21     use Mail::Sendmail;
22     use AptPkg::Config;
23     use Date::Calc;
24    
25 geissert 2738 $configfile = "/srv/qa.debian.org/mia/mia.conf";
26 luk 1752
27     $conf = AptPkg::Config->new();
28     $conf->read_file($configfile);
29     $conf->init();
30    
31     $db = DBI->connect("DBI:CSV:f_dir=" . $conf->get('Dir::Trackerlist'));
32    
33     if ($ARGV[0] eq '--add')
34     {
35     add();
36     }
37    
38     if ($ARGV[0] eq '--list')
39     {
40     list();
41     }
42    
43     if ($ARGV[0] eq '--del')
44     {
45     del();
46     }
47    
48     if ($ARGV[0] eq '--prepare')
49     {
50     prepare();
51     }
52    
53     if ($ARGV[0] eq '--search')
54     {
55     search();
56     }
57    
58     if ($ARGV[0] eq '--searchn')
59     {
60     searchn();
61     }
62    
63     if ($ARGV[0] eq '--mail')
64     {
65     mail();
66     }
67    
68     if ($ARGV[0] ne '--prepare' && $ARGV[0] ne '--add' && $ARGV[0] ne '--del' && $ARGV[0] ne '--list' && $ARGV[0] ne '--search' && $ARGV[0] ne '--searchn' && $ARGV[0] ne '--mail')
69     {
70     help();
71     }
72    
73     $db->disconnect();
74    
75     sub prepare
76     {
77     $qry = $db->prepare('CREATE TABLE miatracker (id INTEGER, name CHAR(40), email CHAR(50), date INTEGER, author CHAR(20))');
78     $qry->execute();
79     $qry->finish();
80     }
81    
82     sub printresult
83     {
84     $qry = $db->prepare($_[0]);
85     $qry->execute();
86    
87     while($entry = $qry->fetchrow_hashref())
88     {
89     print "Person: $entry->{'name'} <$entry->{'email'}>\n";
90     print "Ticket-ID: $entry->{'id'}\n";
91     print "Responsive: $entry->{'author'}\n\n";
92     }
93    
94     $qry->finish();
95     }
96    
97     sub search
98     {
99    
100     if(!$ARGV[1])
101     {
102     help();
103     }
104    
105     if($ARGV[1] =~ /.*\@.*/)
106     {
107     printresult("SELECT * FROM miatracker WHERE email='$ARGV[1]'");
108     }
109     else
110     {
111     printresult("SELECT * FROM miatracker WHERE email='$ARGV[1]\@" . $conf->get('MyDomain') . "'");
112     }
113    
114     }
115    
116     sub searchn
117     {
118    
119     if($ARGV[1])
120     {
121     printresult("SELECT * FROM miatracker WHERE name LIKE '$ARGV[1]'");
122     }
123     else
124     {
125     help();
126     }
127    
128     }
129    
130     sub add
131     {
132    
133     while(<STDIN>)
134     {
135    
136     if($_ =~ /^To: (.*) <(.*\@.*)>/)
137     {
138     $name = $1;
139     $email = $2;
140     }
141    
142     if($_ =~ /^X-MIA-Tracker: (\d{8}) (\S*)/)
143     {
144     $date = $1;
145     $author = $2;
146     }
147    
148     }
149    
150     $id = time();
151    
152     $qry = $db->prepare("INSERT INTO miatracker VALUES ('$id','$name','$email','$date','$author')");
153     $qry->execute();
154     $qry->finish();
155    
156     %mail = (
157     from => 'mia@qa.debian.org',
158     to => $author,
159     subject => "Added MIA tracking for $name <$email>"
160     );
161    
162     $mail{'body'} = "Thank you for adding more MIA information to the database, we have added an automatical notification which will be sent to you on $date\nThe ID for this notification request is: $id";
163    
164     sendmail(%mail);
165     }
166    
167     sub list
168     {
169    
170     if($ARGV[1] =~ /\d{8}/)
171     {
172     $date = $ARGV[1];
173     }
174     else
175     {
176     @today = Date::Calc::Today();
177     $date = "$today[0]$today[1]$today[2]";
178     }
179    
180     printresult("SELECT * FROM miatracker WHERE date='$date'");
181     }
182    
183     sub del
184     {
185    
186     if($ARGV[1] =~ /(\d{10})/)
187     {
188     $qry = $db->prepare("DELETE FROM miatracker WHERE id='$1'");
189     $qry->execute();
190     $qry->finish();
191     print "Ticket with ID $1 deleted\n";
192     }
193     else
194     {
195     help();
196     }
197    
198     }
199    
200     sub mail
201     {
202     @today = Date::Calc::Today();
203     $date = "$today[0]$today[1]$today[2]";
204     $qry = $db->prepare("SELECT * FROM miatracker WHERE date='$date'");
205     $qry->execute();
206    
207     while($entry = $qry->fetchrow_hashref())
208     {
209     %mail = (
210     from => 'mia@qa.debian.org',
211     to => "$entry->{'author'}",
212     subject => "MIA Tracker Notification for
213     $entry->{'name'}"
214     );
215     $mail{'body'} = "Hi, today it's time to ping $entry->{'name'} <$entry->{'email'}> again. Please close then this ticket in the tracker by doing './mia-tracker --del $entry->{'id'}' in the MIA directory on " . $conf->get('MyHost');
216     sendmail(%mail);
217     }
218    
219     $qry->finish();
220     }
221    
222     sub help
223     {
224     print "Usage: ./mia-tracker:\n";
225     print " --list [YYYYMMDD] | Lists the notifications for e defined date, defaults to today\n";
226     print " --del TICKETID | Delete the open notification with a specified ID\n";
227     print " --search MAILADDRESS | Search for an E-Mail address of a person who needs to be pinged\n";
228     print " --searchn \"Prename Lastname\" |Search for a Name of a person who needs to be pinged\n";
229     exit(1);
230     }
231    

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.5