Forum Discussion

Darren_Dudgeon's avatar
3 years ago

virtual datapoint - how to preform expression valuation if statement

Hi Community,

I'm trying to create a complex datapoint that evaluates NAN values as 0 (Zero) using the documented information from logicmonitor and cannot find example or explanation of how to evaluate expression in the if statement.

> according to this - Complex Datapoints | LogicMonitor i can create an if statement and evaluate it like this:

if(or(un(Datapoint1), un(Datapoint2)), unkn(), <expression to evaluate>)

So how do i evaluate against greater than Zero? I have tried may basic operations within the <expression to evaluate>  area with no success.

 

if(un(datapointX),0,datapointX, > 0)  <--- this does not work
{
    myStatus = 1;
}
else
{
    myStatus = 0;
}

return(myStatus);

 

Thanks in advance for your assistance.

 

Darren

3 Replies

  • The operators in this mini-language are a bit incomplete and I get annoyed regularly.  For example, there is no negation (not) and there is no ne (not-equal) condition.  You can workaround it, but it is a weird miss.

    You also cannot format it the way shown, though -- it has to all be RPN (reverse polish) or (possibly) all groovy code.  See https://www.logicmonitor.com/support/logicmodules/datasources/datapoints/complex-datapoints for an overview.

    This should work for your example (I think -- it is untested other than verifying parens match):

    if(un(datapointX),0,if(gt(datapointX,0),1,0))

     

  • 14 minutes ago, mnagel said:

    The operators in this mini-language are a bit incomplete and I get annoyed regularly.  For example, there is no negation (not) and there is no ne (not-equal) condition.  You can workaround it, but it is a weird miss.

    You also cannot format it the way shown, though -- it has to all be RPN (reverse polish) or (possibly) all groovy code.  See https://www.logicmonitor.com/support/logicmodules/datasources/datapoints/complex-datapoints for an overview.

    This should work for your example (I think -- it is untested other than verifying parens match):

    if(un(datapointX),0,if(gt(datapointX,0),1,0))

     

    Mnagel,

    Thank-you for the quick and appropriate reply and the information on PRN/groovy - that helps. 

    It would certainly be great if there was better documentation for this. I have tried your syntax and tried a few modifications to it as well without success.

    Unfortunately i still get invalid syntax in all formulations i have tried. 

     

  • Anonymous's avatar
    Anonymous

    What you need is a nested if statement.

    if( un(DatapointX), 0, if( gt(DatapointX,0),1, -1))

    This means:

    if(
      un(DatapointX),   <-- this is your condition (conditionA)
      0,                         <-- return this if conditionA is true
      if(                          <-- do another if statement if conditionA is false
        gt(DatapointX,0),  <--We know conditionA is false, let's do another condition (conditionB) , in this case if DatapointX is greater than 0.
        1,                          <--return this if conditionB is true
        2                         <-- return this if conditionB is false
        )
      )