monit时间戳检查:如何在每次检查时运行自定义脚本?

时间:2018-11-26 13:16:53

标签: timestamp monit

我想每次monit对文件/tmp/file.txt进行时间戳检查时都运行一个自定义脚本 /tmp/script.sh

我尝试使用以下方法对此进行解决:

如果时间戳记早于1秒,则执行... ”,但它不起作用,但是如果重新启动monit,它将运行。但是只有一次。

我做错了什么?

这是脚本:

check file test_timestamp with path /tmp/file.txt
    every 10 cycles

    # 'script.sh check' should be run always when this monit   check is run but it is not.....
    if timestamp is older than 1 seconds then exec "/tmp/script.sh check"
            as uid "abc" and gid "abc"

    if timestamp is older than 15 minutes then exec "/tmp/script.sh active"
            as uid "abc" and gid "abc"

    alert ab@cd.com on { timestamp } with reminder on 20 cycles

1 个答案:

答案 0 :(得分:0)

由于我的声誉低下,因此我无法将其标记为重复,因此我从here


监控基于triggers,它基本上仅跟踪更改

因此,如果配置的状态未更改,则默认情况下,monit不会再次触发脚本。请参见Monit Changelog上有关5.16.0的注释:

  

已修复::现在,exec操作仅在状态更改时执行一次,与警报操作相同。如果错误仍然存​​在,则可以使用新的repeat选项在给定的周期数后重复执行exec操作。语法:

if <test> then exec <script> [repeat every [x] cycle(s)]
     

如果您想要旧的行为,请使用“重复每个周期”。示例:

if failed port 1234 then exec "/usr/bin/myscript.sh" repeat every cycle

因此,如果您需要多次调用该脚本,只需添加repeat

check file test_timestamp with path /tmp/file.txt
    every 10 cycles

    # 'script.sh check' should be run always when this monit   check is run but it is not.....
    if timestamp
        is older than 1 seconds
        then exec "/tmp/script.sh check"
            as uid "abc" and gid "abc"
        and repeat every 10 cycles

    if timestamp
        is older than 15 minutes
        then exec "/tmp/script.sh active"
            as uid "abc" and gid "abc"
        and repeat every 2 cycles

    alert ab@cd.com on { timestamp } with reminder on 20 cycles