Quick Installation
- Purchase the module and download
haikhavan_server_monitoring-ioncube-8.2-1.0.0-install.zipfrom your VPSrv Client Area Downloads. - Upload and extract the ZIP into your WHMCS root directory so files land in
modules/addons/haikhavan_server_monitoring/. - Verify PHP 8.2–8.4 with ionCube PHP Loader 14+ / 15.5+ is enabled on your server.
- Go to System Settings → Addon Modules in WHMCS Admin, click Activate next to Haikhavan Server Monitoring & Uptime Status Hub, and assign administrator role access.
Version: 1.0.0
Namespace: Haikhavan\ServerMonitoring\
Entry Point: modules/addons/haikhavan_server_monitoring/haikhavan_server_monitoring.php
1. Architecture & File Inventory
modules/addons/haikhavan_server_monitoring/
├── haikhavan_server_monitoring.php # Addon config, lifecycle hooks, Admin & Client dispatchers, autoloader
├── hooks.php # 6 WHMCS hooks (ClientAreaNavbar/Sidebar, AdminServicesTab, AdminHomeWidget, AfterCronJob, DailyCronJob)
├── whmcs.json # WHMCS Marketplace 1.0 manifest
├── lib/
│ ├── Database.php # 7-table Capsule schema installer, settings, AES-256-CBC+HMAC crypto
│ ├── CheckEngine.php # Multi-protocol active prober (HTTP/S, TCP, DNS, SSL, Heartbeat) + incident state machine
│ ├── EscalationService.php # Slack, Discord, Webhook, Email & WHMCS OpenTicket dispatcher + WHMCS Server/Service sync
│ ├── SlaService.php # 90-day uptime bars, P50/P95 latency percentile calculator & tiered SLA credit engine
│ ├── AdminController.php # 6-tab Admin Operations Hub & CSRF-protected AJAX API
│ └── ClientController.php # Public Status Page (view=status), Heartbeat Receiver (view=heartbeat), Client Self-Service Portal
├── templates/
│ ├── admin/dashboard.php # Operations Dashboard with zero-CDN Canvas P95 chart, Monitors, Incidents, SLA & Channels
│ └── client/
│ ├── status_page.tpl # Zero-login Branded Public Status Page with 90-day uptime bars & subscriber form
│ └── monitors.tpl # Authenticated Client Self-Service Monitor Portal
└── assets/
├── css/haikhavan_server_monitoring.css
└── js/haikhavan_server_monitoring.js # Zero-CDN HTML5 Canvas P95/Avg latency trend chart & AJAX controller
2. Database Schema
All 7 custom tables (mod_hk_sm_*) are created idempotently via WHMCS\Database\Capsule::schema().
mod_hk_sm_monitors: Stores monitor configuration, protocol (http|https|tcp|dns|ssl|heartbeat), target, port, expected HTTP status/keyword, SSL warning days, uniqueheartbeat_token, interval, timeout,failure_threshold,consecutive_failures, WHMCS ownership (userid,service_id,server_id),show_on_status_page,sla_target_pct, live status, latency ms, HTTP code,ssl_expires_at,ssl_days_left, andlast_checked_at.mod_hk_sm_check_logs: Granular time-series check executions (monitor_id,status,latency_ms,http_code,ssl_days_left,message,checked_at). Pruned automatically byDailyCronJob.mod_hk_sm_daily_rollups: Pre-aggregated daily uptime and latency stats (monitor_id,day_datecomposite UNIQUE,checks_total,checks_up,checks_down,uptime_pct,avg_latency_ms,p95_latency_ms) powering sub-millisecond rendering of 90-day status bars and 14-day P95 charts.mod_hk_sm_incidents: Incident lifecycle (monitor_id,title,severity,status,summary,updates_json,whmcs_ticket_id,started_at,resolved_at).mod_hk_sm_maintenance: Scheduled maintenance windows (title,component_group,monitor_id,description,starts_at,ends_at,pause_alerts,status).mod_hk_sm_alert_channels: Multi-channel escalations (name,driver,target_encrypted,config_json,on_down,on_recovery,on_ssl_warn,enabled,last_triggered_at,last_status,last_message).mod_hk_sm_subscribers: Public Status Page subscribers (emailUNIQUE,status,verify_token,created_at).
3. Multi-Protocol Probe Engine (CheckEngine)
- HTTP / HTTPS (
probeHttp): Uses cURL with high-resolutionmicrotime(true)timing, validatesexpected_statusand optionalexpected_keyword, and forhttps://inspects the peer TLS certificate viastream_socket_client+openssl_x509_parseto compute exactssl_days_left. - TCP Port (
probeTcp): Opens a raw TCP socket viafsockopen()and records handshake RTT in milliseconds. - DNS Resolution (
probeDns): Queriesdns_get_record(..., DNS_A + DNS_AAAA)and optionally asserts a matching IP/record keyword. - SSL Certificate (
probeSsl): Performs a TLS handshake on:443, flagsdownif expired (<= 0d) ordegradedif<= ssl_warn_days. - Heartbeat / Cron Push (
probeHeartbeat+recordHeartbeatPush): Verifies the elapsed time sincelast_checked_atagainstinterval_seconds + 60sgrace period; accepts unauthenticated token-matched pings atindex.php?m=haikhavan_server_monitoring&view=heartbeat&token=<token>. - Incident State Machine: Automatically suppresses alerts during active maintenance windows; opens a new incident and dispatches
downescalations onceconsecutive_failures >= failure_threshold; automatically resolves open incidents and firesrecoveryescalations when probes returnup.
4. SLA Compliance & Credit Calculator (SlaService)
Computes 30-day average uptime from mod_hk_sm_daily_rollups, P50/P95 latency percentiles, and estimated downtime minutes (((100 - uptime_pct) / 100) * 43200). When uptime_30d < sla_target_pct:
99.000% – 99.899%→ 10% Credit (Minor Breach)98.000% – 98.999%→ 25% Credit (Major Breach)< 98.000%→ 50% Credit (Severe Breach)
Dollar credit estimates multiply the credit tier percentage by the linked WHMCS service's tblhosting.amount (or reference valuation for shared infrastructure monitors).
5. WHMCS Hooks (hooks.php)
| Hook | Priority | Purpose |
|---|---|---|
ClientAreaPrimaryNavbar |
1 |
Adds System Status (public) and Services → My Uptime Monitors (logged-in clients). |
ClientAreaPrimarySidebar |
1 |
Adds Uptime Monitors badge link on Product Details sidebar. |
AdminClientServicesTabFields |
1 |
Displays attached monitors' live status, protocol, latency & SSL days on Admin Client Services tab. |
AdminHomeWidgets |
1 |
Displays fleet Up/Down/Degraded counts, 30d uptime %, P95 latency & active incidents. |
AfterCronJob |
1 |
Runs up to 25 active monitors per cron cycle. |
DailyCronJob |
1 |
Prunes mod_hk_sm_check_logs older than log_retention_days. |
6. Security Model
- Authenticated Encryption at Rest: Alert channel webhook URLs/tokens are stored in
target_encryptedusing AES-256-CBC + HMAC-SHA256 (Encrypt-then-MAC) keyed from WHMCS$cc_encryption_hash. - CSRF Protection: Distinct 192-bit session CSRF tokens (
hk_sm_admin_csrf,hk_sm_client_csrf) verified viahash_equals()on all Admin, Public Subscribe, and Client Monitor AJAX POST requests (HTTP403on failure). - Client Ownership & Quotas: Client monitor creation enforces
client_monitor_limit; check/delete endpoints strictly verifyuserid == $_SESSION['uid'].
7. AJAX & Public Endpoints
- Admin AJAX (
admin/addonmodules.php?module=haikhavan_server_monitoring&ajax=1, POST + CSRF):save_monitor,delete_monitor,toggle_monitor,run_check,run_all_checks,sync_whmcs,create_incident,resolve_incident,create_maintenance,delete_maintenance,save_channel,test_channel,delete_channel. - Public & Client AJAX (
index.php?m=haikhavan_server_monitoring&ajax=1, POST + CSRF):subscribe(public status page),client_create_monitor,client_run_check,client_delete_monitor(authenticated client). - Public Heartbeat Push (
index.php?m=haikhavan_server_monitoring&view=heartbeat&token=<token>, GET/POST): Returns HTTP200JSON on valid active token, HTTP404otherwise.