Skip to content

Show friendly message for Zabbix API permission errors - #11

Merged
Vitexus merged 1 commit into
VitexSoftware:mainfrom
kirtapos:fix/zabbix-api-permission-error
Jul 22, 2026
Merged

Show friendly message for Zabbix API permission errors#11
Vitexus merged 1 commit into
VitexSoftware:mainfrom
kirtapos:fix/zabbix-api-permission-error

Conversation

@kirtapos

@kirtapos kirtapos commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fixes the raw ZabbixApiException dump reported in Api error #10 for the case where the Zabbix user's role has API access disabled entirely (JSON-RPC code -32500, "No permissions to call ...").
  • ZabbixApiException (lib/api/zabbix_api.dart) now exposes code, isPermissionError, and friendlyMessage getters.
  • ProblemsScreen's error branch (lib/screens/problems_screen.dart) shows an icon + actionable message + Retry button (reusing the existing _refreshData()), instead of Text('Error: ${snapshot.error}').

Root cause

As detailed in the investigation on #10: this error isn't a host-group permission gap — it's the Zabbix role's "API access" toggle being off (api.access: 0), which makes every API call fail identically for that account (host.get, problem.get, etc.). The app had no handling for this class of error at all.

Test plan

  • flutter analyze / flutter test (not run here — no Flutter SDK available in this environment; please run in CI)
  • Manually reproduce with a Zabbix user whose role has API access disabled and confirm the friendly message + Retry button render instead of the raw exception
  • Confirm Retry re-fetches once API access is re-enabled server-side

Closes/relates to #10 (root-cause analysis and screenshots posted there).

Summary by CodeRabbit

  • Bug Fixes
    • Improved error messages on the Problems screen.
    • Added a clear permission-related message when access is denied.
    • Added a contextual error icon for permission issues.
    • Added a Retry button to recover from loading errors.

When a user's Zabbix role has API access disabled (JSON-RPC code
-32500, "No permissions to call ..."), every API call fails the same
way regardless of host-group permissions. The app previously surfaced
this as a raw exception dump on a blank screen (issue VitexSoftware#10).

ZabbixApiException now exposes isPermissionError/friendlyMessage, and
ProblemsScreen shows an actionable message with a Retry button instead
of the raw error text.
@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

API error handling

Layer / File(s) Summary
Exception interpretation
lib/api/zabbix_api.dart
ZabbixApiException parses JSON-RPC codes, detects permission denials, and exposes a friendly message.
Problems error UI
lib/screens/problems_screen.dart
The Problems screen displays exception-aware messages and icons, and adds a Retry button wired to _refreshData.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ProblemsScreen
  participant FutureBuilder
  participant ZabbixApiException
  participant ErrorPanel
  ProblemsScreen->>FutureBuilder: observe problems request error
  FutureBuilder->>ZabbixApiException: provide snapshot.error
  ProblemsScreen->>ZabbixApiException: read friendlyMessage and isPermissionError
  ZabbixApiException-->>ProblemsScreen: return message and permission status
  ProblemsScreen->>ErrorPanel: render message and selected icon
  ErrorPanel->>ProblemsScreen: press Retry
  ProblemsScreen->>ProblemsScreen: call _refreshData
Loading

Suggested reviewers: vitexus

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: surfacing friendly Zabbix API permission-error messages.
Linked Issues check ✅ Passed The PR addresses issue #10 by replacing the raw API error with a user-friendly error state and retry action.
Out of Scope Changes check ✅ Passed The changes stay within the reported API error handling and ProblemsScreen UX improvements.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@lib/api/zabbix_api.dart`:
- Around line 263-280: Update the `friendlyMessage` getter’s `isPermissionError`
branch to explain both role-level API access restrictions and method-specific
allow/deny rules, rather than only directing users to enable API access. Add
coverage for `-32500` errors representing each case and verify both produce the
broadened guidance.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fc426525-de73-4a46-bc02-d1ed42b3675a

📥 Commits

Reviewing files that changed from the base of the PR and between 342f230 and 43e362e.

📒 Files selected for processing (2)
  • lib/api/zabbix_api.dart
  • lib/screens/problems_screen.dart

Comment thread lib/api/zabbix_api.dart
Comment on lines +263 to +280
/// True when Zabbix rejected the call because the authenticated user's role
/// isn't allowed to call the API at all (JSON-RPC code -32500 with a
/// "No permissions to call ..." data message). This is a role-level
/// "API access" toggle in Zabbix, not a host-group permission gap, so it
/// affects every API method for that account, not just the one that failed.
bool get isPermissionError =>
code == -32500 &&
(details['data']?.toString().toLowerCase().contains('no permissions') ?? false);

/// A message safe to show directly to end users, instead of the raw
/// JSON-RPC error payload.
String get friendlyMessage {
if (isPermissionError) {
return 'Your Zabbix account is not allowed to use the API.\n\n'
'Ask your Zabbix administrator to enable "Enabled" under API access '
'for your user role (Administration → Users → Roles), then try again.';
}
return message;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n== Files ==\n'
git ls-files 'lib/api/zabbix_api.dart' 'test' | sed -n '1,200p'

printf '\n== Outline: lib/api/zabbix_api.dart ==\n'
ast-grep outline lib/api/zabbix_api.dart --view expanded || true

printf '\n== Relevant lines in lib/api/zabbix_api.dart ==\n'
cat -n lib/api/zabbix_api.dart | sed -n '230,320p'

printf '\n== Search tests / usages for isPermissionError / friendlyMessage / No permissions ==\n'
rg -n "isPermissionError|friendlyMessage|No permissions to call|API access|API method|user role|role" lib test || true

Repository: VitexSoftware/Zabb

Length of output: 4005


🌐 Web query:

Zabbix "No permissions to call" API method denied role API access separate permissions

💡 Result:

The error "No permissions to call [method_name]" in Zabbix indicates that the user account associated with the API request does not have the necessary privileges to execute that specific API method [1][2]. In Zabbix, API access and method execution are strictly governed by User Roles [3][4]. To resolve this issue, verify and adjust the following configurations in your Zabbix web interface: 1. Check the User Role assigned to the user: Go to Users > Users, locate the user associated with your API token or login, and identify their assigned Role [4]. 2. Configure Role-based API access: Navigate to Users > User roles and open the role assigned to that user [4]. Under the API section, ensure that Access to API is enabled [3][2]. Review the API methods section. Zabbix allows you to define an Allow list or a Deny list for API methods [3]. - If you use an Allow list, ensure the specific method (e.g., host.create) is explicitly added to the list [3][2]. - If you use a Deny list, ensure the method is not listed [3]. - Wildcards are supported (e.g., host.* to allow all host-related methods) [3]. 3. Verify other permission dependencies: - User Group Permissions: Even if the API method is allowed by the Role, the user must still have appropriate read/write permissions to the specific host groups or template groups involved in the operation [1][4]. These are assigned via the user's User Group settings [4]. - User Type limitations: The User Role cannot grant permissions that exceed the underlying User Type (User, Admin, or Super admin) [4]. For example, a "User" type cannot be granted "Super admin" capabilities simply by adjusting a custom role [4]. - API Token/User association: Verify that the API token is indeed linked to the user account you intended [1]. Ensure you are not inadvertently using a different user account (e.g., a standard user instead of an administrator) [1]. If you recently upgraded Zabbix, be aware that changes in security defaults or role definitions in newer versions (such as 7.0+) may impact existing permissions [5]. Always verify that the user assigned to the API task has the required scope for the operation [4][6].

Citations:


Broaden the permission message

-32500 with “No permissions to call” can also mean the role blocks the requested API method, not just API access. Update the message to mention both API access and method allow/deny rules, and add coverage for both cases.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/api/zabbix_api.dart` around lines 263 - 280, Update the `friendlyMessage`
getter’s `isPermissionError` branch to explain both role-level API access
restrictions and method-specific allow/deny rules, rather than only directing
users to enable API access. Add coverage for `-32500` errors representing each
case and verify both produce the broadened guidance.

@Vitexus
Vitexus merged commit fa2ec48 into VitexSoftware:main Jul 22, 2026
2 checks passed
@kirtapos
kirtapos deleted the fix/zabbix-api-permission-error branch July 22, 2026 13:42
@kirtapos kirtapos mentioned this pull request Jul 22, 2026
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