[j-nsp] SLAX script, redefining variables

Tom Storey tom at snnap.net
Fri Jun 7 10:45:55 EDT 2013


I do have a for-each loop with a big block of nested IFs. Was hoping to
minimise the depth and size of that nesting though.

One IF block tests for the interface description on the physical interface,
and if that fails it goes to look on a logical interface.

Then within each of those I need to look for the two variations of the
variable that stores the rx power figure.

In addition to Phils suggestion above, I suppose I could break this up in
to even more functions, one to "getDescription" and one to "getRxPower".

That should just about cover it I think.

Sometimes your mind needs a little jiggling till the ideas fall through the
sieve and on to the plate. :-)

Thanks all. :-)


On 7 June 2013 13:34, Alex Arseniev <alex.arseniev at gmail.com> wrote:

> 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<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" <tom at snnap.net>
> To: <juniper-nsp at 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 at puck.nether.net
>> https://puck.nether.net/**mailman/listinfo/juniper-nsp<https://puck.nether.net/mailman/listinfo/juniper-nsp>
>>
>>
> ______________________________**_________________
> juniper-nsp mailing list juniper-nsp at puck.nether.net
> https://puck.nether.net/**mailman/listinfo/juniper-nsp<https://puck.nether.net/mailman/listinfo/juniper-nsp>
>


More information about the juniper-nsp mailing list