0

我正在尝试列出 Geneos 中包含昨天日期的 UNIX 文件夹中的所有文件。我尝试使用 FKM & FTM 插件,但它只列出了它检测到的第一个文件是否我给出了通配符。例如:/位置/*

如何配置 Geneos 使其列出 UNIX 服务器中包含某些固定字符的文件夹中的所有文件?

4

1 回答 1

0

您需要在 FKM 插件中使用两个概念:日期生成动态文件

如果您想将其复制并粘贴到编辑器中,下面包括真正有用的帮助指南和示例 xml 的摘录。

日期生成

FKM 文件定义可以配置为使用当前日期和时间生成文件名。每个样本都会生成目标文件名,如果存在与该名称匹配的文件,则 FKM 将监视该文件(一旦当前文件已处理到最后)。文件名可以使用三个日期代码之一生成;昨天、今天或明天。这些将使用适当的日期在文件名中替换。例如,如果当前日期是 2008 年 8 月 22 日,则将生成以下内容:

Filename            Generated name
app<yesterday>.log  app20080821.log
app<today>.log      app20080822.log
app<tomorrow>.log   app20080823.log

日期的输出格式可以通过在日期标签中放置格式代码来控制。这种用法的例子如下所示。

Filename                    Generated name
app<today %d-%m-%Y>.log     app22-08-2008.log
app<today %d%b%y>.log       app22Aug08.log
app<tomorrow %d_%m_%Y>.log  app23_08_2008.log

以下格式代码可用于此功能。

Code  Meaning
%a    Abbreviated weekday name. (e.g. Wed)
%A    Full weekday name (e.g. Wednesday)
%b    Abbreviated month name. (e.g. Mar)
%B    Full month name (e.g. March)
%c    Date and time representation appropriate for the current locale.
%d    Day of month as a decimal number (01 – 31).
%H    Hour in 24-hour clock format (00 – 23).
%I    Hour in 12-hour clock format (01 – 12).
%j    Day of year as a decimal number (001 – 336).
%m    Month as a decimal number (01 – 12).
%M    Minutes as a decimal number (00 – 59).
%p    Current locale’s AM / PM indicator for 12-hour clock.
%S    Seconds as a decimal number (00 – 61).
%U    Week of the year as a decimal number, with Sunday as the first day. (00 – 53).
%w    Weekday as a decimal number (0 – 6, with Sunday as 0).
%W    Week of the year as a decimal number, with Monday as the first day. (00 – 53).
%x    Date representation appropriate for current locale.
%X    Time representation appropriate for current locale.
%y    Year without century, as a decimal number (00 – 99).
%Y    Year with century, as a decimal number (e.g. 2008).
%z,%Z Time-zone name or abbreviation (e.g. GMT or PST); no characters are shown if the time-zone is unknown.

注意 可以但不建议在文件名中使用秒 (%S) 或分钟 (%M) 时间格式代码。这是因为生成的文件名将包含 FKM 执行样本的时间,不能保证以精确的秒数发生。

动态文件

文件 > 文件 > 源 > 动态文件

dynamicFiles 类型文件源将 FKM 配置为基于配置的路径、模式和可选的别名匹配文件组。

当一个新组被识别时,一个额外的文件行被创建,它作为一个正常的文件名源。此新行的设置是从父 dynamicFiles 行的设置中复制的。当没有剩余文件来创建该分组时,该行将被删除。

此功能类似于使用带有 wildcardMonitorAllMatches 设置的普通文件名源,但不能同时使用这两个功能。如果您尝试这样做,FKM 将报告错误。

使用路径设置指定组,该设置应该是包含通配符通配符(* 和?)的文件路径。将评估此路径,然后将发现的所有文件与配置的正则表达式模式匹配。

视图中行的名称是通过评估文件别名来确定的。别名中的任何编号插入(由 % 后跟数字标识,例如 %4)将替换为正则表达式模式中该捕获组的内容,与文件名匹配。不存在或没有内容的捕获组将被替换为空字符串。可以生成文字百分比字符,将其转义为 %%。使用不区分大小写的正则表达式时,插入将小写以确保行名一致。

例如,与文件“app_Apache_001.log”匹配的正则表达式“app_(.)_\d+.log$”的捕获组 1 的值将是“Apache”(正则表达式的 . 部分的内容)。网站http://www.internetofficer.com/seo-tool/regex-tester/可用于针对各种字符串测试正则表达式,以查看每个捕获组的内容。

给定以下配置:

Path: /var/logs/app_*.log
Regex pattern: app_(.*)_\d+\.log$
Alias: App-%1

和文件:

/var/logs/app_Apache_001.log
/var/logs/app_Apache_002.log
/var/logs/app_Samba_1_01.log
/var/logs/app_Router.log

FKM 将在视图中创建两行:

"App-Apache" monitoring "app_Apache_002.log"
"App-Samba_1" monitoring "app_Samba_1_01.log".

文件 app_Apache_002.log 被选中而不是 app_Apache_001.log,因为它具有更新的修改时间(假设 Apache 通过创建更高编号的日志来滚动文件)。可以使用 wildcardMatchTime 设置来控制用于此检查的时间。文件“app_Router.log”被忽略,因为它没有通过正则表达式。

示例 XML

<sampler name="Example">
    <plugin>
        <fkm>
            <files>
                <file>
                    <source>
                        <dynamicFiles>
                            <path>
                                <data>/my/path/file*.log</data>
                            </path>
                            <pattern>
                                <data>
                                    <regex>file&lt;yesterday&gt;.log</regex>
                                </data>
                            </pattern>
                        </dynamicFiles>
                    </source>
                </file>
            </files>
        </fkm>
    </plugin>
</sampler>

参考

ITRS 资源链接

于 2018-04-11T22:34:39.390 回答