diff --git a/CHANGELOG.md b/CHANGELOG.md index 16c84a186..9ffe8b693 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ This file documents all notable changes made to ITFlow. ### Upgrading -Update from Maintenance > Update — Queue Update hands the job to cron, which updates the files and applies this release's one database change (3.6.6 to 3.6.7) in the same pass. It adds three tables for RMM providers and changes nothing that is there. Nothing else is required. This release has three security fixes - see Security. +Update from Maintenance > Update — Queue Update hands the job to cron, which updates the files and applies this release's two database changes (3.6.6 to 3.6.8) in the same pass. They add four tables for RMM providers and their alerts, and change nothing that is there. Nothing else is required. This release has three security fixes - see Security. ### Security @@ -22,7 +22,10 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u - RMM Providers: an asset from an RMM shows whether the device is online, offline or overdue, beside its status. It also gets a card named after its provider: when it was last seen, who is signed in, its public IP and site, and whether it needs a reboot, has patches waiting or has checks failing. For Tactical RMM, Take Control opens its remote session, and its menu has Open in Tactical RMM and Remote Background. The quick look has the state and Take Control too. - RMM Providers: on the assets list, a dot after a device's name says how it is, and the RMM filter - named after your provider when you have one - shows the online, offline or overdue ones, every device in it, or the assets that aren't in it. - RMM Providers: a device the RMM no longer has keeps its asset, marked as no longer in it. If you delete an asset in ITFlow, the next sync doesn't make it again - Bring back on the client's row does. A client linked to another of your clients brings its devices in there. The assets already made for the first client stay, no longer kept up. Each change is in the asset's history. -- RMM Providers: the RMM Sync job is on Maintenance > Cron. Turning a provider off stops its syncs, and Delete forgets its links - the assets stay as they are either way. API keys are kept like other providers' keys and never shown again. A Tactical RMM key can do whatever its Tactical user can, so make it for a user whose role can see clients and agents and no more. +- RMM Providers: alerts can open tickets. In a provider's Edit, pick which - errors, errors and warnings, or every alert - and the category their tickets go in. A new alert on a device of a linked client opens a ticket on its client and asset within a minute: High for an error, Medium for a warning, Low for the rest, with what the alert says and a link to the device in the RMM. The same alert again on the same device goes on that ticket while it is open, reopening it if it was resolved, so a check that keeps failing doesn't fill the queue. +- RMM Providers: when an alert clears, its ticket gets a note and is resolved - unless someone has written on it, it is in a status someone moved it to, or another of its alerts is still open. Then it gets the note and stays as it is. Alerts already open when you turn this on, or when you link a client, don't open tickets. +- RMM Providers: for Tactical RMM, the alerts are the ones its dashboard shows - a check's or agent's Dashboard alert setting, or its alert template, decides which those are. Nothing needs setting up in Tactical, but the API key's user has to be able to list alerts. A device's open alerts and their tickets show on its card on the asset, and the providers list says which alerts open tickets, how many are open and whether the last look worked. +- RMM Providers: the RMM Sync job is on Maintenance > Cron, and so is RMM Alerts, every minute. Turning a provider off stops its syncs, and Delete forgets its links - the assets stay as they are either way. API keys are kept like other providers' keys and never shown again. A Tactical RMM key can do whatever its Tactical user can, so make it for a user whose role can see clients and agents and no more. ### Developer Updates @@ -31,6 +34,10 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u - `rmmSync($provider, $only = 0, $max_seconds = 120)` asks the kind for its clients, then for each linked client's devices, longest since brought in first, and stops on time to pick up next run. `GET_LOCK('itflow_rmm_sync_')` keeps each provider to one sync at a time. Devices and clients are marked removed by what the RMM listed, never by time, and only for a client whose list came back whole. One client failing doesn't hold up the rest or mark its devices removed. `rmmDeviceSave()` matches (`rmmAssetMatch()` - serial, then a name only one asset has, among this client's unarchived assets no other device of the provider has), makes (`rmmAssetCreate()`) and follows (`rmmAssetFollow()`). The follow rule: a field is written when it is empty or still holds what `rmm_device_synced` says was last written, and a blank never writes. Values go through `rmmText()` first - what `escapeSql()` would store - so a value compares the same on both sides and isn't written again every run. CPU and storage are asset details (`asset_specs`) and are only written for a type that has them. A device two providers have is one asset with a row from each, and each follows only what it wrote. - `cron/rmm_sync.php` is the `rmm_sync` job in `includes/cron_jobs.php`, every 15 minutes: `rmmSyncAll()` syncs each provider that is on, sharing two minutes between them. It stops with the failing providers' notes, or when cron is off. Admin handlers are in `admin/post/rmm.php`; their request keys are in `DEMO_MODE_LOCKS`, and `admin/rmm_providers.php` and `admin/rmm_clients.php` are locked pages in the demo. - `agent/assets.php` takes `rmm` (`any`, `online`, `offline`, `overdue`, `none`) as a subquery on `rmm_devices`, in the list and the tab counts alike. The RMM select only shows once a provider is set up. +- Database 3.6.8: `rmm_providers` gains `rmm_provider_alert_level` (`''` none, `error`, `warning`, `info`), `rmm_provider_alert_category_id`, `rmm_provider_alerts_since` (NULL until the first look), `rmm_provider_alerts_at` and `rmm_provider_alerts_note` (the last look's error, NULL when it worked). `rmm_alerts` is one an alert ITFlow has seen: its device, asset and client, `rmm_alert_about` (what on the device it is about - `check:12`, `task:3`, `availability`), severity, message, raised and cleared times, and `rmm_alert_ticket_id`, 0 for one already open before ITFlow watched. Re-runnable. +- Alerts are two more optional kind functions, `alerts` (the open ones) and `alert` (one by id, null once the RMM no longer has it), each alert in the shape described above `rmmAlertLevels()`. Tactical's are `PATCH /alerts/` with `resolvedFilter: false` and `GET /alerts//`. `rmmAlertsPoll($provider)` takes a lock per provider (`itflow_rmm_alerts_`). The first look after alerts are turned on, or the provider back on, records what is open with no ticket. After that an alert it hasn't seen is new - no clock is compared, except to skip one raised before its device came into ITFlow. Alerts no longer listed as open are asked about one by one, 25 a run. An error is written to App Logs once, when it starts, not every minute it lasts. +- `rmmAlertTicketOpen()` makes the ticket the way a text does (`smsTicketOpen()`): next ticket number, `ticket_source` `RMM`, `applyTicketSla()`, the new-ticket address (`ticketMailNewTicketAddress($ticket_id, 'rmm')`) and `triggerCustomAction('ticket_create')`, but no email to the client's contacts. Its notes are internal replies with `ticket_reply_by` 0, and `rmmTicketWorked()` counts any reply by someone (`ticket_reply_by` > 0). Resolving and reopening go through `ticketResolve()` and `ticketReopen()`, so the SLA clock and history follow. `ticketSourceIcon()` and the ticket page know the `RMM` source. +- `cron/rmm_alerts.php` is the `rmm_alerts` job, every minute. It stops when cron or ticketing is off, or no provider's alerts open tickets. - `agent/ajax.php`: the seventeen GET answers that printed JSON under PHP's default `text/html` now send `Content-Type: application/json` first - `get_credential_via_id`, `get_totp_token_via_id`, `get_readable_pass`, `get_active_clients`, `get_client_contacts`, `get_client_assets`, `get_client_locations`, `get_client_vendors`, `get_client_projects`, `get_internal_users`, `get_document_content`, `get_canned_response`, `ticket_query_views`, `client_duplicate_check`, `contact_email_check`, `network_ip_check` and `domain_check`. Their callers read the body as text (`itflowGet()`) or with `res.json()`, so nothing changes for them. A new JSON answer sets the header the same way: a value that is not escaped for HTML, as a login's username and password are not, must never go out as `text/html`. - `getFieldByIdInScope($table, $id, $field, $client_field)` (`functions/app.php`) is `getFieldById()` for a record that belongs to a client. It gives null unless `hasClientAccess()` passes for the record's client, as it does for a record that isn't there; a record with no client (0) is anyone's. Use it wherever a label is made from an id in the query string. The two labels read with their own query, on `agent/trips.php` and `agent/modals/trip/trip_export.php`, take `clientScopeSql()` instead. - `join.php` puts the login key in its sign-in link only while the invite is `pending` or `accepted` (`userInviteState()`). diff --git a/admin/database_updates/3.6.8.php b/admin/database_updates/3.6.8.php new file mode 100644 index 000000000..3a7faab3b --- /dev/null +++ b/admin/database_updates/3.6.8.php @@ -0,0 +1,56 @@ + "varchar(20) NOT NULL DEFAULT '' AFTER `rmm_provider_sync_note`", + 'rmm_provider_alert_category_id' => "int(11) NOT NULL DEFAULT 0 AFTER `rmm_provider_alert_level`", + 'rmm_provider_alerts_since' => "datetime DEFAULT NULL AFTER `rmm_provider_alert_category_id`", + 'rmm_provider_alerts_at' => "datetime DEFAULT NULL AFTER `rmm_provider_alerts_since`", + 'rmm_provider_alerts_note' => "varchar(500) DEFAULT NULL AFTER `rmm_provider_alerts_at`", + ]; + foreach ($itflow_rmm_columns as $itflow_rmm_column => $itflow_rmm_definition) { + $itflow_column_exists = mysqli_query($mysqli, "SELECT 1 FROM information_schema.COLUMNS + WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'rmm_providers' AND COLUMN_NAME = '$itflow_rmm_column' LIMIT 1"); + if (!$itflow_column_exists || mysqli_num_rows($itflow_column_exists) === 0) { + mysqli_query($mysqli, "ALTER TABLE `rmm_providers` ADD `$itflow_rmm_column` $itflow_rmm_definition"); + } + } + + mysqli_query($mysqli, "CREATE TABLE IF NOT EXISTS `rmm_alerts` ( + `rmm_alert_id` int(11) NOT NULL AUTO_INCREMENT, + `rmm_alert_provider_id` int(11) NOT NULL, + `rmm_alert_remote_id` varchar(100) NOT NULL, + `rmm_alert_device_id` int(11) NOT NULL DEFAULT 0, + `rmm_alert_asset_id` int(11) NOT NULL DEFAULT 0, + `rmm_alert_client_id` int(11) NOT NULL DEFAULT 0, + `rmm_alert_about` varchar(150) NOT NULL DEFAULT '', + `rmm_alert_type` varchar(20) NOT NULL DEFAULT '', + `rmm_alert_severity` varchar(20) NOT NULL DEFAULT '', + `rmm_alert_message` text DEFAULT NULL, + `rmm_alert_raised_at` datetime DEFAULT NULL, + `rmm_alert_cleared_at` datetime DEFAULT NULL, + `rmm_alert_ticket_id` int(11) NOT NULL DEFAULT 0, + `rmm_alert_created_at` datetime NOT NULL DEFAULT current_timestamp(), + PRIMARY KEY (`rmm_alert_id`), + UNIQUE KEY `rmm_alert_remote` (`rmm_alert_provider_id`,`rmm_alert_remote_id`), + KEY `rmm_alert_device_id` (`rmm_alert_device_id`), + KEY `rmm_alert_ticket_id` (`rmm_alert_ticket_id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci"); diff --git a/admin/modals/rmm/rmm_provider_edit.php b/admin/modals/rmm/rmm_provider_edit.php index a5e04bb3c..16291bdab 100644 --- a/admin/modals/rmm/rmm_provider_edit.php +++ b/admin/modals/rmm/rmm_provider_edit.php @@ -4,7 +4,8 @@ * Admin > RMM Providers - one provider's window: Add (no id) or Edit. Which RMM it is is * picked when it is added and stays; each kind brings its own fields (rmmProviderKinds() in * functions/rmm.php) - addresses, a key, a secret. A key or secret is never put back into the - * page, so left empty it stays. Save asks first (check_rmm_provider, admin/post/rmm.php): what + * page, so left empty it stays. A kind that has alerts can have them open tickets, from the + * level picked, in a category. Save asks first (check_rmm_provider, admin/post/rmm.php): what * is wrong shows beside each field and the window stays open; once all is right it saves, and * tries the connection. */ @@ -26,11 +27,16 @@ $kinds = rmmProviderKinds(); $kind_key = $row ? (string) $row['rmm_provider_kind'] : (string) array_key_first($kinds); $kind = $kinds[$kind_key]; -// What the window's script needs of each kind - its name, to follow the kind picked +// What the window's script needs of each kind - its name, to follow the kind picked, and whether it has alerts $kinds_js = array_map(function ($info) { - return ['name' => $info['name']]; + return ['name' => $info['name'], 'alerts' => isset($info['alerts'], $info['alert']), 'alertsHelp' => (string) ($info['alerts_help'] ?? '')]; }, $kinds); +// Alerts open tickets - once the 3.6.8 database update is in, with ticketing on +$alerts_offered = rmmAlertsReady() && !empty($config_module_enable_ticketing); +$alert_level = (string) ($row['rmm_provider_alert_level'] ?? ''); +$alert_category_id = intval($row['rmm_provider_alert_category_id'] ?? 0); + // Where what is wrong with a field shows $error_for = function ($field) { return '
'; @@ -114,6 +120,36 @@ ob_start(); + +
+
+ +
+ + +
+ +
A new alert on a device of a linked client opens a ticket on its asset - High for an error, Medium for a warning, Low for the rest - and the same alert again goes on that ticket while it is open. When the alert clears, the ticket is resolved unless someone has written on it. Alerts already open when this is turned on don't open tickets. +
+
+
+ +
+ + + +
+
+
+ +