Skip to content

Commit

Permalink
update changes
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzad31 committed Oct 18, 2023
1 parent f4dda26 commit 9f067df
Show file tree
Hide file tree
Showing 14 changed files with 250 additions and 167 deletions.
11 changes: 11 additions & 0 deletions docs/api/uptime-api.asciidoc
@@ -0,0 +1,11 @@
[[uptime-apis]]
== Uptime APIs

The following APIs are available for Uptime.

* <<get-settings-api, Get settings API>> to get a settings

* <<update-settings-api, Update settings API>> to update the attributes for existing settings

include::uptime/get-settings.asciidoc[leveloffset=+1]
include::uptime/update-settings.asciidoc[leveloffset=+1]
39 changes: 39 additions & 0 deletions docs/api/uptime/get-settings.asciidoc
@@ -0,0 +1,39 @@
[[get-settings-api]]
== Get settings API
++++
<titleabbrev>Get settings</titleabbrev>
++++

Retrieve uptime settings existing settings.

[[get-settings-api-request]]
=== {api-request-title}

`GET <kibana host>:<port>/api/uptime/settings`

`GET <kibana host>:<port>/s/<space_id>/api/uptime/settings`

=== {api-prereq-title}

You must have `read` privileges for the *uptime* feature in *{observability}* section of the
<<kibana-feature-privileges,{kib} feature privileges>>.

The API returns the following:

[source,sh]
--------------------------------------------------
{
"heartbeatIndices": "heartbeat-8*",
"certExpirationThreshold": 30,
"certAgeThreshold": 730,
"defaultConnectors": [
"08990f40-09c5-11ee-97ae-912b222b13d4",
"db25f830-2318-11ee-9391-6b0c030836d6"
],
"defaultEmail": {
"to": [],
"cc": [],
"bcc": []
}
}
--------------------------------------------------
117 changes: 117 additions & 0 deletions docs/api/uptime/update-settings.asciidoc
@@ -0,0 +1,117 @@
[[update-settings-api]]
== Update settings API
++++
<titleabbrev>Update settings</titleabbrev>
++++

Updates uptime settings attributes like heartbeatIndices, certExpirationThreshold, certAgeThreshold, defaultConnectors or defaultEmail

=== {api-request-title}

`PUT <kibana host>:<port>/api/uptime/settings`

`PUT <kibana host>:<port>/s/<space_id>/api/uptime/settings`

=== {api-prereq-title}

You must have `all` privileges for the *uptime* feature in *{observability}* section of the
<<kibana-feature-privileges,{kib} feature privileges>>.

[[settings-api-update-path-params]]
==== Path parameters

`space_id`::
(Optional, string) An identifier for the space. If `space_id` is not provided in the URL, the default space is used.

[[api-update-request-body]]
==== Request body

A partial update is supported, provided settings keys will be merged with existing settings.

`heartbeatIndices`::
(Optional, string) index pattern string to be used within uptime app/alerts to query heartbeat data. Defaults to `heartbeat-*`.


`certExpirationThreshold`::
(Optional, number) Number of days before a certificate expires to trigger an alert. Defaults to `30`.

`certAgeThreshold`::
(Optional, number) Number of days after a certificate is created to trigger an alert. Defaults to `730`.

`defaultConnectors`::
(Optional, array) List of connector IDs to be used as default connectors for new alerts. Defaults to `[]`.

`defaultEmail`::
(Optional, object) Default email configuration for new alerts. Defaults to `{"to": [], "cc": [], "bcc": []}`.

[[settings-api-update-example]]
==== Example

[source,sh]
--------------------------------------------------
PUT api/uptime/settings
{
"heartbeatIndices": "heartbeat-8*",
"certExpirationThreshold": 30,
"certAgeThreshold": 730,
"defaultConnectors": [
"08990f40-09c5-11ee-97ae-912b222b13d4",
"db25f830-2318-11ee-9391-6b0c030836d6"
],
"defaultEmail": {
"to": [],
"cc": [],
"bcc": []
}
}
--------------------------------------------------

The API returns the following:

[source,json]
--------------------------------------------------
{
"heartbeatIndices": "heartbeat-8*",
"certExpirationThreshold": 30,
"certAgeThreshold": 730,
"defaultConnectors": [
"08990f40-09c5-11ee-97ae-912b222b13d4",
"db25f830-2318-11ee-9391-6b0c030836d6"
],
"defaultEmail": {
"to": [],
"cc": [],
"bcc": []
}
}
--------------------------------------------------
[[settings-api-partial-update-example]]
==== Partial update example

[source,sh]
--------------------------------------------------
PUT api/uptime/settings
{
"heartbeatIndices": "heartbeat-8*",
}
--------------------------------------------------

The API returns the following:

[source,json]
--------------------------------------------------
{
"heartbeatIndices": "heartbeat-8*",
"certExpirationThreshold": 30,
"certAgeThreshold": 730,
"defaultConnectors": [
"08990f40-09c5-11ee-97ae-912b222b13d4",
"db25f830-2318-11ee-9391-6b0c030836d6"
],
"defaultEmail": {
"to": [],
"cc": [],
"bcc": []
}
}
--------------------------------------------------
1 change: 1 addition & 0 deletions docs/user/api.asciidoc
Expand Up @@ -109,3 +109,4 @@ include::{kib-repo-dir}/api/osquery-manager.asciidoc[]
include::{kib-repo-dir}/api/short-urls.asciidoc[]
include::{kib-repo-dir}/api/task-manager/health.asciidoc[]
include::{kib-repo-dir}/api/upgrade-assistant.asciidoc[]
include::{kib-repo-dir}/api/uptime-api.asciidoc[]
Expand Up @@ -48,5 +48,5 @@ export enum SYNTHETICS_API_URLS {
SYNTHETICS_MONITORS_PROJECT_UPDATE = '/api/synthetics/project/{projectName}/monitors/_bulk_update',
SYNTHETICS_MONITORS_PROJECT_DELETE = '/api/synthetics/project/{projectName}/monitors/_bulk_delete',

DYNAMIC_SETTINGS = `/internal/uptime/dynamic_settings`,
DYNAMIC_SETTINGS = `/api/uptime/settings`,
}
Expand Up @@ -24,7 +24,6 @@ journey('OverviewScrolling', async ({ page, params }) => {
const listOfRequests: string[] = [];
const expected = [
'http://localhost:5620/internal/synthetics/service/enablement',
'http://localhost:5620/internal/uptime/dynamic_settings',
'http://localhost:5620/internal/synthetics/monitor/filters',
'http://localhost:5620/internal/uptime/service/locations',
'http://localhost:5620/internal/synthetics/overview?sortField=status&sortOrder=asc&',
Expand Down
Expand Up @@ -21,20 +21,22 @@ import {
import { SYNTHETICS_API_URLS } from '../../../../../common/constants';
import { LocationMonitor } from '.';

const apiPath = SYNTHETICS_API_URLS.DYNAMIC_SETTINGS;

interface SaveApiRequest {
settings: DynamicSettings;
}

export const getDynamicSettings = async (): Promise<DynamicSettings> => {
return await apiService.get(apiPath, undefined, DynamicSettingsCodec);
return await apiService.get(SYNTHETICS_API_URLS.DYNAMIC_SETTINGS, {}, DynamicSettingsCodec);
};

export const setDynamicSettings = async ({
settings,
}: SaveApiRequest): Promise<DynamicSettingsSaveResponse> => {
return await apiService.post(apiPath, settings, DynamicSettingsSaveCodec);
return await apiService.put(
SYNTHETICS_API_URLS.DYNAMIC_SETTINGS,
settings,
DynamicSettingsSaveCodec
);
};

export const fetchLocationMonitors = async (): Promise<LocationMonitor[]> => {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/uptime/common/constants/rest_api.ts
Expand Up @@ -6,7 +6,7 @@
*/

export enum API_URLS {
DYNAMIC_SETTINGS = `/internal/uptime/dynamic_settings`,
DYNAMIC_SETTINGS = `/api/uptime/settings`,
INDEX_STATUS = '/internal/uptime/index_status',
MONITOR_LIST = `/internal/uptime/monitor/list`,
MONITOR_LOCATIONS = `/internal/uptime/monitor/locations`,
Expand Down
Expand Up @@ -27,5 +27,5 @@ export const getDynamicSettings = async (): Promise<DynamicSettings> => {
export const setDynamicSettings = async ({
settings,
}: SaveApiRequest): Promise<DynamicSettingsSaveResponse> => {
return await apiService.post(apiPath, settings, DynamicSettingsSaveCodec);
return await apiService.put(apiPath, settings, DynamicSettingsSaveCodec);
};
Expand Up @@ -5,7 +5,11 @@
* 2.0.
*/

import { SavedObjectsErrorHelpers, SavedObjectsServiceSetup } from '@kbn/core/server';
import {
SavedObjectsClientContract,
SavedObjectsErrorHelpers,
SavedObjectsServiceSetup,
} from '@kbn/core/server';

import { DYNAMIC_SETTINGS_DEFAULT_ATTRIBUTES } from '../../../constants/settings';
import { DynamicSettingsAttributes } from '../../../runtime_types/settings';
Expand All @@ -20,7 +24,10 @@ export const registerUptimeSavedObjects = (savedObjectsService: SavedObjectsServ
export interface UMSavedObjectsAdapter {
config: UptimeConfig | null;
getUptimeDynamicSettings: UMSavedObjectsQueryFn<DynamicSettingsAttributes>;
setUptimeDynamicSettings: UMSavedObjectsQueryFn<void, DynamicSettingsAttributes>;
setUptimeDynamicSettings: (
client: SavedObjectsClientContract,
attr: DynamicSettingsAttributes
) => Promise<DynamicSettingsAttributes>;
}

export const savedObjectsAdapter: UMSavedObjectsAdapter = {
Expand All @@ -43,10 +50,15 @@ export const savedObjectsAdapter: UMSavedObjectsAdapter = {
throw getErr;
}
},
setUptimeDynamicSettings: async (client, settings: DynamicSettingsAttributes | undefined) => {
await client.create(umDynamicSettings.name, settings, {
id: settingsObjectId,
overwrite: true,
});
setUptimeDynamicSettings: async (client, settings: DynamicSettingsAttributes) => {
const newObj = await client.create<DynamicSettingsAttributes>(
umDynamicSettings.name,
settings,
{
id: settingsObjectId,
overwrite: true,
}
);
return newObj.attributes;
},
};

This file was deleted.

0 comments on commit 9f067df

Please sign in to comment.