A small script

Maybe this script will be of use for somebody.

I wanted to receive a summary of the current situations with our queues,
and hacked a small script, which should be attached to this message.

It has only argument: number of days.

We currently use it through crontab:

MAILTO=sysadms@example.com

10 1 * * Tue-Sat        root    [ -x /usr/bin/rt-statuses ] && /usr/bin/rt-statuses 1
10 1 * * Mon            root    [ -x /usr/bin/rt-statuses ] && /usr/bin/rt-statuses 2

Hope this helps,

Misha

rt-statuses (5.17 KB)

Hmm. A better description is needed. :frowning:

It runs through the queues, and creates a list of tickets that owned by
nobody (require attention), those resolved within the specified amount
of days, and those being worked on (owned by somebody). It creates a
html letter, which is sent out to the specified e-mail address.

Misha

Hi,

I had to change the ‘open(MAIL’ line to use “sendmail -t -i”. Otherwise, I
was getting an "Recipient names must be specified’ error message.

SH-----Original Message-----
From: Mikhail Sobolev [mailto:mikhail.sobolev@transas.com]
Sent: Wednesday, September 03, 2003 10:58 AM
To: rt-users@lists.fsck.com
Subject: [rt-users] A small script

Maybe this script will be of use for somebody.

I wanted to receive a summary of the current situations with our queues,
and hacked a small script, which should be attached to this message.

It has only argument: number of days.

We currently use it through crontab:

MAILTO=sysadms@example.com

10 1 * * Tue-Sat        root    [ -x /usr/bin/rt-statuses ] &&

/usr/bin/rt-statuses 1
10 1 * * Mon root [ -x /usr/bin/rt-statuses ] &&
/usr/bin/rt-statuses 2

Hope this helps,

Misha

Hi,
A couple days ago I got 16000 Tickets created from SoBig and other things. I couldn’t find a script to basicly batch erase a bunch of tickets so I wrote one. Figured someone else might have this problem so I’ll share the script. It’s very messy and i’m not 100% positive this is the right way to do it but it works for me, use at your own risk.

– start script –
#!/usr/bin/env python
import MySQLdb

#THE USER NEEDS WRITE ACCESS!
USER=’’
#PASSWORD
PASS=’’

WHERE THE SERVER LIVES

HOST=’’

NAME OF THE DATABASE

DB=’’
#FILE YOU WANT TO LOG TO
LOGFILE=’’

file we’ll log to

log = open(LOGFILE, ‘w’)

try:
dblink = MySQLdb.connect(user=USER, host=HOST, db=DB, passwd=PASS)
db = dblink.cursor()
except:
print "Couldn’t get at the db"
sys.exit(1)

you could put any query you wanted here as long as it returns the id,

where Subject=‘BOUNCED MESSAGE’ would probly be a good one

t = db.execute(“SELECT id FROM Tickets WHERE status=‘dead’;”)
ids = db.fetchall()

log.write("%s entrys to be deleted" % str(int(len(ids))))

for i in range(len(ids)):
log.write(“DELETE FROM Attachments where id=” + str(int(ids[i][0])) )
db.execute(“DELETE FROM Attachments where id=” + str(int(ids[i][0])))
log.write(“DELETE FROM Tickets where id=” + str(int(ids[i][0])) )
db.execute(“DELETE FROM Tickets where id=” + str(int(ids[i][0])))
log.write(“DELETE FROM Transactions where Ticket=” + str(int(ids[i][0])))
db.execute(“DELETE FROM Transactions where Ticket=” + str(int(ids[i][0])))
log.write(“DELETED TICKET ID %s\n” % str(int(ids[i][0])))

db.close()
log.close()
– end script –

And this can be used with RT 2.x, 3.x?!?

Also, small suggestion: hardcoding sendmail’s path isn’t really nice, tho
don’t take this the wrong way please!

Aleš-----Original Message-----
From: rt-users-admin@lists.fsck.com [mailto:rt-users-admin@lists.fsck.com]
On Behalf Of Mikhail Sobolev
Sent: Wednesday, September 03, 2003 5:04 PM
To: rt-users@lists.fsck.com
Subject: Re: [rt-users] A small script

Hmm. A better description is needed. :frowning:

It runs through the queues, and creates a list of tickets that owned by
nobody (require attention), those resolved within the specified amount
of days, and those being worked on (owned by somebody). It creates a
html letter, which is sent out to the specified e-mail address.

Misha
rt-users mailing list
rt-users@lists.fsck.com
http://lists.fsck.com/mailman/listinfo/rt-users

Have you read the FAQ? The RT FAQ Manager lives at http://fsck.com/rtfm

Ale� Su�nik wrote:

And this can be used with RT 2.x, 3.x?!?

Also, small suggestion: hardcoding sendmail’s path isn’t really nice, tho
don’t take this the wrong way please!

The standard location is /usr/lib/sendmail. I believe it is required by
POSIX or some similar document. ALL mail programs which provide a
sendmail interface provide it as /usr/lib/sendmail.

In the script /usr/sbin path is used… that’s why I mentioned this…

A.-----Original Message-----
From: rt-users-admin@lists.fsck.com [mailto:rt-users-admin@lists.fsck.com]
On Behalf Of Sean Perry Sent: Wednesday, September 03, 2003 8:45 PM To: rt-users@lists.fsck.com Subject: Re: [rt-users] A small script Aleš Sušnik wrote:

And this can be used with RT 2.x, 3.x?!?

Also, small suggestion: hardcoding sendmail’s path isn’t really nice, tho
don’t take this the wrong way please!

The standard location is /usr/lib/sendmail. I believe it is required by
POSIX or some similar document. ALL mail programs which provide a
sendmail interface provide it as /usr/lib/sendmail.

rt-users mailing list
rt-users@lists.fsck.com
http://lists.fsck.com/mailman/listinfo/rt-users

Have you read the FAQ? The RT FAQ Manager lives at http://fsck.com/rtfm

Ale� Su�nik wrote:

In the script /usr/sbin path is used… that’s why I mentioned this…

Sorry, my point was to agree with you and recommend the proper solution (-:

“SP” == Sean Perry sean.perry@intransa.com writes:

SP> The standard location is /usr/lib/sendmail. I believe it is required by
SP> POSIX or some similar document. ALL mail programs which provide a
SP> sendmail interface provide it as /usr/lib/sendmail.

Please don’t spread misinormation. If you have evidence it is
required by something, then show it. sendmail hasn’t been in /usr/lib
for years. it is in /usr/sbin on just about every modern system.

I had to change the ‘open(MAIL’ line to use “sendmail -t -i”. Otherwise, I
was getting an "Recipient names must be specified’ error message.
Thanks for pointing that out.

Misha

“SP” == Sean Perry sean.perry@intransa.com writes:

SP> The standard location is /usr/lib/sendmail. I believe it is required
by SP> POSIX or some similar document. ALL mail programs which provide
a SP> sendmail interface provide it as /usr/lib/sendmail.

Please don’t spread misinormation. If you have evidence it is
required by something, then show it. sendmail hasn’t been in /usr/lib
for years. it is in /usr/sbin on just about every modern system.
UnixWare has it (still) in /usr/lib, as does Solaris, to the best of my
knowledge.

LER

Larry Rosenman http://www.lerctr.org/~ler
Phone: +1 972-414-9812 E-Mail: ler@lerctr.org
US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749

“SP” == Sean Perry sean.perry@intransa.com writes:

SP> The standard location is /usr/lib/sendmail. I believe it is required by
SP> POSIX or some similar document. ALL mail programs which provide a
SP> sendmail interface provide it as /usr/lib/sendmail.

Please don’t spread misinormation. If you have evidence it is
required by something, then show it. sendmail hasn’t been in /usr/lib
for years. it is in /usr/sbin on just about every modern system.

And then there are sites that have a local MTA configuration off in some
weird place like /usr/local/postfix/sbin/ or /opt/exim/sbin.
Configurability is a win.


rt-users mailing list
rt-users@lists.fsck.com
http://lists.fsck.com/mailman/listinfo/rt-users

Have you read the FAQ? The RT FAQ Manager lives at http://fsck.com/rtfm

Request Tracker... So much more than a help desk — Best Practical Solutions – Trouble Ticketing. Free.

I had to change the ‘open(MAIL’ line to use “sendmail -t -i”. Otherwise, I
was getting an "Recipient names must be specified’ error message.
Thanks for pointing that out.

There is one other option. RT already has all of this information
internally. You might want to just use the pre-existing RT configuration
for mail sending.


Misha


rt-users mailing list
rt-users@lists.fsck.com
http://lists.fsck.com/mailman/listinfo/rt-users

Have you read the FAQ? The RT FAQ Manager lives at http://fsck.com/rtfm

Request Tracker... So much more than a help desk — Best Practical Solutions – Trouble Ticketing. Free.

“SP” == Sean Perry sean.perry@intransa.com writes:

SP> The standard location is /usr/lib/sendmail. I believe it is required by
SP> POSIX or some similar document. ALL mail programs which provide a
SP> sendmail interface provide it as /usr/lib/sendmail.

Please don’t spread misinormation. If you have evidence it is
required by something, then show it. sendmail hasn’t been in /usr/lib
for years. it is in /usr/sbin on just about every modern system.

and how many of those with links to /usr/lib/sendmail, hmmm?

/usr/lib/sendmail was the standard for years. Where it came from and why,
I don’t know.

And this can be used with RT 2.x, 3.x?!?
:)) And to be used with RT 3.0.4 at least. :slight_smile:

Also, small suggestion: hardcoding sendmail’s path isn’t really nice, tho
don’t take this the wrong way please!
Of course, I will. :slight_smile: What are your suggestions? To bring it out as
variable/parameter in the beginning of the file (to make it easier to
“config” the script)? Or something else?

As it turned out, the script does not work with 3.0.2. Having checked
the ChangeLog, I found that between 3.0.3 and 3.0.4 RT started to allow
more operators for date comparison (I do use “>=”, while at 3.0.2 it
only allowed “>”, “<”, and “=”).

For the record, I am using RT on a Debian (unstable) (package
request-tracker3 of version 3.0.4-2) system, with mysql as the db
backend, and postfix as a MTA. Since it’s a Debian system, I kinda
followed its polciy (which say that the mail sending program must be
available through /usr/sbin/sendmail, 11.6).

Thanks,

Misha

/usr/lib/sendmail is the defacto standard for sendmail. I know what I am
talking about if you have questions issues with this you can send mail via
text to support@sendmai.org with a query as to why it is. I would not
continue this discussion here as it is meaningless and argumentative about
what RT is all about.

Thanks,

Robert SullivanFrom: John Jasen [mailto:jjasen@datafoundation.com]
Sent: Wednesday, September 03, 2003 12:34 PM
To: Vivek Khera
Cc: rt-users@lists.fsck.com
Subject: Re: [rt-users] A small script

“SP” == Sean Perry sean.perry@intransa.com writes:

SP> The standard location is /usr/lib/sendmail. I believe it is required
by
SP> POSIX or some similar document. ALL mail programs which provide a
SP> sendmail interface provide it as /usr/lib/sendmail.

Please don’t spread misinormation. If you have evidence it is
required by something, then show it. sendmail hasn’t been in /usr/lib
for years. it is in /usr/sbin on just about every modern system.

and how many of those with links to /usr/lib/sendmail, hmmm?

/usr/lib/sendmail was the standard for years. Where it came from and why,
I don’t know.

rt-users mailing list
rt-users@lists.fsck.com
http://lists.fsck.com/mailman/listinfo/rt-users

Have you read the FAQ? The RT FAQ Manager lives at http://fsck.com/rtfm

Mitchell Henderson wrote:

A couple days ago I got 16000 Tickets created from SoBig and other
things. I couldn’t find a script to basicly batch erase a bunch of
tickets so I wrote one.

There’s a delete_dead_tickets script for RT2 floating around,
but I’m not sure if anyone has ported it to RT3 yet.

Figured someone else might have this problem
so I’ll share the script. It’s very messy and i’m not 100% positive
this is the right way to do it but it works for me, use at your own risk.

I’m 100% positive it will destroy your database, actually:

t = db.execute(“SELECT id FROM Tickets WHERE status=‘dead’;”)
ids = db.fetchall()

“ids” is a list of Ticket ids…

    db.execute("DELETE FROM Attachments where id=" + str(int(ids[i][0])))

… but you’re deleting Attachments whose Attachment ids match a list
of Ticket ids. That’s Not Good.
Phil Homewood, Systems Janitor, http://www.SnapGear.com
pdh@snapgear.com Ph: +61 7 3435 2810 Fx: +61 7 3891 3630
SnapGear - Custom Embedded Solutions and Security Appliances

Probably the best idea to bring it out as a parameter at the beggining of
the file, yes.
Also a few lines on which versions this was tested (at the beggining also).

A.From: rt-users-admin@lists.fsck.com [mailto:rt-users-admin@lists.fsck.com]
On Behalf Of Mikhail Sobolev
Sent: Wednesday, September 03, 2003 9:36 PM
To: rt-users@lists.fsck.com
Subject: Re: [rt-users] A small script

And this can be used with RT 2.x, 3.x?!?
:)) And to be used with RT 3.0.4 at least. :slight_smile:

Also, small suggestion: hardcoding sendmail’s path isn’t really nice, tho
don’t take this the wrong way please!
Of course, I will. :slight_smile: What are your suggestions? To bring it out as
variable/parameter in the beginning of the file (to make it easier to
“config” the script)? Or something else?

As it turned out, the script does not work with 3.0.2. Having checked
the ChangeLog, I found that between 3.0.3 and 3.0.4 RT started to allow
more operators for date comparison (I do use “>=”, while at 3.0.2 it
only allowed “>”, “<”, and “=”).

For the record, I am using RT on a Debian (unstable) (package
request-tracker3 of version 3.0.4-2) system, with mysql as the db
backend, and postfix as a MTA. Since it’s a Debian system, I kinda
followed its polciy (which say that the mail sending program must be
available through /usr/sbin/sendmail, 11.6).

Thanks,

Misha
rt-users mailing list
rt-users@lists.fsck.com
http://lists.fsck.com/mailman/listinfo/rt-users

Have you read the FAQ? The RT FAQ Manager lives at http://fsck.com/rtfm

I had to change the ‘open(MAIL’ line to use “sendmail -t -i”. Otherwise, I
was getting an "Recipient names must be specified’ error message.
Thanks for pointing that out.

There is one other option. RT already has all of this information
internally. You might want to just use the pre-existing RT configuration
for mail sending.
I would do that, however, RT supports several different ways for sending
a message. And I’d happily just used some internal function of RT3 to
send the messsage out, however I did not find an easy way. (But I am
going to check it better.)

Misha