Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Sophos module allowing the user to navigate the interactive menu prompt. #3489

Merged
merged 1 commit into from
Aug 26, 2024

Conversation

dLoProdz
Copy link
Contributor

The default functionality of Netmiko is passing an initial carriage return once the connection is established, this was breaking the compatibility with the Sophos interface which displays an interactive prompt where you need to make a numeric selection and press enter, this would set up the session in a bad place to pass the command to reach the Device Console as you need another carriage return before passing the numeric selection.

With the changes made now the user can decide whether to use any of these predefined functions of the interactive main menu, including stepping into the Device Console, or even Advanced Shell, by passing the appropriate menu selections to the connection.

…to interact with the main interactive prompt.
@ktbyers
Copy link
Owner

ktbyers commented Aug 26, 2024

capmerah does this change work for you?

@ktbyers
Copy link
Owner

ktbyers commented Aug 26, 2024

Breaking change...as it leaves your Sophos device in a different state than the previous code (but this probably okay).

@ktbyers ktbyers changed the title Minor changes to the functionality of Sophos module allowing the user to navigate the interactive menu prompt. Change Sophos module allowing the user to navigate the interactive menu prompt. Aug 26, 2024
@dLoProdz
Copy link
Contributor Author

Thanks @ktbyers! This state change is probably for the best as Sophos has different consoles/shells for different use cases, Sophos admins will probably be happy with this.

@ktbyers ktbyers merged commit f295c03 into ktbyers:develop Aug 26, 2024
20 checks passed
@dLoProdz dLoProdz deleted the sophos_module_fix branch August 26, 2024 16:51
@capmerah
Copy link

Hi @ktbyers , @dLoProdz,

Will test this change tomorrow as I have other projects to finish.

Thanks for the contribution.

@capmerah
Copy link

capmerah commented Aug 30, 2024

Hi @ktbyers / @dLoProdz ,

I have tested with the newer code you've contributed.
Unfortunately, the results are still the same.

@dLoProdz
Copy link
Contributor Author

dLoProdz commented Aug 30, 2024

@capmerah you sure you are using the new code?

Try this:

...
[connection_object].send_command_expect("[numeric_selection]", expect_string=r'Select Menu Number')
...

@capmerah
Copy link

capmerah commented Aug 30, 2024

Hi @dLoProdz , It finally works!

I code the following:


from netmiko import ConnectHandler
import os

log_directory = rf"C:\Users\name\OneDrive\username\Backup config\Sophos Firewall\Netmiko"
os.makedirs(log_directory, exist_ok=True)


ipaddrs = ["10.1.1.1"]

devices = [
    {
        "device_type": "sophos_sfos_ssh",
        "host": ip,
        "username": "admin",
        "password": "password",
        "session_log": os.path.join(log_directory, f"netmiko_session_{ip}.log"),
    }
    for ip in ipaddrs
]

for device in devices:
    print(f'Connecting to the device: {device["host"]}')

    with ConnectHandler(**device) as net_connect:  
        output = net_connect.send_command_expect("5\n3", expect_string=r'Select Menu Number')
        output = net_connect.send_command_expect("ls")
        print(output)

And it finally show the exact output.

But since the file system for Sophos SG 430 is Linux based. With normal SSH, it will show list of files as the picture below.

Screenshot 2024-08-30 145617

With Netmiko output, it will become jumbled up like the picture below:

Screenshot 2024-08-30 145755

At least it can able to connect to Sophos with Netmiko.
Thanks for the contribution.

@ktbyers
Copy link
Owner

ktbyers commented Sep 2, 2024

@capmerah There is a good chance that is expected. Netmiko sets the terminal width to be wider (generally) as it is for automation and not intending to be a person.

So with the ls command, you would typically programmatically process the output to get all of the file names or do an ls -1 if you want everything in a single column.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants