RT4 allows for a new CustomField consisting of a validated ipv4 or ipv6 address, and also allows for multiple values. This allows me to have an “IP Addresses” custom field that has several addresses for a ticket.
I cannot seem to get a scrip that will accept multiple addresses from an email (or any correspond event for that matter), only one address will be accepted.
The scrip I am using is a custom action that looks like this:
my $Ticket = $self->TicketObj;
my $Transaction = $self->TransactionObj;
my $body = $Transaction->Content();
my $cf = new RT::CustomField($RT::SystemUser);
my $id;
my $msg;
my $queue = 'Testes';
#---IPS
if($body =~ /X-addresses\:(.*)\n/i){
my $iplist = $1;
($id,$msg) = $cf->LoadByNameAndQueue (Name=>'addresses', Queue=>$queue);
($id,$msg) = $Ticket->AddCustomFieldValue (Field => $cf, Value =>$iplist);
}
return(1);
I’m not opposed to being told I’m going about this the wrong way; present practice for my RT install is to have a web form submit requests, currently that request will have an IP address field that is picked up by a similar scrip (in addition to x-fqdn, x-contact, x-OS, and other information being collected) and I was thinking a comma-seperated list of mixed ipv4,ipv6 could be snarfed in one line and, as long as RT’s address parser validated it, we’d be in business.
Any suggestions would be appreciated, except those that direct me to the hideous BestPractical wiki, I have combed through every tumbleweed-ridden page and come up empty.
The problem here is that you only perform the regex once, and only get the first match. You sound like you want to loop through and find as many matches as you can. To demonstrate I made some quick perl scripts (I don’t have my RT installation in front of me, so I have left out the RT specific stuff).
The first works very similarly to yours, grabbing the first match and printing it:
The output of this script is:
The second demonstrates the syntax you want to use:
The output for this script is:
Instead of printing the $ip variable, you can pass it in to another function or method, such as AddCustomFieldValue.
To explain: The regex is changed slightly to use the g (or global) switch, indicating that it will search through the entire string rather than stopping at the first match
The if is changed to a while – you could probably do this with an if somehow – I just don’t know how. If you did, you would have to get all the matches in one variable – likely an array. After that you would need to iterate through the array anyway running AddCustomFieldValue for each element. My perl is not strong enough to figure it out using an if, but I think it’s a little more readable and neat with a while anyway.