Forum Discussion

SteveBamford's avatar
3 years ago
Solved

Creating a Complex Data Source to check the Interface Description and then the state of an interface to generate an alert.

The plan is on our switches we include "MO-CRIT" in the description if we want to generate an alert within LogicMonitor, it is fairly obvious to me that we need to create the datasource using Groovy which I have done, but when ever  I run I get the following for the data source "Exception=No Such Property: output for class: Scriptnnn

I have set up the variable name IntName and have tried the system.instanceDescription and the auto.interface.alias nether seem to work

  def IntName=taskProps.get('system.instanceDescription') (I have tried instanceProps.get)

Any suggestions.
 

 

  • Anonymous's avatar
    Anonymous
    3 years ago

    Just a recommendation, but why rebuild that datasource? I suggest modifying the discovery script to output an additional instance level property with value 0 or 1 depending on whether or not the description contains the "MO-CRIT" string. This would involve changing one line of code and adding one datapoint.

    Using the SNMP_Network_Interfaces datasource, look at line 173 of the discovery script. This line outputs the list of instances:

    println "${ifIndex}##${ifEntry.description} [ID:${ifIndex}]##${description}####${ifEntry.collect { "auto.interface.${it}" }.join("&")}"

    Remember from AD that there are 5 terms here, divided by ##:

    1. Wildvalue - unique identifier
    2. Wildalias - display name
    3. Wildvalue2 - not used much
    4. Description - instance description, which in this case is a modified version of the interface description
    5. Instance level properties list - this list is comprised of key value pairs. the pair is separated by =, and the pairs are separated from other pairs by &.

    So in this case, we have ifIndex as the wildvalue, "ifEntry.description + [ID:ifIndex]"as the display name, a modified description as the description and we have a list of instance level properties.

    Let's look at the instance level properties a little closer:

    ifEntry.collect { "auto.interface.${it}" }.join("&")

    This is some advanced Groovy syntax, but it basically takes the contents of ifEntry, which is a Groovy Map (similar to Python dict). For one of the interfaces on one of my devices, ifEntry looks like this:

    [ifIndex:13, name:cpu, description: CPU Interface for Slot: 5 Port: 1, mac:c4:04:15:b3:d4:d7, type:other, mtu:1500, alias:, speed:0, has_traffic:true, operational.state:up, admin.state:up]

    So, the AD script would output something like this for that interface (forgive the horizontal scrolling/carriage return, this is actually one line):

    13## CPU Interface for Slot: 5 Port: 1 [ID:13]##cpu - c4:04:15:b3:d4:d7####auto.interface.ifIndex=13&auto.interface.name=cpu&auto.interface.description= CPU Interface for Slot: 5 Port: 1&auto.interface.mac=c4:04:15:b3:d4:d7&auto.interface.type=other&auto.interface.mtu=1500&auto.interface.alias=&auto.interface.speed=0&auto.interface.has_traffic=true&auto.interface.operational.state=up&auto.interface.admin.state=up

    One thing we could do would be to add to this println statement in the AD script to evaluate the description and return a 0 or 1 if the description contains "MO-CRIT". This could be done like this:

    println "${ifIndex}##${ifEntry.description} [ID:${ifIndex}]##${description}####${ifEntry.collect { "auto.interface.${it}" }.join("&")}&auto.interface.alert_on_desc=${ifEntry.description.contains("MO-CRIT")?1:0}"

    This would set an instance level property called auto.interface.alert_on_desc with a value of either 0 or 1.

    Then you could create a datapoint called alert_on_desc with ##auto.interface.alert_on_desc## as the infix expression. This will get a 0 or 1 into the datapoint, which could be used in any datapoints that alert to turn the alert on or off.

2 Replies

  • Anonymous's avatar
    Anonymous

    Just a recommendation, but why rebuild that datasource? I suggest modifying the discovery script to output an additional instance level property with value 0 or 1 depending on whether or not the description contains the "MO-CRIT" string. This would involve changing one line of code and adding one datapoint.

    Using the SNMP_Network_Interfaces datasource, look at line 173 of the discovery script. This line outputs the list of instances:

    println "${ifIndex}##${ifEntry.description} [ID:${ifIndex}]##${description}####${ifEntry.collect { "auto.interface.${it}" }.join("&")}"

    Remember from AD that there are 5 terms here, divided by ##:

    1. Wildvalue - unique identifier
    2. Wildalias - display name
    3. Wildvalue2 - not used much
    4. Description - instance description, which in this case is a modified version of the interface description
    5. Instance level properties list - this list is comprised of key value pairs. the pair is separated by =, and the pairs are separated from other pairs by &.

    So in this case, we have ifIndex as the wildvalue, "ifEntry.description + [ID:ifIndex]"as the display name, a modified description as the description and we have a list of instance level properties.

    Let's look at the instance level properties a little closer:

    ifEntry.collect { "auto.interface.${it}" }.join("&")

    This is some advanced Groovy syntax, but it basically takes the contents of ifEntry, which is a Groovy Map (similar to Python dict). For one of the interfaces on one of my devices, ifEntry looks like this:

    [ifIndex:13, name:cpu, description: CPU Interface for Slot: 5 Port: 1, mac:c4:04:15:b3:d4:d7, type:other, mtu:1500, alias:, speed:0, has_traffic:true, operational.state:up, admin.state:up]

    So, the AD script would output something like this for that interface (forgive the horizontal scrolling/carriage return, this is actually one line):

    13## CPU Interface for Slot: 5 Port: 1 [ID:13]##cpu - c4:04:15:b3:d4:d7####auto.interface.ifIndex=13&auto.interface.name=cpu&auto.interface.description= CPU Interface for Slot: 5 Port: 1&auto.interface.mac=c4:04:15:b3:d4:d7&auto.interface.type=other&auto.interface.mtu=1500&auto.interface.alias=&auto.interface.speed=0&auto.interface.has_traffic=true&auto.interface.operational.state=up&auto.interface.admin.state=up

    One thing we could do would be to add to this println statement in the AD script to evaluate the description and return a 0 or 1 if the description contains "MO-CRIT". This could be done like this:

    println "${ifIndex}##${ifEntry.description} [ID:${ifIndex}]##${description}####${ifEntry.collect { "auto.interface.${it}" }.join("&")}&auto.interface.alert_on_desc=${ifEntry.description.contains("MO-CRIT")?1:0}"

    This would set an instance level property called auto.interface.alert_on_desc with a value of either 0 or 1.

    Then you could create a datapoint called alert_on_desc with ##auto.interface.alert_on_desc## as the infix expression. This will get a 0 or 1 into the datapoint, which could be used in any datapoints that alert to turn the alert on or off.

  • Great followed this through and looks to be working, just need to test the datapoint alert now in our test environment, but this seems to fit the bill a lot simpler than I was trying to do it, thanks very much :)/emoticons/smile@2x.png 2x" title=":)" width="20" />