-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcyoiEvents.js
85 lines (77 loc) · 2.3 KB
/
cyoiEvents.js
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
const axios = require('axios');
const randomWords = require('random-words');
exports.sendCYOIEvents = function(apiKey, batchSize = 5) {
let usbankEvents;
try {
usbankEvents = require('./usbankEvents.json');
} catch (error) {
return console.error('usbankEvents not found')
}
const url = 'https://api.dev.moogsoft.cloud/express/v1/integrations/custom/661ef5c042ac/netcool';
if (!url || !apiKey) {
console.log('cannot send to CYOI. Need to add in api key and specific endpoint url');
return;
}
const sendFn = async function(payload) {
try {
await axios({
method: 'post',
url,
data: payload,
headers: {
apiKey,
'Content-Type': 'application/json'
}
});
} catch(e) {
if (e.response.status === 403) {
console.error('API Key invalid. Get new one from your instance');
process.exit();
}
console.log('caught an error: ', e);
}
}
const events = {
'batch': []
};
const severities = [
'clear',
'minor',
'major',
'warning',
'critical'
];
for(let i = 0; i < batchSize; i += 1) {
const words = Math.floor(Math.random() * 100) + 5;
const tags = {
'animal': 'cow',
'noise': 'moo',
'www': 'www.mywwwurl.com',
'http': 'http://moogsoft.com',
'camelCase': 'cc',
'under_score': 'underscore',
};
const location = {
street: 'battery st',
city: 'SF',
region: 'us-west-2',
};
const singleEvent = {
source: randomWords(),
description: randomWords({exactly: 1, wordsPerString: words }).toString(),
check: randomWords(),
severity: severities[Math.floor(Math.random() * 5)],
service: randomWords(),
tags,
location,
}
events.batch.push(singleEvent);
}
const send = () => {
// sendFn(events);
sendFn(usbankEvents);
console.log(`Sent batch of ${batchSize} events`);
}
send();
// setInterval(() => send, 600);
}