Script Processor Conditional

Hi,

I have a field - src-station-id in the logs that brings in IP and Hostnames as string.
Now in order to create a new field when src-station-id only contains IP, I am trying to get a script processor identify that as IP or String.

def fieldValue = ctx.src-station-id;
          if (fieldValue != null) {
            if (fieldValue instanceof String) {
              if (fieldValue =~ /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/) {
                ctx.sourcefieldType = "IP";
              } else {
                ctx.sourcefieldType = "String";
              }
            } else {
              ctx.sourcefieldType = "Not a String";
            }
          }

If ctx.sourcefieldType = IP , src-station-id will be converted to source.ip as IP type once identified correctly.
For some reason this script processor does not detect the IP correctly all the times. There must be a better way to handle it. Please suggest :slight_smile:

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.