[rt-users] rt-crontool - "increase" the value of a CF.
Bart
bart at pleh.info
Mon Dec 5 08:35:03 EST 2011
Optimized the scrip by quite a bit, below the result:
#!/bin/bash
datum=`date "+%d%m%y"`
if [ $datum -eq 261211 -o $datum -eq 090412 ]
then
echo "Mag niet!"
else
for i in `/opt/rt4/bin/rt ls -t ticket "Status!='resolved' and
Status!='rejected' and Status!='spam' and Status!='deleted'" -f status |
grep ^[0-9] | cut -f 1`; do
case `/opt/rt4/bin/rt ls -t ticket "id=$i" -f status | grep ^[0-9]
| cut -f 2` in
new) /opt/rt4/bin/rt edit ticket/$i set CF-'Teller New'=$((
`/opt/rt4/bin/rt ls -t ticket "id=$i" -f CF-'Teller New' | grep ^[0-9] |
cut -f 2` + 5 ))&
;;
open) /opt/rt4/bin/rt edit ticket/$i set CF-'Teller Open'=$((
`/opt/rt4/bin/rt ls -t ticket "id=$i" -f CF-'Teller Open' | grep ^[0-9] |
cut -f 2` + 5 ))&
;;
*) ;;
esac
done
fi
It's the dutch version but I suspect it to be pretty well readable for
everyone (datum = date, open = open, teller = counter, new = new, etc.)
The first script took roughly 112-120 minutes, the above version finishes
in 46-47 minutes on the same set of tickets (6700 active tickets). In our
production environment this will result in a run that's finished in less
than a minute.
Biggest speed boost came because of setting the RT edit command into the
background using the & character at the end of the line. It results in
having maybe 2 to 3 edit actions running in the background while the script
keeps doing it's job instead of waiting on the edit.
The performance is still ok on the server when this script is running
(non noticeable).
-- Bart
Op 29 november 2011 12:27 schreef Bart <bart at pleh.info> het volgende:
> Hi,
>
> I've created a bash script which will do what I want it to do, using the
> RT Tool since this ended up being the easiest for me (I'll look into
> improving this further, but for now this works).
>
> Below the code of what I've created:
>
> #!/bin/bash
>
> for i in `/opt/rt4/bin/rt ls -t ticket "Status!='resolved' and
> Status!='rejected' and Status!='spam' and Status!='deleted'" -f status |
> grep ^[0-9] | cut -f 1`; do
> status=`/opt/rt4/bin/rt ls -t ticket "id=$i" -f status | grep ^[0-9] |
> cut -f 2`
> cnew=`/opt/rt4/bin/rt ls -t ticket "id=$i" -f CF-'Counter New' | grep
> ^[0-9] | cut -f 2`
> copen=`/opt/rt4/bin/rt ls -t ticket "id=$i" -f CF-'Counter Open' | grep
> ^[0-9] | cut -f 2`
> if [ "$status" = "new" ]
> then
> cnew=$(( $cnew + 5 ))
> /opt/rt4/bin/rt edit ticket/$i set CF-'Counter New'=$cnew
> fi
> if [ "$status" = "open" ]
> then
> copen=$(( $copen + 5 ))
> /opt/rt4/bin/rt edit ticket/$i set CF-'Counter Open'=$copen
> fi
> done
>
> In the for statement I'm listing all the ticket ID's.
> Then I'm extracting specific fields from the ticket by looking it up, I've
> found that I need to somehow do it this way because when fields are empty
> the entire scrip kinda breaks (e.g. if I put the output into an array, the
> array expects space separated input and it will not understand when 1 field
> is empty).
>
> Thus, even if it's kinda ugly I request information three times.
>
> From there an if statement checks the ticket status, for each status it
> will do almost the same (again, I'll probably make this nicer) and increase
> the value of the counter CF by 5 (for 5 minutes).
>
> The downside of this script is that it isn't exactly "fast", takes roughly
> 1 second for each ticket. In our case a typical daily "active" tickets in
> queue are roughly 120 so it will take 2 minutes to run. Since we run it
> every 5 minutes this is (barely) within the allowed time.
>
> As for improvements, next step is to make this scrip faster and probably
> do things via the RT-Crontool.
>
> But for now I'm happy with this :-) (this gives me some time to think-up a
> better solution)
>
> -- Bart
>
>
> Op 23 november 2011 20:29 schreef Bart <bart at pleh.info> het volgende:
>
> Did some reading on the RT-Tool page (
>> http://requesttracker.wikia.com/wiki/UseRtTool ) and found this command:
>>
>> bin/rt list -i "Queue = 'testqueue'" | bin/rt edit - set status=resolved
>>
>> I'm lacking the documentation and our test environment a.t.m. (am at
>> home). So I'll do some experimenting in the test environment tomorrow at
>> work, hopefully it will show me some nice results ^_^
>>
>>
>> -- Bart
>>
>>
>> Op 23 november 2011 19:57 schreef Bart <bart at pleh.info> het volgende:
>>
>> Hi Yan,
>>>
>>> I'll also have a look at the rt script and see if I can manage it using
>>> that, thanks :)
>>>
>>> -- Bart
>>>
>>>
>>> Op 23 november 2011 19:50 schreef Yan Seiner <yan at seiner.com> het
>>> volgende:
>>>
>>> Wouldn't this work (snippet from a bigger script):
>>>>
>>>> # and set custom fields
>>>> /opt/rt4/bin/rt edit ticket/${ticket} set
>>>> 'CF.{contractor}'="${contractor}"
>>>> /opt/rt4/bin/rt edit ticket/${ticket} set 'CF.{amount}'="${amount}"
>>>>
>>>> That's how I set custom fields. You could get the value that way,
>>>> increment it or whatever in a script, and then set it again.
>>>>
>>>>
>>>>
>>>> On Wed, November 23, 2011 10:23 am, Bart wrote:
>>>> > Hi Kevin,
>>>> >
>>>> > Thanks for the reply,
>>>> >
>>>> > Guess I'll have to learn Perl a bit more then and experiment a little
>>>> with
>>>> > this.
>>>> >
>>>> > Will post the results once I've gained some progress.
>>>> >
>>>> > -- Bart
>>>> >
>>>> >
>>>> > Op 23 november 2011 18:08 schreef Kevin Falcone
>>>> > <falcone at bestpractical.com>het volgende:
>>>> >
>>>> >> On Wed, Nov 23, 2011 at 05:25:01PM +0100, Bart wrote:
>>>> >> > I've then created a simple rt-crontool command to see if I could
>>>> >> find
>>>> >> a ticket and if I could
>>>> >> > set a value when I found that ticket. This worked as well, below
>>>> >> the
>>>> >> result:
>>>> >> > /opt/rt4/bin/rt-crontool \
>>>> >> > --search RT::Search::FromSQL \
>>>> >> > --search-arg "status = 'open'" \
>>>> >> > --action RT::Action::SetPriority --action-arg 3 \
>>>> >> > --verbose
>>>> >> > So now for the question(s):
>>>> >> >
>>>> >> > * First a simple one, how do I set a value for a custom field?
>>>> >> > * And the more difficult one, how do I increase a value
>>>> instead
>>>> >> of
>>>> >> replacing it? (adding +
>>>> >> > or something like that doesn't seem to work)
>>>> >> >
>>>> >> > Hopefully this is possible with the rt-crontool, if not then I'd
>>>> >> like
>>>> >> to hear your thoughts on
>>>> >> > how I'd be able to do the above in a different manner.
>>>> >>
>>>> >> Unfortunately, you'll need to write your own RT::Action to change
>>>> the CF
>>>> >>
>>>> >> You could turn this into a pretty trivial perl script using the RT
>>>> API
>>>> >> and calling $tickets->FromSQL("status = 'open'") and then iterating
>>>> >> the list to call AddCustomFieldValue
>>>> >>
>>>> >> -kevin
>>>> >>
>>>> >> --------
>>>> >> RT Training Sessions (
>>>> http://bestpractical.com/services/training.html)
>>>> >> * Barcelona, Spain — November 28 & 29, 2011
>>>> >>
>>>> >
>>>> >
>>>> > !DSPAM:4ecd3a6094962612618147!
>>>> > --------
>>>> > RT Training Sessions (http://bestpractical.com/services/training.html
>>>> )
>>>> > * Barcelona, Spain ? November 28 & 29, 2011
>>>> >
>>>> > !DSPAM:4ecd3a6094962612618147!
>>>> >
>>>>
>>>>
>>>> --
>>>> Pain is temporary. It may last a minute, or an hour, or a day, or a
>>>> year,
>>>> but eventually it will subside and something else will take its place.
>>>> If
>>>> I quit, however, it lasts forever.
>>>>
>>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.bestpractical.com/pipermail/rt-users/attachments/20111205/64ffede0/attachment.htm>
More information about the rt-users
mailing list