<chapter id="generic-agent">
<title>Generic-Agent</title>
<para>
The Generic-Agent (bin/GenericAgent.pl) is a command line program (executed by cron) wich can 
do some actions (like move, add note, set state, set owner) on tickets.
</para>
<para>
Note: It's also possible to write own generic agent modules to do some
actions (see chapter "Writing OTRS Modules" for examples).
</para>

<section id="generic-agent-web">
<title>Web-Interface (preferred)</title>
<para>
OTRS 1.3 or higher comes with an web interface to configure jobs for the
generic agent.
</para>
<para>
    Admin - GenericAgent Job-Overview
    <screenshot>
    <screeninfo>Admin - GenericAgent Job-Overview</screeninfo>
    <graphic fileref="screenshots/admin-genericagent1.png" scale="40" srccredit="generic agent screen - screenshot"></graphic>
    </screenshot>
</para>
<para>
    Admin - GenericAgent Job-Edit
    <screenshot>
    <screeninfo>Admin - GenericAgent Job-Edit</screeninfo>
    <graphic fileref="screenshots/admin-genericagent2.png" scale="40" srccredit="generic agent screen - screenshot"></graphic>
    </screenshot>
</para>
</section>

<section id="generic-agent-config-file">
<title>Config File (optional)</title>
<para>
Kernel/Config/GenericAgent.pm is the default config file which must be copied 
(cp Kernel/Config/GenericAgent.pm.dist Kernel/Config/GenericAgent.pm). 
</para>
<para>
It's also possibe to use different config files. For example, copy 
the "cp Kernel/Config/GenericAgent.pm.examples Kernel/Config/GenericAgentFileB.pm"
and rename the package name in the new file:
<programlisting>
[...]
package Kernel::Config::GenericAgentFileB;
[...]
</programlisting>
Execute the bin/GenericAgent.pl with option "-c Kernel::Config::GenericAgentFileB"
and the new config file (Kernel/Config/GenericAgentFileB.pm) will be used.
</para>


<section id="generic-agent-example">
<title>Examples</title>
<para>
Now we want to go through a few examples. There is also a example config file 
(Kernel/Config/GenericAgent.pm.examples). 
</para>
<para>
Here all possible options:
<programlisting>
   'name of job' => {
      # get all tickets with these properties 
      TicketNumber => '200%01',
      Queue => 'system queue',
      States => ['new', 'open'],
      Priorities => ['1 very low', '2 low', '3 normal'],
      Locks => ['unlock'],
      From => '%spam@example.com%',
      To => '%support@example.com%',
      Cc => '%client@example.com%',
      TicketFreeKey1 => 'Product',
      TicketFreeText1 => 'adasd',
      TicketFreeKey2 => 'Product',
      TicketFreeText2 => 'adasd',
      Subject => '%VIRUS 32%',
      Body => '%VIRUS 32%',
      CustomerID => '123',
      CustomerUserLogin => 'uid123',
      # tickets older the 60 minutes
      TicketCreateTimeOlderMinutes => 60,
      # tickets newer then 60 minutes
      TicketCreateTimeNewerMinutes => 60,
      # tickets with create time older then ....
      TicketCreateTimeOlderDate => '2004-01-19 00:00:01',
      # tickets with create time newer then ...
      TicketCreateTimeNewerDate => '2004-01-09 23:59:59',

      # or escalation tickets
      Escalation => 1,

      # new ticket properties (no option is required, use just the options
      # which should be changed!)
      New => {
        # new queue
        Queue => 'new system queue',
        # possible states (closed successful|closed unsuccessful|open|new|removed) 
        State => 'closed successful',
        # new priority
        Priority => '3 normal',
        # new ticket free text
        TicketFreeKey1 => 'Product123',
        TicketFreeText1 => 'adasd123',
        # new ticket owner (if needed)
        Owner => 'root@localhost',
        # set customer id and customer user
        CustomerID => '123',
        CustomerUserLogin => 'usd213', 
        # if you want to add a Note
        Note => {
          From => 'GenericAgent',
          Subject => 'Your subject!',
          Body => 'Some comment!',
          ArticleType => 'note-internal', # note-internal|note-external|note-report
        },
        # your program (/path/to/your/program) will be executed like
        # "/path/to/your/program $TicketNumber $TicketID" ARG[0] will 
        # be the ticket number and ARG[1] the ticket id
        CMD => '/path/to/your/program',
        # DELETE ticket from database and filesystem
        Delete => 1,
     },
</programlisting>
</para>

<section>
<title>close spam tickets</title>
<para>
If you get spam tickets in your system and you want spend much time on it, 
create a queue (named spam) and just move the spam tickets into this queue.
If the bin/GenericAgent.pl runs, all open tickets in the queue spam will be
closed by the bin/GenericAgent.pl.
</para> 
<para>
Example for Kernel/Config/GenericAgent.pm
<programlisting>
[...]
   # --
   # [name of job] -> close all tickets in queue spam
   # --
   'close spam' => {
      # get all tickets with this properties  
      Queue => 'spam',
      States => ['new', 'open'],
      Locks => ['unlock'],
      # new ticket properties (no option is required, use just the options
      # which should be changed!)
      New => {
        # new queue
        Queue => 'spam',
        # possible states (closed successful|closed unsuccessful|open|new|removed) 
        State => 'closed successful',
        # new ticket owner (if needed)
        Owner => 'root@localhost',
        # if you want to add a Note
        Note => {
          From => 'GenericAgent',
          Subject => 'spam!',
          Body => 'Closed by GenericAgent.pl because it is spam!',
       },
     },
   },
[...]
</programlisting>
</para> 
</section>

<section>
<title>delete tickets</title>
<para>
If you want to delete (means delete ticket from database and filesystem) 
a ticket from a queue use this.
</para> 
<para>
Example for Kernel/Config/GenericAgent.pm
<programlisting>
[...]
   # --
   # [name of job] -> close and delete all tickets in queue delete
   # --
   'delete' => {
      # get all tickets with this properties  
      Queue => 'delete',
      States => ['new', 'open'],
      Locks => ['unlock'],
      # new ticket properties (no option is required, use just the options
      # witch should be changed!)
      New => {
        # DELETE!
        Delete => 1,
     },
   },
[...]
</programlisting>
</para> 
</section>

<section>
<title>move tickets from tricky to experts</title>
<para>
Moved ticket from tricky to experts queue and add note.
</para> 
<para>
Example for Kernel/Config/GenericAgent.pm
<programlisting>
[...]
   # --
   # [name of job] -> move all tickets from tricky to experts
   # --
   'move tickets from tricky to experts' => {
      # get all tickets with this properties  
      Queue => 'tricky',
      States => ['new', 'open'],
      Locks => ['unlock'],
      # new ticket properties
      New => {
        Queue => 'experts',
        Note => {
          From => 'GenericAgent',
          Subject => 'Moved!',
          Body => 'Moved from "tricky" to "experts" because it was not possible to find a sollution!',
          ArticleType => 'note-internal', # note-internal|note-external|note-report
        },
      },
   },
[...]
</programlisting>
</para> 
</section>

<section>
<title>send escalation notifications</title>
<para>
Send escalation notifications to agents which subscribed to the custom queue
of the ticket.
</para> 
<para>
Example for Kernel/Config/GenericAgent.pm
<programlisting>
[...]
   # --
   # [name of job] -> send escalation notifications 
   # --
   'send escalation notifications' => {
      Escalation => 1,
      # new ticket properties
      New => {
          Module => 'Kernel::System::GenericAgent::NotifyAgentGroupOfCustomQueue',
      },
   },
[...]
</programlisting>
</para> 
</section>

<section>
<title>move tickets from abc to experts and change priority</title>
<para>
Moved ticket from abc with priority "3 normal" to experts queue and change priority to "4 high".
</para> 
<para>
Example for Kernel/Config/GenericAgent.pm
<programlisting>
[...]
   # --
   # [name of job] -> move all tickets from abc to experts and change priority
   # --
   'move all abc priority "3 normal" tickets to experts and change priority'=> {
      # get all tickets with this properties  
      Queue => ['abc'],
      States => ['new', 'open'],
      Locks => ['unlock'],
      Priorities => ['3 normal'],
      # new ticket properties
      New => {
        Queue => 'experts',
        Priority => '4 high',
        TicketFreeKey1 => 'ProductSkill',
        TicketFreeText1 => 'Expert required!',
      },
   },
[...]
</programlisting>
</para> 
</section>

<section>
<title>move escalation ticket to experts and execute CMD</title>
<para>
If there is a escalation ticket, move it to experts and execute a command.
</para> 
<para>
Example for Kernel/Config/GenericAgent.pm
<programlisting>
[...]
   # --
   # [name of job] -> move all tickets from xyz to experts
   # --
   'move escalation ticket to experts and execute CMD' => {
      # get all tickets with this properties  
      Queue => 'xyz',
      Escalation => 1,
      # new ticket properties
      New => {
        Queue => 'experts',
        # your program (/path/to/your/program) will be executed like
        # "/path/to/your/program $TicketNumber $TicketID" ARG[0] will 
        # be the ticket number and ARG[1] the ticket id
        CMD => '/path/to/your/program',
      },
   },
[...]
</programlisting>
</para> 
</section>


<section>
<title>delete all tickets with subject "VIRUS 32" in queue abc</title>
<para>
Delete all tickets with subject "VIRUS 32" in queue abc.
</para> 
<para>
Example for Kernel/Config/GenericAgent.pm
<programlisting>
[...]
   'delete all tickets with subject "VIRUS 32" in queue abc' => {
      # get all tickets with this properties  
      Queue => 'abc',
#      From => '%spam@example.com%',
#      To => '%support@example.com%',
#      Cc => '%client@example.com%',
      Subject => '%VIRUS 32%',
#      Body => '%testing case 1245%',
      # new ticket properties
      New => {
        # DELETE!
        Delete => 1,
      },
   },
[...]
</programlisting>
</para>
</section>

</section>

</section>


</chapter>
