7 Replies Latest reply on May 10, 2019 10:11 AM by Andrew Waters

    How to show a parameter value

    Ana Lorite
      Share:|

      Hi all,

       

      I have a report with a parameter and I'd like to show it as a part of the result. I mean:

       

      <report name="MyReport">

          <title>My title</title>

          <description>My description</description>

          <kind>DiscoveredListeningPort</kind>

          <show>

            name,

            local_port as 'Selected Port', #InferredElement:Inference:Primary:HostInfo.#DiscoveryResult:DiscoveryAccessResult:DiscoveryAccess:DiscoveryAccess.#DiscoveryAccess:DiscoveryAccessResult:DiscoveryResult:NetworkConnectionList.#List:List:Member:DiscoveredListeningPort.local_port as 'Opened ports'

          </show>

          <parameters>

              <parameter name="myparameter">

                  <title>Puerto</title>

                  <type name="TextField">

                    <size>5</size>

                  </type>

                  <where>local_port = %(value)s traverse Member:List:List:NetworkConnectionList traverse DiscoveryResult:DiscoveryAccessResult:DiscoveryAccess:DiscoveryAccess traverse DiscoveryAccess:DiscoveryAccessResult:DiscoveryResult:HostInfo traverse Primary:Inference:InferredElement:Host</where>

              </parameter>

          </parameters>

      </report>

       

      The column 'Selected Port' is "Not set" because of the traverse clause.

       

      Is it possible to show the value of the parameter?

       

      Thanks in advance.

       

      Ana.

        • 1. Re: How to show a parameter value
          Andrew Waters

          You should be able to do something like

          <show>

             name,

             %(local_port)s,

          and add <key> entry

          <parameter name="myparameter>

            <title>Puerto</title>

            ..

            <key>local_port</key>

          </parameter>

          • 2. Re: How to show a parameter value
            Ana Lorite

            Hi,

             

            Thanks for your help.

             

            I don't know if i understand the key tag.

             

             

            I modified the reports as you suggested:

             

            <show>

                  name,

                  %(local_port)s as 'Selected Port',

             

            <parameter name="MyParameter">

                        <title>Puerto</title>

                        <type name="TextField">

                          <size>5</size>

                        </type>

                        <key>local_port</key>

                        <where>local_port = %(value)s traverse Member:List:List:NetworkConnectionList traverse DiscoveryResult:DiscoveryAccessResult:DiscoveryAccess:DiscoveryAccess traverse DiscoveryAccess:DiscoveryAccessResult:DiscoveryResult:HostInfo traverse Primary:Inference:InferredElement:Host</where>

            </parameter>

             

            And I get a syntax error:

             

            Syntax Error = 1 : SEARCH DiscoveredListeningPort  SHOW name, local_port = 21 traverse Member:List:List:NetworkConnectionList traverse DiscoveryResult:DiscoveryAccessResult:DiscoveryAccess:DiscoveryAccess traverse DiscoveryAccess:DiscoveryAccessResult:DiscoveryResult:HostInfo traverse Primary:Inference:InferredElement:Host as 'Selected Port'

             

            It seems the local_port key contains all the <where> tag value

            • 3. Re: How to show a parameter value
              Andrew Waters

              You are going to need something like

              <reports version="2.0">

                <report name="MyReport">

                  <title>My title</title>

                  <description>My description</description>

                  <kind>DiscoveredListeningPort</kind>

                  <where>

                    local_port = %(local_port)d

                    traverse Member:List:List:NetworkConnectionList

                    traverse DiscoveryResult:DiscoveryAccessResult:DiscoveryAccess:DiscoveryAccess

                    traverse DiscoveryAccess:DiscoveryAccessResult:DiscoveryResult:HostInfo

                    traverse Primary:Inference:InferredElement:Host

                  </where>

                  <show>

                    name,

                    %(local_port)d as 'Selected Port',

                    #InferredElement:Inference:Primary:HostInfo.

                      #DiscoveryResult:DiscoveryAccessResult:DiscoveryAccess:DiscoveryAccess.

                      #DiscoveryAccess:DiscoveryAccessResult:DiscoveryResult:NetworkConnectionList.

                      #List:List:Member:DiscoveredListeningPort.local_port as 'Opened ports'

                  </show>

                  <parameters>

                    <parameter name="myparameter">

                      <title>Puerto</title>

                      <type name="TextField">

                        <convert>lambda x: int(x)</convert>

                        <size>5</size>

                      </type>

                      <key>local_port</key>

                    </parameter>

                  </parameters>

                </report>

              </reports>

              • 4. Re: How to show a parameter value
                Ana Lorite

                Oh! Thank you!

                 

                So many questions come to me but i will explore before to ask.

                 

                Yes, it works!!!!

                 

                I have this in the parameter:

                 

                            <type name="TextField">

                              <size>5</size>

                              <convert>lambda x: int(x)</convert>

                              <validate>NotEmpty</validate>

                              <validate>integer</validate>

                            </type>

                 

                Is it necessary the convert tag then?

                 

                Thank you, Andrew.

                 

                Ana.

                • 5. Re: How to show a parameter value
                  Danny Fleer

                  You need the convert to change the data type of the parameter from string to number. Otherwise the query would return no data because "0" (string) is not 0 (number) for example.

                  2 of 2 people found this helpful
                  • 6. Re: How to show a parameter value
                    Ana Lorite

                    Hi, Danny Fleer

                     

                    Thanks for your help!

                     

                    I see the next error in the tw_appserver.log

                     

                    WARNING: Error parsing /usr/tideway/data/custom/reports/01custom_reports.xml, line 140, column 31: Duplicate tag <validate>

                     

                    So I assume that only one instance of a tag validate is permited. And I write <validate>Not Empty</validate>

                     

                    If I insert a none value, I have this:

                             

                    what it is correct. But, If a insert a string "u", I have this error:

                     

                     

                    If  I replace <validate>Not Empty</validate> with <validate>integer</validate>, I have this:

                     

                     

                    what it's right. I confirm that a none value returns a invalid value too.

                     

                    Anyway, is it possible to validate more than once? I mean more than one validate tag.

                     

                    Thanks a million!!!

                    • 7. Re: How to show a parameter value
                      Andrew Waters

                      No, you cannot have more than one validate - it does not really make sense. integer by definition means it is not empty.

                      2 of 2 people found this helpful