-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
109 lines (99 loc) · 3.51 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import { v1 } from "@datadog/datadog-api-client";
import {
EventsApiCreateEventRequest,
MetricsApiSubmitMetricsRequest
} from "@codefresh-io/datadog-api-client-10-1/dist/packages/datadog-api-client-v1";
// import * as fs from "fs";
// import {ApiKeyConfiguration} from "@datadog/datadog-api-client/dist/packages/datadog-api-client-v1/auth/auth";
const DD_SITE="datadoghq.com"
const DD_API_KEY="c63300c80c1dea10386eedfb3c1b83a6"
const DD_APP_KEY="5ed7234648daec96054c58951bed3c00ba90260e"
const configuration = v1.createConfiguration({
authMethods:{
apiKeyAuth: DD_API_KEY,
appKeyAuth: DD_APP_KEY, // for events - can use DD-API-KEY value
}}
);
const test1 = async () => {
const apiInstance = new v1.AuthenticationApi(configuration);
const data = await apiInstance.validate()
console.log(
"API called successfully. Returned data: " + JSON.stringify(data)
);
}
const test2 = async () => {
const apiInstance = new v1.MetricsApi(configuration);
const payload : MetricsApiSubmitMetricsRequest = {
body: {
"series" : [
{
"metric": "system.load.1",
"points": [
[
(new Date()).getTime(),
1234.5
]
]
}
]
}
}
const data = await apiInstance.submitMetrics(payload)
console.log(`Response ${JSON.stringify(data)}`)
// const apiInstance = new v1.MonitorsApi(configuration);
// let params:v1.MonitorsApiGetMonitorRequest = {
// // number | The ID of the monitor
// monitorId: 1,
// };
//
// const data = await apiInstance.getMonitor(params)
// console.log('API called successfully. Returned data: ' + data);
}
const testEvent = async () => {
const apiInstance = new v1.EventsApi(configuration);
const payload : EventsApiCreateEventRequest = {
body: {
title: "Did you hear the news today?",
text: "Oh boy!",
aggregationKey: "adip",
alertType: "info",
deviceName: "ut cillum occaecat amet eu",
host: "do ani",
priority: "normal",
// relatedEventId: -20896850,
sourceTypeName: "in in sit",
tags: [
"environment:test"
] ,
payload: " {x:1}"
}
}
const delay = 30
const startTime = Math.floor((new Date()).getTime()/1000)
const endTime = startTime+delay
const data = await apiInstance.createEvent(payload)
console.log(`start ${startTime} end ${endTime} Response ${JSON.stringify(data)}`)
const lst0 = await apiInstance.listEvents({start:startTime, end:endTime})
await new Promise((resolve,reject)=> setTimeout( resolve, delay*1000 ) )
const lst = await apiInstance.listEvents({start:startTime, end:endTime})
console.log(`lst start ${startTime} end ${endTime} Response ${JSON.stringify(lst)}`)
// const apiInstance = new v1.MonitorsApi(configuration);
// let params:v1.MonitorsApiGetMonitorRequest = {
// // number | The ID of the monitor
// monitorId: 1,
// };
//
// const data = await apiInstance.getMonitor(params)
// console.log('API called successfully. Returned data: ' + data);
}
async function main() {
await test1()
await test2()
await testEvent()
}
main().then(
()=>{
console.log('Done')
}).catch((error)=>{
console.error(error)
})