Monit中存在文件的警报

时间:2013-04-12 03:23:52

标签: monit

我一直在使用monit,但是如果文件存在,我想报警。这是the main documentation的相反用例。

这是医生说的:

IF [DOES] NOT EXIST [[<X>] <Y> CYCLES] THEN action [ELSE IF SUCCEEDED [[<X>] <Y> CYCLES] THEN action]
action is a choice of "ALERT", "RESTART", "START", "STOP", "EXEC" or "UNMONITOR".

这给了我“如果文件丢失就吓坏了”的秘诀。但我想“如果文件在那里就吓坏了”。行动的选择意味着没有“无所作为”的行动。我可以选择无操作,但对于“无所事事”的标准情况来说,这真的很愚蠢。

我猜到了一些基本情况:

IF EXISTS THEN alarm
IF EXIST THEN ALARM

那么,是否有标准方法IF IT DOES EXIST

4 个答案:

答案 0 :(得分:7)

我最近正在寻找和你一样的解决方案,不幸的是,我无法在monit中找到这样做的方法。

我的情况与你的情况略有不同,所以我最终警告文件是否不存在,并执行了一个shell脚本。和你一样,我不想因为文件不存在而产生shell,并且在/ var / log / messages中显示“文件不存在”对我来说不是什么大问题。

我知道你说你可以向无操作人员发出警告,所以你可能不需要以下内容,但我会为那些可能遇到同样问题且不知道如何操作的人添加它。

check file testfile with path /path/to/file
    if not exist then exec "/bin/bash -c 'echo dne > /dev/null'" else if succeeded then alarm

注意你必须exec / bin / bash将echo的输出写入/ dev / null或者monit将字面上回显“dne&gt; / dev / null”

编辑:由于它被反对引起了我的注意,Monit的新版本使用警报而不是警报,因此检查将如下所示:

check file testfile with path /path/to/file
    if not exist then exec "/bin/bash -c 'echo dne > /dev/null'" else if succeeded then alert

答案 1 :(得分:2)

请查看:

check program not_exist_file_root_test with path "/bin/ls /root/test"

if status = 0 then alert

check program not_exist_file_root_test with path /bin/sh -c "test -f /root/test"

if status = 0 then alert

我的2美分

答案 2 :(得分:2)

renab,至少在我的版本(5.2.5)中,你的支票应以“然后提醒”而不是“然后报警”结束。

testfile with path /path/to/file
  if not exist then exec "/bin/bash -c 'echo dne > /dev/null'" else if succeeded then alert

答案 3 :(得分:0)

从monit 5.21.0开始,直接支持对生存状态的更改:

check file testfile with path /path/to/file
    if exist then alert

请参见更改日志https://mmonit.com/monit/changes/#5.21.0

相关问题