Skip to content

Commit 07547bf

Browse files
refactor: improve code formatting and documentation comments with prettier
1 parent 576edd8 commit 07547bf

File tree

3 files changed

+93
-37
lines changed

3 files changed

+93
-37
lines changed

src/tools/hosts/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Central export file for the Datadog Hosts management tools.
33
* Re-exports the tools and their handlers from the implementation file.
4-
*
4+
*
55
* HOSTS_TOOLS: Array of tool schemas defining the available host management operations
66
* HOSTS_HANDLERS: Object containing the implementation of each host management operation
77
*/

src/tools/hosts/schema.ts

+48-13
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,64 @@ import { z } from 'zod'
88
/**
99
* Schema for muting a host in Datadog.
1010
* Defines required and optional parameters for temporarily silencing a host's alerts.
11-
*
11+
*
1212
* @param hostname - Required. Identifies the host to be muted
1313
* @param message - Optional. Adds context about why the host is being muted
1414
* @param end - Optional. Unix timestamp defining when the mute should automatically expire
1515
* @param override - Optional. Controls whether to replace an existing mute's end time
1616
*/
1717
export const MuteHostZodSchema = z.object({
1818
hostname: z.string().describe('The name of the host to mute'),
19-
message: z.string().optional().describe('Message to associate with the muting of this host'),
20-
end: z.number().int().optional().describe('POSIX timestamp for when the mute should end'),
21-
override: z.boolean().optional().default(false).describe('If true and the host is already muted, replaces existing end time')
19+
message: z
20+
.string()
21+
.optional()
22+
.describe('Message to associate with the muting of this host'),
23+
end: z
24+
.number()
25+
.int()
26+
.optional()
27+
.describe('POSIX timestamp for when the mute should end'),
28+
override: z
29+
.boolean()
30+
.optional()
31+
.default(false)
32+
.describe(
33+
'If true and the host is already muted, replaces existing end time',
34+
),
2235
})
2336

2437
/**
2538
* Schema for unmuting a host in Datadog.
2639
* Defines parameters for re-enabling alerts for a previously muted host.
27-
*
40+
*
2841
* @param hostname - Required. Identifies the host to be unmuted
2942
*/
3043
export const UnmuteHostZodSchema = z.object({
31-
hostname: z.string().describe('The name of the host to unmute')
44+
hostname: z.string().describe('The name of the host to unmute'),
3245
})
3346

3447
/**
3548
* Schema for retrieving active host counts from Datadog.
3649
* Defines parameters for querying the number of reporting hosts within a time window.
37-
*
50+
*
3851
* @param from - Optional. Time window in seconds to check for host activity
3952
* Defaults to 7200 seconds (2 hours)
4053
*/
4154
export const GetActiveHostsCountZodSchema = z.object({
42-
from: z.number().int().optional().default(7200).describe('Number of seconds from which you want to get total number of active hosts (defaults to 2h)'),
55+
from: z
56+
.number()
57+
.int()
58+
.optional()
59+
.default(7200)
60+
.describe(
61+
'Number of seconds from which you want to get total number of active hosts (defaults to 2h)',
62+
),
4363
})
4464

4565
/**
4666
* Schema for listing and filtering hosts in Datadog.
4767
* Defines comprehensive parameters for querying and filtering host information.
48-
*
68+
*
4969
* @param filter - Optional. Search string to filter hosts
5070
* @param sort_field - Optional. Field to sort results by
5171
* @param sort_dir - Optional. Sort direction ('asc' or 'desc')
@@ -60,8 +80,23 @@ export const ListHostsZodSchema = z.object({
6080
sort_field: z.string().optional().describe('Field to sort hosts by'),
6181
sort_dir: z.string().optional().describe('Sort direction (asc/desc)'),
6282
start: z.number().int().optional().describe('Starting offset for pagination'),
63-
count: z.number().int().max(1000).optional().describe('Max number of hosts to return (max: 1000)'),
64-
from: z.number().int().optional().describe('Search hosts from this UNIX timestamp'),
65-
include_muted_hosts_data: z.boolean().optional().describe('Include muted hosts status and expiry'),
66-
include_hosts_metadata: z.boolean().optional().describe('Include host metadata (version, platform, etc)'),
83+
count: z
84+
.number()
85+
.int()
86+
.max(1000)
87+
.optional()
88+
.describe('Max number of hosts to return (max: 1000)'),
89+
from: z
90+
.number()
91+
.int()
92+
.optional()
93+
.describe('Search hosts from this UNIX timestamp'),
94+
include_muted_hosts_data: z
95+
.boolean()
96+
.optional()
97+
.describe('Include muted hosts status and expiry'),
98+
include_hosts_metadata: z
99+
.boolean()
100+
.optional()
101+
.describe('Include host metadata (version, platform, etc)'),
67102
})

src/tools/hosts/tool.ts

+44-23
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
import { ExtendedTool, ToolHandlers } from '../../utils/types'
22
import { v1 } from '@datadog/datadog-api-client'
33
import { createToolSchema } from '../../utils/tool'
4-
import { ListHostsZodSchema, GetActiveHostsCountZodSchema, MuteHostZodSchema, UnmuteHostZodSchema } from './schema'
4+
import {
5+
ListHostsZodSchema,
6+
GetActiveHostsCountZodSchema,
7+
MuteHostZodSchema,
8+
UnmuteHostZodSchema,
9+
} from './schema'
510
import { datadogConfig } from '../../utils/datadog'
611

712
/**
8-
* This module implements Datadog host management tools for muting, unmuting,
13+
* This module implements Datadog host management tools for muting, unmuting,
914
* and retrieving host information using the Datadog API client.
1015
*/
1116

1217
/** Available host management tool names */
13-
type HostsToolName = 'list_hosts' | 'get_active_hosts_count' | 'mute_host' | 'unmute_host'
18+
type HostsToolName =
19+
| 'list_hosts'
20+
| 'get_active_hosts_count'
21+
| 'mute_host'
22+
| 'unmute_host'
1423
/** Extended tool type with host-specific operations */
1524
type HostsTool = ExtendedTool<HostsToolName>
1625

@@ -19,11 +28,7 @@ type HostsTool = ExtendedTool<HostsToolName>
1928
* Each tool is created with a schema for input validation and includes a description.
2029
*/
2130
export const HOSTS_TOOLS: HostsTool[] = [
22-
createToolSchema(
23-
MuteHostZodSchema,
24-
'mute_host',
25-
'Mute a host in Datadog',
26-
),
31+
createToolSchema(MuteHostZodSchema, 'mute_host', 'Mute a host in Datadog'),
2732
createToolSchema(
2833
UnmuteHostZodSchema,
2934
'unmute_host',
@@ -57,7 +62,9 @@ export const HOSTS_HANDLERS: HostsToolHandlers = {
5762
* Silences alerts and notifications for the host until unmuted or until the specified end time.
5863
*/
5964
mute_host: async (request) => {
60-
const { hostname, message, end, override } = MuteHostZodSchema.parse(request.params.arguments)
65+
const { hostname, message, end, override } = MuteHostZodSchema.parse(
66+
request.params.arguments,
67+
)
6168

6269
await API_INSTANCE.muteHost({
6370
hostName: hostname,
@@ -72,10 +79,14 @@ export const HOSTS_HANDLERS: HostsToolHandlers = {
7279
content: [
7380
{
7481
type: 'text',
75-
text: JSON.stringify({
76-
status: 'success',
77-
message: `Host ${hostname} has been muted successfully${message ? ` with message: ${message}` : ''}${end ? ` until ${new Date(end * 1000).toISOString()}` : ''}`
78-
}, null, 2),
82+
text: JSON.stringify(
83+
{
84+
status: 'success',
85+
message: `Host ${hostname} has been muted successfully${message ? ` with message: ${message}` : ''}${end ? ` until ${new Date(end * 1000).toISOString()}` : ''}`,
86+
},
87+
null,
88+
2,
89+
),
7990
},
8091
],
8192
}
@@ -96,10 +107,14 @@ export const HOSTS_HANDLERS: HostsToolHandlers = {
96107
content: [
97108
{
98109
type: 'text',
99-
text: JSON.stringify({
100-
status: 'success',
101-
message: `Host ${hostname} has been unmuted successfully`
102-
}, null, 2),
110+
text: JSON.stringify(
111+
{
112+
status: 'success',
113+
message: `Host ${hostname} has been unmuted successfully`,
114+
},
115+
null,
116+
2,
117+
),
103118
},
104119
],
105120
}
@@ -110,8 +125,10 @@ export const HOSTS_HANDLERS: HostsToolHandlers = {
110125
* Provides total counts of hosts that are reporting and operational.
111126
*/
112127
get_active_hosts_count: async (request) => {
113-
const { from } = GetActiveHostsCountZodSchema.parse(request.params.arguments)
114-
128+
const { from } = GetActiveHostsCountZodSchema.parse(
129+
request.params.arguments,
130+
)
131+
115132
const response = await API_INSTANCE.getHostTotals({
116133
from,
117134
})
@@ -120,10 +137,14 @@ export const HOSTS_HANDLERS: HostsToolHandlers = {
120137
content: [
121138
{
122139
type: 'text',
123-
text: JSON.stringify({
124-
total_active: response.totalActive || 0, // Total number of active hosts (UP and reporting) to Datadog
125-
total_up: response.totalUp || 0 // Number of hosts that are UP and reporting to Datadog
126-
}, null, 2),
140+
text: JSON.stringify(
141+
{
142+
total_active: response.totalActive || 0, // Total number of active hosts (UP and reporting) to Datadog
143+
total_up: response.totalUp || 0, // Number of hosts that are UP and reporting to Datadog
144+
},
145+
null,
146+
2,
147+
),
127148
},
128149
],
129150
}

0 commit comments

Comments
 (0)