Rt-crontool - "increase" the value of a CF

Hi,

Before I start with the actual question I’ll explain what I’m trying to
achieve first, just in case someone has a better idea for achieving it :wink:

As you know the SLA plugin does it’s job quite well but what if you’d want
to know exactly how long something was at a supplier or how long a customer
left you waiting for your reports?
It’s quite difficult to find this information, and in our case we use
Business Objects to datamine RT’s database and it’s quite complicated
within BO to calculate these values (and taking into account the actual SLA
service windows + holidays).

Because of that we decided that we needed to solve this within RT, but how?

Below a list of our status types:

  • New
  • Open
  • Parked
  • At_supplier
  • At_requestor
  • At_Internal_department

(roughly translated since we use Dutch names for this)

Our solution was to create a Custom Field for every active/initial ticket
status type, this CF would have the soul purpose of simply showing the
amount of minutes a ticket had this status.
Thus the names of these CF’s would look something like this: (these fields
will be hidden from users)

  • Time_New
  • Time_Open
  • Time_Parked
  • Time_At_supplier
  • Time_At_requestor
  • Time_At_Internal_department

Just to keep things clear I’m leaving these names as they are, this part up
to now is rather simple. The difficult part is to get a value inside those
fields.

We thought it would be good to create a cron job which will execute a bash
script (or perl, though I’m more familiar with bash) which will use
rt-crontool to search for all tickets with status X and then increase the
value of the CF Time_X by 5.
The cron job would run every 5 minutes, only during our service window and
within the bash script we’ll add the intelligence for skipping the holidays.

So far so good.

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.

Thanks in advance for replying :slight_smile:

– Bart

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

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@bestpractical.comhet 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

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@bestpractical.comhet 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.

Hi Yan,

I’ll also have a look at the rt script and see if I can manage it using
that, thanks :slight_smile:

– BartOp 23 november 2011 19:50 schreef Yan Seiner yan@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@bestpractical.comhet 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.

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 :slight_smile:

– BartOp 23 november 2011 19:57 schreef Bart bart@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 :slight_smile:

– Bart

Op 23 november 2011 19:50 schreef Yan Seiner yan@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@bestpractical.comhet 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.

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 :slight_smile: (this gives me some time to think-up a
better solution)

– BartOp 23 november 2011 20:29 schreef Bart bart@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 :slight_smile:

– Bart

Op 23 november 2011 19:57 schreef Bart bart@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 :slight_smile:

– Bart

Op 23 november 2011 19:50 schreef Yan Seiner yan@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@bestpractical.comhet 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.

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).

– BartOp 29 november 2011 12:27 schreef Bart bart@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 :slight_smile: (this gives me some time to think-up a
better solution)

– Bart

Op 23 november 2011 20:29 schreef Bart bart@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 :slight_smile:

– Bart

Op 23 november 2011 19:57 schreef Bart bart@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 :slight_smile:

– Bart

Op 23 november 2011 19:50 schreef Yan Seiner yan@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@bestpractical.comhet 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.