netfishers-onl / Netshot

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

HPE Switches Drivers #54

Open bernie791023 opened 4 years ago

bernie791023 commented 4 years ago

Hello! Any idea if there's plan to write a driver for HPE switches?

Thanks!

hemh commented 4 years ago

Hi all, Netshot seems to be a great software, but unfortunately there is no driver for HPE switches. I try to write my own, I started from the Huawei driver, because the commands are very similar. So I replaced all the specific Huawei commands with HPE commands, but I am stocked with an error:

[INFO] Snapshot task for device [NONAME] (X.X.X.X). [ERROR] Error while taking the snapshot: Error while running CLI macro 'user' in at line number 143 at column number 4 [TRACE] Will try Telnet credentials RDL Telnet. [ERROR] I/O error: Timeout waiting for the command output. [ERROR] Error while running snapshot using driver HPE SWITCH: 'Error while running CLI macro 'user' in at line number 143 at column number 4'.

As I am not a developer, it is quite hard for me to find out the solution. Any help?

SCadilhac commented 4 years ago

@hemh, the error message means the 'user' prompt /^(<[A-Za-z\-_0-9\.]+>)$/ was not matched in the output coming from the switch. You can try to run the snapshot in debug mode (see https://github.com/netfishers-onl/Netshot/wiki/Snapshot-troubleshooting) to identify the mismatch. Share the result if you want some help.

hemh commented 4 years ago

Thank you very much SCadilhac! It helped me a lot. I then learned how to use regex tanks to this site:https://rubular.com/ and I have been abble to write my own script for HPE switches(I built it for the version 3208P03, not shure it will work for other versions. I share my driver if other people are interested to improve it. HPE switch 3208P03.zip

hemh commented 4 years ago

Other question, why the HPE driver is not automatically selected when I had a HPE device, like for cisco device? Each time, it is the Generic SNMP that is used if I do not force the utilization of HPE driver

SCadilhac commented 4 years ago

@hemh, you need to customize the snmpAutoDiscover function with the sysObjectId and sysDesc values which identify any HPE device compatible with your driver.

hemh commented 4 years ago

Thanks, autodiscover work now. If other people are intersted in improve the HPE driver, don't hesitate to contact me by MP.

hemh commented 4 years ago

I am trying to use my driver on another HPE model (7900) and the driver is stocked, check the logs:

[ERROR] I/O error: Timeout waiting for the command output. [ERROR] I/O error: Read timed out [ERROR] Error while running snapshot using driver HPE SWITCH 7900: 'Error while waiting for a response from the device after command 'display current-configuration' in at line number 224 at column number 5'.

It is like the command in the following line is not issued : var currentConfig = cli.command("display current-configuration"); Any idea?

hemh commented 4 years ago

Hi,

To bring more details about the above problem here are the netshot logs for a specific snapshot that doesn't work:

2019-10-17 13:16:38,290 ERROR [QuartzSchedulerWorker-1] TakeSnapshotTask: Error while taking the snapshot. javax.script.ScriptException: Error while waiting for a response from the device after command 'save force' in at line number 224 at column number 5 at jdk.nashorn.api.scripting.NashornScriptEngine.throwAsScriptException(NashornScriptEngine.java:470) at jdk.nashorn.api.scripting.NashornScriptEngine.invokeImpl(NashornScriptEngine.java:392) at jdk.nashorn.api.scripting.NashornScriptEngine.invokeFunction(NashornScriptEngine.java:190) at onl.netfishers.netshot.device.script.SnapshotCliScript.run(SnapshotCliScript.java:92) at onl.netfishers.netshot.device.script.CliScript.connectRun(CliScript.java:339) at onl.netfishers.netshot.device.script.CliScript.connectRun(CliScript.java:194) at onl.netfishers.netshot.work.tasks.TakeSnapshotTask.run(TakeSnapshotTask.java:200) at onl.netfishers.netshot.work.TaskJob.execute(TaskJob.java:90) at org.quartz.core.JobRunShell.run(JobRunShell.java:202) at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573) Caused by: jdk.nashorn.internal.runtime.ECMAException: Error while waiting for a response from the device after command 'save force' at jdk.nashorn.internal.runtime.ECMAException.create(ECMAException.java:113) at jdk.nashorn.internal.scripts.Script$Recompilation$17673$6172AA$\^eval\.connect#command(:224) at jdk.nashorn.internal.scripts.Script$Recompilation$17574$3371AAA$\^eval_.snapshot(:174) at jdk.nashorn.internal.scripts.Script$Recompilation$17669$795AAAA$\^eval\._connect(:534) at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:645) at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:494) at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393) at jdk.nashorn.api.scripting.ScriptObjectMirror.callMember(ScriptObjectMirror.java:199) at jdk.nashorn.api.scripting.NashornScriptEngine.invokeImpl(NashornScriptEngine.java:386) ... 8 common frames omitted

It is very weird, because my HPE driver work for about 50 devices and is not working for 10 other witch are of the same model, same version...I try to find out but I see no difference in the behaviour, what could cause this? And the most weir is that I can see in the switch logs that the command is issued, but Netshot seems unable to proccess the output.

SCadilhac commented 4 years ago

In both cases, the logs indicate a timeout after the passed command. In most cases:

You should look at the debugging logs to see the precise data sent by the device. Or share your code and the debugging logs to get some help.

hemh commented 4 years ago

Thank you SCadilhac...Sorry for that, the problem was due to the fact that SSH prompt is different than TELNET prompt.

Here is the telnet prompt: **login: login Password:

** Here is the SSH prompt: **login as: login login@1x.x.x.1's password:** But If I force to use telnet, The driver work. I add my new driver version. [HPE switch 3208P03-v2.zip](https://github.com/netfishers-onl/Netshot/files/3744543/HPE.switch.3208P03-v2.zip)
SCadilhac commented 4 years ago

When using SSH, the username and login are not exposed to the script (authentication is handled directly at the SSH level), so you don't have to adjust username and password macros for SSH. Your password prompt doesn't look good as a regular expression even if it may work. Please provide a debug of the snapshot (https://github.com/netfishers-onl/Netshot/wiki/Snapshot-troubleshooting) if you want more help (for SSH only, or with a fake password for Telnet).

hemh commented 4 years ago

So I change my password prompt.

Here is the debug file of a host that doesn't work: debug_2411.zip

Here is the driver updated HPE switch 3208P03-v2.zip

Here are the Netshol logs: [INFO] Snapshot task for device [NONAME] (172.19.1.3). [ERROR] Error while taking the snapshot: Error while waiting for a response from the device after command 'save force' in at line number 224 at column number 5 [ERROR] I/O error: Timeout waiting for the command output. [ERROR] I/O error: Read timed out [ERROR] Error while running snapshot using driver HPE SWITCH: 'Error while waiting for a response from the device after command 'save force' in at line number 224 at column number 5'.

Thank you very much for your help.

SCadilhac commented 4 years ago

Is this Telnet or SSH snapshot attempt?

hemh commented 4 years ago

It is a telnet attempt,

SCadilhac commented 4 years ago

I can't see an exact correlation between the trace and the version of the driver you provided. Are you sure they match? I thought Telnet was OK. I shall try with a virtual Comware device.

hemh commented 4 years ago

Hi Sylvain, my driver works well with HPE 5130, and HPE 5700 but no way to make it work with HPE FF 7910 and HPE 5120. I guess this is because of the history of HP(old mix of 3COM, Huawei and H3C) You can find a good history of the brand here: https://sites.google.com/site/jrbinks/code/rancid/h3c. But my main need is for the HP FF 7910, as this is our Core router, do you have a way to get the hand on a virtual version of that model?

SCadilhac commented 4 years ago

@hemh, I have no experience with HPE switches, I have no idea whether the virtual edition version would look to which of the versions you use, so I'm not willing to waste time on this. If you want more help, please provide the full login sequence (copy/paste from your preferred terminal when you connect manually) for each version in both Telnet and SSH.

tbiens commented 3 years ago

hpswitch.js.tar.gz

Hello,

I worked on this issue and have a bit of a working driver. Sort of used the example attached but it has been heavily modified.

It is able to pull hostname and config. Otherwise the script is a mess. Literally my first time in javascript.

I have tried to get snmp autodiscover working but it doesnt work. The OID there does give that result. It ought to always be that but it doesnt seem to pull.

SCadilhac commented 3 years ago

SNMP autodiscovery is pretty simple. Your script's snmpAutoDiscover function will get sysObjectID and sysDesc values, it must return true or false whether it supports the device or not. What is the result of snmpwalk -v2c -c [community] [IP of the device] 1.3.6.1.2.1.1 for your device?

tbiens commented 3 years ago

That's the difficulty I think. That OID doesn't exist for procurve switches.

Name/OID: system; Value (NoSuchObject): (Snmp No Such Object)

Though looking at it now.

ObjectID and Desc is following:

Name/OID: sysObjectID.0; Value (OID): .1.3.6.1.4.1.11.2.3.7.11.88

Name/OID: sysDescr.0; Value (OctetString): ProCurve J9279A Switch 2510G-24, revision Y.11.41, ROM N.10.02 (/sw/code/build/cod)

If I do the follow it just shows up as Generic SNMP device.

function snmpAutoDiscover(sysObjectID, sysDesc) { return sysObjectID.substring(0, 255) == ".1.3.6.1.4.1.11.2.3.7.11.88" && sysDesc.match(/ProCurve*/); }

hemh commented 3 years ago

Hi, did you read this page: https://networkangle.com/rancid-for-hp-h3c-huawei-switches/

On Mon, Feb 22, 2021 at 2:08 PM tbiens notifications@github.com wrote:

That's the difficulty I think. That OID doesn't exist for procurve switches.

Name/OID: system; Value (NoSuchObject): (Snmp No Such Object)

Though looking at it now.

ObjectID and Desc is following:

Name/OID: sysObjectID.0; Value (OID): .1.3.6.1.4.1.11.2.3.7.11.88

Name/OID: sysDescr.0; Value (OctetString): ProCurve J9279A Switch 2510G-24, revision Y.11.41, ROM N.10.02 (/sw/code/build/cod)

If I do the follow it just shows up as Generic SNMP device.

function snmpAutoDiscover(sysObjectID, sysDesc) { return sysObjectID.substring(0, 255) == ".1.3.6.1.4.1.11.2.3.7.11.88" && sysDesc.match(/ProCurve*/); }

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/netfishers-onl/Netshot/issues/54#issuecomment-783604043, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACI5EM6GMGCO6SNLSJGOMJTTAKTTFANCNFSM4I5GJJUQ .

SCadilhac commented 3 years ago

Name/OID: sysObjectID.0; Value (OID): .1.3.6.1.4.1.11.2.3.7.11.88 Name/OID: sysDescr.0; Value (OctetString): ProCurve J9279A Switch 2510G-24, revision Y.11.41, ROM N.10.02 (/sw/code/build/cod)

1.3.6.1.4.1.11.2.3.7.11.88 points to a specific model, hpSwitchJ9279A

function snmpAutoDiscover(sysObjectID, sysDesc) { return sysObjectID.substring(0, 255) == ".1.3.6.1.4.1.11.2.3.7.11.88" && sysDesc.match(/ProCurve*/); }

You may want to write something like:

function snmpAutoDiscover(sysObjectID, sysDesc) {
    return sysObjectID.substring(0, 24) == "1.3.6.1.4.1.11.2.3.7.11." && sysDesc.match(/ProCurve/);
}
tbiens commented 3 years ago

No luck with that. Still being detected as Generic SNMP Device.