def check_ssh_team2(): current_number = utils.get_current_check('team2', 'ssh') score = Score(team='team2', check_name='ssh', check_number=current_number + 1) creds = SSHCreds.query.all() the_cred = None for cred in creds: if cred.team == 'team2': the_cred = cred logger.info('starting ssh check for team 2') try: result = SSH.check('10.120.2.13', port, username, the_cred.password) print(result) if result: logger.debug('team 2 ssh result: {}'.format(result)) score.success = True except Exception as e: logger.error('team 2 ssh failed with {}'.format(e)) logger.info('finished ssh check for team 2') second_check = utils.get_current_check('team2', 'ssh') if second_check != current_number: score.current_number = second_check + 1 db.session.add(score) db.session.commit()
def check_ping_team2(): logger.info('checking ping for team 2') servers = ['10.120.2.11', '10.120.2.13', '10.120.2.10', '10.120.2.12'] #servers = ['127.0.0.1'] current_number = utils.get_current_check('team2', 'ping') score = Score(team='team2', check_name='ping', check_number=current_number+1) try: score.success = True for server in servers: result = os.system('ping -c 1 ' + server) # for host try 3 times, if all pass it passes if result: logger.debug('team 2 host {} failed ping check'.format(server)) score.success = False if score.success: logger.debug('team 2 passed ping check') except Exception as e: logger.error('team 2 ping {}'.format(e)) logger.info('finished checking ping for team 2') second_check = utils.get_current_check('team2', 'ping') if second_check != current_number: score.current_number = second_check + 1 db.session.add(score) db.session.commit()
def score(): scores = Score.query.all() current_check_team1 = utils.get_current_check('team1', 'ping') current_check_team2 = utils.get_current_check('team2', 'ping') team1 = [ '{} {} -'.format(score.check_name, score.success) for score in scores if score.team == 'team1' and score.check_number == current_check_team1 ] team2 = [ '{} {} -'.format(score.check_name, score.success) for score in scores if score.team == 'team2' and score.check_number == current_check_team2 ] text = '<html><body><p>' text += '<h1>Check #{}</h1>'.format(current_check_team1) text += '{}={}'.format('team1', ' '.join(team1)) text += '</p>\n<p>' text += '{}={}'.format('team2', ' '.join(team2)) text += '</p><h1>Past Checks</h1>' for i in range(1, current_check_team1): text += '<a href="./score/{}">{}</a><br>'.format(i, i) text += '</body></html>' return text
def check_imap(host, team): current_number = utils.get_current_check(team, 'imap') score = Score(team=team, check_name='imap', check_number=current_number + 1) creds = SSHCreds.query.all() for cred in creds: if cred.team == team: the_cred = cred logger.info('starting imap check for {}'.format(team)) try: result = IMAP.check(host, 143, 'superadmin', the_cred.password) if result: logger.debug('{} imap result: {}'.format(team, result)) score.success = True except Exception as e: logger.error('{} imap failed with {}'.format(team, e)) logger.info('finished imap check for {}'.format(team)) second_check = utils.get_current_check(team, 'imap') if second_check != current_number: score.current_number = second_check + 1 db.session.add(score) db.session.commit()
def check_dns(host, team): current_number = utils.get_current_check(team, 'dns') score = Score(team=team, check_name='dns', check_number=current_number + 1) logger.info('starting dns check for {}'.format(team)) try: result = DNS.check(host, 'wakanda.{}.benron'.format(team)) if result: logger.debug('{} dns result: {}'.format(team, result)) if team == 'team1': if result.address == '10.1.1.20': logger.debug('team 1 passed dns') score.success = True else: if result.address == '10.2.2.20': logger.debug('team 2 passed dns') score.success = True except Exception as e: logger.error('{} dns failed with {}'.format(team, e)) logger.info('finished dns check for {}'.format(team)) second_check = utils.get_current_check(team, 'dns') if second_check != current_number: score.current_number = second_check + 1 db.session.add(score) db.session.commit()