How to retrieve all IPs from CustomFieldValues('IP')

Good afternoon,

Hope everything is fine with you.

I want to retrieve all IPs inside the CustomFieldValues(‘IP’)

my $ips = $self->TicketObj->CustomFieldValues(‘IP’);

But it returns RT::ObjectCustomFieldValues=HASH(0xe4f43d8)

How can I “decode” this HASH to real IP’s?

Thank you very much

You can iterate with a while loop:

my $ips = $self->TicketObj->CustomFieldValues(‘IP’);
while ( my $ip = $ips->Next ) {
    # Do something
}

Thank you, but does not work, on rt.log:

[Thu Sep 30 16:05:53 2021] [error]: Scrip 105 Prepare failed: Can't call method "Next" without a package or object reference at (eval 3178) line 12.

Can you show the scrip code

Custom action preparation code:

use warnings;
use LWP::UserAgent;
require HTTP::Request;
use JSON::PP;
use Try::Tiny;
use Data::Dumper;
my $ip;

my $ips = $self->TicketObj->FirstCustomFieldValue('IP');
my $t_id = $self->TicketObj->Id;

#Debbug
while ( $ip = $ips->Next ) {

   $RT::Logger->error( "$ip"); 

}

my $api_url = "URL/api";
my $api_key = "TOKEN";
my $request; 
my $response_content;
my $decoded;
my $job_id;

my $cortex_analyzer_id = 'ANALYZER ID';
my $run_analyzer_uri = "${api_url}/analyzer/${cortex_analyzer_id}/run";
my $json = "{
            \"data\": \"$ip\",
            \"dataType\":\"ip\",
            \"tlp\":0,
            \"message\": \"A message that can be accessed from the analyzer\"
        }";

$request = HTTP::Request->new(POST => $run_analyzer_uri);
$request->header( 'Content-Type' => 'application/json' );
$request->header( 'Authorization' => $api_key);
$request->content( $json );

my $ua = LWP::UserAgent->new;
my $response = $ua->request($request);

if ( $response->is_success() ) {

$response_content = $response->decoded_content;
$decoded = decode_json($response_content);
$job_id = $decoded->{id};
system("echo $job_id,$t_id,$ip > /var/log/ip_analyzer.txt");
return 1;
}

My guess is you’re not getting a collection back but just a string here. Previously you were using the CustomFieldValues method

Yes I am using CustomFieldValues I just made a test before and forgot to remove the new changes

1 Like
my $ips = $self->TicketObj->CustomFieldValues('IP');
my $t_id = $self->TicketObj->Id;

#Debbug
while ( $ip = $ips->Next ) {
    print $ip->Content; 
}
1 Like

It is working

Thank you very much!