Debian Codegraph @

docs/TableView.rst

raw
1 :Author: Nitin Kumar <[email protected]>
2
3 ************
4 Table & View
5 ************
6
7 Tutorial page for PyEZ table and view
8
9 |
10
11 Table & View for Structured output
12 ##################################
13
14 `Understanding Junos PyEZ Tables and Views for structured (xml) output
15 <https://www.juniper.net/documentation/en_US/junos-pyez/topics/concept/junos-pyez-tables-and-views-overview.html>`_
16
17 |
18
19 Table & View for UnStructured output
20 ####################################
21
22 PyEZ table/view is extended to parse unstructured data. for example VTY commands
23 and CLI output for which we don't have structured (xml) output and convert them
24 to JSON.
25
26 Table Keywords
27 ==============
28
29 .. table:: YAML definition to fetch command output from Junos device.
30 :widths: auto
31
32 ====================== =============================================================
33 Parameter Description
34 ====================== =============================================================
35 :ref:`table-name` User-defined Table identifier.
36 :ref:`table-command` CLI/VTY command to be executed.
37 :ref:`table-target` (Optional) If the command is vty, provide the targeted fpc.
38 :ref:`table-args` (Optional) Commmand can be a jinja template. args takes key/value pair,
39 value associated with a given key is used to render command template.
40 :ref:`table-key` (Optional) Defines key to be used while forming JSON.
41 :ref:`table-key-items` (Optional) Only get the data for given keys in this list.
42 :ref:`table-item` (Optional) This is used to split whole data in different sections which
43 become the iterable reference for the associated View.
44
45 If item is '*', parsing is done on whole string blob and not on each line.
46
47 Item can also be regular expression, where regular expression is used to get key.
48 :ref:`table-title` (Optional) Title help in defining from which section the data should be parsed.
49 :ref:`table-delimiter` (Optional) delimiter to be used to split data of each line and store them as key
50 value pair in the dictionary.
51 :ref:`table-eval` (Optional) Mathematical expression which can be evaluated using python eval
52 function. This can be used on `data` dictionary which is returned by table
53 view.
54 :ref:`table-view` (Optional) View that is used to extract field data from the Table items.
55 ====================== =============================================================
56
57 .. _table-name:
58
59 Table name
60 ^^^^^^^^^^
61
62 The Table name is a user-defined identifier for the Table. The YAML file or
63 string can contain one or more Tables. The start of the YAML document must be
64 left justified. For example::
65
66 ---
67 FPCMemory:
68 command: show memory
69
70 .. _table-command:
71
72 command
73 ^^^^^^^
74
75 Command to be executed on CLI or VTY::
76
77 # CLI command
78 ---
79 EthernetSwitchStatistics:
80 command: show chassis ethernet-switch statistics
81
82 # VTY command to be exectued on target FPC1
83 ---
84 CMErrorTable:
85 command: show cmerror module brief
86 target: fpc1
87
88 .. _table-target:
89
90 target
91 ^^^^^^
92
93 Target FPC on which given command is to get executed::
94
95 # VTY command to be exectued on target FPC1
96 ---
97 FPCMemory:
98 command: show memory
99 target: fpc1
100
101 Given FPC target in Table can be overridden through get API::
102
103 from jnpr.junos.command.fpcmemory import FPCMemory
104
105 stats = FPCMemory(dev)
106 stats = stats.get(target='fpc2')
107
108 .. _table-args:
109
110 args
111 ^^^^
112
113 CLI/VTY command can take parameter(s). Variable parameters in the command can be
114 Jinja template, dictionary under args is used to render command template::
115
116 ---
117 XMChipIfdListTable:
118 command: show xmchip {{ XM_instance }} ifd list {{ direction }}
119 target: fpc1
120 args:
121 XM_instance: 0
122 direction: 0
123
124
125 .. _table-key:
126
127 key
128 ^^^^
129
130 The optional key property is a tag or tags that are used to uniquely identify a
131 Table::
132
133 # Value of task_name key will be taken from the dictionary created from view
134 ---
135 TaskIOTable:
136 command: show task io
137 key: task_name
138 view: TaskIOView
139
140 TaskIOView:
141 columns:
142 task_name: Task Name
143 reads: Reads
144 writes: Writes
145 rcvd: Rcvd
146 sent: Sent
147 dropped: Dropped
148
149
150 # Key can be a list also
151 ---
152 FPCIPV4AddressTable:
153 command: show ipv4 address
154 target: fpc1
155 key:
156 - name
157 - addr
158 view: FPCIPV4AddressView
159
160 FPCIPV4AddressView:
161 columns:
162 index: Index
163 addr: Address
164 name: Name
165
166 .. _table-key-items:
167
168 key_items
169 ^^^^^^^^^
170
171 The optional key_items property is used to select only certain key data in JSON::
172
173 ---
174 FPCMemory:
175 command: show memory
176 target: fpc1
177 key: ID
178 key_items:
179 - 1
180 - 2
181 view: FPCMemoryView
182
183 FPCMemoryView:
184 columns:
185 id: ID
186 base: Base
187 total: Total(b)
188 free: Free(b)
189 used: Used(b)
190 perc: "%"
191 name: Name
192
193 Output for **show memory** is::
194
195 ID Base Total(b) Free(b) Used(b) % Name
196 -- ---------- ----------- ----------- ----------- --- -----------
197 0 4d9ad8e8 1726292636 1514622708 211669928 12 Kernel
198 1 b47ffb88 67108860 53057404 14051456 20 LAN buffer
199 2 bcdfffe0 52428784 52428784 0 0 Blob
200 3 b87ffb88 73400316 73400316 0 0 ISSU scratch
201
202 Even though we have four ID row here, data returned will be for just 1 & 2 as
203 provided in key_items::
204
205 {1: {'base': 'b47ffb88',
206 'free': 53057404,
207 'id': 1,
208 'name': 'LAN buffer',
209 'perc': 20,
210 'total': 67108860,
211 'used': 14051456},
212 2: {'base': 'bcdfffe0',
213 'free': 52428784,
214 'id': 2,
215 'name': 'Blob',
216 'perc': 0,
217 'total': 52428784,
218 'used': 0}}
219
220 .. _table-item:
221
222 item
223 ^^^^
224 The item value is a string or regular expression to split the output in sections.
225
226 Say the out of the command **show devices local** is::
227
228 TSEC Ethernet Device Driver: .le1, Control 0x4296c218, (1000Mbit)
229 HW reg base 0xff724000
230 [0]: TxBD base 0x7853ce20, RxBD Base 0x7853d640
231 [1]: TxBD base 0x7853d860, RxBD Base 0x7853e080
232 [2]: TxBD base 0x7853e2a0, RxBD Base 0x785422c0
233 [3]: TxBD base 0x785426e0, RxBD Base 0x78544700
234 Receive:
235 185584608 bytes, 2250212 packets, 0 FCS errors, 0 multicast packets
236 107271 broadcast packets, 0 control frame packets
237 0 PAUSE frame packets, 0 unknown OP codes
238 0 alignment errors, 0 frame length errors
239 0 code errors, 0 carrier sense errors
240 0 undersize packets, 0 oversize packets
241 0 fragments, 0 jabbers, 0 drops
242 Receive per queue:
243 [0]: 0 bytes, 0 packets, 0 dropped
244 0 jumbo, 0 truncated jumbo
245 [1]: 0 bytes, 0 packets, 0 dropped
246 0 jumbo, 0 truncated jumbo
247 [2]: 0 bytes, 0 packets, 0 dropped
248 0 jumbo, 0 truncated jumbo
249 [3]: 203586808 bytes, 2250219 packets, 0 dropped
250 0 jumbo, 0 truncated jumbo
251 Transmit:
252 288184646 bytes, 2038370 packets, 0 multicast packets
253 106531 broadcast packets, 0 PAUSE control frames
254 0 deferral packets, 0 excessive deferral packets
255 0 single collision packets, 0 multiple collision packets
256 0 late collision packets, 0 excessive collision packets
257 0 total collisions, 0 drop frames, 0 jabber frames
258 0 FCS errors, 0 control frames, 0 oversize frames
259 0 undersize frames, 0 fragments frames
260 Transmit per queue:
261 [0]: 10300254 bytes, 72537 packets
262 0 dropped, 0 fifo errors
263 [1]: 4474302 bytes, 106531 packets
264 0 dropped, 0 fifo errors
265 [2]: 260203538 bytes, 1857137 packets
266 0 dropped, 0 fifo errors
267 [3]: 199334 bytes, 2179 packets
268 0 dropped, 0 fifo errors
269 TSEC status counters:
270 kernel_dropped:0, rx_large:0 rx_short: 0
271 rx_nonoctet: 0, rx_crcerr: 0, rx_overrun: 0
272 rx_bsy: 0,rx_babr:0, rx_trunc: 0
273 rx_length_errors: 0, rx_frame_errors: 0 rx_crc_errors: 0
274 rx_errors: 0, rx_ints: 2250110, collisions: 0
275 eberr:0, tx_babt: 0, tx_underrun: 0
276 tx_timeout: 0, tx_timeout: 0,tx_window_errors: 0
277 tx_aborted_errors: 0, tx_ints: 2038385, resets: 1
278
279
280 TSEC Ethernet Device Driver: .le3, Control 0x42979220, (1000Mbit)
281 HW reg base 0xff726000
282 [0]: TxBD base 0x78545720, RxBD Base 0x78545f40
283 [1]: TxBD base 0x78546160, RxBD Base 0x78546980
284 [2]: TxBD base 0x78546ba0, RxBD Base 0x7854abc0
285 [3]: TxBD base 0x7854afe0, RxBD Base 0x7854d000
286 Receive:
287 0 bytes, 0 packets, 0 FCS errors, 0 multicast packets
288 0 broadcast packets, 0 control frame packets
289 0 PAUSE frame packets, 0 unknown OP codes
290 0 alignment errors, 0 frame length errors
291 0 code errors, 0 carrier sense errors
292 0 undersize packets, 0 oversize packets
293 0 fragments, 0 jabbers, 0 drops
294 Receive per queue:
295 [0]: 0 bytes, 0 packets, 0 dropped
296 0 jumbo, 0 truncated jumbo
297 [1]: 0 bytes, 0 packets, 0 dropped
298 0 jumbo, 0 truncated jumbo
299 [2]: 0 bytes, 0 packets, 0 dropped
300 0 jumbo, 0 truncated jumbo
301 [3]: 0 bytes, 0 packets, 0 dropped
302 0 jumbo, 0 truncated jumbo
303 Transmit:
304 6817984 bytes, 106531 packets, 0 multicast packets
305 106531 broadcast packets, 0 PAUSE control frames
306 0 deferral packets, 0 excessive deferral packets
307 0 single collision packets, 0 multiple collision packets
308 0 late collision packets, 0 excessive collision packets
309 0 total collisions, 0 drop frames, 0 jabber frames
310 0 FCS errors, 0 control frames, 0 oversize frames
311 0 undersize frames, 0 fragments frames
312 Transmit per queue:
313 [0]: 0 bytes, 0 packets
314 0 dropped, 0 fifo errors
315 [1]: 4474302 bytes, 106531 packets
316 0 dropped, 0 fifo errors
317 [2]: 0 bytes, 0 packets
318 0 dropped, 0 fifo errors
319 [3]: 0 bytes, 0 packets
320 0 dropped, 0 fifo errors
321 TSEC status counters:
322 kernel_dropped:0, rx_large:0 rx_short: 0
323 rx_nonoctet: 0, rx_crcerr: 0, rx_overrun: 0
324 rx_bsy: 0,rx_babr:0, rx_trunc: 0
325 rx_length_errors: 0, rx_frame_errors: 0 rx_crc_errors: 0
326 rx_errors: 0, rx_ints: 0, collisions: 0
327 eberr:0, tx_babt: 0, tx_underrun: 0
328 tx_timeout: 0, tx_timeout: 0,tx_window_errors: 0
329 tx_aborted_errors: 0, tx_ints: 106531, resets: 1
330
331
332 And the table to parse above output, item is used to split them into sections.::
333
334 ---
335 DevicesLocalTable:
336 command: show devices local
337 target: fpc1
338 item: 'TSEC Ethernet Device Driver: (\.?\w+),'
339 key: name
340 view: DevicesLocalView
341
342 DevicesLocalView:
343 fields:
344 TSEC_status_counters: _TSECStatusCountersTable
345 receive_counters: _ReceiveTable
346 transmit_per_queue: _TransmitQueueTable
347
348 `key` in above table is fetched from the regex group used in item.
349
350 **item** Can also be provided as '*' if we dont want each line matching but from
351 whole output.::
352
353 _ReceiveTable:
354 item: '*'
355 title: 'Receive:'
356 view: _ReceiveView
357
358 _ReceiveView:
359 regex:
360 bytes: '(\d+) bytes'
361 packets: '(\d+) packets'
362 FCS_errors: '(\d+) FCS errors'
363 broadcast_packets: '(\d+) broadcast packets'
364
365
366 .. _table-title:
367
368 title
369 ^^^^^
370 Title helps in deciding the data to be parsed starting point.::
371
372 _TSECStatusCountersTable:
373 item: '*'
374 title: 'TSEC status counters:'
375 view: _TSECStatusCountersView
376
377 _TSECStatusCountersView:
378 regex:
379 kernel_dropped: 'kernel_dropped:(\d+)'
380 rx_large: 'rx_large:(\d+)'
381
382 helps to parse data from::
383
384 TSEC status counters:
385 kernel_dropped:0, rx_large:0 rx_short: 0
386 rx_nonoctet: 0, rx_crcerr: 0, rx_overrun: 0
387 rx_bsy: 0,rx_babr:0, rx_trunc: 0
388 rx_length_errors: 0, rx_frame_errors: 0 rx_crc_errors: 0
389 rx_errors: 0, rx_ints: 2250110, collisions: 0
390 eberr:0, tx_babt: 0, tx_underrun: 0
391 tx_timeout: 0, tx_timeout: 0,tx_window_errors: 0
392 tx_aborted_errors: 0, tx_ints: 2038385, resets: 1
393
394 .. note:: In above table '*' consider whole data as one paragraph.
395
396
397 .. _table-delimiter:
398
399 delimiter
400 ^^^^^^^^^
401
402 There are some command output which are just key value pairs. They can be split
403 using given delimiter and converted to JSON. Consider below table::
404
405 ---
406 FPCLinkStatTable:
407 command: show link stats
408 target: fpc1
409 delimiter: ":"
410
411 Output for command **show links stats**::
412
413 PPP LCP/NCP: 0
414 HDLC keepalives: 0
415 RSVP: 0
416 ISIS: 0
417 OSPF Hello: 539156
418 OAM: 0
419 BFD: 15
420 UBFD: 0
421 LMI: 0
422 LACP: 0
423 ETHOAM: 0
424 SYNCE: 0
425 PTP: 0
426 L2TP: 0
427 LNS-PPP: 0
428 ARP: 4292
429 ELMI: 0
430 VXLAN MRESOLVE: 0
431 Unknown protocol: 42
432
433 Using given delimiter ":" output is parsed to get::
434
435 {'ARP': 4292, 'ELMI': 0, 'SYNCE': 0, 'ISIS': 0, 'BFD': 15, 'PPP LCP/NCP': 0,
436 'OAM': 0, 'ETHOAM': 0, 'LACP': 0, 'LMI': 0, 'Unknown protocol': 42,
437 'UBFD': 0, 'L2TP': 0, 'HDLC keepalives': 0, 'LNS-PPP': 0,
438 'OSPF Hello': 539156, 'RSVP': 0, 'VXLAN MRESOLVE': 0, 'PTP': 0}
439
440 .. _table-eval:
441
442 eval
443 ^^^^
444
445 Using eval keyword, we can add extra key/value to the final data returned from Table/View.
446 value is evaluated from the Mathematical expression provided by the user.
447 eval expression can use **data** which can be considered as the dictionary returned from
448 table/view. data should be kept under Jinja template so that PyEZ can replace data with
449 dictonary.
450
451
452 .. note:: For more details about python eval function. check this `Link <https://docs.python.org/3/library/functions.html#eval>`_
453
454 Examples::
455
456 ---
457 CChipLiInterruptStatsTable:
458 command: show mqss {{ chip_instance }} li interrupt-stats
459 target: NULL
460 args:
461 chip_instance: 0
462 key:
463 - li_block
464 - name
465 view: CChipLiInterruptStatsView
466 eval:
467 cchip_errors_from_lkup_chip: "reduce(lambda x,y: x+y, [v['interrupts'] for k,v in {{ data }}.items()])"
468
469 CChipLiInterruptStatsView:
470 columns:
471 li_block: LI Block
472 name: Interrupt Name
473 interrupts: Number of Interrupts
474 last_occurance: Last Occurrence
475
476 |
477
478 ::
479
480 ---
481 CChipLiInterruptStatsTable:
482 command: show xmchip {{ chip_instance }} li interrupt-stats
483 target: NULL
484 args:
485 chip_instance: 0
486 key:
487 - li_block
488 - name
489 eval:
490 cchip_errors_from_lkup_chip: "reduce(lambda x,y: x+y, [v['interrupts'] for k,v in {{ data }}.items()])"
491 view: CChipLiInterruptStatsView
492
493 CChipLiInterruptStatsView:
494 columns:
495 li_block: LI Block
496 name: Interrupt Name
497 interrupts: Number of Interrupts
498 last_occurance: Last Occurrence
499
500
501 eval can be used to calculate multile values::
502
503 ---
504 CChipDRDErrTable:
505 command: show mqss {{ instance }} drd error-stats
506 args:
507 instance: 0
508 target: NULL
509 key: Interrupt Name
510 item: '*'
511 view: CChipDRDErrView
512 eval:
513 cchip_drd_wan_errors: sum([v['interrupt_count_wan'] for k, v in {{ data }}.items() if isinstance(v, dict)])
514 cchip_drd_fab_errors: sum([v['interrupt_count_fab'] for k, v in {{ data }}.items() if isinstance(v, dict)])
515
516 CChipDRDErrView:
517 regex:
518 cchip_drd_wan_timeouts: 'Total WAN reorder ID timeout errors:\s+(\d+)'
519 cchip_drd_fab_timeouts: 'Total fabric reorder ID timeout errors:\s+(\d+)'
520 columns:
521 interrupt_name: Interrupt Name
522 interrupt_count_wan:
523 - Number of
524 - Reorder Engine 0
525 interrupt_count_fab:
526 - Interrupts
527 - Reorder Engine 1
528
529 |
530
531 ::
532
533 ---
534 CChipDRDErrTable:
535 command: show xmchip {{ instance }} drd error-stats
536 args:
537 instance: 0
538 target: NULL
539 key: Interrupt Name
540 item: '*'
541 view: CChipDRDErrView
542 eval:
543 cchip_drd_wan_errors: sum([v['interrupt_count'] for k, v in {{ data }}.items() if k.endswith('_0')])
544 cchip_drd_fab_errors: sum([v['interrupt_count'] for k, v in {{ data }}.items() if k.endswith('_1')])
545
546 CChipDRDErrView:
547 regex:
548 cchip_drd_wan_timeouts: 'Total WAN reorder ID timeout errors:\s+(\d+)'
549 cchip_drd_fab_timeouts: 'Total fabric reorder ID timeout errors:\s+(\d+)'
550 columns:
551 interrupt_name: Interrupt Name
552 interrupt_count: Number of Interrupts
553 filters:
554 - interrupt_count
555
556
557 .. _table-view:
558
559 view
560 ^^^^^
561
562 View is defined how the output from the table to be parsed. Different keyword
563 which can be used with view is defined in next section. Every view will be
564 associated with a table.
565
566 Example::
567
568 ---
569 CMErrorTable:
570 command: show cmerror module brief
571 target: fpc1
572 key: module
573 view: CMErrorView
574
575 CMErrorView:
576 columns:
577 module: Module
578 name: Name
579 errors: Active Errors
580
581 View Keywords
582 =============
583
584 Junos PyEZ Tables select specific data from the command reply from devices running Junos OS.
585 A Table is associated with a View, which is used to access fields in the Table items.
586 You associate a Table with a particular View by including the view property in the Table
587 definition, which takes the View name as its argument.
588
589 A View maps your user-defined field names to string elements in the selected Table
590 items. A View enables you to access specific fields in the output as variables
591 with properties that can be manipulated in Python. Junos PyEZ handles the extraction
592 of the data into JSON for unstructured command output.
593
594 .. table:: YAML definition to parse command output
595 :widths: auto
596
597 ==================== =============================================================
598 Parameter Description
599 ==================== =============================================================
600 :ref:`view-columns` (Optional) List of column title as seen in command output
601 :ref:`view-regex` (Optional) List of regular expression to match desired content
602 :ref:`view-fields` (Optional) List of nested tables.
603 :ref:`view-exists` (Optional) If the given statement exists, sets True else False
604 :ref:`view-filters` (Optional) list of column item which should only go to dictionary data
605 ==================== =============================================================
606
607
608
609 .. _view-columns:
610
611 columns
612 ^^^^^^^
613
614 Consider the case where the output of the command is in row/column format. For
615 Example **show lkup-asic wedge-client**::
616
617 Wedge poll thread state : 'Started'
618 Total registered clients : 4
619 CID Name PfeInst AscIdx PPEMask ZoneMask RordChk Mode
620 ----------------------------------------------------------------------------------
621 0 LUCHIP(0) 0 0 0x0000000000000000 0x000000000000ffff 0x0000f000 Disabled NORMAL
622 1 LUCHIP(4) 0 1 0x0000000000000000 0x000000000000ffff 0x0000f000 Disabled NORMAL
623 2 LUCHIP(8) 0 2 0x0000000000000000 0x000000000000ffff 0x0000f000 Disabled NORMAL
624 3 LUCHIP(12) 0 3 0x0000000000000000 0x000000000000ffff 0x0000f000 Disabled NORMAL
625
626 Client ID Curr State Prev State Last read
627 ------------------------------------------------------
628 0 NORMAL NORMAL 6294337620
629 1 DISABLED NORMAL 6294337620
630 2 DISABLED NORMAL 6294337620
631 3 DISABLED NORMAL 6294337620
632
633 And we want to parse the data of second section consisting of client id, curr state,
634 previous state and last read. We will define table/view with view declares all columns::
635
636 ---
637 LUChipStatusTable:
638 command: show lkup-asic wedge-client
639 target: fpc1
640 key: Client ID
641 view: LUChipStatusView
642
643 LUChipStatusView:
644 columns:
645 client_id: Client ID
646 curr_state: Curr State
647 prev_state: Prev State
648 last_read: Last read
649
650 Output received will be::
651
652 {0: {'client_id': 0,
653 'curr_state': 'NORMAL',
654 'last_read': 6294337620,
655 'prev_state': 'NORMAL'},
656 1: {'client_id': 1,
657 'curr_state': 'DISABLED',
658 'last_read': 6294337620,
659 'prev_state': 'NORMAL'},
660 2: {'client_id': 2,
661 'curr_state': 'DISABLED',
662 'last_read': 6294337620,
663 'prev_state': 'NORMAL'},
664 3: {'client_id': 3,
665 'curr_state': 'DISABLED',
666 'last_read': 6294337620,
667 'prev_state': 'NORMAL'}}
668
669 .. note:: In columns we need to provide all column title to help parse the data.
670
671
672 There are situation when column title are spread across multiple line. In such
673 cases columns keys element should be list of words corresponding to their columns.
674
675 For command ``show cmerror module brief`` with cli output::
676
677 -------------------------------------------------------------------------
678 Module Name Active Errors PFE Callback ModuleData
679 Specific Function
680 -------------------------------------------------------------------------
681 1 PQ3 Chip 0 Yes 0x00000000 0x00000000
682 2 Host Loopback 0 No 0x00000000 0x464295b0
683 3 CM[0] 0 No 0x41f550f0 0x462f767c
684
685
686 Table/View to parse above output::
687
688 ---
689 CMErrorTable:
690 command: show cmerror module brief dummy multiline
691 target: Null
692 key: module
693 view: CMErrorView
694
695 CMErrorView:
696 columns:
697 module: Module
698 name: Name
699 errors: Active Errors
700 pfe:
701 - PFE
702 - Specific
703 callback:
704 - Callback
705 - Function
706 data: ModuleData
707
708 Similarly for command ``show mqss 0 fi interrupt-stats`` with cli output::
709
710 FI interrupt statistics
711 -----------------------
712
713 --------------------------------------------------------------------------------------
714 Stream Total RLIM Total Cell timeout Total Reorder Total cell Total number
715 request PT/MALLOC Ignored cell timeout drops in of times
716 counter Usemeter errors secure mode entered into
717 saturation Drops secure mode
718 --------------------------------------------------------------------------------------
719 36 0 0 1 1 0 0
720 128 0 0 1 49 0 0
721 142 0 0 1 53 0 0
722 --------------------------------------------------------------------------------------
723 --------------------------------------------------------------------------
724 Stream Stream reconfiguration Total Error Total Late Total CRC Errored
725 count due to pointers Cells Cells Packets
726 stalled in secure mode
727 --------------------------------------------------------------------------
728 36 0 0 1 0
729 --------------------------------------------------------------------------
730
731 Table/View to parse above output::
732
733 CChipFiStatsTable:
734 command: show mqss {{ chip_instance }} fi interrupt-stats
735 target: fpc8
736 args:
737 chip_instance: 0
738 key: Stream
739 view: CChipFiStatsView
740
741 CChipFiStatsView:
742 columns:
743 stream: Stream
744 req_sat:
745 - Total RLIM
746 - request
747 - counter
748 - saturation
749 cchip_fi_malloc_drops:
750 - Total
751 - PT/MALLOC
752 - Usemeter
753 - Drops
754 cell_timeout_ignored:
755 - Cell timeout
756 - Ignored
757 cchip_fi_cell_timeout:
758 - Total Reorder
759 - cell timeout
760 - errors
761 drops_in_secure:
762 - Total cell
763 - drops in
764 - secure mode
765 times_in_secure:
766 - Total number
767 - of times
768 - entered into
769 - secure mode
770
771
772 .. _view-regex:
773
774 regex
775 ^^^^^
776 list of regular expression which combined together should match one line.
777 consider command output for ``show icmp statistics``
778
779 ::
780
781 ICMP Statistics:
782 0 requests
783 0 throttled
784 0 network unreachables
785 0 ttl expired
786 0 redirects
787 0 mtu exceeded
788 0 source route denials
789 0 filter prohibited
790 0 other unreachables
791 0 parameter problems
792 0 ttl captured
793 0 icmp/option handoffs
794 0 igmp v1 handoffs
795 0 tag te requests
796 0 tag te to RE
797
798 ICMP Errors:
799 0 unknown unreachables
800 0 unsupported ICMP type
801 0 unprocessed redirects
802 0 invalid ICMP type
803 0 invalid protocol
804 0 bad input interface
805 0 bad route lookup
806 0 bad nh lookup
807 0 bad cf mtu
808 0 runts
809
810 ICMP Discards:
811 0 multicasts
812 0 bad source addresses
813 0 bad dest addresses
814 0 IP fragments
815 0 ICMP errors
816 0 unknown originators
817
818 ICMP Debug Messages:
819 0 throttled
820
821 ICMP Rate Limit Settings:
822 500 pps per iff
823 1000 pps total
824
825 Here datas are under different title and data is numbers + word(s).
826 Hence the below table/view use regular expression to parse key (numbers)
827 and value (words).
828
829 Table/View::
830
831 ---
832 ICMPStatsTable:
833 command: show icmp statistics
834 target: fpc1
835 view: ICMPStatsView
836
837 ICMPStatsView:
838 fields:
839 discards: _ICMPDiscardsTable
840 errors: _ICMPErrorsTable
841 rate: _ICMPRateTable
842
843 _ICMPDiscardsTable:
844 title: ICMP Discards
845 key: name
846 view: _ICMPDiscardsView
847
848 _ICMPDiscardsView:
849 regex:
850 value: \d+
851 name: '(\w+(\s\w+)*)'
852
853 _ICMPErrorsTable:
854 title: ICMP Errors
855 key: name
856 view: _ICMPErrorsView
857
858 _ICMPErrorsView:
859 regex:
860 error: numbers
861 name: words
862
863 _ICMPRateTable:
864 title: ICMP Rate Limit Settings
865 key: name
866 view: _ICMPRateView
867
868 _ICMPRateView:
869 regex:
870 rate: numbers
871 name: words
872
873 Check _ICMPDiscardsTable and _ICMPDiscardsView. *title* (ICMP Discards) under
874 _ICMPDiscardsTable is used to get to the starting point for parsing.
875 value and name are the keys and corresponding regex value is combined to parse
876 each line. Also in such data key cannot be value, so we can select right hand
877 side data *name* as the key.
878
879 We also define some inbuilt keywords which can be used in place of regular
880 expression. Check _ICMPErrorsView. Below are the list of inbuilt keywords and
881 corresponding expression used.
882
883 * **numbers** = (pp.Word(pp.nums) + pp.Optional(pp.Literal('.') + pp.Word(pp.nums))).setParseAction(lambda i: ''.join(i))
884 * **hex_numbers** = pp.OneOrMore(pp.Word(pp.nums, min=1)) & pp.OneOrMore(pp.Word('abcdefABCDEF', min=1))
885 * **word** = pp.Word(pp.alphanums) | pp.Word(pp.alphas)
886 * **words** = (pp.OneOrMore(word)).setParseAction(lambda i: ' '.join(i))
887 * **percentage** = pp.Word(pp.nums) + pp.Literal('%')
888 * **printables** = pp.OneOrMore(pp.Word(pp.printables))
889
890 Here **pp** is coming from (import pyparsing as pp)
891
892 When table :ref:`table-item` is proved, regex is used on the splitted items.
893 Say when item is * regex is used on whole string blob and not combined to parse
894 each line. For example check the output of command ``show ithrottle id 0``::
895
896 SENT: Ukern command: show ithrottle id 0
897
898 ID Usage % Cfg State Oper State Name
899 -- ------- --------- ---------- --------
900 0 50.0 1 1 TOE ithrottle
901
902 Throttle Times: In hptime ticks In ms
903 --------------- ------
904 Timer Interval 333333 5.000
905 Allowed time 166666 2.500
906 Allowed excess 8333 0.125
907 Start time 488655082 n/a
908 Run time this interval 0 0.000
909 Deficit 0 0.000
910 Run time max 17712 0.266
911 Run time total 144154525761 2162317
912
913 Min Usage Perc: 25.0
914 Max Usage Perc: 50.0
915 AdjustUsageEnable: 1
916
917 Throttle Stats:
918 Starts : 65708652
919 Stops : 65708652
920 Checks : 124149442
921 Enables : 0
922 Disables : 0
923 AdjUp : 6
924 AdjDown : 4
925
926 Table/View used for parsing above output::
927
928 IthrottleIDTable:
929 command: show ithrottle id {{ id }}
930 args:
931 id: 0
932 item: '*'
933 target: fpc1
934 view: IthrottleIDView
935
936 IthrottleIDView:
937 regex:
938 min_usage: 'Min Usage Perc: (\d+\.\d+)'
939 max_usage: 'Max Usage Perc: (\d+\.\d+)'
940 usg_enable: 'AdjustUsageEnable: (\d)'
941 fields:
942 throttle_stats: _ThrottleStatsTable
943
944 _ThrottleStatsTable:
945 title: Throttle Stats
946 delimiter: ":"
947
948 Here item is \*, hence whole string blob is used to search for given regular expressions.
949
950 output::
951
952 {'max_usage': 50.0,
953 'min_usage': 25.0,
954 'throttle_stats': {'AdjDown': 4,
955 'AdjUp': 6,
956 'Checks': 124149442,
957 'Disables': 0,
958 'Enables': 0,
959 'Starts': 65708652,
960 'Stops': 65708652},
961 'usg_enable': 1}
962
963 .. note:: grouping is used to get specific data from regex expression. For example. (\d+\.\d+) is used to get the float value from string search expression. if we change expression to **Max Usage Perc: (\d+)\.\d+** we will get integer part only.
964
965
966 .. _view-fields:
967
968 fields
969 ^^^^^^
970
971 Where the command output has different sections of data which need different logic
972 to parse those subset of data, we can define nested tables under fields section.
973
974 For command ``show xmchip 0 pt stats`` we have 2 section of data::
975
976 SENT: Ukern command: show xmchip 0 pt stats
977
978
979 WAN PT statistics (Index 0)
980 ---------------------------
981
982 PCT entries used by all WI-1 streams : 0
983 PCT entries used by all WI-0 streams : 0
984 PCT entries used by all LI streams : 0
985 CPT entries used by all multicast packets : 0
986 CPT entries used by all WI-1 streams : 0
987 CPT entries used by all WI-0 streams : 0
988 CPT entries used by all LI streams : 0
989
990 Fabric PT statistics (Index 1)
991 ------------------------------
992
993 PCT entries used by all FI streams : 0
994 PCT entries used by all WI (Unused) streams : 0
995 PCT entries used by all LI streams : 0
996 CPT entries used by all multicast packets : 0
997 CPT entries used by all FI streams : 0
998 CPT entries used by all WI (Unused) streams : 0
999 CPT entries used by all LI streams : 0
1000
1001 So we defined fields with two nested table each used to parse different subset
1002 of data::
1003
1004 ---
1005 XMChipStatsTable:
1006 command: show xmchip 0 pt stats
1007 target: fpc1
1008 view: XMChipStatsView
1009
1010 XMChipStatsView:
1011 fields:
1012 wan_pt_stats: _WANPTStatTable
1013 fabric_pt_stats: _FabricPTStatTable
1014
1015 _WANPTStatTable:
1016 title: WAN PT statistics (Index 0)
1017 delimiter: ":"
1018
1019 _FabricPTStatTable:
1020 title: Fabric PT statistics (Index 1)
1021 delimiter: ":"
1022
1023 Output::
1024
1025 {'fabric_pt_stats': {'CPT entries used by all FI streams': 0,
1026 'CPT entries used by all LI streams': 0,
1027 'CPT entries used by all WI (Unused) streams': 0,
1028 'CPT entries used by all multicast packets': 0,
1029 'PCT entries used by all FI streams': 0,
1030 'PCT entries used by all LI streams': 0,
1031 'PCT entries used by all WI (Unused) streams': 0},
1032 'wan_pt_stats': {'CPT entries used by all LI streams': 0,
1033 'CPT entries used by all WI-0 streams': 0,
1034 'CPT entries used by all WI-1 streams': 0,
1035 'CPT entries used by all multicast packets': 0,
1036 'PCT entries used by all LI streams': 0,
1037 'PCT entries used by all WI-0 streams': 0,
1038 'PCT entries used by all WI-1 streams': 0}}
1039
1040 Another example using command output for ``show ttp statistics``::
1041
1042 SENT: Ukern command: show ttp statistics
1043
1044 TTP Statistics:
1045 Receive Transmit
1046 ---------- ----------
1047 L2 Packets 4292 1093544
1048 L3 Packets 542638 0
1049 Drops 0 0
1050 Netwk Fail 0 0
1051 Queue Drops 0 0
1052 Unknown 0 0
1053 Coalesce 0 0
1054 Coalesce Fail 0 0
1055
1056 TTP Transmit Statistics:
1057 Queue 0 Queue 1 Queue 2 Queue 3
1058 ---------- ---------- ---------- ----------
1059 L2 Packets 1093544 0 0 0
1060 L3 Packets 0 0 0 0
1061
1062 TTP Receive Statistics:
1063 Control High Medium Low Discard
1064 ---------- ---------- ---------- ---------- ----------
1065 L2 Packets 0 0 4292 0 0
1066 L3 Packets 0 539172 3466 0 0
1067 Drops 0 0 0 0 0
1068 Queue Drops 0 0 0 0 0
1069 Unknown 0 0 0 0 0
1070 Coalesce 0 0 0 0 0
1071 Coalesce Fail 0 0 0 0 0
1072
1073 TTP Receive Queue Sizes:
1074 Control Plane : 0 (max is 4473)
1075 High : 0 (max is 4473)
1076 Medium : 0 (max is 4473)
1077 Low : 0 (max is 2236)
1078
1079 TTP Transmit Queue Size: 0 (max is 6710)
1080
1081 Table/View used to parse above output using nested table/view under fields::
1082
1083 ---
1084 FPCTTPStatsTable:
1085 command: show ttp statistics
1086 target: fpc2
1087 view: FPCTTPStatsView
1088
1089 FPCTTPStatsView:
1090 fields:
1091 TTPStatistics: _FPCTTPStatisticsTable
1092 TTPTransmitStatistics: _FPCTTPTransmitStatisticsTable
1093 TTPReceiveStatistics: _FPCTTPReceiveStatisticsTable
1094 TTPQueueSizes: _FPCTTPQueueSizesTable
1095
1096 _FPCTTPStatisticsTable:
1097 title: TTP Statistics
1098 view: _FPCTTPStatisticsView
1099
1100 _FPCTTPStatisticsView:
1101 columns:
1102 rcvd: Receive
1103 tras: Transmit
1104
1105 _FPCTTPTransmitStatisticsTable:
1106 title: TTP Transmit Statistics
1107 view: _FPCTTPTransmitStatisticsView
1108
1109 _FPCTTPTransmitStatisticsView:
1110 columns:
1111 queue0: Queue 0
1112 queue1: Queue 1
1113 queue2: Queue 2
1114 queue3: Queue 3
1115 filters:
1116 - queue2
1117
1118 _FPCTTPReceiveStatisticsTable:
1119 title: TTP Receive Statistics
1120 key: name
1121 key_items:
1122 - Coalesce
1123 view: _FPCTTPReceiveStatisticsView
1124
1125 _FPCTTPReceiveStatisticsView:
1126 columns:
1127 control: Control
1128 high: High
1129 medium: Medium
1130 low: Low
1131 discard: Discard
1132
1133 _FPCTTPQueueSizesTable:
1134 title: TTP Receive Queue Sizes
1135 delimiter: ":"
1136
1137 Output::
1138
1139 {'TTPQueueSizes': {'Control Plane': '0 (max is 4473)',
1140 'High': '0 (max is 4473)',
1141 'Low': '0 (max is 2236)',
1142 'Medium': '0 (max is 4473)'},
1143 'TTPReceiveStatistics': {'Coalesce': {'control': 0,
1144 'discard': 0,
1145 'high': 0,
1146 'low': 0,
1147 'medium': 0,
1148 'name': 'Coalesce'}},
1149 'TTPStatistics': {'Coalesce': {'name': 'Coalesce', 'rcvd': 0, 'tras': 0},
1150 'Coalesce Fail': {'name': 'Coalesce Fail',
1151 'rcvd': 0,
1152 'tras': 0},
1153 'Drops': {'name': 'Drops', 'rcvd': 0, 'tras': 0},
1154 'L2 Packets': {'name': 'L2 Packets',
1155 'rcvd': 0,
1156 'tras': 7468},
1157 'L3 Packets': {'name': 'L3 Packets', 'rcvd': 0, 'tras': 0},
1158 'Netwk Fail': {'name': 'Netwk Fail',
1159 'rcvd': 0,
1160 'tras': 173},
1161 'Queue Drops': {'name': 'Queue Drops',
1162 'rcvd': 0,
1163 'tras': 0},
1164 'Unknown': {'name': 'Unknown', 'rcvd': 0, 'tras': 0}},
1165 'TTPTransmitStatistics': {'L2 Packets': {'queue2': 0},
1166 'L3 Packets': {'queue2': 0}}}
1167
1168 .. note:: fields in unstructured table/view is different compared to rpc based table/view. For RPC, fields are xpath tags.
1169
1170
1171 .. _view-exists:
1172
1173
1174 exists
1175 ^^^^^^
1176
1177 If we just need to check if the given string statement is present or not in the
1178 command output. we can use ``exists`` option. For example
1179
1180 For command output of ``show host_loopback status-summary``::
1181
1182 SENT: Ukern command: show host_loopback status-summary
1183
1184 Host Loopback Toolkit Status Summary:
1185
1186 No detected wedges
1187
1188 No toolkit errors
1189
1190
1191 Table/View defined::
1192
1193 ---
1194 HostlbStatusSummaryTable:
1195 command: show host_loopback status-summary
1196 target: fpc1
1197 view: HostlbStatusSummaryView
1198
1199 HostlbStatusSummaryView:
1200 exists:
1201 no_detected_wedges: No detected wedges
1202 no_toolkit_errors: No toolkit errors
1203
1204 Output::
1205
1206 {'no_detected_wedges': True, 'no_toolkit_errors': True}
1207
1208 .. _view-filters:
1209
1210 filters
1211 ^^^^^^^
1212
1213 When we are interested in only few keys from the parsed output, we can filter
1214 filter out the desired key/value using filters. Filters takes a list of keys
1215 from columns items. Final output dictionary should only consist of items listed
1216 in filters per iteration of view output.
1217
1218 Consider below table/view::
1219
1220 ---
1221 CMErrorTable:
1222 command: show cmerror module brief
1223 target: fpc1
1224 key:
1225 - module
1226 view: CMErrorView
1227
1228 CMErrorView:
1229 columns:
1230 module: Module
1231 name: Name
1232 errors: Active Errors
1233 filters:
1234 - errors
1235
1236 Output from command ``show cmerror module brief``::
1237
1238 ---------------------------------------
1239 Module Name Active Errors
1240 ---------------------------------------
1241 1 PQ3 Chip 0
1242 2 Host Loopback 0
1243 3 CM[0] 0
1244 4 LUCHIP(0) 0
1245 5 TOE-LU-0:0:0 0
1246 6 LUCHIP(4) 0
1247 7 TOE-LU-0:1:0 0
1248 8 LUCHIP(8) 0
1249 9 TOE-LU-0:2:0 0
1250 10 LUCHIP(12) 0
1251 11 TOE-LU-0:3:0 0
1252 12 XMCHIP(0) 0
1253 13 TOE-XM-0:0:0 0
1254 14 MPC 0
1255 15 GE Switch 0
1256 16 PMB 0
1257 17 JNH 0
1258 18 PRECL:0:XM:0 0
1259 19 PRECL:1:XM:0 0
1260
1261
1262 Output::
1263
1264 {1: {'errors': 0}, 2: {'errors': 0}, 3: {'errors': 0}, 4: {'errors': 0},
1265 5: {'errors': 0}, 6: {'errors': 0}, 7: {'errors': 0}, 8: {'errors': 0},
1266 9: {'errors': 0}, 10: {'errors': 0}, 11: {'errors': 0}, 12: {'errors': 0},
1267 13: {'errors': 0}, 14: {'errors': 0}, 15: {'errors': 0}, 16: {'errors': 0},
1268 17: {'errors': 0}, 18: {'errors': 0}, 19: {'errors': 0}}