Skip to content

health

The health command runs diagnostic checks to verify that NextDNS Blocker is properly configured and can communicate with the NextDNS API.

Terminal window
nextdns-blocker health [OPTIONS]
OptionDescription
--config-dirConfig directory (default: auto-detect)
--helpShow help message

The health command performs four critical checks:

Verifies that:

  • .env file exists and is readable
  • Required environment variables are set (NEXTDNS_API_KEY, NEXTDNS_PROFILE_ID)
  • Configuration values are valid

Verifies that:

  • config.json file exists and is valid JSON
  • Domain entries are properly formatted
  • Schedules are syntactically correct

Verifies that:

  • API key is valid
  • Profile ID exists
  • NextDNS API is reachable
  • Current denylist can be fetched

Verifies that:

  • Log directory exists or can be created
  • Directory is writable
  • Audit log can be accessed
Terminal window
nextdns-blocker health

Output (healthy system):

Health Check
------------
[✓] Configuration loaded
[✓] Domains loaded (5 domains, 2 allowlist)
[✓] API connectivity (12 items in denylist)
[✓] Log directory: /Users/you/.local/share/nextdns-blocker/logs
Result: 4/4 checks passed
Status: HEALTHY
Terminal window
nextdns-blocker health

Output (issues detected):

Health Check
------------
[✓] Configuration loaded
[✓] Domains loaded (5 domains, 2 allowlist)
[✗] API connectivity failed
Result: 2/4 checks passed
Status: DEGRADED
Terminal window
nextdns-blocker health --config-dir /path/to/config
CodeMeaning
0All checks passed (HEALTHY)
1One or more checks failed (DEGRADED)

Run health when:

  • After installation - Verify setup is correct
  • After configuration changes - Ensure changes are valid
  • When sync fails - Diagnose connection issues
  • Before troubleshooting - Quick system status overview
  • In automation - Verify system is operational
[✗] Configuration: Missing required environment variable: NEXTDNS_API_KEY

Solution: Run nextdns-blocker init to set up configuration.

[✗] Domains: Invalid JSON in config.json

Solution:

  1. Validate your config: nextdns-blocker config validate
  2. Fix syntax errors in config.json
[✗] API connectivity failed

Solutions:

  1. Check internet connection
  2. Verify API key is correct
  3. Verify profile ID exists
  4. Check NextDNS service status
[✗] Log directory: Permission denied

Solution: Check permissions on the data directory or run with appropriate user.

Use health as part of a diagnostic workflow:

Terminal window
# Quick system check
nextdns-blocker health
# If healthy, run sync
nextdns-blocker config push
# If degraded, run fix
nextdns-blocker fix

Use in scripts to verify system before operations:

#!/bin/bash
if nextdns-blocker health > /dev/null 2>&1; then
echo "System healthy, proceeding..."
nextdns-blocker config push
else
echo "System degraded, please check configuration"
exit 1
fi