configfile = '/etc/nagios/dsa-check-backuppg.conf'
f = open(configfile)
- config = yaml.load(f.read())
+ config = yaml.safe_load(f.read())
f.close()
return config
(w1,w2) = w
if w2 == 0:
w1 -= 1
- if (host,db) in ( ('moszumanska', 'main'), ):
- w2 = 0xFE
- else:
- w2 = 0xFF
+ w2 = 0xFF
else:
w2 -= 1
f.close()
return i
+def get_retention(config, host, db):
+ assert('retention' in config)
+
+ assert('backups' in config)
+ assert(isinstance(config['backups'], dict))
+
+ assert(host in config['backups'])
+ assert(isinstance(config['backups'][host], dict))
+
+ assert(db in config['backups'][host])
+ if isinstance(config['backups'][host][db], dict) and 'retention' in config['backups'][host][db]:
+ r = config['backups'][host][db]['retention']
+ elif '_retention' in config['backups'][host]:
+ r = config['backups'][host]['_retention']
+ else:
+ r = config['retention']
+
+ assert(isinstance(r, int))
+ return r
parser = optparse.OptionParser()
parser.set_usage("%prog [-c=<CONFFILE>] (nagios mode)\n" +
os.chdir(config['rootdir'])
for dir in os.listdir('.'):
- if dir.startswith('.') or dir.endswith('.old'):
+ if dir.startswith('.') or dir.endswith('.old') or dir == 'lost+found':
note_info('IGNORED', dir)
continue
files.sort()
- unhandled_backups = copy.copy(config['backups'][dir])
+ notyetseen_dbs = copy.copy(config['backups'][dir])
ignored_dbs = {}
backup_state = {}
else:
note_warning_db(dir, db, 'MISSING-BASE', basefn)
continue
+ if db in notyetseen_dbs: del notyetseen_dbs[db]
files.remove(basefn)
if backup_state[db]['can_expire_next']:
backup_state[db]['expires'].append(baseffn)
backup_state[db]['base_needs_wal_until'] = walbase
start = time.mktime(time.strptime(info['start time'], '%Y-%m-%d %H:%M:%S %Z'))
- if start + config['retention'] < time.time():
+ if start + get_retention(config, dir, db) < time.time():
backup_state[db]['can_expire_for_base_hit'] = True
continue
for f in backup_state[db]['expires']:
global_expires.append(f)
+ for db in notyetseen_dbs:
+ if db.startswith('_'): continue
+ note_warning_db(dir, db, 'NO-BACKUP', 'no backups! (no .backup files found)')
+
#if not db in backup_state:
# note_warning('BASE-WITHOUT-WAL', ffn)
# ignored_dbs[db] = True
for p in problems_seq:
print p
-for p in notices_seq:
- print p
+if options.verbose:
+ for p in notices_seq:
+ print p
if options.expire:
for f in global_expires: