【问题标题】:Parse logs on Windows Server 2003 to find user actions [closed]解析 Windows Server 2003 上的日志以查找用户操作 [关闭]
【发布时间】:2011-02-13 01:32:15
【问题描述】:

平台:带 Perl 的 Windows 2003 我正在研究如何从 IIS 日志文件中删除用户 ID。然后找出那个用户做了什么。上传的文件,CWD .. 之类的。有 [uniqu_ID] 用户 ID。如何检索该 ID 并搜索它的作用。请帮忙。

【问题讨论】:

  • 您能发布几行示例代码吗?这个问题看起来很简单,但例子会很棒。

标签: perl windows-server-2003 logging


【解决方案1】:

Log Parser 2.2:

日志解析器是一个功能强大、用途广泛的 提供通用查询的工具 访问基于文本的数据,例如日志 文件、XML 文件和 CSV 文件,如 以及关键数据源 Windows® 操作系统,例如 事件日志、注册表、文件 系统和 Active Directory®。

【讨论】:

  • 我无法在服务器上下载任何内容。我必须用我目前拥有的东西工作。 Windows 2003 上的 Perl
  • 下载到本地盒子,并在那里处理日志。
  • 我希望我能... 我编写了一个 perl 脚本,它将在服务器本身上运行以报告状态。该脚本通过电子邮件发送状态报告。我不能从我的电脑上做到这一点。它必须在服务器上运行。
  • LogParser 是解析 Windows 日志的魔法。如果你正在重新发明轮子,祝你好运!它也可以通过一个不错的 API 访问。您几乎可以肯定也可以从 Perl 中使用它。
  • 对于 perl 来说这是一个微不足道的问题——到目前为止你到底尝试过写什么?
【解决方案2】:

我在 Windows 2003 Server here 上找到了一个 IIS 日志文件的示例。不过,请发布您自己的示例日志行。

192.168.114.201, -, 03/20/01, 7:55:20, W3SVC2, SERVER, 172.21.13.45, 4502, 163, 3223, 200, 0, GET, /DeptLogo.gif, -,

由于这只不过是一个逗号分隔的文件,因此您有几种不同的方法可以访问这里。如果你的机器上安装了Text::CSV,你可以使用它。如果没有,这里有一个简单的例子。

use strict;
use warnings;
use Data::Dumper;

my $user = {}; # we will store the actions in here

# This is what the log file looks like when split into an array
# 0: Client IP address
# 1: User name
# 2: Date
# 3: Time
# 4: Service and instance
# 5: Server name
# 6: Server IP
# 7: Time taken
# 8: Client bytes sent
# 9: Server bytes sent
# 10: Service status code
# 11: Windows status code
# 12: Request type
# 13: Target of operation
# 14: Parameters

open $log, '<', 'path/to/logfile.log';
while (my $line = <$log>) {
  my @fields = split /, /, $line; # split on comma and space
  # you'll get an array of actions for each user
  push @{ $user->{$fields[1]} }, "$fields[12] $fields[13]";  
  # or more specific:
#   push @{ $user->{$fields[1]} }, { 
#     'time' => $fields[3],
#     'action' => $fields[12],
#     'target' => $fields[13],
#   };
}
close $log;

print Dumper $user; # lets have a look

# More stuff to do with the data here...

这是输出:

$VAR1 = {
          '-' => [
                   'GET /DeptLogo.gif'
                 ]
        };

然后您可以将$user 的内容写入另一个文件或文件组。

foreach my $u (sort keys %$user) {
  print "$u\r\n";
  foreach $action (@{ $user->{$u} }) {
    print "$action\r\n";
  }
}

【讨论】:

  • @Moe:如果答案不可接受,请解释原因,以便进一步挖掘您的问题。
猜你喜欢
  • 2012-11-22
  • 2012-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多