| CA-AutoSys documentation | Contained in the CA-AutoSys distribution. |
CA::AutoSys - Interface to CA's AutoSys job control.
This module was born out of the need to control some AutoSys jobs via a Perl/CGI script. It is sort of a quick hack, but it works for me... should you have some wishes / requirements that are not mentioned in TODOs, please let me know.
use CA::AutoSys;
my $hdl = CA::AutoSys->new( [OPT] ) ;
my $jobs = $hdl->find_jobs($jobname) ;
while (my $job = $jobs->next_job()) {
:
}
my $status = $job->get_status() ;
my $children = $job->find_children() ;
while (my $child = $children->next_child()) {
:
}
my $hdl = CA::AutoSys->new( [OPT] ) ;
Creates a new CA::AutoSys object.
Below is a list of valid options:
Specify the DSN of the AutoSys' database server to connect to. If nothing is specified, Sybase will be assumed: dbi:Sybase:server=<your_server> With this option you should be able to connect to databases other than Sybase.
This option is deprecated - rather use the dsn option. Specify the AutoSys' database server to connect to. Either this option or the dsn option above must be given. Please note, that when specifying this server option, a Sybase database backend is assumed.
Specify the database user. With an out-of-the-box AutoSys installation, the default user should work.
Specify the database password. With an out-of-the-box AutoSys installation, the default password should work.
Example:
my $hdl = CA::AutoSys->new(server => "AUTOSYS_DEV");
my $jobs = $hdl->find_jobs($jobname) ;
Finds jobs with a given name. When you have the wildcard character '%' somewhere in the job name, it will return all matching jobs, i.e.:
To find all jobs starting with the string 'MY_JOB':
$jobs = $hdl->find_jobs('MY_JOB%');
To find all jobs that have the string 'JOB' somewhere in the name:
$jobs = $hdl->find_jobs('%JOB%');
To find a job with an exact name:
$jobs = $hdl->find_jobs('JOB_42');
See also CA::AutoSys::Job
my $rc = $hdl->send_event( [OPT] ) ;
Sends an event to the given job. Returns 1 on success, 0 otherwise. At least the event name should be given. Depending on the event, more options may be necessary (see below). For details, consult your AutoSys' User Guide.
Below is a list of valid options:
The name of the job - no wildcards allowed.
Event name. The following list contains all available event names in alphabetical order:
ALARM CHANGE_PRIORITY CHANGE_STATUS
CHECK_HEARTBEAT CHK_BOX_TERM CHK_MAX_ALARM
CHK_N_START CHK_RUN_WINDOW COMMENT
DELETEJOB EXTERNAL_DEPENDENCY FORCE_STARTJOB
HEARTBEAT JOB_OFF_HOLD JOB_OFF_ICE
JOB_ON_HOLD JOB_ON_ICE KILLJOB
QUE_RECOVERY REFRESH_BROKER RESEND_EXTERNAL_STATUS
SEND_SIGNAL SET_GLOBAL STARTJOB
The job status when the event is CHANGE_STATUS. The following list contains all possible states for the CHANGE_STATUS event in alphabetical order:
ACTIVATED FAILURE INACTIVE
ON_HOLD ON_ICE QUE_WAIT
REFRESH_DEPENDENCIES REFRESH_FILEWATCHER RESTART
RUNNING STARTING SUCCESS
TERMINATED
Use this when you want to schedule an event at a given time. The argument should have the format 'YYYY/MM/DD HH:MM:SS'.
To force a job start at a given time:
my $rc = $hdl->send_event(job_name => 'HAPPY_NEW_YEAR', event => 'FORCE_STARTJOB',
event_time => '2007/12/31 23:59:59');
To mark an job as inactive:
my $rc = $hdl->send_event(job_name => 'JOB_42', event => 'CHANGE_STATUS', status => 'INACTIVE');
Make the interface more "perlish", e.g. return an array of jobs instead of forcing the user
to call next_job() / next_child().
Make the interface more "OO", e.g. allow the user to send an event directly from an CA::AutoSys::Job object
to the underlying job instead of having to use CA::AutoSys->send_event().
There are lots of missing AutoSys features, e.g. "alarms".
Sinisa Susnjar <sini@cpan.org>
See the CHANGES file.
Copyright (c) 2007 Sinisa Susnjar. All rights reserved.
This program is free software; you can use and redistribute it under the terms of the L-GPL. See the LICENSE file for details.
| CA-AutoSys documentation | Contained in the CA-AutoSys distribution. |
# # $Id: AutoSys.pm 68 2008-02-11 10:50:27Z sini $ # # CA::AutoSys - Perl Interface to CA's AutoSys job control. # Copyright (c) 2007 Sinisa Susnjar <sini@cpan.org> # See LICENSE for terms of distribution. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # package CA::AutoSys; require CA::AutoSys::Job; require CA::AutoSys::Status; use strict; use warnings; use DBI; use vars qw($VERSION); $VERSION = '1.05'; use Exporter; use vars qw(@ISA @EXPORT); @ISA = qw(Exporter); @EXPORT = qw(&new); our $errstr; sub new { my $self = {}; my $class = shift(); $errstr = ''; if (@_) { my %args = @_; $self->{dsn} = $args{dsn} ? $args{dsn} : undef; $self->{server} = $args{server} ? $args{server} : undef; $self->{user} = $args{user} ? $args{user} : undef; $self->{password} = $args{password} ? $args{password} : undef; } if (!defined($self->{dsn})) { if (!defined($self->{server})) { $errstr = "no dsn given in new()"; return undef; } # Default to Sybase when no dsn was given... $self->{dsn} = "dbi:Sybase:server=$self->{server}"; } $self->{dbh} = DBI->connect($self->{dsn}, $self->{user}, $self->{password}); if (!$self->{dbh}) { $errstr = "can't connect to dsn ".$self->{dsn}.": ".$DBI::errstr; return undef; } bless($self); return $self; } # new() sub find_jobs { my $self = shift(); my $job_name = shift(); my $job = CA::AutoSys::Job->new(parent => $self, database_handle => $self->{dbh}); return $job->find_jobs($job_name); } # find_jobs() sub send_event { my $self = shift(); my ($job_name, $event, $status, $event_time); if (@_) { my %args = @_; $job_name = $args{job_name} ? $args{job_name} : ''; $event = $args{event} ? $args{event} : ''; $status = $args{status} ? $args{status} : ''; $event_time = $args{event_time} ? $args{event_time} : ''; } my $sth = $self->{dbh}->prepare(qq{ exec sendevent '$event', '$job_name', '$status', '', '$event_time', '' }); $sth->execute(); my ($rc) = $sth->fetchrow_array(); return $rc; } # send_event() 1; __END__