stratosphereips / AIP

The Attacker IP Prioritizer(AIP) dynamically generates resource-friendly IPv4 blocklists from Zeek network flows.
https://www.stratosphereips.org
GNU General Public License v3.0
30 stars 9 forks source link

Better error catching when date is out of range #44

Open verovaleros opened 3 days ago

verovaleros commented 3 days ago

AIP allows to run models for a specific date, but some models require some history (minimum number of data) to run.

2024-10-26 16:04:41,530 - root - ERROR - Error running Prioritize_New model: date value out of range
Traceback (most recent call last):
  File "/home/aip/AIP/bin/aip", line 66, in run_model
    blocklist = aip_model.run(day)
                ^^^^^^^^^^^^^^^^^^
  File "/home/aip/AIP/lib/aip/models/prioritize.py", line 176, in run
    self.db = Knowledgebase(load_until=for_date - timedelta(days=1))
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/aip/AIP/lib/aip/models/prioritize.py", line 116, in __init__
    self._load_knowledge_until(day)
  File "/home/aip/AIP/lib/aip/models/prioritize.py", line 106, in _load_knowledge_until
    self.build(end=datetime.strptime(day, '%Y-%m-%d').date())
  File "/home/aip/AIP/lib/aip/models/prioritize.py", line 133, in build
    day = str(end - timedelta(days=days_ago))
              ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
OverflowError: date value out of range
verovaleros commented 3 days ago

The same happens with two other models:

2024-10-26 16:04:46,816 - root - ERROR - Error running Prioritize_Consistent model: date value out of range
Traceback (most recent call last):
  File "/home/aip/AIP/bin/aip", line 66, in run_model
    blocklist = aip_model.run(day)
                ^^^^^^^^^^^^^^^^^^
  File "/home/aip/AIP/lib/aip/models/prioritize.py", line 176, in run
    self.db = Knowledgebase(load_until=for_date - timedelta(days=1))
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/aip/AIP/lib/aip/models/prioritize.py", line 116, in __init__
    self._load_knowledge_until(day)
  File "/home/aip/AIP/lib/aip/models/prioritize.py", line 106, in _load_knowledge_until
    self.build(end=datetime.strptime(day, '%Y-%m-%d').date())
  File "/home/aip/AIP/lib/aip/models/prioritize.py", line 133, in build
    day = str(end - timedelta(days=days_ago))
              ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
OverflowError: date value out of range
2024-10-26 16:04:52,263 - root - ERROR - Error running Random_Forest model: date value out of range
Traceback (most recent call last):
  File "/home/aip/AIP/bin/aip", line 66, in run_model
    blocklist = aip_model.run(day)
                ^^^^^^^^^^^^^^^^^^
  File "/home/aip/AIP/lib/aip/models/prioritize.py", line 255, in run
    training, target = self._get_training_target_set(for_date=for_date)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/aip/AIP/lib/aip/models/prioritize.py", line 230, in _get_training_target_set
    target = Knowledgebase(load_until=for_date - timedelta(days=1))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/aip/AIP/lib/aip/models/prioritize.py", line 116, in __init__
    self._load_knowledge_until(day)
  File "/home/aip/AIP/lib/aip/models/prioritize.py", line 106, in _load_knowledge_until
    self.build(end=datetime.strptime(day, '%Y-%m-%d').date())
  File "/home/aip/AIP/lib/aip/models/prioritize.py", line 133, in build
    day = str(end - timedelta(days=days_ago))
              ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
OverflowError: date value out of range