netfishers-onl / Netshot

Network Configuration and Compliance Management
http://www.netfishers.onl/netshot
249 stars 60 forks source link

Diagnostic results problem #306

Open menemat opened 7 months ago

menemat commented 7 months ago

Hi folks, We've created a diagnostic tool for Juniper switches. The command used is "show configuration interfaces | display xml". However, the diagnostic fails. But when we execute a command like "show configuration interfaces ge-0/0/0 | display xml", it works perfectly.

{ "type": ".SimpleDiagnostic", "id": 4, "name": "Juniper_interfaces_xml", "targetGroup": { "type": "StaticDeviceGroup", "changeDate": 1712574127000, "id": 30, "name": "test", "folder": "test", "hiddenFromReports": false }, "enabled": true, "resultType": "TEXT", "deviceDriver": "JuniperJunos", "cliMode": "operate", "command": "show configuration interfaces | display xml", "modifierPattern": "", "modifierReplacement": "", "deviceDriverDescription": "Juniper Junos" }

Output:

[WARN] Setting value for diagnostic key 'Juniper_interfaces_xml' [ERROR] Error while executing the diagnostics: org.hibernate.exception.DataException: could not execute statement

Netshot version 0.18.3

The switch is a Juniper ex2200-24p-4g. There are no virtual chassis, so the network interfaces are limited.

Thanks in advance. M.

SCadilhac commented 7 months ago

The result of the diagnostic is too long to be stored in the DB as per current constraints. Diagnostics were designed to report rather short results. May I know why you are trying to store the entire interface config block in XML format rather that using curly and set config formats already stored by the Junos driver?

menemat commented 7 months ago

At the moment there are no way to retrive the configured vlan on a specific port. In /devices/{id}/interfaces there aren't info about vlan.

With this diagnostic we are able to retrive this information as a text:

`` import re

def extract_interface_vlan(output): clean_configs = [re.sub(r"^set interfaces |unit 0 family ethernet-switching vlan members ", "", line) for line in output.split('\n') if line.startswith("set interfaces") and not line.startswith("set interfaces vlan") and not line.startswith("set interfaces irb") and "native" not in line] return '\n'.join(clean_configs)

def diagnose(cli, device, diagnostic): cli.macro("operate") output = cli.command("show configuration interfaces | display set | match vlan") interface_configs = extract_interface_vlan(output) diagnostic.set(interface_configs)

``

The output is like this: ge-0/0/0 199-200 ge-0/0/0 204 ge-0/0/0 301 ge-0/0/1 204 ge-0/0/2 204 ....

The idea would then be to make a simple graphical interface (with django) to read and modify the vlan of a port.