https://github.com/garyelephant/pygrok/pull/3的临时包
pygroker的Python项目详细描述
内容
皮格罗克
用于解析字符串和从中提取信息的python库 结构化/非结构化数据
What can I use Grok for?
- 解析和匹配字符串(日志、消息等)中的模式
- 从复杂的正则表达式中解脱出来。
- 从结构化/非结构化数据中提取信息
Installation
$ pip install pygrok
或者从下载、解压缩并安装pygrok here:
$ tar zxvf pygrok-xx.tar.gz
$ cd pygrok_dir
$ sudo python setup.py install
Getting Started
>>>importpygrok>>>text='gary is male, 25 years old and weighs 68.5 kilograms'>>>pattern='%{WORD:name} is %{WORD:gender}, %{NUMBER:age} years old and weighs %{NUMBER:weight} kilograms'>>>printpygrok.grok_match(text,pattern){'gender':'male','age':'25','name':'gary','weight':'68.5'}
很酷!下面列出了一些您可以使用的模式:
`WORD` means \b\w+\b in regular expression. `NUMBER` means (?:%{BASE10NUM}) `BASE10NUM` means (?<![0-9.+-])(?>[+-]?(?:(?:[0-9]+(?:\.[0-9]+)?)|(?:\.[0-9]+))) other patterns such as `IP`, `HOSTNAME`, `URIPATH`, `DATE`, `TIMESTAMP_ISO8601`, `COMMONAPACHELOG`..
查看所有模式here
More details
beause python re模块不支持正则表达式语法 原子分组(?)>;),因此pygrok需要 regex待 安装。
pygrok的灵感来自Grok 约旦西塞尔开发。这不是乔丹·西塞尔的包装纸 完全由我来执行。
grok是一个简单的软件,允许您轻松地解析字符串、日志 以及其他文件。使用grok,您可以转换非结构化日志和事件数据 在结构化数据中,pygrok做了同样的事情。
我建议你看看logstash filter grok, 它解释了怪兽的工作原理。
Contribute
- 我们鼓励你 fork,改进 编码,然后发出请求。
- Issue tracker
Get Help
mail:garygaowork@gmail.com twitter:@garyelephant