Posted Thu, 01 Jan 2015 06:00:00 GMT by Portal Admin

Q:
Is there a way that I can test for an condition in the snmp-device-display section of a probe?

For example, if I polled a variable and it was defined or contained a string I could print a block of text. If that was undefined or failed do not display the text.

I’m trying to poll line card status in switches where one slot may be occupied on one switch but not on another.

It would be like this:

If defined($Slot1Status) {
Status: $Slot1Status
Name:$Slot1Name
Type:$Slot1Type
}

A:
There are three things you need to know about -- the eval macro, the 'defined'
function, and the ternary operator '?:'.

The eval macro is

${eval: [expr]}

and it lets you do calculations in the display section of the probe.

The 'defined' function returns 1 if the variable is defined, and 0 if not.
Please note that the way the 'defined' function works is to send it the *name* of the variable, not the actual variable.

This: defined('Slot1Status')

Not: defined($Slot1Status)

The last thing is the ternary operator ?: If you've worked with other programming languages, it's the same as the corresponding operator found in most languages related to C. If you haven't seen it before, it's a terse if-then, and the general form is

condition ? value-if-true : value-if-false

Putting these all together, you would use something like this:

${eval: defined("Slot1Status") == 1 ? "Status: ${Slot1Status}\nName:
${Slot1Name}\nType: ${Slot1Type}" : ""}


The probe calculations section of the DevGuide
(http://download.intermapper.com/docs/DevGuide/) expounds on these in much greater detail. The section on Built-in Variables has more on the 'eval' macro, too.

You must be signed in to post in this forum.