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