ARS-Simple

 view release on metacpan or  search on metacpan

Config.PL  view on Meta::CPAN

# Config.PL
#
# Configuration file generation for ARS::Simple

# Just to tell make we are done with configuring
open CFG, '>', 'Config';
print CFG "\n";
close CFG;

# Are we being run from ActiveStates PPM
if ($0 =~ /\.PPM$/i)
{
    print "Running from PPM...\n\n";
    chdir '..';

    # find ARS::Simple.pm
    foreach $dir (@INC)
    {
        if (-e $dir.'/ARS/Simple.pm')
        {
            $configfile = $dir.'Simple.cfg';
            last;
        }
    }
    unless ($configfile)
    {
        print STDERR "The module ARS::Simple.pm is not found. Are you realy running the script via PPM install?\n";
        <STDIN>;
        exit(1);
    }
}
else
{
    # called directly
    unless (-d 'blib/lib')
    {
        die "Do not execute this script directly, run:\n\tperl Makefile.PL

Config.PL  view on Meta::CPAN

    }
}

if (($configfile && -f $configfile) || -f 'blib/lib/ARS/Simple.cfg') { exit; }

my $user     = '';
my $password = '';
my $proxy    = '';
unless ($ENV{PERL_MM_USE_DEFAULT} || $ENV{AUTOMATED_TESTING} || !-t STDIN)
{
    print "\n================ Set the defaults for module ARS::Simple ================\n";
    print "\nSpecify defaults for ARS::Simple? (y/N) ";
    $res = <STDIN>;
    exit unless $res =~ /^y$/i;

    if (! $configfile)
    {
        print "\n\t... will be saved to .../lib/ARS/Simple.cfg\n";
        $configfile = 'blib/lib/ARS/Simple.cfg';
    }
    else
    {
        print "\n\t... will be saved to $configfile\n";
    }

    #exit if -f $configfile;

    # Gather the defaults
    print "\nDefault user to use for Remedy: ";
    $user = <STDIN>;
    $user =~ s/^\s+//;
    $user =~ s/\s+$//;

    print "Password for user '$user': ";
    $password = <STDIN>;
    $password =~ s/^\s+//;
    $password =~ s/\s+$//;

    print "\nSaving config file, using the following:\n";
}

if (! $configfile)
{
    $configfile = 'blib/lib/ARS/Simple.cfg';
}
open $fh, '>', $configfile || die "failed to open $configfile: $!";
print $fh "# Config file for ARS::Simple\n# generated by Config.PL (".scalar(localtime).")\n# This file MUST be valid perl (as it is 'required')\n# Note user and password are obfuscated, NOT encrypted.\n\n";
print $fh q{%config = (} . "\n";

# Doing simple obfuscation of user and password
my $k = '5Jv@sI9^bl@D*j5H3@:7g4H[2]d%Ks314aNuGeX;';
my $x = substr($k, 0, length($user));
my $u = $user ^ $x;
my $up = unpack('H*', $u);
print $fh "\tuser     => '$up',\n";

$x = substr($k, 0, length($password));
$u = $password ^ $x;
$up = unpack('H*', $u);
print $fh "\tpassword => '$up',\n";
print $fh ");\n1;\n#--< End of File >--#\n";
close $fh;

unless ($ENV{PERL_MM_USE_DEFAULT} || $ENV{AUTOMATED_TESTING} || !-t STDIN)
{
    print "\tuser     => '$user' (obfuscated),\n";
    print "\tpassword => '$password' (obfuscated),\n";
    print "\nFinished configuration\n";
}


#####################################################################
# DO NOT REMOVE THE FOLLOWING LINE, IT IS NEEDED TO LOAD THIS LIBRARY
1;

#---< End of File >---#

Makefile.PL  view on Meta::CPAN

        ARS     => 1.68,
    },
    dist  => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
    clean => { FILES => 'ARS-Simple-*' },
);

makeTestConfig();

if (!$ENV{AUTOMATED_TESTING})
{
    print "
    Type 'make' (windows: 'nmake' or 'dmake') to build ARS::Simple.
    Type 'make test' to test ARS::Simple before installing.
    Type 'make install' to install ARS::Simple.

    ";
}

exit 0;


Makefile.PL  view on Meta::CPAN

    my ($i, $u, $p) = ('', $ENV{USERNAME}, '');

    if(-e './t/config.cache')
    {
        do './t/config.cache';
        $i = &CCACHE::server;
        $u = &CCACHE::user;
        $p = &CCACHE::password;
    }

    print "=== ARS::Simple 'make test' configuration. ===

Test on your own dev system where you know the user you select below
is in the administrator group.

Please enter the following information. This information will be
recorded in ./t/config.cache.  YOU SHOULD REMOVE this file once
you have finished testing as the data is in plain text.

As an alternate, skip testing and install and start trying it out!

Makefile.PL  view on Meta::CPAN

    $server = prompt("The Remedy server hostname (or IP Address)", $i);
    if ($server eq '') { $server = $i if ($i ne ''); }

    $user = prompt("Remedy user with admin", $u);
    if($user eq '') { $user = $u if ($u ne ''); }

    $password = prompt("Password", $p);;
    if($password eq '') { $password = $p if ($p ne ''); }

    open (FD, '>', './t/config.cache') || die "open of './t/config.cache' failed: $!";
    print FD "package CCACHE;\n";
    print FD "\# enter your remedy server, username and password below.\n\n";
    print FD qq{sub server { '$server' ; }\n};
    print FD qq{sub user     { '$user' ; }\n};
    print FD qq{sub password { '$password' ; }\n};
    print FD "1;\n";
    close(FD);
}

examples/generate_fid_hash.pl  view on Meta::CPAN

use ARS::Simple;
use Win32::Clipboard;

my $CLIP = Win32::Clipboard();
my $ars  = ARS::Simple->new({
        server   => 'dev_machine',
        user     => 'greg',
        password => 'password',
        });

print "Enter the name of the Remedy form: ";
my $form = <STDIN>;
chomp $form;

#----------
my $sql = qq{select
f.fieldName,
f.fieldID,
decode(FOption, 1, 'Required ', 2, 'Optional ', 3, 'System RO', '*Unknown*'),
decode(datatype, 0, 'AR_DATA_TYPE_NULL', 1, 'AR_DATA_TYPE_KEYWORD', 2, 'AR_DATA_TYPE_INTEGER', 3, 'AR_DATA_TYPE_REAL', 4, 'AR_DATA_TYPE_CHAR', 5, 'AR_DATA_TYPE_DIARY', 6, 'AR_DATA_TYPE_ENUM', 7, 'AR_DATA_TYPE_TIME', 8, 'AR_DATA_TYPE_BITMASK', 9, 'AR_...
c.maxlength

examples/generate_fid_hash.pl  view on Meta::CPAN

# [ 'ChangeLicenseUsed'        , 220000003,    '*Unknown*', 'AR_DATA_TYPE_INTEGER', undef ],
# [ 'HelpDeskLicenseUsed'      , 220000004,    '*Unknown*', 'AR_DATA_TYPE_INTEGER', undef ],
# [ 'NumberofLicenseAvailable' , 220000000,    '*Unknown*', 'AR_DATA_TYPE_INTEGER', undef ],
# [ 'SLALicenseUsed'           , 220000001,    '*Unknown*', 'AR_DATA_TYPE_INTEGER', undef ],
# ],
# };


unless ($m && $m->{numMatches})
{
    print "No data returned, quitting\n";
    exit;
}

# Check size and replace spaces with '_', you could also remove them!
my $max_len = 0;
foreach my $row (@{ $m->{rows} })
{
    $row->[0] =~ s/\s+/_/gms;
    if (length($row->[0]) > $max_len)
    {
        $max_len = length($row->[0]);
    }
}

# Construct the hash
my $fid_hash = "# Label/FID hash for form '$form'\n\%fid = (\n";
foreach my $row (@{ $m->{rows} })
{
    $fid_hash .= sprintf("    '%s'%s=> %10d,\t\t# %s type=%s %d\n", $row->[0], ' ' x ($max_len + 1 - length($row->[0])), $row->[1], $row->[2], $row->[3], $row->[4]);
}
$fid_hash .= "    );\n";

$CLIP->Set($fid_hash);
print "$fid_hash\nFormatted data copied to clipboard\n";

examples/get_data_by_label.pl  view on Meta::CPAN

        'SLALicenseUsed'           => 220000001,    # *Unknown* type=AR_DATA_TYPE_INTEGER
        );

my $data = $ars->get_data_by_label({
        form        => 'User',
        query       => '1=1',
        lfid        => \%fid,
        max_returns => 50,
        });

print Dumper($data), "\n";

examples/get_list.pl  view on Meta::CPAN

# Get the Entry-Id of all User form records

my $ars = ARS::Simple->new({
        server   => 'dev_machine',
        user     => 'greg',
        password => 'password',
        });

my $eids = $ars->get_list({ form => 'User', query => '1=1', });

print Dumper($eids), "\n";

html/Simple.html  view on Meta::CPAN

     <span class="string">user</span>     <span class="operator">=&gt;</span> <span class="string">'admin'</span><span class="operator">,</span>
     <span class="string">password</span> <span class="operator">=&gt;</span> <span class="string">'admin'</span><span class="operator">,</span>
     <span class="operator">}</span><span class="operator">);</span>
 
 <span class="comment"># Get the Entry-ID/Request-ID for all User's with Login starting with 'g'</span>
 <span class="comment"># Here $eid is any array reference of entry-id/request-id values</span>
 <span class="keyword">my</span> <span class="variable">$eid</span> <span class="operator">=</span> <span class="variable">$ar</span><span class="operator">-&gt;</span><span class="variable">get_list</span><span class="operator">(</span><span class="...
     <span class="string">form</span>  <span class="operator">=&gt;</span> <span class="string">'User'</span><span class="operator">,</span>
     <span class="string">query</span> <span class="operator">=&gt;</span> <span class="string">qq{'Login' LIKE "g%"}</span><span class="operator">,</span>
     <span class="operator">}</span><span class="operator">);</span>
 <span class="keyword">print</span> <span class="variable">Data::Dumper</span><span class="operator">-&gt;</span><span class="variable">Dump</span><span class="operator">(</span><span class="operator">[</span><span class="variable">$eid</span><span c...
 
 <span class="comment"># Get data from a form, based on a query (as you would use in the User Tool)</span>
 <span class="keyword">my</span> <span class="variable">%lfid</span> <span class="operator">=</span> <span class="operator">();</span>
 <span class="keyword">my</span> <span class="variable">$form</span>  <span class="operator">=</span> <span class="string">'User'</span><span class="operator">;</span>
 <span class="keyword">my</span> <span class="variable">$query</span> <span class="operator">=</span> <span class="string">qq('FID' = "value")</span><span class="operator">;</span>
 <span class="keyword">my</span> <span class="variable">$data</span> <span class="operator">=</span> <span class="variable">$ar</span><span class="operator">-&gt;</span><span class="variable">get_data_by_label</span><span class="operator">(</span><sp...
 <span class="string">form</span>  <span class="operator">=&gt;</span> <span class="variable">$form</span><span class="operator">,</span>
 <span class="string">query</span> <span class="operator">=&gt;</span> <span class="variable">$query</span><span class="operator">,</span>
 <span class="string">lfid</span>  <span class="operator">=&gt;</span> <span class="operator">{</span> <span class="variable">label1</span><span class="operator">,</span> <span class="variable">fid1</span><span class="operator">,</span> <span class="...
 <span class="operator">}</span><span class="operator">);</span>

lib/ARS/Simple.pm  view on Meta::CPAN


    my $rv = ars_SetEntry($self->{ctl}, $form, $eID, 0, %lvp);

    # Check for errors
    unless (defined $rv && $rv == 1)
    {
        # Update failed
        my $msg = "update_record(eid=$eID, form=$form, ...) failed:\nars_errstr=$ars_errstr\nlvp data was:\n";
        foreach my $label (sort keys %{$args->{lvp}})
        {
            $msg .= sprintf("%30s (%10d) ---> %s\n", $label, $args->{lfid}{$label}, defined($lvp{$args->{lfid}{$label}}) ? $lvp{$args->{lfid}{$label}} : '<undefined>');
        }
        carp($msg);
    }
    return $rv;
}

sub get_ctl
{
    my $self = shift;

lib/ARS/Simple.pm  view on Meta::CPAN

    else
    {
        croak(__PACKAGE__ . " object initialisation failed, server, user and password are required\n");
    }
}


    # GG test - need to find and store the current value of AR_SERVER_INFO_MAX_ENTRIES
    #           so we can set reset_limit if not defined
    #my %s = ars_GetServerInfo($self->{ctl});
    #print  Dumper(\%s);


1; # End of ARS::Simple


__END__

=head1 NAME

ARS::Simple - A simplified interface to Remedy ARSystem

lib/ARS/Simple.pm  view on Meta::CPAN

     user     => 'admin',
     password => 'admin',
     });

 ### Get the Entry-ID/Request-ID for all User's with Login starting with 'g'
 # Here $eid is any array reference of entry-id/request-id values
 my $data = $ar->get_list({
     form  => 'User',
     query => qq{'Login' LIKE "g%"},
     });
 print Data::Dumper->Dump([$data], ['data']), "\n";
 # Resulting data dump:
 # $data = {
 #   'eids' => [
 #     '000000000004467',
 #     '000000000004469',
 #     '000000000004470',
 #   ],
 #   'numMatches' => 3
 #};

 ### Get data from a form, based on a query (as you would use in the User Tool)
 my $form  = 'User';
 my $entryListLabel = $ar->get_data_by_label({
     form  => $form,
     query => qq{'Login Name' LIKE "ge%"},  # Login Name = FID 101
     lfid  => { 'LoginName', 101, 'FullName', 8, 'LicenseType', 109, },
     });
 print Data::Dumper->Dump([$entryListLabel], ['entryListLabel']), "\n";
 # Resulting data dump:
 # $entryListLabel = {
 #  '000000000014467' => {
 #    'FullName' => 'Geoff Batty',
 #    'LicenseType' => 0,
 #    'LoginName' => 'gbatty'
 #  },
 #  '000000000014469' => {
 #    'FullName' => 'Greg George',
 #    'LicenseType' => 2,

t/00-load.t  view on Meta::CPAN

#!perl -T
use 5.006;
use strict;
use warnings FATAL => 'all';
use Test::More;

plan tests => 1;

BEGIN {
    use_ok( 'ARS::Simple' ) || print "Bail out!\n";
}

diag( "Testing ARS::Simple $ARS::Simple::VERSION, Perl $], $^X" );



( run in 0.924 second using v1.01-cache-2.11-cpan-de7293f3b23 )