Monitoring Gateway SIP Trunk Status via SSH through Command line
Hi,
I am trying to monitor the status of the Gateway SIP trunk using the command "show sip-ua register status" via SSH. However, I am encountering issues while running a custom script provide by the support team. Initially, when I ran the script a few times, I received an error: "Unable to establish the SSH Connection". After some time, the error changed to "No Signature Method."
I have verified the SSH connection from the collector server to the end device, and it works fine when I manually establish the SSH session. I also tested my own script , but it returned a similar error: "Error: Unable to establish SSH session/channel."
I have attached the error snapshot and the script I am using for reference. Please guide me on how to monitor the SIP status via the command line using SSH.
When running the command "show sip-ua register status", the output is either Yes (registered) or No (unregistered) from the device end. In LogicMonitor, the expected output should be:
- Yes = 0
- No = 1
I tried to attach the Script but it will not support Txt Format, Sorry for the inconvenience
Below is the script Provided by the support team
import com.santaba.agent.groovyapi.expect.Expect;
// Get the hostname and credentials from the device property table
hostname = hostProps.get("system.hostname");
userid = hostProps.get("ssh.user");
passwd = hostProps.get("ssh.pass");
// Ensure required properties are not null
if (!hostname || !userid || !passwd) {
throw new Exception("Missing required device properties: hostname, ssh.user, or ssh.pass.");
}
// Initiate an SSH connection to the host using the provided credentials
def ssh_connection = Expect.open(hostname, userid, passwd);
// Wait for the CLI prompt to confirm connection
ssh_connection.expect("# "); // Adjust prompt based on your device
// Send the `show sip-ua register status` command
ssh_connection.send("show sip-ua register status\n");
// Wait for the response to complete
ssh_connection.expect("#"); // Replace with your device's prompt
// Print the output of the command
println "Command Output: " + ssh_connection.getLastOutput();
// Logout
ssh_connection.send("exit\n");
// Close the SSH connection handle
ssh_connection.expectClose();
return 0;
This is another script Created by Me
import com.santaba.agent.groovyapi.expect.Expect
// Device credentials and details
def deviceIP = hostProps.get("system.ip") // IP address of the device
def username = hostProps.get("ssh.user") // SSH username from LogicMonitor
def password = hostProps.get("ssh.pass") // SSH password from LogicMonitor
// Command to execute
def command = "show sip-ua register status"
// Initialize result
def resultCode = 1 // Default to 1 (Unregistered)
// Start SSH session
try {
def session = Expect.open(deviceIP, username, password)
// Send the command
session.send(command + "\n")
// Wait for the output
def output = session.expect(10, ".*") // Adjust timeout (10 seconds) as needed
println("Command output: ${output}")
// Check the output for 'Yes' or 'No'
if (output.toLowerCase().contains("yes")) {
resultCode = 0 // Registered
} else if (output.toLowerCase().contains("no")) {
resultCode = 1 // Unregistered
} else {
throw new Exception("Unexpected output: ${output}")
}
// Close the session
session.close()
} catch (Exception e) {
println("Error: ${e.message}")
// Optionally log additional details for debugging
}
// Print the result for LogicMonitor
println(resultCode)
return resultCode
Sharath Ramanna
OP1 year agoAfter of changing this i am getting IO Exceptional Java Error
Sharath Ramanna
OP1 year agoI tried this, I am getting an error " Connection Refused Connect"
Shack
·1 year agoDid you change line #8 to ssh port 22? You should also be able to uncomment line #37, assuming all the expect lines are accurate and work.
Sharath Ramanna
OP1 year agoMike Moniz, Can you suggest how to achieve this?
Mike Moniz
·1 year agoI don't really know Cisco very well, might be best to talk with LM support.
In case it is an issue with ssh and Expect, try switching between the jsch and sshj libraries as mentioned at https://www.logicmonitor.com/support/terminology-syntax/scripting-support/groovy-or-expect-text-based-interaction
Michael Rodrigues
·1 year agoYou can also do this at the collector level with the following directive in agent.conf:
Shack
·1 year 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.
Below is for data collection.
I have one datapoint named Status and it looks like this.
Mike Moniz
·1 year agoWhat kinda device are you attempting to SSH into?
There was an older forum post at https://community.logicmonitor.com/discussions/product-discussions/lm-expect-packages-and-ed25519/14285 that mentions issues with Expect and Fortigate. That LM's Expect might not support some of the newer SSH encryption systems.
Sharath Ramanna
OP1 year agoModel - ISR4431/K9 Router
firmware_version 17.6.1
hardware_version V07
Vendor - Cisco