Skip to content

Add custom User-Agent header to requests in website monitor script#1171

Merged
jokob-sk merged 1 commit intonetalertx:mainfrom
cvc90:NetAlertX-Adding-user-agent-header-in-website_monitor-script-py
Sep 11, 2025
Merged

Add custom User-Agent header to requests in website monitor script#1171
jokob-sk merged 1 commit intonetalertx:mainfrom
cvc90:NetAlertX-Adding-user-agent-header-in-website_monitor-script-py

Conversation

@cvc90
Copy link
Contributor

@cvc90 cvc90 commented Sep 11, 2025

Hi @jokob-sk,

Pull Request

Description

Problem:

By default, the requests library identifies itself with a User-Agent header of "python-requests/version". Many modern security systems (such as web application firewalls, intrusion prevention systems, or rate limiters) are configured to block, rate-limit, or challenge traffic based on this default user agent, interpreting it as suspicious or malicious.

Solution:

This change adds a custom User-Agent string ("NetAlertX") to the HTTP requests made by the script website_monitor/script.py.

What this change means:

  • Requests sent by the Website Monitor plugin will now be less likely to be blocked by firewalls or intrusion prevention systems.

  • NetAlertX traffic will be easier to identify and distinguish in server logs, since it carries its own unique user agent instead of the generic "python-requests".

  • This provides a more reliable monitoring experience, especially in environments with stricter security policies.

Changes

Update Plugin Website Monitor (/front/plugins/website_monitor/script.py)

Updated the requests.get(...) call to include:

headers={"User-Agent": "NetAlertX"}

Ensuring all outgoing HTTP requests carry the custom identifier.

Test

  • Run local tests and verified that the User-Agent header is set correctly in outbound HTTP requests.

  • Confirmed that monitoring continues to operate as expected, without interference from security filters that previously flagged the "python-requests" user-agent.

Summary by CodeRabbit

  • Bug Fixes
    • Improved website health checks by adding a standard User-Agent to outbound requests, reducing false negatives and improving compatibility with servers that block unidentified traffic.
  • Chores
    • Updated request metadata for external health checks to aid server identification and diagnostics. No changes to configuration, UI, or workflows.

Added user-agent header
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 11, 2025

Walkthrough

Adds a User-Agent header ("NetAlertX") to the HTTP GET request in check_services_health within front/plugins/website_monitor/script.py. No other logic, parameters (verify=False, timeout), error handling, latency measurement, or return values are changed.

Changes

Cohort / File(s) Summary
Website monitor HTTP request header
front/plugins/website_monitor/script.py
Add headers={"User-Agent": "NetAlertX"} to requests.get in check_services_health; no other logic modified.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~6 minutes

Pre-merge checks (2 passed, 1 warning)

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly and accurately describes the primary change—adding a custom User-Agent header to outbound requests in the website monitor script—and matches the PR summary and the modification in front/plugins/website_monitor/script.py.

Poem

I twitched my whiskers, tapped the wire,
“User-Agent set!” I happily chired.
A gentle hop through webs so vast,
Now servers know I’m hopping past.
With header neat and paws held tight,
NetAlertX sniffs the bytes just right. 🐇🌐

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cvc90 cvc90 marked this pull request as ready for review September 11, 2025 02:22
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
front/plugins/website_monitor/script.py (2)

60-60: Make UA configurable and more descriptive (include plugin/name/version)

Let admins override the UA and include the plugin name for clarity.

Apply within this hunk:

-        resp = requests.get(site, verify=False, timeout=get_setting_value('WEBMON_RUN_TIMEOUT'), headers={"User-Agent": "NetAlertX"})
+        resp = requests.get(site, verify=False, timeout=get_setting_value('WEBMON_RUN_TIMEOUT'), headers=DEFAULT_HEADERS)

Then add near other globals (outside this hunk):

# Default and configurable User-Agent for Website Monitor
USER_AGENT = (get_setting_value('WEBMON_USER_AGENT') or 'NetAlertX WebsiteMonitor').strip()
DEFAULT_HEADERS = {'User-Agent': USER_AGENT}

Want me to open a small follow-up PR to wire the WEBMON_USER_AGENT setting into the UI/docs?


53-61: Minor: reuse a Session and set headers once

For multiple URLs, a shared requests.Session with default headers can reduce overhead and centralize UA.

Example (outside this hunk):

SESSION = requests.Session()
SESSION.headers.update(DEFAULT_HEADERS)

# then:
resp = SESSION.get(site, verify=verify_tls, timeout=get_setting_value('WEBMON_RUN_TIMEOUT'))
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3653d2e and a823301.

📒 Files selected for processing (1)
  • front/plugins/website_monitor/script.py (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
front/plugins/website_monitor/script.py (1)
server/helper.py (1)
  • get_setting_value (358-411)
🪛 Ruff (0.12.2)
front/plugins/website_monitor/script.py

60-60: Probable use of requests call with verify=False disabling SSL certificate checks

(S501)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: docker_dev
🔇 Additional comments (1)
front/plugins/website_monitor/script.py (1)

60-60: Custom User-Agent addition: LGTM

Using a non-default UA helps avoid blocks and improves log attribution. No behavior change otherwise.

Comment on lines 57 to +60
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

try:
resp = requests.get(site, verify=False, timeout=get_setting_value('WEBMON_RUN_TIMEOUT'))
resp = requests.get(site, verify=False, timeout=get_setting_value('WEBMON_RUN_TIMEOUT'), headers={"User-Agent": "NetAlertX"})
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Avoid verify=False; make TLS verification configurable and default to True

Disabling cert verification (S501) is a security risk. Keep verification on by default and only suppress warnings when explicitly disabled.

Change the call in this hunk:

-        resp = requests.get(site, verify=False, timeout=get_setting_value('WEBMON_RUN_TIMEOUT'), headers={"User-Agent": "NetAlertX"})
+        resp = requests.get(site, verify=verify_tls, timeout=get_setting_value('WEBMON_RUN_TIMEOUT'), headers={"User-Agent": "NetAlertX"})

Add just above the request (outside this hunk):

verify_tls = get_setting_value('WEBMON_VERIFY_TLS')
if verify_tls in ('', None):
    verify_tls = True
if not verify_tls:
    requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

If adding a new setting isn’t desired, at minimum consider setting verify=True and allowing per-URL exceptions.

🧰 Tools
🪛 Ruff (0.12.2)

60-60: Probable use of requests call with verify=False disabling SSL certificate checks

(S501)

🤖 Prompt for AI Agents
In front/plugins/website_monitor/script.py around lines 57 to 60, the
requests.get call currently uses verify=False which disables TLS verification;
change this to make TLS verification configurable and default to True by reading
a setting (e.g. get_setting_value('WEBMON_VERIFY_TLS')), treat empty/None as
True, store the boolean in a verify_tls variable, call
requests.packages.urllib3.disable_warnings(InsecureRequestWarning) only if
verify_tls is False, and pass verify=verify_tls into requests.get so
verification is enabled by default and only suppressed when explicitly
configured.

@jokob-sk
Copy link
Collaborator

Thansk @cvc90 🙏

@jokob-sk jokob-sk merged commit ad9babd into netalertx:main Sep 11, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants