-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck-vc.slax
90 lines (79 loc) · 3.29 KB
/
check-vc.slax
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
*
* check-vc.slax is a proof-of-concept poller for the internal PFE and VC
* ports. It pushes the traffic stats as found:
* root@switch> show virtual-chassis vc-port statistics
* into a bunch of rows. If the interface names stay the same, the OIDs
* should do so as well. YMMV.
*
* Install this script in fpc0:/var/db/scripts/op/check-vc.slax
* even though it is an event script.
*
* This script isn't perfect and is basically a lot of SLAX I copied and
* pasted together. You are warned (especially your CPU).
*
* find the latest at https://github.com/yeled/check-vc
*
*/
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> {
/*
* dump all VC stats
*/
var $connection = jcs:open();
var $rpc = {
<get-virtual-chassis-port-statistics> {
<brief>;
}
}
var $switch-output = jcs:execute( $connection, $rpc );
/* var $switch-output = jcs:invoke($rpc); */
expr jcs:close( $connection );
/*
* this block takes each port name, and iterates through them, and prints
* them via templates. the FPC is found by moving back a few blocks. it
* could be prettier.
*/
for-each ($switch-output//port-name) {
var $port-name = ../port-name;
var $fpc-name = $port-name/../../../..//re-name;
var $input-bytes = ../input-bytes;
var $output-bytes = ../output-bytes;
var $input-packets = ../input-packets;
var $output-packets = ../output-packets;
/* call pretty-print($fpc-name,$port-name,$input-bytes,$output-bytes,$input-packets,$output-packets); */
/*
* for each stat, call the template and push it into snmp
*/
call fetch-object($fpc-name,$port-name,$fetch-object = $input-packets,$object-name = "input-packets");
/* <output> jcs:printf("%-16s%s-%s: %12s","input-packets:",$fpc-name,$port-name,$input-packets); */
call fetch-object($fpc-name,$port-name,$fetch-object = $output-packets,$object-name = "output-packets");
/* <output> jcs:printf("%-16s%s-%s: %12s","output-packets:",$fpc-name,$port-name,$output-packets); */
call fetch-object($fpc-name,$port-name,$fetch-object = $input-bytes,$object-name = "input-bytes");
/* <output> jcs:printf("%-16s%s-%s: %12s","input-bytes:",$fpc-name,$port-name,$input-bytes); */
call fetch-object($fpc-name,$port-name,$fetch-object = $output-bytes,$object-name = "output-bytes");
/* <output> jcs:printf("%-16s%s-%s: %12s","output-bytes:",$fpc-name,$port-name,$output-bytes); */
}
}
}
/*
* push the data into snmp in a first-come-first-served basis
*/
template fetch-object($fpc-name,$port-name,$object-name,$fetch-object) {
var $rpc-input-bytes = <request-snmp-utility-mib-set> {
<object-type> "counter64";
<instance> $fpc-name _ "-" _ $port-name _ "-" _ $object-name;
<object-value> $fetch-object;
}
/* jcs:execute is faster than jcs:invoke */
var $rpc-snmp-set = jcs:open();
var $results-input-bytes = jcs:execute ( $rpc-snmp-set, $rpc-input-bytes );
/* debug */
/* expr jcs:trace('setting snmp oid'); */
expr jcs:close( $rpc-snmp-set );
}