def test_delete_raw_logs (self, mock_ansible): print("Testing test_delete_raw_logs") mock_ansible.return_value = {'dark':{}, 'contacted':{'127.0.0.1':{'msg':'Todo ok', 'failed':False}}} (ret, msg) = delete_raw_logs("127.0.0.1", start="2011/01/20", end="2012/01/22", path="/tmp") nose.tools.ok_ (ret == True, "Response must be true") nose.tools.ok_ (msg['msg'] == 'Todo ok', "Bad message returned") nose.tools.ok_ (msg['failed'] == False, "Bad message returned") mock_ansible.assert_called_with(host_list=['127.0.0.1'], module="av_logger", args="start=2011/01/20 end=2012/01/22 path=/tmp ") # Test paraams (ret, msg) = delete_raw_logs("127.0.0.1", start="2011/01/20") nose.tools.ok_ (ret == True, "Response must be true") nose.tools.ok_ (msg['msg'] == 'Todo ok', "Bad message returned") nose.tools.ok_ (msg['failed'] == False, "Bad message returned") mock_ansible.assert_called_with(host_list=['127.0.0.1'], module="av_logger", args="start=2011/01/20 path=/var/ossim/logs ") # Test the error: mock_ansible.return_value = {'dark':{'127.0.0.1':{'msg':"Fallo"}}} (ret, msg) = delete_raw_logs("127.0.0.1", start="2011/01/20") nose.tools.ok_ (ret == False, "Response must be false") nose.tools.ok_ (msg == 'Fallo', "Bad response") # Test the error with failed mock_ansible.return_value = {'dark':{}, 'contacted':{'127.0.0.1':{'failed':True, 'msg':'Fallo 2'}}} (ret, msg) = delete_raw_logs("127.0.0.1", start="2011/01/20") nose.tools.ok_ (ret == False, "Response must be false") nose.tools.ok_ (msg == 'Fallo 2', "Bad response")
def clean_logger(): # First obtain the logger conf from return_value = False try: conf = get_logger_storage_days_life_time() if conf > 0: d = datetime.utcnow().date() + timedelta(days=-conf) args = "end=%s" % datetime.strftime(d, "%Y/%m/%d") # Call ansible # I need to obtain the IP from the Alienvault_Config try: server_ip = get_server_address_from_config() if server_ip is not None: # Verify the ip (result, msg) = delete_raw_logs(server_ip, end=datetime.strftime( d, "%Y/%m/%d")) return_value = result if result == False: notifier.error("Can't delete all logs in %s msg: %s" % (server_ip, str(msg))) else: notifier.debug("Result from delete_raw_logs" + str(msg)) else: notifier.error( "Bad configuration. The server ip address is not a valid ip address" ) except NoResultFound: notifier.error( "Bad configuration. No server_ip in Alienvault_Config") except MultipleResultsFound: notifier.error( "Bad configurarion. Several servers_ip in Alienvault_Config" ) else: notifier.info("Logger clean disabled") return_value = True except ValueError: notifier.error( "Bad error in logger_storage_days_lifetime. Must be a number >=0") except NoResultFound: notifier.info("Logger window not configured") except MultipleResultsFound: notifier.error( "Multiple entris in Alienvault_Config with key logger_storage_days_lifetime" ) return return_value
def clean_logger(): # First obtain the logger conf from return_value = False try: conf = get_logger_storage_days_life_time() if conf > 0: d = datetime.utcnow().date() + timedelta(days=-conf) args = "end=%s" % datetime.strftime(d, "%Y/%m/%d") # Call ansible # I need to obtain the IP from the Alienvault_Config try: server_ip = get_server_address_from_config() if server_ip is not None: # Verify the ip (result, msg) = delete_raw_logs(server_ip, end=datetime.strftime(d, "%Y/%m/%d")) return_value = result if not result: notifier.error("Can't delete all logs in %s msg: %s" % (server_ip, str(msg))) else: notifier.debug("Result from delete_raw_logs" + str(msg)) else: notifier.error("Bad configuration. The server ip address is not a valid ip address") except NoResultFound: notifier.error("Bad configuration. No server_ip in Alienvault_Config") except MultipleResultsFound: notifier.error("Bad configurarion. Several servers_ip in Alienvault_Config") else: notifier.info("Logger clean disabled") return_value = True except ValueError: notifier.error("Bad error in logger_storage_days_lifetime. Must be a number >=0") except NoResultFound: notifier.info("Logger window not configured") except MultipleResultsFound: notifier.error("Multiple entris in Alienvault_Config with key logger_storage_days_lifetime") return return_value