The following sections explain each of the extension functions available when you write JUNOS commit and automation scripts. The functions are organized alphabetically.
jcs:break-lines(expression)
Break a simple element into multiple elements, delimited by new lines. This is especially useful for large <output> elements, such as those produced by the show pfe commands.
var $lines = jcs:break-lines($output);
jcs:empty(node-set)
jcs:empty(string)
Return TRUE if the node set or string arguments are empty.
if(jcs:empty($set)) { .... }
jcs:first-of(object,+ "expression")
Return the first nonempty (non-null) item in a list.
In the following example, if the value of a is empty, b is checked. If the value of b is empty, c is checked. If the value of c is empty, d is checked. If the value of d is empty, the string none is returned.
jcs:first-of($a, $b, $c, $d, “ none” )
The following example selects the description of a logical interface if there is a logical interface description. If not, it selects the description of the (parent) physical interface if there is a physical interface description. If not, it selects the concatenation of the physical interface name with a “ .” and the logical unit number.
<xsl:variable name="description"
select="jcs:first-of(description, ../description, concat(../name, '.', name))"/>
Displaying DNS Hostname Information
jcs:hostname(expression)
Return the fully qualified domain name of an address or hostname.
<xsl:variable name="name" select="jcs:hostname($dest)"/>
<xsl:value-of select="concat($address, ' is ', jcs:hostname($address))"/>
Finding LSPs to Multiple Destinations
jcs:invoke(rpc)
Invoke a remote procedure call (RPC). It can be called with one argument, either a string containing a JUNOS XML or JUNOScript RPC method name or a tree containing an RPC. The result is the contents of the <rpc-reply> element, not the <rpc-reply> tag element itself.
In the following example, there is a test to see if the interface argument is included on the command line when the script is executed. If it is, the operational mode output of the show interfaces terse command is narrowed to include information about that interface only.
<xsl:param name=” interface” />
<xsl:variable name="rpc">
<get-interface-information>
<terse/>
<xsl:if test="$interface">
<interface-name>
<xsl:value-of select="$interface"/>
</interface-name>
</xsl:if>
</get-interface-information>
</xsl:variable>
<xsl:variable name="out" select="jcs:invoke($rpc)"/>
In this example, the jcs:invoke() function calls an RPC without modifying the output:
<xsl:variable name="sw" select="jcs:invoke('get-software-information')"/>
Customizing Output of the show interfaces terse Command
jcs:output(expression)
Generate unformatted output text. The function emits an <output> element. The text appears in the CLI.
- <xsl:variable name="ignore" select="jcs:output('The
VPN is up.')"/>
jcs:printf('expression')
Generate formatted output text. The text appears in the CLI. Most standard printf formats are supported, in addition to some JUNOS software-specific ones.
The %j1 operator emits the field only if the field was changed from the last time the function was run.
The %jc operator capitalizes the first letter of the format output.
The %jt{TAG} operator emits the tag if the field is not empty.
<xsl:value-of select="jcs:printf('%-24j1s %-5jcs %-5jcs %s%jt{ --> }s\n',
'so-0/0/0', 'up', 'down', '10.1.2.3', '')"/>
jcs:progress('expression')
Issue a progress message back to the client (CLI) containing the single argument.
<xsl:variable name="ignore" select="jcs:progress('Working...')"/>
jcs:regex(expression, string)
Return the set of strings matched by the given regular expression. This function requires two arguments, the regular expression and the string to match.
var $pat = "([0-9]+)(:*)([a-z]*)";
var $a = jcs:regex($pat, "123:xyz");
var $b = jcs:regex($pat, "r2d2");
var $c = jcs:regex($pat, "test999!!!");
$a[1] == "123:xyz" # full string that matches the regex
$a[2] == "123" # ([0-9]+)
$a[3] == ":" # (:*)
$a[4] == "xyz" # ([a-z]*)
$b[1] == "2d" # full string that matches the regex
$b[2] == "2" # ([0-9]+)
$b[3] == "" # (:*) [empty match]
$b[4] == "d" # ([a-z]*)
$c[1] == "999" # full string that matches the regex
$c[2] == "999" # ([0-9]+)
$c[3] == "" # (:*) [empty match]
$c[4] == "" # ([a-z]*) [empty match]
jcs:sleep(seconds <, milliseconds>)
Cause the script to sleep for a specified number of seconds and optionally, milliseconds. You can use this function to help determine how a routing component is working over time. To do this, write a script that issues a command, calls the jcs:sleep() function, and reissues the same command.
In this example, jcs:sleep(1) means 1 second and jcs:sleep(0, 10) means 10 milliseconds.
<xsl:variable name="ignore" select="jcs:sleep(1)"/>
<xsl:variable name="ignore" select="jcs:sleep(0, 10)"/>
jcs:sysctl("expression", "I")
jcs:sysctl("expression", "s")
Return the value of the given expression or object as a string or an integer. Use the "i" argument to specify an integer. Use the "s" argument to specify a string.
var $value = jcs:sysctl("kern.hostname", "s");
jcs:trace('expression')
Issue a trace message, which is sent to the trace file.
<xsl:variable name="ignore" select="jcs:trace('test')"/>