Skip to content

asn, fake expert: default paths, asn: add checks #2606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

sebix
Copy link
Member

@sebix sebix commented Apr 23, 2025

asn, fake expert: use state path for database default
asn: Check for database file existence and writability fixes #2566

@sebix sebix added the bug Indicates an unexpected problem or unintended behavior label Apr 23, 2025
@sebix sebix added this to the 3.4.1 Patch release milestone Apr 23, 2025
@sebix sebix force-pushed the sane-default-path branch 2 times, most recently from bf38b18 to 905a62e Compare April 28, 2025 08:28
@sebix
Copy link
Member Author

sebix commented Apr 28, 2025

rebased to fix the tests

@@ -40,6 +41,8 @@ def init(self):
self.logger.error("Read 'bots/experts/asn_lookup/README' and "
"follow the procedure.")
self.stop()
if not Path(self.database).is_file:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An idea - maybe add also a check in the check method that would verify if the file is not a file or is not writable (also check from L121)? Not existing file should not cause a failure in check (it could be like this for a new bot), but could be an info

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The line is actually wrong. is_file is a method, not a member, therefore is_file always evaluates to true.

An idea - maybe add also a check in the check method that would verify if the file is not a file or is not writable (also check from L121)?

I updated the existence check and added a type check

Not existing file should not cause a failure in check (it could be like this for a new bot), but could be an info

I can follow you, but on the other hand, if the database file does not exist at the time of checking, the bot can also not operate with this current state and needs intervention by the admin to get into a working state.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, good that you caught it!

I can follow you, but on the other hand, if the database file does not exist at the time of checking, the bot can also not operate with this current state and needs intervention by the admin to get into a working state.

This is also true, so a failure may be expected. I'd anyway keep it more as warning as an error as it could be handled automatically, and is a desired state on the first run - until manual or automated action take place - and the bot configuration itself might be correct.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd anyway keep it more as warning as an error as it could be handled automatically, and is a desired state on the first run - until manual or automated action take place - and the bot configuration itself might be correct.

I disagree with you that the configuration is correct if it's not able to operate.

A better solution, solving your and my concerns, could be to run the auto update method at initialization if the database doesn't exist.
However, I'd like to postpone that feature in favor of getting the changes with improved checks and default values done.

@sebix sebix requested a review from kamil-certat May 21, 2025 19:25
@sebix sebix force-pushed the sane-default-path branch from d50588a to 3092f9e Compare May 21, 2025 19:48
@sebix
Copy link
Member Author

sebix commented Jul 8, 2025

Hehe, the added check already works:

FAILED intelmq/tests/bots/experts/asn_lookup/test_expert.py::TestASNLookupExpertBot::test_static_bot_check_method - ValueError: checks is [['warning', 'Database (/home/runner/work/intelmq/intelmq/intelmq/tests/bots/experts/asn_lookup/ipasn.dat) is older than one week. Check the auto update, see: https://docs.intelmq.org/latest/user/bots/#asn-lookup.']]

I believe the line raising that exception is actually a bug.

EDIT: Addressed by #2622

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ASN Lookup expert: Missing sane default value for database path
2 participants