首页 > 解决方案 > 监控 git repo 中更改的状态

问题描述

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

我已经读过(这里)“git ls-files”将是做到这一点的最佳方式,但我不确定如何在 monit 中运行 exec 命令作为测试。他们的文档显示了在测试通过后运行 exec 命令的示例,但没有显示如何在 exec 上进行测试。

做这个的最好方式是什么?

==========

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

内部监控配置(/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

标签: gitmonitoringmonit

解决方案


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

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

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


推荐阅读