DX NetOps

 Spectrum Oneclick customisation and Regex

Jump to Best Answer
posted 07-29-2021 01:08 AM

Hi all

I want a custom menu item to launch a URL based on the device name however it needs to be the short name , not the FQDN. Unfortunately I can't limit the device models to just use the short name.

So my devices (including pingables) are as shown on the left and on the right is what I need for the URL
device1.domain.com                     ->             device1
device2.domain.com                    ->             device2
device3.otherdomain.com           ->             device3

What I need is to just use only everything up to the first "."

The result should be 

http://url/file/device1
http://url/file/device2  etc 

Here is my starting point and , as you can see, I've not gone too far yet :-) 

<item name="url target">
<action>
<launch-browser>
<url>http://url/file/?name={0}</url>
<param>
<attribute>AttributeID.MODEL_NAME</attribute>
</param>
</launch-browser>
</action>
</item>


Thanks

Broadcom Employee Best Answer
Hi Jason,

param section supports embedded Java code expressions. Try this option.

    <item name="url target">
      <action>
        <launch-browser>
          <url>http://url/file/?name={0}</url>
            <param>
              <expression>
                (((String)attr(AttributeID.MODEL_NAME)).split("\\."))[0]
              </expression>
           </param>
         </launch-browser>
       </action>
     </item>


Regards
Hello, 

Is launching a script to cut the Hostname an option ? 

Don
Thanks to Jose, that worked perfectly, great tip