Web request from custom scrip

Hi,

I’m trying to write a scrip that sends a web request to an external server
and depending on the answer set a specific priority level

So far the web request goes out and the priority can be set. The only
missing part is that I can’t get a hold of the external web server response.

Following, a few lines that I wrote in the ‘custom action commit’ section:

— code
require LWP::UserAgent;
my $ua = LWP::UserAgent->new;

my $url = ‘https://extwebserv/’.somePieceOfData;
my $response = $ua->get($url);

if ($response->is_success) {

FAILS!

RT::Logger->info($response->as_string); #decoded_content);

my $newpriority = 100;

my ($status, $msg) = $self->TicketObj->SetPriority($newpriority);
unless ($status) {
$RT::Logger->warning(“unable to set new priority value”);
return undef;
}
return 1;
}
— end code

Any help will be highly appreciated

Regards,

Hugo Escobar

http://www.associationfinancialservices.com/

4770 Biscayne Blvd, Ste 700
Miami, FL 33137

main: 305.677.0022
support: 305.921.4620
email: hescobar@afslc.com

Follow us on Facebook and Linked-In
http://www.facebook.com/pages/Miami-FL/ASSOCIATION-FINANCIAL/64952991864
http://www.linkedin.com/companies/1006276

NOTICE: This email and any attachment to this email may contain
confidential information. If you are not the intended recipient, you must
not review, retransmit, convert to hard copy, photocopy, use or disseminate
this email or any attachments to it. If you have received this email in
error, please notify us immediately by return email and delete this
message. Please note that if this email contains a forwarded message or is
a reply to a prior message, some or all of the contents of this message or
any attachments may not have been produced by our firm. As our firm may be
deemed a debt collector, if your payment is in default, we may be
attempting to collect a debt on behalf of the association, and any
information obtained may be used for that purpose.

Hi,

I’m trying to write a scrip that sends a web request to an external server
and depending on the answer set a specific priority level

So far the web request goes out and the priority can be set. The only
missing part is that I can’t get a hold of the external web server response.

Hi Hugo,

Firstly - Does https://extwebserv/ have a real certificate?

Try the following instead. I haven’t tested it but basically it tries the URL and sets the priority if it was successful. It also logs the response message (a short human readable single line string that explains the response code) regardless of what it was. It returns whatever $status is (if it’s set then it’ll be non-zero).

use LWP::UserAgent;

my $url = ‘https://extwebserv/’.somePieceOfData;
RT::Logger->info("Ticket “.$self->TicketObj->id.” Checking ".$url);
my $ua = LWP::UserAgent->new;
my $response = $ua->get($url);
my ($status, $msg); # Set these up as empty for now
($status, $msg) = $self->TicketObj->SetPriority(‘100’) if $response->is_success;
RT::Logger->info("Ticket “.$self->TicketObj->id.” ".$response->message);
return $status;

Landon Stewart : lstewart@iweb.com
Lead Specialist, Abuse and Security Management
Spécialiste principal, gestion des abus et sécurité
http://iweb.com : +1 (888) 909-4932

signature.asc (203 Bytes)

Hi Landon,

For some reason the result is not being written in log files (I’ll have to
check my RT_SiteConfig.pm :slight_smile:
I parsed the response directly and I got what I needed.

Thank youOn Thu, Apr 2, 2015 at 2:55 PM, Landon Stewart lstewart@iweb.com wrote:

On Apr 2, 2015, at 11:03 AM, Hugo Escobar hescobar@afslc.com wrote:

Hi,

I’m trying to write a scrip that sends a web request to an external server
and depending on the answer set a specific priority level

So far the web request goes out and the priority can be set. The only
missing part is that I can’t get a hold of the external web server
response.

Hi Hugo,

Firstly - Does https://extwebserv/ have a real certificate?

Try the following instead. I haven’t tested it but basically it tries the
URL and sets the priority if it was successful. It also logs the response
message (a short human readable single line string that explains the
response code) regardless of what it was. It returns whatever $status is
(if it’s set then it’ll be non-zero).

use LWP::UserAgent;

my $url = ‘https://extwebserv/’.somePieceOfData;
RT::Logger->info("Ticket “.$self->TicketObj->id.” Checking ".$url);
my $ua = LWP::UserAgent->new;
my $response = $ua->get($url);
my ($status, $msg); # Set these up as empty for now
($status, $msg) = $self->TicketObj->SetPriority(‘100’)
if $response->is_success;
RT::Logger->info("Ticket “.$self->TicketObj->id.” ".$response->message);
return $status;

Landon Stewart : lstewart@iweb.com
Lead Specialist, Abuse and Security Management
Spécialiste principal, gestion des abus et sécurité
http://iweb.com : +1 (888) 909-4932

Regards,

Hugo Escobar

http://www.associationfinancialservices.com/

4770 Biscayne Blvd, Ste 700
Miami, FL 33137

main: 305.677.0022
support: 305.921.4620
email: hescobar@afslc.com

Follow us on Facebook and Linked-In
http://www.facebook.com/pages/Miami-FL/ASSOCIATION-FINANCIAL/64952991864
http://www.linkedin.com/companies/1006276

NOTICE: This email and any attachment to this email may contain
confidential information. If you are not the intended recipient, you must
not review, retransmit, convert to hard copy, photocopy, use or disseminate
this email or any attachments to it. If you have received this email in
error, please notify us immediately by return email and delete this
message. Please note that if this email contains a forwarded message or is
a reply to a prior message, some or all of the contents of this message or
any attachments may not have been produced by our firm. As our firm may be
deemed a debt collector, if your payment is in default, we may be
attempting to collect a debt on behalf of the association, and any
information obtained may be used for that purpose.