Configure Network Devices via SSH (for example Mikrotik) #9475
Replies: 4 comments 13 replies
-
I guess this topic should be posted in https://github.com/netbox-community/netbox/discussions/categories/ideas next time. |
Beta Was this translation helpful? Give feedback.
-
You haven't shown what you tried, or the complete script, or the error you got, but I'm guessing you did something like this:
This will fail because you can't concatenate a string to an object. You'll need to find a suitable string property, e.g.
Aside: Python 3.6 and later also support string interpolation
If you had used this, then actually the default
|
Beta Was this translation helpful? Give feedback.
-
Thanks everyone for the advice. Here is the working config #########################################################
######################################################### |
Beta Was this translation helpful? Give feedback.
-
Hello netbox community. I would like to continue my idea and combine my script with several types of devices (for example, Mikrotik and Cisco) select the type of Mikrotik device, and the next line should appear where there will be 3 commands to choose from: "Show IP address", "Show User", "Show Interfaces". But if I select the Cisco device type, then a line with two options should appear: "Show IP address", " Show User " in this case, the desired command should be selected, because The syntax is different on different devices. I have a simple script example with options selection.
Thank you all for the tips and clarifications. |
Beta Was this translation helpful? Give feedback.
-
NetBox version
v3.2.2
Feature type
New functionality
Proposed functionality
Hello, netbox community!
I have an idea to create scripts to manage network devices from web interface.
for example, here is a ready-made simple script for adding VLAN to Mikrotik.
###########################################
#add netmiko to the local_requirements.txt
from django.utils.text import slugify
import paramiko
import netbox.settings
from extras.scripts import *
from netmiko import ConnectHandler
from routeros_ssh_connector import MikrotikDevice
class RunCommand(Script):
class Meta:
name = "Set VLAN on Mikrotik"
description = "Mikrotik via SSH"
field_order = [
'input_ip',
'input_bridge',
'input_vlan_name',
'input_vlan_id'
]
input_ip = StringVar(
description="Enter the IP Address:"
)
input_bridge = StringVar(
description="Name Bdrige:"
)
input_vlan_name = StringVar(
description="Vlan Name:"
)
input_vlan_id = StringVar(
description="Vlan id:"
)
def run(self, data, commit):
###################################################
In this script, I enter variables myself, but I would like to enter variables from the netbox database -
for example through ObjectVar or MultiObjectVar.
############################################
#################################
I can't pass these variables to commands that need to be written on the remote device !
'/interface bridge add name='+[bridge from Interfacebridge ] + '\n'
Can you tell me, at least with one example, how can I do this?
All scripts will be laid out in open form, so that everyone can use them!
Thanks a lot!
Use case
Use netbox as a platform for template configuration of network devices using the netbox database.
(Mikrotik, Cisco etc)
Database changes
No response
External dependencies
No response
Beta Was this translation helpful? Give feedback.
All reactions