diff options
author | Leonardo Arena <rnalrd@alpinelinux.org> | 2014-06-12 07:56:57 +0000 |
---|---|---|
committer | Leonardo Arena <rnalrd@alpinelinux.org> | 2014-06-12 07:57:18 +0000 |
commit | 15f898ca8068419fc02364231bb2981cc54971cb (patch) | |
tree | e3ec5995d70831834d467d40615870b44bca7044 /main/aaudit/aaudit-repo | |
parent | 94983a506d2e95be0a5864ae7bcc7d7d61dc6cce (diff) | |
download | aports-15f898ca8068419fc02364231bb2981cc54971cb.tar.bz2 aports-15f898ca8068419fc02364231bb2981cc54971cb.tar.xz |
testing/aaudit: move to main
Diffstat (limited to 'main/aaudit/aaudit-repo')
-rwxr-xr-x | main/aaudit/aaudit-repo | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/main/aaudit/aaudit-repo b/main/aaudit/aaudit-repo new file mode 100755 index 0000000000..dbacd976bf --- /dev/null +++ b/main/aaudit/aaudit-repo @@ -0,0 +1,47 @@ +#!/usr/bin/lua5.2 + +local posix = require 'posix' +local aac = require 'aaudit.common' +local aas = require 'aaudit.server' + +local pullafter = aas.serverconfig["pull-after"] or 24*60*60 +local warnafter = aas.serverconfig["warn-after"] or 4*24*60*60 + +local function dorepo(repodir) + -- Check if it's time to update + local repoconf = aas.loadrepoconfig(repodir) + local stampfile = ("%s/lastcheck"):format(repodir) + local mtime = posix.stat(stampfile, "mtime") or 0 + + if os.time() > mtime + pullafter then + -- Pull for changes + local req = { + command = "commit", + target_address = repoconf.address, + message = "Unexpected configuration change", + local_change = true, + } + local ret, msg = aas.handle(req) + print(("Updating repository %s -> %s: %s"):format(repodir, repoconf.address, msg)) + mtime = posix.stat(stampfile, "mtime") or 0 + end + + return mtime, repoconf.address +end + +local home = os.getenv("HOME") +local outdated = {"List of unreachable monitored hosts:"} +for _, repodir in ipairs(posix.glob(("%s/*.git"):format(home))) do + local mtime, address = dorepo(repodir) + if os.time() > mtime + warnafter then + table.insert(outdated, address) + end +end + +if #outdated > 1 and aas.serverconfig["notify-unreachables"] then + aas.sendemail { + to = aas.serverconfig["notify-unreachables"], + subject = "aaudit report of unreachable hosts", + message = table.concat(outdated, "\n"), + } +end |