3 Replies Latest reply on Oct 29, 2018 3:39 AM by Alvaro Paronuzzi

    Comparing Enum with String in MRL

    Alvaro Paronuzzi
      Share This:

      Hello everyone,

       

      in an MRL rule I am trying to compare the value of a slot defined as enum with the value of a slot defined as string. Is there any function/primitive to do this?

       

      Example of what I'm trying to do:

       

      if $EV.stringslot == tostring ($EV.enumslot)

       

      Where the enum slot value is defined as:

      1 ALPHA

      2 BETA

       

      and string slot contains ALPHA.

       

      Please don't tell me that I need a data table... :-)

       

      Thank you in advance for any help you can provide.

       

      Kind Regards,

      Alvaro Paronuzzi

        • 1. Re: Comparing Enum with String in MRL
          Kaushik KM

          Hi @Alvaro Paronuzzi

          Have you figured out yet ?
          if not could you Please post the class definition of the above two slots..

           

          Thanks,

          Kaushik KM

          • 2. Re: Comparing Enum with String in MRL
            Brendan Murray

            Hi Al,

             

            You were very close. It's not tostring, it's simply string. Here is an example (tested and working):

             

            refine enum_test :

                 EVENT ($EV) where [$EV.mc_object_class == 'test']

                      {

                          $SEV = 'CRITICAL';

             

                           if string($EV.severity) == $SEV

                           then

                               {

                                     $EV.msg = concat([string($EV.severity)," equals ",$SEV]);

                                }

                           else

                                {

                                     $EV.msg = concat([string($EV.severity)," does not equal ",$SEV]);

                                }

                           }

            END

             

            With this msend command:

             

            msend -n pncell_hostname -a EVENT -r MAJOR -b "mc_object_class=test"

             

            I get this message:

             

             

            With this msend command:

             

            msend -n pncell_hostname -a EVENT -r CRITICAL -b "mc_object_class=test"

             

            I get this message:

             

             

            No data table required. ;-)

             

            MRL has a pretty good selection of data type conversion functions. You will find them listed under Value type conversion primitives in the documentation.

             

            Regards,

             

            Brendan

            1 of 1 people found this helpful
            • 3. Re: Comparing Enum with String in MRL
              Alvaro Paronuzzi

              Thank you, Brendan!