[j-nsp] SLAX script, redefining variables

2013-06-07 Thread Tom Storey
Hi all.

It seems that older SLAX implementations dont have the ability to redefine
variable (Juniper is calling them immutable variables). This is apparently
fixed in 1.1 on JunOS12+ boxes with something called a mutable variable
(defined with mvar instead of var) but all of the boxes I am using are not
on JunOS12+ yet.

Has anyone found a way to collect a whole bunch of information, and then
display it at the end of the script, rather than duplicating their output
code 50 times to handle the various exceptions?

e.g. a script I am writing grabs the tx/rx figures for optics and lists
them, along with the description of the interface, so I can run my op
script and get a list of power levels, grep for destination devices etc and
see whats happening with my circuits.

But there are a couple of exceptions that I hit along the way:

1) Descriptions arent always on the physical interface, so if theres no
description there I need to look at a logical interface, which is usually
unit 0 in my case
2) SONET interfaces dont use the same variable to store the rx power
figure as ethernet interfaces, so depending on the interface type I need to
look at a different variable for the rx power figure

To handle these exceptions would be quite easy if I could simply use a
bunch of IF blocks to test for the various locations of the information I
want, set them in to variables, and then at the end dump it out to the
screen.

But without being able to redefine a variable, and with variables defined
inside an IF block not being accessible outside of that IF block, I will
need to reproduce my output code numerous times.

Anyone know of a solution?

Thanks
Tom
___
juniper-nsp mailing list juniper-nsp@puck.nether.net
https://puck.nether.net/mailman/listinfo/juniper-nsp


Re: [j-nsp] SLAX script, redefining variables

2013-06-07 Thread Phil Mayers

On 07/06/13 09:54, Tom Storey wrote:


But without being able to redefine a variable, and with variables defined
inside an IF block not being accessible outside of that IF block, I will
need to reproduce my output code numerous times.


Move the output code to a function?
___
juniper-nsp mailing list juniper-nsp@puck.nether.net
https://puck.nether.net/mailman/listinfo/juniper-nsp


Re: [j-nsp] SLAX script, redefining variables

2013-06-07 Thread Alex Arseniev

The checks can be embedded into if/for-each constructs, see example here
https://code.google.com/p/junoscriptorium/source/browse/trunk/library/public/op/display/op-show-lsp-interface/op-show-lsp-interface.slax

  if ($ifdescrdb/logical-interface[name == $if]/description) {


The above means that only IFLs whose name XML tag matches a string stored 
in variable $if will be processed.

HTH
Thanks
Alex

- Original Message - 
From: Tom Storey t...@snnap.net

To: juniper-nsp@puck.nether.net
Sent: Friday, June 07, 2013 9:54 AM
Subject: [j-nsp] SLAX script, redefining variables



Hi all.

It seems that older SLAX implementations dont have the ability to redefine
variable (Juniper is calling them immutable variables). This is apparently
fixed in 1.1 on JunOS12+ boxes with something called a mutable variable
(defined with mvar instead of var) but all of the boxes I am using are not
on JunOS12+ yet.

Has anyone found a way to collect a whole bunch of information, and then
display it at the end of the script, rather than duplicating their output
code 50 times to handle the various exceptions?

e.g. a script I am writing grabs the tx/rx figures for optics and lists
them, along with the description of the interface, so I can run my op
script and get a list of power levels, grep for destination devices etc 
and

see whats happening with my circuits.

But there are a couple of exceptions that I hit along the way:

1) Descriptions arent always on the physical interface, so if theres no
description there I need to look at a logical interface, which is usually
unit 0 in my case
2) SONET interfaces dont use the same variable to store the rx power
figure as ethernet interfaces, so depending on the interface type I need 
to

look at a different variable for the rx power figure

To handle these exceptions would be quite easy if I could simply use a
bunch of IF blocks to test for the various locations of the information I
want, set them in to variables, and then at the end dump it out to the
screen.

But without being able to redefine a variable, and with variables defined
inside an IF block not being accessible outside of that IF block, I will
need to reproduce my output code numerous times.

Anyone know of a solution?

Thanks
Tom
___
juniper-nsp mailing list juniper-nsp@puck.nether.net
https://puck.nether.net/mailman/listinfo/juniper-nsp



___
juniper-nsp mailing list juniper-nsp@puck.nether.net
https://puck.nether.net/mailman/listinfo/juniper-nsp


Re: [j-nsp] SLAX script, redefining variables

2013-06-07 Thread Tom Storey
Duh. Thats what happens when you spend all night coding, you forget silly
little things. :-P

Theres still some duplication of the function call, but I guess thats
better than nothing.

Would much prefer to do a bulk collection and then a dump at the end.

I'll take this route for the time being.


On 7 June 2013 11:43, Phil Mayers p.may...@imperial.ac.uk wrote:

 On 07/06/13 09:54, Tom Storey wrote:

  But without being able to redefine a variable, and with variables defined
 inside an IF block not being accessible outside of that IF block, I will
 need to reproduce my output code numerous times.


 Move the output code to a function?
 __**_
 juniper-nsp mailing list juniper-nsp@puck.nether.net
 https://puck.nether.net/**mailman/listinfo/juniper-nsphttps://puck.nether.net/mailman/listinfo/juniper-nsp

___
juniper-nsp mailing list juniper-nsp@puck.nether.net
https://puck.nether.net/mailman/listinfo/juniper-nsp


Re: [j-nsp] SLAX script, redefining variables

2013-06-07 Thread Phil Shafer
Tom Storey writes:
It seems that older SLAX implementations dont have the ability to redefine
variable (Juniper is calling them immutable variables).

Not my term; it's a limited of XSLT, on which SLAX is based.

Some details (and implementation notes on the new mvars) can
be found here:

http://code.google.com/p/libslax/wiki/ImmutableVariables

This is apparently
fixed in 1.1 on JunOS12+ boxes with something called a mutable variable
(defined with mvar instead of var) but all of the boxes I am using are not
on JunOS12+ yet.

SLAX-1.1 is in 12.2.  You can also get it (for offline use) from
libslax.googlecode.com and juise.googlecode.com.  libslax is the
base language.  juise adds JUNOS-specific bits like the jcs:*
functions.

[Yes, we're in the process of moving to github, but not done yet]

Has anyone found a way to collect a whole bunch of information, and then
display it at the end of the script, rather than duplicating their output
code 50 times to handle the various exceptions?

I'm not quite following; can you share your script?

e.g. a script I am writing grabs the tx/rx figures for optics and lists
them, along with the description of the interface, so I can run my op
script and get a list of power levels, grep for destination devices etc and
see whats happening with my circuits.

But there are a couple of exceptions that I hit along the way:

1) Descriptions arent always on the physical interface, so if theres no
description there I need to look at a logical interface, which is usually
unit 0 in my case

You can put logic inside the var, like:

var $desc = {
if (description) {
expr description;
} else if (../description) {
expr ../description;
} else {
expr --;
}
}

For this specific case, there's the jcs:first-of() function to
shorten this:

var $desc = jcs:first-of(description, ../description, --);

where jcs:first-of returns the first non-null argument.

But you can use this like:

var $links := {
for-each (link) {
link {
   name name;
   description jcs:first-of(description, ../description, --);
   /* ... */
}
}
}

to build custom data structures.

Also there's always the original model from XSLT of apply-templates
and recursive traversal:

http://my.safaribooksonline.com/book/xml/0596003722/selecting-and-traversing/xsltckbk-chp-4-sect-7

2) SONET interfaces dont use the same variable to store the rx power
figure as ethernet interfaces, so depending on the interface type I need to
look at a different variable for the rx power figure

var $power = {
if (type == aa) {
expr where/ever/it/is/stored;
} else if (type == bb) {
expr some/where/else;
} else {
expr -;
}
}

Hope this helps..

Thanks,
 Phil

___
juniper-nsp mailing list juniper-nsp@puck.nether.net
https://puck.nether.net/mailman/listinfo/juniper-nsp