MCPcopy Create free account
hub / github.com/dflow-sh/dflow / netdataAPI

Function netdataAPI

src/lib/netdata/netdataAPI.ts:14–82  ·  view source on GitHub ↗
(
  params: NetdataApiParams,
  endpoint: string,
  version: 'v1' | 'v2' = 'v1',
)

Source from the content-addressed store, hash-verified

12 * @returns Response data or error
13 */
14export const netdataAPI = async (
15 params: NetdataApiParams,
16 endpoint: string,
17 version: 'v1' | 'v2' = 'v1',
18): Promise<any> => {
19 const {
20 host = 'localhost',
21 port = 19999,
22 after,
23 before,
24 points,
25 group,
26 dimensions,
27 nodes,
28 contexts,
29 } = params
30
31 // Build base URL for API
32 const baseUrl = `/api/${version}/${endpoint}`
33
34 // Check if endpoint already has query parameters
35 const hasQueryParams = baseUrl.includes('?')
36
37 // Create URLSearchParams object for query parameters
38 const queryParams = new URLSearchParams()
39
40 // Add query parameters from endpoint if they exist
41 if (hasQueryParams) {
42 const [path, queryString] = baseUrl.split('?')
43 new URLSearchParams(queryString).forEach((value, key) => {
44 queryParams.append(key, value)
45 })
46 }
47
48 // Add common parameters if provided
49 if (after !== undefined) queryParams.append('after', after.toString())
50 if (before !== undefined) queryParams.append('before', before.toString())
51 if (points !== undefined) queryParams.append('points', points.toString())
52 if (group !== undefined) queryParams.append('group', group.toString())
53
54 // Additional v2 parameters
55 if (version === 'v2') {
56 if (dimensions !== undefined)
57 queryParams.append('dimensions', dimensions.toString())
58 if (nodes !== undefined) queryParams.append('nodes', nodes.toString())
59 if (contexts !== undefined)
60 queryParams.append('contexts', contexts.toString())
61 }
62
63 // Get the query string
64 const queryString = queryParams.toString()
65
66 // Complete endpoint with query parameters
67 const fullEndpoint = hasQueryParams
68 ? baseUrl.split('?')[0] + '?' + queryString
69 : baseUrl + (queryString ? '?' + queryString : '')
70
71 try {

Callers 15

getTimeSeriesDataFunction · 0.90
getAlarmsValuesFunction · 0.90
getAlarmsFunction · 0.90
getAlarmVariablesFunction · 0.90
getAlarmLogFunction · 0.90
getAlarmCountFunction · 0.90
getBadgeFunction · 0.90
getServerDetailsFunction · 0.90
getSystemAlertsFunction · 0.90
getRequestStatusCodesFunction · 0.90
getServerStatusFunction · 0.90
getServicesHealthFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected