Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: updated info about string quoting and what language we're using

...

NMIS version 8.4.8G and later support modelling such scenarios using custom variables, or CVARs. With this mechanism you can temporarily capture up to 10 separate SNMP properties as a CVAR and define an arbitrarily complex expression (in perl) that transforms these CVARs into the one measurement that you want to collect and/or display.

...

In both cases the syntax is very straight-forward:

  • The expression must be a valid perl statement and return exactly one value.
  • The tokens $r, and CVAR0 to CVAR9 are interpreted by NMIS; everything else is perl.
  • Defining and using local variables with my is ok, but don't attempt to change any global NMIS variables.
  • "CVAR1=some_snmp_var;" defines what SNMP object CVAR1 is supposed to hold. The parser understands CVAR0 to CVAR9 for a total of 10 captures.
  • "return $r/$CVAR1;" accesses the value of CVAR1 in an expression. The variable "$r" represents the SNMP variable that the calculate expression is attached to.

Please note that the $CVARn replacement in the expression is performed on a purely textual basis, before the expression is handed to the perl interpreter for evaluation :

  • For string variables you have to provide quotes in your expression, e.

...

  • g.

    Code Block
    calculate => 'CVAR1=somestringthing; return 42 if ("$CVAR1" eq "online");'
  • Numeric variables can be used straight without quotes.