Search code examples
gitmonitoringmonit

Monit check status of changes in git repo


I'm using Monit to monitor an ubuntu server, and would like to run a test for changes in a git repo.

I've read (here) that "git ls-files" would be the best way to do this, but am not sure how to run a exec command as a test in monit. Their docs show examples for running exec commands after a test has passed, but not how to test on a exec.

What is the best way to do this?

==========

PS - I found the solution based on @TheCodeKiller answer below. Here is the final code now working great. The answer was actually in the docs but i didn't recognized it as my solution. It is here.

Inside monit config (/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

Then inside that file:

#!/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

Solution

  • You can run program or custom script with check program:

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

    So you will have to write a custom script to do it and take action depeding of the script exit code.