Forum Discussion

Egis's avatar
Egis
Icon for Neophyte rankNeophyte
4 days ago

Complex datapoint - groovy script to calculate the value from the device property

Hi All,

I have a case where I need to take AWS device property called ##system.aws.bandwidth## that can have values 1Gbps, 10Gbps or 50Gbps, convert it to bytes and return the value to the datapoint. I'm trying to use groovy script for complex datapoint but can't get it to work even with the most simple scripts: "Error Invalid enum value, must be EXPRESSION".

Example script:

    if ('##system.aws.bandwidth##' == '1Gbps') {
        return 1000000000
    } else if ('##system.aws.bandwidth##' == '10Gbps') {
        return 10000000000
    } else if ('##system.aws.bandwidth##' == '50Gbps') {
        return 50000000000
    } else {
        return 0
    }

Has anyone tried to create something similar? What I'm doing wrong?

Thanks.

  • You can't use ## in groovy.  I think those are reserved for PowerShell.  

    Try something like this.  You can do hostProps.get or instanceProps.get depending on where the property is.

    def answer = instanceProps.get("auto.myproperty123");
    if(answer == "true")
    {
        return "0";
    }
    if(answer == "false")
    {
        return "1";
    }

  • I don't understand the specific error message but using '##token##' thing is more for powershell. For Groovy you would use something like bandwidth = hostProps.get("system.aws.bandwidth") instead (see https://www.logicmonitor.com/support/logicmodules/datasources/datapoints/complex-datapoints#groovy). Also is that an LM Cloud device? I'm not sure if you can use groovy with a LM cloud collector.

    • Egis's avatar
      Egis
      Icon for Neophyte rankNeophyte

      Yes, I tried to use both - hostProps and token. This is LM Cloud so I might need to check with the vendor probably.

      • Mike_Rodrigues's avatar
        Mike_Rodrigues
        Icon for Product Manager rankProduct Manager

        I'd guess it has something to do with it being LM Cloud.

        Is there a collector assigned to that resource? If not, the Groovy CDP won't have a place to run.

        ##TOKENS## should work in Groovy or Powershell, it's just string replace. hostProps, taskProps, instanceProps are preferred (and more performant, as the script can avoid recompilation for different values)

  • Have you tried doing this inside of the script itself instead of a complex datapoint? Then return the value as a standard datapoint?

    • Egis's avatar
      Egis
      Icon for Neophyte rankNeophyte

      I can't do it because the data is collected via AWS CloudWatch collection method where we cannot perform any changes.