YQL table for Apache access logs

一世执手 提交于 2019-12-11 15:18:29

问题


YQL SHOW TABLES has CSV and HTML. What about a table for Apache access logs?


回答1:


There is now a regex table

http://developer.yahoo.com/yql/console/?q=select%20*%20from%20regex%20where%20expression%20%3D%20%22(.*)%22%20and%20text%3D%22test%22&env=http%3A%2F%2Fdatatables.org%2Falltables.env

If you have a regex for your log format, you can use that table to parse it.




回答2:


Apache logs actually have a customizable format so I'm assuming that you mean the common log format or one of th defaults. If we add something like this it will likely be with a regex based line reader that you could then apply to apache logs. Thanks for the suggestion.




回答3:


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.

<?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; select * from table

You could then extend it look up geo data by ip: use "http://{your domain}/table.xml" as table; select * from pidgets.geoip where ip in (select IP from table)



来源:https://stackoverflow.com/questions/1036404/yql-table-for-apache-access-logs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!