Netshot icon indicating copy to clipboard operation
Netshot copied to clipboard

JunOS software version incorrect on newer version of JunOS

Open ChilliGeologist opened this issue 8 months ago • 4 comments

In the JunOS driver, the regex that finds the version is as follows:

/^JUNOS .* \[(.*)\]/m

In newer version of JunOS, the "show version" command (the output of which this regex is ran against) is slightly different.

Older JunOS versions:

fpc0:
--------------------------------------------------------------------------
Hostname: Hostname
Model: ex2200-24p-4g
JUNOS Base OS boot [12.3R9.4]
JUNOS Base OS Software Suite [12.3R9.4]
JUNOS Kernel Software Suite [12.3R9.4]

Newer JunOS version:

fpc0:
--------------------------------------------------------------------------
Hostname: Hostname
Model: ex2300-c-12p
Junos: 21.2R1.11
JUNOS OS Kernel 32-bit  [20210709.5ccb29e_builder_stable_12_212]
JUNOS OS libs [20210709.5ccb29e_builder_stable_12_212]
JUNOS OS runtime [20210709.5ccb29e_builder_stable_12_212]

With the current regex the software version that Netshot pulls out from the newer format is the build number in the square brackets. If the original expression was modified as follows it would match the correct line in the newer output: /^JUNOS.*/im

The only thing I'm unsure of is how this line is later trimmed down to only include the version number, so there would likely need to be a modification made elsewhere too.

ChilliGeologist avatar Mar 24 '25 02:03 ChilliGeologist

Hello, The following should work:

	var softVersion = "Unknown";
	var version = showVersion.match(/^(JUNOS .* \[(\S+)\]|Junos: (\S+))/m);
	if (version) {
		var softVersion = version[2] || version[3];
	}
	device.set("softwareVersion", softVersion);
	config.set("junosVersion", softVersion);

Can you confirm?

Thanks.

SCadilhac avatar Mar 30 '25 15:03 SCadilhac

Hey @SCadilhac sorry for my ignorance, how would I go about testing this?

ChilliGeologist avatar Mar 30 '25 22:03 ChilliGeologist

Hello, you can test on your Netshot instance: download the latest Junos driver from GitHub (https://raw.githubusercontent.com/netfishers-onl/Netshot/refs/heads/master/src/main/resources/drivers/Juniper_Junos.js), edit it and load it using the procedure https://github.com/netfishers-onl/Netshot/wiki/Loading-an-alternative-driver-into-Netshot

SCadilhac avatar Mar 31 '25 05:03 SCadilhac

Hi @SCadilhac I've tested this and it seems to be working correctly! A switch with the version 23.4R2-S4.11 is now reading that correctly, rather than the build number. It also has not caused any issues with ones that were previously correct. Thanks very much for this!

ChilliGeologist avatar Apr 10 '25 03:04 ChilliGeologist