2022-08-12 10:16:15 -07:00
|
|
|
[Home](https://kellyjonbrazil.github.io/jc/)
|
|
|
|
<a id="jc.parsers.syslog_bsd"></a>
|
|
|
|
|
|
|
|
# jc.parsers.syslog\_bsd
|
|
|
|
|
|
|
|
jc - JSON Convert Syslog RFC 3164 string parser
|
|
|
|
|
2022-08-15 18:10:43 -07:00
|
|
|
This parser accepts a single syslog line string or multiple syslog lines
|
|
|
|
separated by newlines. A warning message to `STDERR` will be printed if an
|
2022-08-16 10:01:27 -07:00
|
|
|
unparsable line is found unless `--quiet` or `quiet=True` is used.
|
2022-08-12 10:16:15 -07:00
|
|
|
|
|
|
|
Usage (cli):
|
|
|
|
|
2022-08-15 18:10:43 -07:00
|
|
|
$ echo '<34>Oct 11 22:14:15 mymachine su: su root...' | jc --syslog-bsd
|
2022-08-12 10:16:15 -07:00
|
|
|
|
|
|
|
Usage (module):
|
|
|
|
|
|
|
|
import jc
|
|
|
|
result = jc.parse('syslog_bsd', syslog_command_output)
|
|
|
|
|
|
|
|
Schema:
|
|
|
|
|
|
|
|
[
|
|
|
|
{
|
2022-08-15 18:10:43 -07:00
|
|
|
"priority": integer/null,
|
|
|
|
"date": string,
|
|
|
|
"hostname": string,
|
2022-08-16 10:01:27 -07:00
|
|
|
"tag": string/null,
|
2022-08-15 18:10:43 -07:00
|
|
|
"content": string,
|
|
|
|
"unparsable": string, # [0]
|
2022-08-12 10:16:15 -07:00
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2022-08-15 18:10:43 -07:00
|
|
|
[0] this field exists if the syslog line is not parsable. The value
|
|
|
|
is the original syslog line.
|
|
|
|
|
2022-08-12 10:16:15 -07:00
|
|
|
Examples:
|
|
|
|
|
2022-08-15 18:10:43 -07:00
|
|
|
$ cat syslog.txt | jc --syslog-bsd -p
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"priority": 34,
|
|
|
|
"date": "Oct 11 22:14:15",
|
|
|
|
"hostname": "mymachine",
|
|
|
|
"tag": "su",
|
|
|
|
"content": "'su root' failed for lonvick on /dev/pts/8"
|
|
|
|
}
|
|
|
|
]
|
2022-08-12 10:16:15 -07:00
|
|
|
|
2022-08-15 18:10:43 -07:00
|
|
|
$ cat syslog.txt | jc --syslog-bsd -p -r
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"priority": "34",
|
|
|
|
"date": "Oct 11 22:14:15",
|
|
|
|
"hostname": "mymachine",
|
|
|
|
"tag": "su",
|
|
|
|
"content": "'su root' failed for lonvick on /dev/pts/8"
|
|
|
|
}
|
|
|
|
]
|
2022-08-12 10:16:15 -07:00
|
|
|
|
|
|
|
<a id="jc.parsers.syslog_bsd.parse"></a>
|
|
|
|
|
|
|
|
### parse
|
|
|
|
|
|
|
|
```python
|
|
|
|
def parse(data: str, raw: bool = False, quiet: bool = False) -> List[Dict]
|
|
|
|
```
|
|
|
|
|
|
|
|
Main text parsing function
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
|
|
|
|
data: (string) text data to parse
|
|
|
|
raw: (boolean) unprocessed output if True
|
|
|
|
quiet: (boolean) suppress warning messages if True
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
List of Dictionaries. Raw or processed structured data.
|
|
|
|
|
|
|
|
### Parser Information
|
|
|
|
Compatibility: linux, darwin, cygwin, win32, aix, freebsd
|
|
|
|
|
|
|
|
Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com)
|