(Logic: The while loop steps through the element id until the element no longer exists.)
Original Message:
Sent: 10-04-2023 21:36
From: GERALD NICOLE RODRIGUEZ
Subject: SLAX Script Help
Hi Sir Gavin,
Thank you for your time. Here is the xml output
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/21.2R0/junos">
<subscribers-summary-information xmlns="http://xml.juniper.net/junos/21.2R0/junos-subscribers">
<counters junos:style="state-summary">
<session-state-active>3</session-state-active>
<session-state-total>3</session-state-total>
</counters>
<counters junos:style="type-summary">
<session-type-dhcp>1</session-type-dhcp>
<session-type-vlan>1</session-type-vlan>
<session-type-pppoe>1</session-type-pppoe>
<session-type-total>3</session-type-total>
</counters>
<counters junos:style="lsri-summary">
<lsri-name>default</lsri-name>
<lsri-count>1</lsri-count>
<lsri-name>default:INSIDE</lsri-name>
<lsri-count>2</lsri-count>
<lsri-total>3</lsri-total>
</counters>
</subscribers-summary-information>
<cli>
<banner>{master}</banner>
</cli>
</rpc-reply>
And when I run my test-script, here is the output.
default
default:INSIDE
1
2
I am thinking that lsri-name & lsri-count are siblings since they are same level within the counters. That's why I can't map lsri-name to lsri-count when using slax script. Or are there another way around.
------------------------------
GERALD NICOLE RODRIGUEZ
Original Message:
Sent: 10-04-2023 20:49
From: GAVIN WHITE
Subject: SLAX Script Help
Hi Gerald,
I don't have a working example with me. But you may be able to summarize some of those for-each loops to start at the sub-branch and take action on each element within each XML branch.
To better understand the XML tree structure, can you provide the XML output of the show command for us? JSON can be a bit mysterious to read.
You will get something similar to below but with data we can verify your scripts against...
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/22.4R0/junos"> <subscribers-summary-information xmlns="http://xml.juniper.net/junos/22.4R0/junos-subscribers"> <counters junos:style="state-summary"> <session-state-total>0</session-state-total> </counters> <counters junos:style="type-summary"> <session-type-total>0</session-type-total> </counters> <counters junos:style="lsri-summary"> </counters> <counters junos:style="lsri-zero-summary"> <lsri-total>0</lsri-total> </counters> </subscribers-summary-information> <cli> <banner></banner> </cli></rpc-reply>
------------------------------
GAVIN WHITE
Original Message:
Sent: 10-04-2023 01:40
From: GERALD NICOLE RODRIGUEZ
Subject: SLAX Script Help
Thanks Gavin. Another question, how can I map the default:INSIDE lsir-name to its lsri-count. Based on my slax script, it seems that the lsri-name & lsri-count is same object level.
show command in json
{
"attributes" : {"junos:style" : "lsri-summary"},
"lsri-name" : [
{
"data" : "default"
}
],
"lsri-count" : [
{
"data" : "1"
}
],
"lsri-name" : [
{
"data" : "default:INSIDE"
}
],
"lsri-count" : [
{
"data" : "2"
}
],
"lsri-total" : [
{
"data" : "3"
}
]
0riginal Command:
show subscribers summary all
Subscribers by State
Active: 3
Total: 3
Subscribers by Client Type
DHCP: 1
VLAN: 1
PPPoE: 1
Total: 3
Subscribers by LS:RI
default: 1
default:INSIDE: 2
Total: 3
My slax script to verify elements.
version 1.0;
ns junos = "http://xml.juniper.net/junos/*/junos";
ns xnm = "http://xml.juniper.net/xnm/1.1/xnm";
ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0";
import "../import/junos.xsl";
match / {
<op-script-results>{
var $cmd = <command> "show subscribers summary all";
var $out = jcs:invoke($cmd);
mvar $pppoe_users = 0;
for-each ($out/counters/lsri-name) {
expr jcs:output(.);
}
for-each ($out/counters/lsri-count){
expr jcs:output(.);
}
}
}
Thanks again
------------------------------
GERALD NICOLE RODRIGUEZ
Original Message:
Sent: 10-03-2023 16:18
From: GAVIN WHITE
Subject: SLAX Script Help
Hi Gerald,
Create a mutable varible:
mvar $totalusers = 0;
Under the for each statement you want to add the pool user to the total count
set $totalusers = $totalusers + $poolusers;
Then print the total at the end.
expr jcs:output("Total Users: " _ $totalusers);
------------------------------
GAVIN WHITE
Original Message:
Sent: 09-14-2023 08:00
From: GERALD NICOLE RODRIGUEZ
Subject: SLAX Script Help
Hi All,
Here below is my slax script for show services nat source pool all command.
version 1.0;
ns junos = "http://xml.juniper.net/junos/*/junos";
ns xnm = "http://xml.juniper.net/xnm/1.1/xnm";
ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0";
import "../import/junos.xsl";
match / {
<op-script-results> {
var $rpc = {
<retrieve-srv-source-nat-pool-information> {
<all>;
}
}
var $out = jcs:invoke($rpc);
/*expr jcs:output($out);*/
for-each ($out/source-nat-pool-info-entry) {
var $poolname = ./pool-name;
var $poolusers = ./source-pool-users;
expr jcs:output("Pool-name: ", $poolname);
expr jcs:output("Users Count: ", $poolusers);
}
}
}
The output of the script is:
Pool-Name: Pool-1
Users Count: 5
Pool-Name: Pool-2
Users Count: 2
I want to get the total users count, for ex. pool-1+pool-2... any idea on how to execute using slax. Thanks.
------------------------------
GERALD NICOLE RODRIGUEZ
------------------------------