1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-17 00:07:37 +02:00
Files
jc/docs/parsers/ping_s.md

110 lines
3.5 KiB
Markdown
Raw Normal View History

2021-09-13 21:15:26 -07:00
[Home](https://kellyjonbrazil.github.io/jc/)
2022-01-25 17:07:47 -08:00
<a id="jc.parsers.ping_s"></a>
# jc.parsers.ping\_s
2021-09-13 21:15:26 -07:00
2022-03-04 13:27:39 -08:00
jc - JSON Convert `ping` command output streaming parser
2021-09-13 21:15:26 -07:00
2022-04-28 13:38:24 -07:00
> This streaming parser outputs JSON Lines (cli) or returns an Iterable of
Dictionaries (module)
2021-09-20 13:21:20 -07:00
Supports `ping` and `ping6` output.
2021-09-13 21:15:26 -07:00
Usage (cli):
2022-01-25 18:03:34 -08:00
$ ping | jc --ping-s
2021-09-13 21:15:26 -07:00
2022-01-19 17:30:14 -08:00
> Note: When piping `jc` converted `ping` output to other processes it may
2022-01-25 18:03:34 -08:00
appear the output is hanging due to the OS pipe buffers. This is because
`ping` output is too small to quickly fill up the buffer. Use the `-u`
option to unbuffer the `jc` output if you would like immediate output.
See the [readme](https://github.com/kellyjonbrazil/jc/tree/master#unbuffering-output)
for more information.
2021-09-20 13:21:20 -07:00
2021-09-13 21:15:26 -07:00
Usage (module):
2022-01-25 18:03:34 -08:00
import jc
2022-01-18 15:38:03 -08:00
2022-03-10 13:32:26 -08:00
result = jc.parse('ping_s', ping_command_output.splitlines())
2022-01-25 18:03:34 -08:00
for item in result:
# do something
2021-09-13 21:15:26 -07:00
Schema:
2022-01-25 18:03:34 -08:00
{
"type": string, # [0]
"source_ip": string,
"destination_ip": string,
"sent_bytes": integer,
"pattern": string, # (null if not set)
"destination": string,
"timestamp": float,
"response_bytes": integer,
"response_ip": string,
"icmp_seq": integer,
"ttl": integer,
"time_ms": float,
"duplicate": boolean,
"packets_transmitted": integer,
"packets_received": integer,
"packet_loss_percent": float,
"duplicates": integer,
"round_trip_ms_min": float,
"round_trip_ms_avg": float,
"round_trip_ms_max": float,
"round_trip_ms_stddev": float,
2022-03-10 10:10:57 -08:00
# below object only exists if using -qq or ignore_exceptions=True
"_jc_meta": {
"success": boolean, # false if error parsing
"error": string, # exists if "success" is false
"line": string # exists if "success" is false
}
2022-01-25 18:03:34 -08:00
}
[0] 'reply', 'timeout', 'summary', etc. See `_error_type.type_map`
for all options.
Examples:
$ ping 1.1.1.1 | jc --ping-s
{"type":"reply","destination_ip":"1.1.1.1","sent_bytes":56,"patte...}
{"type":"reply","destination_ip":"1.1.1.1","sent_bytes":56,"patte...}
{"type":"reply","destination_ip":"1.1.1.1","sent_bytes":56,"patte...}
...
$ ping 1.1.1.1 | jc --ping-s -r
{"type":"reply","destination_ip":"1.1.1.1","sent_bytes":"56","patte...}
{"type":"reply","destination_ip":"1.1.1.1","sent_bytes":"56","patte...}
{"type":"reply","destination_ip":"1.1.1.1","sent_bytes":"56","patte...}
...
2022-01-25 17:07:47 -08:00
<a id="jc.parsers.ping_s.parse"></a>
2022-03-05 12:15:14 -08:00
### parse
2022-01-25 17:07:47 -08:00
2021-09-13 21:15:26 -07:00
```python
2022-02-03 15:47:46 -08:00
@add_jc_meta
2022-01-25 17:07:47 -08:00
def parse(data, raw=False, quiet=False, ignore_exceptions=False)
2021-09-13 21:15:26 -07:00
```
2022-04-28 13:30:11 -07:00
Main text parsing generator function. Returns an iterable object.
2021-09-13 21:15:26 -07:00
2022-01-25 18:03:34 -08:00
Parameters:
2022-01-19 17:30:14 -08:00
2022-01-25 18:03:34 -08:00
data: (iterable) line-based text data to parse
(e.g. sys.stdin or str.splitlines())
2021-09-13 21:15:26 -07:00
2022-01-25 18:03:34 -08:00
raw: (boolean) unprocessed output if True
quiet: (boolean) suppress warning messages if True
2022-02-04 12:14:16 -08:00
ignore_exceptions: (boolean) ignore parsing exceptions if True
2021-09-13 21:15:26 -07:00
2022-01-25 18:03:34 -08:00
Returns:
2022-04-28 13:30:11 -07:00
Iterable of Dictionaries
2021-09-21 16:03:00 -07:00
2022-01-25 19:18:54 -08:00
### Parser Information
2021-09-21 12:32:34 -07:00
Compatibility: linux, darwin, freebsd
2021-09-13 21:15:26 -07:00
2022-02-03 15:47:46 -08:00
Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com)