6 Replies Latest reply on Oct 18, 2019 8:28 AM by Bernard Stern

    TPL regex.extract issue

    Bernard Stern
      Share This:

      Hello Community

       

      Trying to figure out why I am getting the following error when debugging a custom pattern.

       

      // $ /var/app/oud/oud_ed/OUD/bin/status --version

      // Oracle Unified Directory 11.1.2.3.181016

      // Build 20180830103720Z

      oud_cmd := '/var/app/oud/oud_ed/OUD/bin/status';

      if discovery.fileInfo(host, oud_cmd) then

        log.debug("OUD command exists = %oud_cmd%");

        output := discovery.runCommand(host, "%oud_cmd% --version | grep 'Oracle Unified Directory'");

        if output and output.result then

          log.debug("output.result = (%output.result%)");

          if output.result matches regex 'Oracle Unified Directory (\S+)' then

            log.debug ("OK regex match");

          else

            log.debug ("NOK regex not match");

          end if;

          raw_version := regex.extract(output.result, regex 'Oracle Unified Directory (\S+)', raw "\1");

        else

          log.debug ("could not extract output from command - check command output with regex.");

        end if;

      else

        log.debug("not enough privileges or command not found on %host.name%");

      end if;

       

      I am seeing the following debugging output:

       

      /etc/alternatives/jre_1.7.0/bin/java (115): 4603ms: OUD command exists = /var/app/oud/oud_ed/OUD/bin/status

      /etc/alternatives/jre_1.7.0/bin/java (115): 6726ms: output.result = (

      Oracle Unified Directory 11.1.2.3.181016

      )

      /etc/alternatives/jre_1.7.0/bin/java (115): 6726ms: OK regex match

      /etc/alternatives/jre_1.7.0/bin/java (115): 6734ms: RuleError on rule tpl_Server_body_2 due to: Error while executing a rule -- AttributeError: 'str' object has no attribute 'get'

       

      That does not look rocket science, but somehow I can't get it to work properly - I have tried some variations on the code but none worked. I am simply trying to get the complete version after the string 'Oracle Unified Directory'. The regex SEEMS to be OK as I am testing it before (for debugging purposes only).

        • 1. Re: TPL regex.extract issue
          Andrew Waters

          Why are you so sure it is the regex.extract and not something that follows? It looks okay.

          • 2. Re: TPL regex.extract issue
            Bernard Stern

            Well I am actually not 100% sure, but since there is nothing afer that statement excepting the end statements, that looks like the best candidate, but it looks bloody OK to me as well. Here is the complete body of the pattern. Note that for debugging purposes there is a lot that can be removed afterwards.

             

              triggers

                on process := DiscoveredProcess where cmd matches unix_cmd "java"

                              and args matches regex "\boud_ed\b";

              end triggers;

             

              body

                // Host and cluster information.

                host := model.host(process);

                hosting_node := related.hostingNode(fallback_kind := "Cluster");

                log.debug("Hostname: " + hosting_node.name);

             

                // Initialize variables.

                si_key := '';

                si_type := '';

                si_short_type := '';

                si_name := '';

                si_short_name := '';

                si_instance := '';

                si_version := '';

                si_fullversion := '';

                package_regex := '';

             

                // Oracle Unified Directory Server specification.

                si_type := 'Oracle Unified Directory Server';

                si_short_type := 'OUD';

                si_short_name := si_short_type;

                log.debug("short SI type = %si_short_type%, SI type = %si_type%");

             

                // ODSP AV: the version should be based on command:

                // $ /var/app/oud/oud_ed/OUD/bin/status --version

                // Oracle Unified Directory 11.1.2.3.181016

                // Build 20180830103720Z

                oud_cmd := '/var/app/oud/oud_ed/OUD/bin/status';

                if discovery.fileInfo(host, oud_cmd) then

                  log.debug("OUD command exists = %oud_cmd%");

                  output := discovery.runCommand(host, "%oud_cmd% --version | grep 'Oracle Unified Directory'");

                  if output and output.result then

                    log.debug("output.result = (%output.result%)");

                    if output.result matches regex 'Oracle Unified Directory (\S+)' then

                      log.debug ("OK regex match");

                    else

                      log.debug ("NOK regex not match");

                    end if;

                    raw_version := regex.extract(output.result, regex 'Oracle Unified Directory (\S+)', raw "\1");

                  else

                    log.debug ("could not extract output from command - check command output with regex.");

                  end if;

                else

                  log.debug("not enough privileges or command not found on %host.name%");

                end if;

             

              end body;

             

            end pattern;

            • 3. Re: TPL regex.extract issue
              Andrew Waters

              Do you have more details on the error?

               

              Is this pattern calls Server?

              • 4. Re: TPL regex.extract issue
                Bernard Stern

                Hi Andrew,

                 

                I stopped and started the tideway stack - no changes, still the same error. I also tried to print a debug output immediately after the regex.extract statement, this would not print. That lead me to conclude that the regex.extract was somehow not OK.

                Now I rewrote the regex.extract statement - no copy paste at all - uploaded it - and now it works.

                Any invisible character? No idea. Really not! Do you have some similar experiences?

                • 5. Re: TPL regex.extract issue
                  Brice-Emmanuel Loiseaux

                  I remember having issues with quotes if cut and pasted from windows...

                  1 of 1 people found this helpful
                  • 6. Re: TPL regex.extract issue
                    Bernard Stern

                    I definitely cut and pasted from windows, so this may well be it...