24

我们正在使用 Nagios 来监控我们的网络并取得了巨大成功。但是,我们有一个用于严重应用程序错误的系统日志,当我设置 check_log 时,它似乎不像监控设备那样工作。

问题是:

  • 它只显示最后一个条目
  • 似乎没有办法确认严重错误并将监视器恢复到良好状态

nagios 是错误的工具,还是我们没有正确设置服务监控?

这是我的条目

# log file
define command{
        command_name    check_log
        command_line    $USER1$/check_log -F /var/log/applications/appcrit.log -O /tmp/appcrit.log -q ?
}


# Define the log monitering service
define service{
        name                            logfile-check           ;
        use                             generic-service         ;
        check_period                    24x7                    ;
        max_check_attempts              1                       ;
        normal_check_interval           5                       ;
        retry_check_interval            1                       ;
        contact_groups                  admins                  ;
        notification_options            w,u,c,r                 ;
        notification_period             24x7                    ;
        register                        0                       ;
        }

define service{
        use                             logfile-check
        host_name                       localhost
        service_description             CritLogFile
        check_command                   check_log
}
4

6 回答 6

28

对于使用 Nagios 监控日志,通常日志检查器只会在每次调用时仅针对新发现的错误消息返回警告(因此它必须保留一些状态才能知道在后续运行中忽略它们)。因此我通常设置:

max_check_attempts              1
is_volatile                     1

这会导致 Nagios 立即发出警报,但只发出一次,然后恢复正常。

我最喜欢的日志检查器是logwarn,但我有偏见,因为我在没有找到任何我喜欢的现有日志后自己编写了它。logwarn 包包含一个 Nagios 插件。

于 2011-01-25T21:40:16.730 回答
4

有一个 Nagios 插件可用于检查日志文件:它称为check_logfiles,用于扫描文件的行以查找正则表达式。

以下链接显示了如何check_logfiles为 Nagios 和 Opsview 安装和配置: https ://www.opsview.com/resources/nagios-alternative/blog/syslog-monitoring-nagios-opsview

于 2011-11-13T12:02:15.717 回答
3

您的配置中的任何内容都不会因为配置错误而引起我的注意。

根据设计,check_log 将仅显示 OK 消息或触发警报的最后一个日志条目。如果您需要查看多个条目,则需要修改插件。

然而,我发现你没有得到恢复的事实有点奇怪。check_log 的工作方式(通过将当前日志与以前的版本进行比较),您应该在下一次服务检查时恢复。当然,除非自上次检查以来已将其他匹配条目添加到日志中。

强制另一个服务检查(或几个)会导致它恢复吗?

另外,我不是故意的,但要确保它确实出现故障。您的日志是否在检查之间获得了额外的匹配条目,导致它无法恢复?您的支票匹配“?” 这将匹配日志中的任何新内容。是否将其他内容(非错误)添加到日志中并无意中导致匹配?

如果以上都不是问题,我建议通过将 Nagios 排除在外来缩小范围。尝试手动运行 check_log(从命令行,但使用与 nagios 相同的用户),并使用不同的 oldlog。它应该是这样的 -

  1. 使用新的“旧日志”运行检查 - 获取初始化消息
  2. 运行检查 - 检查确定
  3. 更改日志
  4. 运行检查 - 检查失败
  5. 运行检查 - 检查确定

如果这不起作用,那么您知道要关注日志、旧日志以及 check_log 是如何进行检查的。

如果它有效,那么它更多地指向您的 nagios 配置的问题。

于 2010-03-03T20:33:28.000 回答
3

由于实现目标的方法有很多,Consol 还提供了一个不错的插件: https ://labs.consol.de/lang/en/nagios/check_logfiles/

  • 支持正则表达式
  • 支持日志轮换

要使用它,您需要一个 cfg 文件,这是 oracle 数据库的示例

@searches = ({
  tag => 'oraalerts',
options => 'sticky=28800',
  logfile => '/u01/app/oracle/diag/rdbms/davmdkp/DAVMDKP1/trace/alert_DAVMDKP1.log',
  criticalpatterns => [
      'ORA\-0*204[^\d]',        # error in reading control file
      'ORA\-0*206[^\d]',        # error in writing control file
      'ORA\-0*210[^\d]',        # cannot open control file
      'ORA\-0*257[^\d]',        # archiver is stuck
      'ORA\-0*333[^\d]',        # redo log read error
      'ORA\-0*345[^\d]',        # redo log write error
      'ORA\-0*4[4-7][0-9][^\d]',# ORA-0440 - ORA-0485 background process failure
      'ORA\-0*48[0-5][^\d]',
      'ORA\-0*6[0-3][0-9][^\d]',# ORA-6000 - ORA-0639 internal errors
      'ORA\-0*1114[^\d]',        # datafile I/O write error
      'ORA\-0*1115[^\d]',        # datafile I/O read error
      'ORA\-0*1116[^\d]',        # cannot open datafile
      'ORA\-0*1118[^\d]',        # cannot add a data file
      'ORA\-0*1122[^\d]',       # database file 16 failed verification check
      'ORA\-0*1171[^\d]',       # datafile 16 going offline due to error advancing checkpoint
      'ORA\-0*1201[^\d]',       # file 16 header failed to write correctly
      'ORA\-0*1208[^\d]',       # data file is an old version - not accessing current version
      'ORA\-0*1578[^\d]',        # data block corruption
      'ORA\-0*1135[^\d]',        # file accessed for query is offline
      'ORA\-0*1547[^\d]',        # tablespace is full
      'ORA\-0*1555[^\d]',        # snapshot too old
      'ORA\-0*1562[^\d]',        # failed to extend rollback segment
      'ORA\-0*162[89][^\d]',     # ORA-1628 - ORA-1632 maximum extents exceeded
      'ORA\-0*163[0-2][^\d]',
      'ORA\-0*165[0-6][^\d]',    # ORA-1650 - ORA-1656 tablespace is full
      'ORA\-16014[^\d]',      # log cannot be archived, no available destinations
      'ORA\-16038[^\d]',      # log cannot be archived
      'ORA\-19502[^\d]',      # write error on datafile
      'ORA\-27063[^\d]',         # number of bytes read/written is incorrect
      'ORA\-0*4031[^\d]',        # out of shared memory.
      'No space left on device',
      'Archival Error',
  ],
  warningpatterns => [
      'ORA\-0*3113[^\d]',        # end of file on communication channel
      'ORA\-0*6501[^\d]',         # PL/SQL internal error
      'ORA\-0*1140[^\d]',         # follows WARNING: datafile #20 was not in online backup mode
      'Archival stopped, error occurred. Will continue retrying',
  ]
});
于 2015-01-26T10:14:33.957 回答
1

我相信现在有一个真正的 Nagios 插件可以有效地监控日志。

http://support.nagios.com/forum/viewtopic.php?f=6&t=8851&p=42088&hilit=unixautomation#p42088

该页面上 Nagios 插件的主页是Nagios Log Monitor

Your [ commands.cfg file ] will contain:

define command {
                            command_name         NagiosLogMonitor
                            command_line            $USER1$/NagiosLogMonitor $HOSTNAME$ $ARG1$ $ARG2$ $ARG3$ $ARG4$ '$ARG5$' '$ARG6$' $ARG7$ $ARG8$ $ARG9$ $ARG10$
}


OR


define command {
                            command_name         NagiosLogMonitor
                            command_line            $USER1$/NagiosLogMonitor $HOSTADDRESS$ $ARG1$ $ARG2$ $ARG3$ $ARG4$ '$ARG5$' '$ARG6$' $ARG7$ $ARG8$ $ARG9$ $ARG10$
}




Your [ services.cfg file ] will look similar to:

define service {
                      check_command                         NagiosLogMonitor!logrobot!autofig!/var/log/proteus.log!15!500.html!500 Internal Server Error!1!2!-foundn
                      max_check_attempts                  1
                      service_description                     500_ERRORS_LOGCHECK
                      host_name                                  sky.blat-01.net,sky.blat-02.net,sky.blat-03.net
                      use                                              fifteen-minute-interval
 }
于 2013-02-25T23:37:43.950 回答
0

Nagios 现在有一个与 Nagios Core、XI 等紧密集成的解决方案。

Nagios 日志服务器,它可以对基础架构中任何系统上的任何日志文件的任何查询发出警报。

于 2014-10-23T19:54:09.123 回答