def test_analyze_mult_exiting(agents_fixtures): """ Test `prewikka.views.agents.agents.Agents.analyze` view. Multiple heartbeats with "exiting" status. """ view = agents_fixtures analyzer_id = '123456' idmef_id = '01123581-3213-4558-9144' idmef_id_2 = '01123581-3213-4558-9145' idmef = create_heartbeat(idmef_id, status='exiting', analyzer_id=analyzer_id) idmef_2 = create_heartbeat(idmef_id_2, status='exiting', analyzer_id=analyzer_id) env.idmef_db.insert(idmef) env.idmef_db.insert(idmef_2) assert view.render(analyzer_id) # clean delete_heartbeat(idmef_id) delete_heartbeat(idmef_id_2)
def test_analyze_mult_run_unexint(agents_fixtures): """ Test `prewikka.views.agents.agents.Agents.analyze` view. Multiple heartbeats with "running" status but unexpected interval between 2 heartbeats. """ view = agents_fixtures analyzer_id = '123456' idmef_id = '01123581-3213-4558-9144' idmef_id_2 = '01123581-3213-4558-9145' current_date = datetime.now() previous_date = current_date - timedelta(seconds=600) idmef = create_heartbeat( idmef_id, status='running', heartbeat_date=current_date.strftime('%Y-%m-%d %H:%M:%S'), analyzer_id=analyzer_id, heartbeat_interval=599) idmef_2 = create_heartbeat( idmef_id_2, status='running', heartbeat_date=previous_date.strftime('%Y-%m-%d %H:%M:%S'), analyzer_id=analyzer_id, heartbeat_interval=599) env.idmef_db.insert(idmef) env.idmef_db.insert(idmef_2) assert view.render(analyzer_id) # clean delete_heartbeat(idmef_id) delete_heartbeat(idmef_id_2)
def test_analyze_mult_missing(agents_fixtures): """ Test `prewikka.views.agents.agents.Agents.analyze` view. Multiple heartbeats with "missing" status. """ view = agents_fixtures analyzer_id = '123456' idmef_id = '01123581-3213-4558-9144' idmef_id_2 = '01123581-3213-4558-9145' idmef = create_heartbeat(idmef_id, heartbeat_date='2013-01-01 10:09:08', status='Online', analyzer_id=analyzer_id) idmef_2 = create_heartbeat(idmef_id_2, heartbeat_date='2013-12-11 10:19:08', status='Online', analyzer_id=analyzer_id) env.idmef_db.insert(idmef) env.idmef_db.insert(idmef_2) assert view.render(analyzer_id) # clean delete_heartbeat(idmef_id) delete_heartbeat(idmef_id_2)
def test_analyze_mult_no_interval(agents_fixtures): """ Test `prewikka.views.agents.agents.Agents.analyze` view. Multiple heartbeats without `heartbeat.heartbeat_interval`. """ view = agents_fixtures analyzer_id = '123456' idmef_id = '01123581-3213-4558-9144' idmef_id_2 = '01123581-3213-4558-9145' idmef = create_heartbeat(idmef_id, heartbeat_interval=None, status='Online', analyzer_id=analyzer_id) idmef_2 = create_heartbeat(idmef_id_2, heartbeat_interval=None, status='Online', analyzer_id=analyzer_id) env.idmef_db.insert(idmef) env.idmef_db.insert(idmef_2) assert view.render(analyzer_id) # clean delete_heartbeat(idmef_id) delete_heartbeat(idmef_id_2)
def test_agents(agents_fixtures): """ Test `prewikka.views.agents.agents.Agents.agents` view. """ view = agents_fixtures idmef = create_heartbeat('01123581-3213-4558-9144') env.idmef_db.insert(idmef) assert view.render() # clean delete_heartbeat('01123581-3213-4558-9144')
def test_analyze(agents_fixtures): """ Test `prewikka.views.agents.agents.Agents.analyze` view. """ view = agents_fixtures idmef_id = '01123581-3213-4558-9144' idmef = create_heartbeat(idmef_id) env.idmef_db.insert(idmef) assert view.render(idmef_id.replace('-', '')) # clean delete_heartbeat(idmef_id)
def test_agents_status_unknown(agents_fixtures): """ Test `prewikka.views.agents.agents.Agents.agents` view. """ view = agents_fixtures backup_parameters = deepcopy(env.request.parameters) idmef = create_heartbeat('01123581-3213-4558-9144', status='online') env.idmef_db.insert(idmef) env.request.parameters['status'] = ['unknown'] assert view.render() # clean delete_heartbeat('01123581-3213-4558-9144') env.request.parameters = backup_parameters
def test_analyze_mult_no_status(agents_fixtures): """ Test `prewikka.views.agents.agents.Agents.analyze` view. Multiple heartbeats without `additional_data('Analyzer status')`. """ view = agents_fixtures analyzer_id = '123456' idmef_id = '01123581-3213-4558-9144' idmef_id_2 = '01123581-3213-4558-9145' idmef = create_heartbeat(idmef_id, analyzer_id=analyzer_id) idmef_2 = create_heartbeat(idmef_id_2, analyzer_id=analyzer_id) env.idmef_db.insert(idmef) env.idmef_db.insert(idmef_2) assert view.render(analyzer_id) # clean delete_heartbeat(idmef_id) delete_heartbeat(idmef_id_2)
def test_get_analyzer_status(): """ Test `prewikka.utils.misc.get_analyzer_status_from_latest_heartbeat()`. """ heartbeat_id = 'NqnYbirynpr' idmef_db = env.dataprovider._backends["alert"]._db criteria = Criterion('heartbeat.messageid', '=', heartbeat_id) heartbeats = [ (create_heartbeat(heartbeat_id, status='exiting'), 'offline'), (create_heartbeat(heartbeat_id, heartbeat_interval=None), 'unknown'), (create_heartbeat(heartbeat_id, heartbeat_date='1991-08-25 20:57:08'), 'missing'), (create_heartbeat(heartbeat_id), 'online') ] for idmef, expected_status in heartbeats: idmef_db.insert(idmef) heartbeat = env.dataprovider.get(criteria)[0]['heartbeat'] status = misc.get_analyzer_status_from_latest_heartbeat(heartbeat, 0) assert status[0] == expected_status delete_heartbeat(heartbeat_id)