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.

  • 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.

  • 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_Moniz's avatar
        Mike_Moniz
        Icon for Professor rankProfessor

        I would try as a test just "return 10" to see if even that works. If it does then perhaps try rebuilding your script in steps, like do the hostprops assignment and just return 10, then add one if statement, etc. See what exact line it's complaining about.

  • 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";
    }