【问题标题】:Monit check status of changes in git repo监控 git repo 中更改的状态
【发布时间】:2018-05-08 21:09:32
【问题描述】:

我正在使用Monit 来监控一个 ubuntu 服务器,并希望对 git repo 中的更改进行测试。

我读过 (here) 说“git ls-files”是最好的方法,但我不确定如何在 monit 中运行 exec 命令作为测试。他们的文档显示了在测试通过后运行 exec 命令的示例,但没有显示如何在 exec 上进行测试。

最好的方法是什么?

===========

PS - 我根据下面的@TheCodeKiller 答案找到了解决方案。这是现在运行良好的最终代码。答案实际上在文档中,但我不认为它是我的解决方案。是here

内部监控配置(/etc/monit/monitrc):

check program changed_files with path "/path/to/git/directory/monit_alert_changed_files.sh"
    if status != 0 for 3 cycles then alert

然后在那个文件里面:

#!/bin/bash

# Script to check if there are changes in the current git directory

if [[ `git --git-dir "/path/to/git/directory/.git" --work-tree "/path/to/git/directory/" ls-files -m -o --exclude-standard` ]]; then
  # Changes
  exit 1
else
  # No changes
  exit 0
fi

【问题讨论】:

    标签: git monitoring monit


    【解决方案1】:

    您可以使用检查程序运行程序或自定义脚本:

    check program my_check with path "/path/to/my/script.sh arg1 arg2 arg3"
        if status != 0 for 3 cycles then alert
    

    因此,您必须编写一个自定义脚本来执行此操作并根据脚本退出代码采取行动。

    【讨论】:

    • 感谢@TheCodeKiller! !这是一个完美的解决方案,因为它可以让我测试各种事情。我在文档中错过了这一点。我会尽快测试一下。
    猜你喜欢
    • 2013-09-16
    • 2012-12-09
    • 2021-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-05
    相关资源
    最近更新 更多