X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=dsa-nagios-checks%2Fchecks%2Fdsa-check-backuppg;h=886336f1446cccf7b319985fc82b65ad9250b0c6;hb=bfc386f0b11feb1f427d083aa4bfabf319d766f9;hp=6f405e886237a426f3a8d348e675dd64b76a1116;hpb=923c011b2ad9c4777814d646982b150caac56d3a;p=mirror%2Fdsa-nagios.git diff --git a/dsa-nagios-checks/checks/dsa-check-backuppg b/dsa-nagios-checks/checks/dsa-check-backuppg index 6f405e8..886336f 100755 --- a/dsa-nagios-checks/checks/dsa-check-backuppg +++ b/dsa-nagios-checks/checks/dsa-check-backuppg @@ -65,6 +65,7 @@ def load_conf(cf): return config +notices_seq = [] problems_seq = [] problems_per_db = {} global_expires = [] @@ -75,6 +76,12 @@ global_expires = [] # global problems_per_db # if not host in problems_per_db: problems_per_db[host] = {} # problems_per_db[host][db] = True +def note_info(key, value, pre=None): + global notices_seq + if pre is None: + notices_seq.append("%s: %s"%(key, value)) + else: + notices_seq.append("[%s] %s: %s"%(pre, key, value)) def note_warning(key, value, pre=None): global problems_seq @@ -131,8 +138,23 @@ config = load_conf(options.conffile) os.chdir(config['rootdir']) for dir in os.listdir('.'): + if dir.startswith('.') or dir.endswith('.old'): + note_info('IGNORED', dir) + continue + if not os.path.isdir(dir): - note_warning('NOT-A-DIR', dir) + try: + mtime = os.path.getmtime(dir) + ctime = os.path.getctime(dir) + except OSError as e: + if e.errno == errno.ENOENT: + continue + else: + raise e + if min(mtime, ctime) + 3600*4 > time.time(): + note_info('IGNORED', dir) + else: + note_warning('NOT-A-DIR', dir) continue if not dir in config['backups']: @@ -205,8 +227,11 @@ for dir in os.listdir('.'): basefn = '%s.BASE.%s-%s.tar.gz'%(db, info['label'], info['start wal location'].split(' ',2)[0].replace('/', '_')) baseffn = os.path.join(dir, basefn) if not basefn in files: - note_warning_db(dir, db, 'MISSING-BASE', basefn) - continue + basefn = '%s.BASE.%s.tar.gz'%(db, info['label']) + baseffn = os.path.join(dir, basefn) + if not basefn in files: + note_warning_db(dir, db, 'MISSING-BASE', basefn) + continue files.remove(basefn) if backup_state[db]['can_expire_next']: backup_state[db]['expires'].append(baseffn) @@ -266,18 +291,18 @@ for dir in os.listdir('.'): for db in backup_state: if not 'newest-base' in backup_state[db]: - note_warning(dir, db, 'NO-BASE', 'no base backup found?') + note_warning_db(dir, db, 'NO-BASE', 'no base backup found?') else: age = time.time() - os.stat(backup_state[db]['newest-base']).st_mtime if age > config['warn-age']['base']: - note_warning(dir, db, 'BASE-IS-OLD', 'latest base backup is too old') + note_warning_db(dir, db, 'BASE-IS-OLD', 'latest base backup is too old') if not 'newest-wal-file' in backup_state[db]: - note_warning(dir, db, 'NO-BASE', 'no WAL files found?') + note_warning_db(dir, db, 'NO-BASE', 'no WAL files found?') else: age = time.time() - os.stat(backup_state[db]['newest-wal-file']).st_mtime if age > config['warn-age']['wal']: - note_warning(dir, db, 'WAL-IS-OLD', 'latest wal file is too old') + note_warning_db(dir, db, 'WAL-IS-OLD', 'latest wal file is too old') for db in backup_state: if len(backup_state[db]['expires']) > 0: @@ -302,6 +327,8 @@ for dir in os.listdir('.'): for p in problems_seq: print p +for p in notices_seq: + print p if options.expire: for f in global_expires: