added borg check to zabbix-agent
This commit is contained in:
parent
a7a44c908b
commit
974230c3d6
2 changed files with 81 additions and 3 deletions
72
modules/borg_check.sh
Normal file
72
modules/borg_check.sh
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
#!/usr/bin/env bash
|
||||
export BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK=yes
|
||||
export BORG_RELOCATED_REPO_ACCESS_IS_OK=yes
|
||||
function statistics {
|
||||
journalctl _SYSTEMD_INVOCATION_ID=$(systemctl show --value -p InvocationID borgbackup-job-default) | grep -Eio "$2 archive[s]?.*" | awk '$'$(($1 + 1))'~/^TB/{printf "%.f", $'$1'*1000*1000*1000*1000};$'$(($1 + 1))'~/^GB/{printf "%.f", $'$1'*1000*1000*1000}; $'$(($1 + 1))'~/^MB/{printf "%u", $'$1'*1000*1000}; $'$(($1 + 1))'~/^kB/{printf "%u", $'$1'*1000}; $'$(($1 + 1))'~/^B/{print $'$1'};'
|
||||
}
|
||||
function discover {
|
||||
dirname $(grep -silm1 "This is a Borg Backup repository" /mnt/sdf1/borg/*/README) | awk 'BEGIN{printf "{\"data\":["}; {i=split($1,path,"/"); printf c"{\"{#PATH}\":\""$1"\", \"{#HOST}\":\"" path[i-1] "\", \"{#DIR}\":\"" path[i] "\"}";c="," }; END{print "]}"}'
|
||||
}
|
||||
function check {
|
||||
borg check $1 2> /dev/null | wc -l
|
||||
}
|
||||
function _time {
|
||||
date -d "$(borg info --bypass-lock $1::$(borg list $1 --bypass-lock --short | tail -n1) | grep -i "time ($2)" | sed 's/^.*): //;s/$//')" $3
|
||||
}
|
||||
fail=1
|
||||
while [[ $fail -ne 0 ]]; do
|
||||
case $1 in
|
||||
discover)
|
||||
discover && fail=0
|
||||
;;
|
||||
check)
|
||||
path="$1"
|
||||
check "$path" && fail=0
|
||||
;;
|
||||
time)
|
||||
path="$3"
|
||||
case $2 in
|
||||
start_time)
|
||||
_time "$path" "start" "" && fail=0
|
||||
;;
|
||||
start_timestamp)
|
||||
_time "$path" "start" "+%s" && fail=0
|
||||
;;
|
||||
end_time)
|
||||
_time "$path" "end" "" && fail=0
|
||||
;;
|
||||
end_timestamp)
|
||||
_time "$path" "end" "+%s" && fail=0
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
|
||||
statistics)
|
||||
path="$4"
|
||||
case $2 in
|
||||
original)
|
||||
scope=3
|
||||
;;
|
||||
compressed)
|
||||
scope=5
|
||||
;;
|
||||
dedup)
|
||||
scope=7
|
||||
;;
|
||||
esac
|
||||
_type=$3
|
||||
statistics $scope $_type && fail=0
|
||||
fail=0
|
||||
;;
|
||||
debug)
|
||||
echo "12414"
|
||||
tmpfile="$(mktemp)"
|
||||
echo "whyyyy" > "$tmpfile"
|
||||
echo "asedfasdf" > "/zabbix"
|
||||
fail=0
|
||||
;;
|
||||
*)
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
|
@ -5,11 +5,17 @@
|
|||
server = "zabbix-server";
|
||||
package = pkgs.zabbix.agent2;
|
||||
settings = {
|
||||
UserParameter = ''
|
||||
systemd.exitstatus[*],systemctl show --value -p ExecMainStatus "$1"
|
||||
'';
|
||||
UserParameter = [
|
||||
"systemd.exitstatus[*],systemctl show --value -p ExecMainStatus '$1'"
|
||||
"borg.check[*],borg_check.sh '$1' '$2' '$3'"
|
||||
];
|
||||
};
|
||||
};
|
||||
systemd.services.zabbix-agent.path = [
|
||||
(pkgs.writeShellScriptBin "borg_check.sh" (builtins.readFile ./borg_check.sh))
|
||||
pkgs.gawk
|
||||
];
|
||||
users.users.zabbix-agent.extraGroups = [ "systemd-journal" ];
|
||||
}
|
||||
|
||||
# vim: set et ts=2 sw=2 ai:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue