Forum Discussion
Mike_Rodrigues
Product Manager
3 months agoYou can also do this at the collector level with the following directive in agent.conf:
ssh.preferredlibrary=jsch
Shack
Advisor
2 months agoTry this one for Active Discovery. My applies to is hasCategory("CiscoVoiceDialControl") It was created for telnet but you should be able to tweak it. It is multi instance.
// Import the LogicMonitor expect helper class
import com.santaba.agent.groovyapi.expect.Expect
// Get the hostname and credentials from the device property table
def hostname = hostProps.get("system.hostname")
def userid = hostProps.get("ssh.user")
def passwd = hostProps.get("ssh.pass")
def port = 23 // Default Telnet port
def timeout = 5000 // Timeout in milliseconds
// Open a Telnet connection
def telnet_connection = Expect.open(hostname, port, timeout)
telnet_connection.expect("Username:")
telnet_connection.send("${userid}\n")
telnet_connection.expect("Password:")
telnet_connection.send("${passwd}\n")
telnet_connection.expect("#")
// Disable pagination and set terminal width
telnet_connection.send("terminal width 0\n")
telnet_connection.expect("#")
telnet_connection.send("terminal pager 0\n")
telnet_connection.expect("#")
// Send command to display the SIP UA register status
telnet_connection.send("show sip-ua register status\n")
telnet_connection.expect("#")
// Collect the command output
def config = telnet_connection.before()
// Close the Telnet connection
telnet_connection.send("exit\n")
telnet_connection.expectClose()
// Print the raw output for debugging
//println config
// Initialize a list to hold parsed entries
def entries = []
// Use regex to match each line of data
def matcher = config =~ /(\d+)\s+(\d+)\s+(\d+)\s+(\w+)\s+(\w+)\s+(\S+)/
while (matcher.find()) {
def line = matcher.group(1)
def peer = matcher.group(2)
def expires = matcher.group(3).toInteger()
def reg = matcher.group(4)
def survival = matcher.group(5)
def p_associ_uri = matcher.group(6)
// Map Reg field: 0 for "yes" and 1 for "no"
def regStatus = (reg == "yes") ? 0 : 1
// Create an entry map with the mapped Reg value
def entry = [
'Line': line,
'Peer': peer,
'Expires': expires,
'Reg': regStatus, // Mapped value
'Survival': survival,
'P-Associ-URI': p_associ_uri
]
// Add entry to entries list
entries << entry
}
// Output the parsed entries for LogicMonitor to pick up as individual datapoints
entries.each { entry ->
// println "Line: ${entry['Line']}, Peer: ${entry['Peer']}, Expires: ${entry['Expires']}, Reg: ${entry['Reg']}, Survival: ${entry['Survival']}, P-Associ-URI: ${entry['P-Associ-URI']}"
println "${entry.Line}##${entry.Line}"
}
// Return a success code
return 0
Below is for data collection.
// Import the LogicMonitor expect helper class
import com.santaba.agent.groovyapi.expect.Expect
// Get the hostname and credentials from the device property table
def hostname = hostProps.get("system.hostname")
def userid = hostProps.get("ssh.user")
def passwd = hostProps.get("ssh.pass")
def port = 23 // Default Telnet port
def timeout = 5000 // Timeout in milliseconds
// Open a Telnet connection
def telnet_connection = Expect.open(hostname, port, timeout)
telnet_connection.expect("Username:")
telnet_connection.send("${userid}\n")
telnet_connection.expect("Password:")
telnet_connection.send("${passwd}\n")
telnet_connection.expect("#")
// Disable pagination and set terminal width
telnet_connection.send("terminal width 0\n")
telnet_connection.expect("#")
telnet_connection.send("terminal pager 0\n")
telnet_connection.expect("#")
// Send command to display the SIP UA register status
telnet_connection.send("show sip-ua register status\n")
telnet_connection.expect("#")
// Collect the command output
def config = telnet_connection.before()
// Close the Telnet connection
telnet_connection.send("exit\n")
telnet_connection.expectClose()
// Print the raw output for debugging
//println config
// Initialize a list to hold parsed entries
def entries = []
// Use regex to match each line of data
def matcher = config =~ /(\d+)\s+(\d+)\s+(\d+)\s+(\w+)\s+(\w+)\s+(\S+)/
while (matcher.find()) {
def line = matcher.group(1)
def peer = matcher.group(2)
def expires = matcher.group(3).toInteger()
def reg = matcher.group(4)
def survival = matcher.group(5)
def p_associ_uri = matcher.group(6)
// Map Reg field: 0 for "yes" and 1 for "no"
def regStatus = (reg == "yes") ? 0 : 1
// Create an entry map with the mapped Reg value
def entry = [
'Line': line,
'Peer': peer,
'Expires': expires,
'Reg': regStatus, // Mapped value
'Survival': survival,
'P-Associ-URI': p_associ_uri
]
// Add entry to entries list
entries << entry
}
// Output the parsed entries for LogicMonitor to pick up as individual datapoints
entries.each { entry ->
println "${entry.Line}.Reg:${entry.Reg}"
}
// Return a success code
return 0
I have one datapoint named Status and it looks like this.
Related Content
- 18 days ago
- 2 years ago
- 10 months ago