#!/bin/bash INST="$1" if [ -z "$1" ]; then echo "Usage: $0 " exit 1 fi REPOS_D="{{ gitolite_base_path }}/$INST/repositories" if [ ! -d "$REPOS_D" ]; then echo "instance $INST not found." exit 2 fi repos=$(find $REPOS_D -type d -name '*.git') declare -A results for repo in $repos; do echo "*** $repo ***" git --bare --git-dir "$repo" fsck --full --strict --root results[$repo]=$? echo "" done if [ -d "/var/lib/prometheus-node-exporter/textfile-collector/" ]; then echo "reporting results to prometheus" { echo "# HELP git_fsck_run Last time git-fsck has been run." echo "# TYPE git_fsck_run gauge" echo "git_fsck_run{gitolite_instance=\"$INST\"} $(date +"%s")" echo "" echo "# HELP git_fsck_failed Result of git-fsck (0 means OK)." echo "# TYPE git_fsck_failed gauge" for repo in "${!results[@]}"; do repo_name=$(realpath --relative-to "$REPOS_D" "$repo") echo "git_fsck_failed{repository=\"$repo_name\",gitolite_instance=\"$INST\"} ${results[$repo]}" done } | sponge "/var/lib/prometheus-node-exporter/textfile-collector/git-fsck-$INST.prom" fi