2021-09-13 21:15:26 -07:00
[Home ](https://kellyjonbrazil.github.io/jc/ )
# jc.parsers.ping_s
jc - JSON CLI output utility `ping` command output streaming parser
2021-09-27 10:35:08 -07:00
> This streaming parser outputs JSON Lines
2021-09-20 13:21:20 -07:00
Supports `ping` and `ping6` output.
2021-09-13 21:15:26 -07:00
Usage (cli):
2021-09-20 11:51:27 -07:00
$ ping | jc --ping-s
2021-09-13 21:15:26 -07:00
2021-09-26 16:29:36 -07:00
> Note: When piping `jc` converted `ping` output to other processes it may 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):
import jc.parsers.ping_s
2021-09-21 12:32:34 -07:00
result = jc.parsers.ping_s.parse(ping_command_output.splitlines()) # result is an iterable object
2021-09-13 21:15:26 -07:00
for item in result:
# do something
Schema:
{
2021-09-20 11:51:27 -07:00
"type": string, # 'reply', 'timeout', 'summary', etc. See `_error_type.type_map` for all options.
"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,
2021-09-24 09:24:30 -07:00
"_jc_meta": # This object only exists if using -qq or ignore_exceptions=True
2021-09-13 21:15:26 -07:00
{
2021-09-20 11:51:27 -07:00
"success": booean, # true if successfully parsed, false if error
"error": string, # exists if "success" is false
"line": string # exists if "success" is false
2021-09-13 21:15:26 -07:00
}
}
Examples:
2021-09-20 11:51:27 -07:00
$ ping 1.1.1.1 | jc --ping-s
{"type":"reply","destination_ip":"1.1.1.1","sent_bytes":56,"pattern":null,"response_bytes":64,"response_ip":"1.1.1.1","icmp_seq":0,"ttl":56,"time_ms":23.703}
{"type":"reply","destination_ip":"1.1.1.1","sent_bytes":56,"pattern":null,"response_bytes":64,"response_ip":"1.1.1.1","icmp_seq":1,"ttl":56,"time_ms":22.862}
{"type":"reply","destination_ip":"1.1.1.1","sent_bytes":56,"pattern":null,"response_bytes":64,"response_ip":"1.1.1.1","icmp_seq":2,"ttl":56,"time_ms":22.82}
2021-09-13 21:15:26 -07:00
...
2021-09-20 11:51:27 -07:00
$ ping 1.1.1.1 | jc --ping-s -r
{"type":"reply","destination_ip":"1.1.1.1","sent_bytes":"56","pattern":null,"response_bytes":"64","response_ip":"1.1.1.1","icmp_seq":"0","ttl":"56","time_ms":"23.054"}
{"type":"reply","destination_ip":"1.1.1.1","sent_bytes":"56","pattern":null,"response_bytes":"64","response_ip":"1.1.1.1","icmp_seq":"1","ttl":"56","time_ms":"24.739"}
{"type":"reply","destination_ip":"1.1.1.1","sent_bytes":"56","pattern":null,"response_bytes":"64","response_ip":"1.1.1.1","icmp_seq":"2","ttl":"56","time_ms":"23.232"}
2021-09-13 21:15:26 -07:00
...
## info
```python
info()
```
Provides parser metadata (version, author, etc.)
## parse
```python
2021-09-23 11:48:39 -07:00
parse(data, raw=False, quiet=False, ignore_exceptions=False)
2021-09-13 21:15:26 -07:00
```
2021-09-21 16:03:00 -07:00
Main text parsing generator function. Returns an iterator object.
2021-09-13 21:15:26 -07:00
Parameters:
2021-09-23 11:48:39 -07:00
data: (iterable) line-based text data to parse (e.g. sys.stdin or str.splitlines())
raw: (boolean) output preprocessed JSON if True
quiet: (boolean) suppress warning messages if True
ignore_exceptions: (boolean) ignore parsing exceptions if True
2021-09-13 21:15:26 -07:00
Yields:
Dictionary. Raw or processed structured data.
2021-09-21 16:03:00 -07:00
Returns:
Iterator object
2021-09-13 21:15:26 -07:00
## Parser Information
2021-09-21 12:32:34 -07:00
Compatibility: linux, darwin, freebsd
2021-09-13 21:15:26 -07:00
Version 0.5 by Kelly Brazil (kellyjonbrazil@gmail .com)