[SOLVED] Run generic agent task once a month
Moderator: crythias
[SOLVED] Run generic agent task once a month
Hi,
Looking at the generic agent administration page I see that it's possible to define time periods for the task execution up to weekly, but it seems it isn't possible to do it once a month. The need for this is because there's an external system that sends to our OTRS some notifications when something happens, but they become invalid when the next month starts, so we need to close all those tickets created by the notifications the first of each month. Is this possible to accomplish ?
Looking at the generic agent administration page I see that it's possible to define time periods for the task execution up to weekly, but it seems it isn't possible to do it once a month. The need for this is because there's an external system that sends to our OTRS some notifications when something happens, but they become invalid when the next month starts, so we need to close all those tickets created by the notifications the first of each month. Is this possible to accomplish ?
Last edited by jbaptiste on 09 Dec 2015, 12:26, edited 1 time in total.
Want to run OTRS on docker ? checkout my OTRS on docker HOWTO | Project's github page
-
- Znuny guru
- Posts: 2210
- Joined: 13 Mar 2014, 09:16
- Znuny Version: 6.0.14
- Real Name: Rolf Straub
Re: Run generic agent task once a month
The simplest way would probably be a generic agent WITHOUT a schedule that you trigger manually once a month.
As you can't (afaik) trigger a GA via console, you would need a custom standalone module that you can trigger via cronjobs - to automate this.
As you can't (afaik) trigger a GA via console, you would need a custom standalone module that you can trigger via cronjobs - to automate this.
Currently using: OTRS 6.0.14 -- MariaDB -- Ubuntu 16 LTS
Re: Run generic agent task once a month
Thanks for your answer, could you elaborate a little more about the custom standalone modules ?RStraub wrote:The simplest way would probably be a generic agent WITHOUT a schedule that you trigger manually once a month.
As you can't (afaik) trigger a GA via console, you would need a custom standalone module that you can trigger via cronjobs - to automate this.
Want to run OTRS on docker ? checkout my OTRS on docker HOWTO | Project's github page
-
- Znuny guru
- Posts: 2210
- Joined: 13 Mar 2014, 09:16
- Znuny Version: 6.0.14
- Real Name: Rolf Straub
Re: Run generic agent task once a month
Sure!
Create a minimal working example (meaning, can be executed from the shell), like this:
You then can call it via shell or cron "perl NameOfYourFile.pl".
In that file you can manipulate OTRS Data just as in any module that's called by OTRS itself.
Create a minimal working example (meaning, can be executed from the shell), like this:
Code: Select all
#!/usr/bin/perl
use strict;
use warnings;
use lib '/opt/otrs/';
use lib '/opt/otrs/Kernel/cpan-lib';
use lib '/opt/otrs/Custom';
use DBI();
use Kernel::System::ObjectManager;
local $Kernel::OM = Kernel::System::ObjectManager->new(
'Kernel::System::Log' => {
LogPrefix => 'TTO-tto.RemindOpenSicknessTickets',
},
);
my $TicketObject = $Kernel::OM->Get('Kernel::System::Ticket');
my @OpenTickets = $TicketObject->TicketSearch(
Result => 'ARRAY',
States => ['open', 'new'],
UserID => 1,
);
use Data::Dumper;
printf Dumper(\@OpenTickets);
1;
In that file you can manipulate OTRS Data just as in any module that's called by OTRS itself.
Currently using: OTRS 6.0.14 -- MariaDB -- Ubuntu 16 LTS
Re: Run generic agent task once a month
Thanks for your answer, one last thing (for now), could you point me to the correct documentation ? I'm looking at:
https://otrs.github.io/doc/api/otrs/4.0 ... te.pm.html
but it seems that that's the documentation for the interface, and I can't find the implementation like you put with TicketSearch.
PS: I'm a developer but I'm not familiar with perl, so please have some patience with me
https://otrs.github.io/doc/api/otrs/4.0 ... te.pm.html
but it seems that that's the documentation for the interface, and I can't find the implementation like you put with TicketSearch.
PS: I'm a developer but I'm not familiar with perl, so please have some patience with me
Want to run OTRS on docker ? checkout my OTRS on docker HOWTO | Project's github page
-
- Znuny guru
- Posts: 2210
- Joined: 13 Mar 2014, 09:16
- Znuny Version: 6.0.14
- Real Name: Rolf Straub
Re: Run generic agent task once a month
I use a either of these sites:
http://otrs.perl-services.de/docs/otrs/ ... earch.html
or
https://otrs.github.io/doc/api/otrs/4.0 ... ch.pm.html
Either of them works fine and I only had very few problems with a wrong documentation (one example beeing the "GroupMemberList" of the GroupObject).
http://otrs.perl-services.de/docs/otrs/ ... earch.html
or
https://otrs.github.io/doc/api/otrs/4.0 ... ch.pm.html
Either of them works fine and I only had very few problems with a wrong documentation (one example beeing the "GroupMemberList" of the GroupObject).
Currently using: OTRS 6.0.14 -- MariaDB -- Ubuntu 16 LTS
Re: Run generic agent task once a month
But those pages are for TicketSearch, I'm looking at how to update the tickets with the new state, and by what I have found, I need to use TicketUpdate, right ?RStraub wrote:I use a either of these sites:
http://otrs.perl-services.de/docs/otrs/ ... earch.html
or
https://otrs.github.io/doc/api/otrs/4.0 ... ch.pm.html
Either of them works fine and I only had very few problems with a wrong documentation (one example beeing the "GroupMemberList" of the GroupObject).
Want to run OTRS on docker ? checkout my OTRS on docker HOWTO | Project's github page
-
- Znuny guru
- Posts: 2210
- Joined: 13 Mar 2014, 09:16
- Znuny Version: 6.0.14
- Real Name: Rolf Straub
Re: Run generic agent task once a month
Well, if you want to close it (read: change the state) use this page:
https://otrs.github.io/doc/api/otrs/4.0 ... et.pm.html
with the function TicketStateSet()
https://otrs.github.io/doc/api/otrs/4.0 ... et.pm.html
with the function TicketStateSet()
Currently using: OTRS 6.0.14 -- MariaDB -- Ubuntu 16 LTS
Re: Run generic agent task once a month
Thanks! I got a basic example working, now to learn perl (lol) and make it go through all the needed tickets to be closed, this is a good startRStraub wrote:Well, if you want to close it (read: change the state) use this page:
https://otrs.github.io/doc/api/otrs/4.0 ... et.pm.html
with the function TicketStateSet()
Want to run OTRS on docker ? checkout my OTRS on docker HOWTO | Project's github page
Re: Run generic agent task once a month
I just noticed something, it only closes the ticket in the second run, this is my script:
Any idea why it could be happening ?
Code: Select all
#!/usr/bin/perl
use strict;
use warnings;
use lib '/opt/otrs/';
use lib '/opt/otrs/Kernel/cpan-lib';
use lib '/opt/otrs/Custom';
use DBI();
use Kernel::System::ObjectManager;
local $Kernel::OM = Kernel::System::ObjectManager->new(
'Kernel::System::Log' => {
LogPrefix => 'CloseAkamaiAlertTickets',
},
);
my $TicketObject = $Kernel::OM->Get('Kernel::System::Ticket');
my @OpenTickets = $TicketObject->TicketSearch(
Result => 'ARRAY',
States => ['open', 'new'],
UserID => 1,
);
my $Success = $TicketObject->TicketStateSet(
State => 'closed successful',
TicketID => 2,
UserID => 1,
Subject => '%New Alert%',
);
use Data::Dumper;
printf Dumper(\@OpenTickets);
1;
Want to run OTRS on docker ? checkout my OTRS on docker HOWTO | Project's github page
-
- Znuny guru
- Posts: 5018
- Joined: 13 Mar 2011, 09:54
- Znuny Version: 6.0.x
- Real Name: Renée Bäcker
- Company: Perl-Services.de
- Contact:
Re: Run generic agent task once a month
Why do you think that the script closes the ticket only on the second run? If you think so, because you see the ticket in the dump, then note that you get the list of open tickets first, then close the ticket and then dump the list of open tickets. You should get the list of open tickets after the state change again and dump the second list
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
Re: Run generic agent task once a month
You are right, after I removed the dump line, I see it's working. This is the full script if someone else is interested:
Code: Select all
use strict;
use warnings;
use lib '/opt/otrs/';
use lib '/opt/otrs/Kernel/cpan-lib';
use lib '/opt/otrs/Custom';
use DBI();
use Kernel::System::ObjectManager;
local $Kernel::OM = Kernel::System::ObjectManager->new(
'Kernel::System::Log' => {
LogPrefix => 'CloseAkamaiAlertTickets',
},
);
my $TicketObject = $Kernel::OM->Get('Kernel::System::Ticket');
my @OpenTickets = $TicketObject->TicketSearch(
Result => 'ARRAY',
States => ['open', 'new'],
UserID => 1,
From => '%noreply@alertsystem.com%',
Subject => '%New Alert%',
);
sub closeTickets {
foreach my $v (@_) {
my $Success = $TicketObject->TicketStateSet(
State => 'closed successful',
TicketID => $v,
UserID => 1,
);
}
}
closeTickets(@OpenTickets);
Want to run OTRS on docker ? checkout my OTRS on docker HOWTO | Project's github page
-
- Znuny guru
- Posts: 2210
- Joined: 13 Mar 2014, 09:16
- Znuny Version: 6.0.14
- Real Name: Rolf Straub
Re: Run generic agent task once a month
Glad we found another happy modder
Currently using: OTRS 6.0.14 -- MariaDB -- Ubuntu 16 LTS
Re: Run generic agent task once a month
Yeah ! I just updated the OP topic to mark it as solved. Thanks !RStraub wrote:Glad we found another happy modder
Want to run OTRS on docker ? checkout my OTRS on docker HOWTO | Project's github page