Central Error Monitor

This plugin is designed to monitor multiple WordPress sites from a central location for various issues, including crashes, critical errors, 404s, downtime, missing files, and to capture snapshots of the monitored sites.



Here's a detailed explanation of its functionalities:

1. Core Functionality: Monitoring WordPress Sites

  • Centralized Monitoring: The plugin allows you to add and manage multiple WordPress sites from a single WordPress installation (where this plugin is active).
  • Error Reporting: It can receive error reports from client sites. For this to work, a separate "Site Error Tracker" plugin (presumably from bestseoplugins.site) needs to be installed on the client sites. This client-side plugin sends error data to the Central Error Monitor via a REST API endpoint.
  • Downtime Detection: It actively checks if a monitored site is "Up" or "Down" by:
    • Pinging the Server IP: It attempts to establish a connection to the server's IP address on port 80. If this fails, the site is considered "Down."
    • Checking for WordPress Files: It tries to access the WordPress REST API endpoint (/wp-json/wp/v2/status) to verify the presence of WordPress files and a healthy WordPress installation. If this fails or indicates a "Theme missing" status, the site is considered "Down."
    • General HTTP Response: It makes a general HTTP GET request to the site's URL and checks for a 200 OK response. It also looks for wp_die or theme directory strings in the response body, which often indicate critical errors.
  • Snapshot Capturing: If a site is "Up" and a ScreenshotMachine API key is provided, the plugin attempts to take a visual snapshot of the monitored site. This can be useful for visually confirming the site's appearance.
  • Error and Status Tracking: For each monitored site, the plugin stores and displays:
    • Current status (Up, Down, Error, Unknown)
    • Last detected error message
    • Last checked timestamp
    • Server IP address
    • Last connection error
    • Snapshot URL and any snapshot errors

2. Admin Interface and User Experience

  • Admin Menu Integration: Adds a "Site Monitor" menu item under the main WordPress admin menu, accessible to users with manage_options capability.
  • Site Grid Display: The main admin page (cem_admin_page) presents a grid view of all monitored sites. Each site box shows its name, URL, IP, status (with a relevant icon and color-coding), last error, last checked time, and schedule.
  • Snapshot Display: If a snapshot is successfully taken, a small image preview is displayed within the site box. A placeholder image is shown if no snapshot is available.
  • Action Buttons: Each site box includes buttons for:
    • "Test Connection": Manually triggers an immediate status check and snapshot attempt for that specific site.
    • "Edit": (Implicitly handled by AJAX, likely opens a form to edit site details).
    • "Delete": Removes the site from monitoring.
  • Add New Site Form: A dedicated form allows users to add new sites for monitoring, requiring:
    • Site Name
    • Site URL
    • Site Error Tracker API Key (from the client site)
    • ScreenshotMachine API Key (optional)
    • Monitoring Schedule (Hourly, Daily, Monthly)
  • Tutorials: Provides clear, step-by-step instructions within the admin page on how to:
    • Obtain a WordPress Site Error Tracker API Key from a client site.
    • Obtain a ScreenshotMachine API Key.

3. Background Processes and Integration

  • WordPress Cron Integration: Utilizes WordPress's built-in cron system to schedule periodic checks of the monitored sites. Each site has its own scheduled event (cem_check_site_{site_id}).
  • AJAX Handlers: Uses AJAX for dynamic interactions within the admin interface, such as:
    • Editing site details (cem_handle_edit_site)
    • Deleting sites (cem_handle_delete_site)
    • Testing connections (cem_test_connection)
  • REST API Endpoint: Registers a custom REST API endpoint (/wp-json/cem/v1/report) to receive error reports from the client "Site Error Tracker" plugin. This endpoint requires an X-API-Key header for authentication.
  • Email Notifications: Sends email alerts to the WordPress administrator's email address when:
    • A site's server IP becomes unresponsive.
    • A site is detected to have no WordPress files or a missing theme.
    • A site is down or has a critical error.
    • An error report is received from a client site.

4. Data Management

  • WordPress Options API: Stores the list of monitored sites and their configurations in the WordPress options table (cem_monitored_sites).
  • Data Sanitization: Uses WordPress sanitization functions (e.g., sanitize_text_field, esc_url_raw) to secure user input.
  • Error Logging (WP_DEBUG): Includes conditional error logging using error_log if WP_DEBUG is enabled, which is helpful for debugging purposes.

5. External Dependencies

  • Font Awesome: Enqueues Font Awesome for icons, likely used for status indicators.
  • ScreenshotMachine API: Integrates with ScreenshotMachine.com for capturing website snapshots, requiring an API key from their service.

In essence, the Central Error Monitor plugin provides a robust solution for website administrators to keep a watchful eye on the health and status of multiple WordPress sites from a single dashboard, proactively alerting them to potential issues and providing visual context through snapshots.

 CLIENT PLUGIN (WEBSITE TO MONITOR)

This plugin is designed to run on individual WordPress sites (client sites) and report their errors and status to a central monitoring system, such as the "Central Error Monitor" plugin.



Here's a detailed explanation of its functionalities:

1. Core Functionality: Error Tracking and Reporting

  • Error Interception: The plugin hooks into WordPress's error handling mechanism (wp_error action). When a WordPress error occurs, the set_report_error function is triggered, capturing the error type and message.
  • Reporting to a Central Monitor: It sends intercepted error information to a specified "Central Monitor URL". This communication happens via an HTTP POST request to the /wp-json/cem/v1/report endpoint on the central monitor.
  • API Key Authentication: Each report includes an X-API-Key header for authentication, ensuring that only authorized central monitors receive error data.
  • Site Status Reporting: The plugin adds a custom REST API endpoint (/wp-json/wp/v2/status). This endpoint provides information about the WordPress site's status, specifically checking for the presence of the active theme directory. If the theme directory is missing, it reports a "Theme missing" status. Otherwise, it reports "WordPress active". This is crucial for the central monitor to detect issues like corrupted installations or missing themes.

2. Admin Interface and Configuration

  • Settings Page: The plugin registers a dedicated settings page within the WordPress admin area under "Settings > Error Tracker". This page allows administrators to configure the plugin.
  • Central Monitor URL Input: On the settings page, there's an input field for the "Central Monitor URL," which is the address of the central monitoring system. This URL is saved as a WordPress option (set_central_monitor_url).
  • Automatic API Key Generation: If an API key doesn't exist, the plugin automatically generates a unique UUID (Universally Unique Identifier) as an API key and saves it. This key is displayed on the settings page and is read-only.
  • Connection Test: When settings are saved, a test connection is automatically initiated to the configured Central Monitor URL. This helps verify if the client site can successfully communicate with the central monitor.
  • Connection Error Display: If the test connection fails, an error message is displayed on the settings page, providing details about the connection issue (e.g., missing URL/API key, HTTP error, network error).

3. Data Management and Security

  • WordPress Options API: Configuration settings, such as the Central Monitor URL, API key, and last connection error, are stored in the WordPress options table.
  • Data Sanitization: The plugin uses esc_url_raw for sanitizing the Central Monitor URL to prevent security vulnerabilities.
  • Direct Access Prevention: Includes a standard WordPress security measure to prevent direct access to the plugin file by checking !defined('ABSPATH').
  • Error Logging (WP_DEBUG): If WP_DEBUG is enabled, the plugin logs connection success or failure messages to the WordPress error log.

In summary, the "Site Error Tracker" plugin acts as an agent on individual WordPress sites, silently monitoring for errors and reporting them, along with the site's general status, to a designated central monitoring system. This allows for a proactive approach to site maintenance and problem detection across multiple WordPress installations.






Comentarii

Postări populare de pe acest blog

Mallware scanner plugin - securewordpress

WordPress sandbox installations on remote VPS servers

A conceptual WordPress plugin to display website statistics and provide advice, leveraging Google Site Kit.