简体   繁体   English

Apache访问日志的YQL表

[英]YQL table for Apache access logs

YQL SHOW TABLES has CSV and HTML. YQL SHOW TABLES具有CSV和HTML。 What about a table for Apache access logs? 关于Apache访问日志的表呢?

Apache logs actually have a customizable format so I'm assuming that you mean the common log format or one of th defaults. Apache日志实际上具有可自定义的格式,因此我假设您是指通用日志格式或默认值之一。 If we add something like this it will likely be with a regex based line reader that you could then apply to apache logs. 如果我们添加类似的内容,则可能是基于正则表达式的行读取器,然后您可以将其应用于apache日志。 Thanks for the suggestion. 谢谢你的建议。

Here's the start of a common log parsing table. 这是常见日志解析表的开始。 The code as-is will blindly split on empty spaces, which isn't accurate, but it's a start. 原样的代码将盲目地分割在空白处,虽然不准确,但这只是一个开始。 You'd probably want to pass in the url of the log file, split the entries on newline, and then parse each line. 您可能想要传递日志文件的url,在换行符上拆分条目,然后解析每一行。

<?xml version="1.0" encoding="UTF-8"?>
<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd">
    <meta>
        <author></author>
        <sampleQuery>select * from {table}</sampleQuery>
    </meta>
    <bindings>
        <select itemPath="" produces="XML">
            <inputs>
                <key id="url" type="xs:string" paramType="variable"/>
            </inputs>
            <execute><![CDATA[

                    //http://en.wikipedia.org/wiki/Common_Log_Format
            var entry = '208.240.243.170 - frank [10/Oct/2000:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326';

            var names = ['IP', 'RFC 1413', 'userid', 'date', 'request', 'status', 'size'];
            var values = entry.split(' ');

            var resp = {};

            for (var i in names) {
                var name = names[i];
                resp[name] = values[i];
            }

            response.object = resp;

      ]]></execute>
        </select>
    </bindings>
</table>

You can run it like this: use "http://{your domain}/table.xml" as table; 您可以像这样运行它:将“ http:// {您的域} /table.xml”用作表; select * from table 从表中选择*

You could then extend it look up geo data by ip: use "http://{your domain}/table.xml" as table; 然后,您可以通过ip扩展它以查找地理数据:使用“ http:// {您的域} /table.xml”作为表格; select * from pidgets.geoip where ip in (select IP from table) 从pidgets.geoip中选择*,其中ip输入(从表中选择IP)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM