-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsendEvents.js
123 lines (113 loc) · 4.44 KB
/
sendEvents.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
const axios = require('axios');
const randomWords = require('random-words');
exports.sendEvents = function(apiKey, count = 10) {
const sendFn = async function(event) {
try {
// console.log(`event: ${JSON.stringify(event)}`);
await axios({
method: 'post',
url: 'https://api.dev.moogsoft.cloud/v1/integrations/events',
data: event,
headers: {
'Accept': 'application/json',
apiKey: 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 numEvents = count;
const severities = [
'minor',
'major',
'warning',
'critical'
];
// for (let i = 0; i < numEvents; 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({exactlyg: 1, wordsPerString: words }).toString(),
// check: randomWords(),
// severity: severities[Math.floor(Math.random() * 5)],
// service: randomWords(),
// tags,
// location,
// }
// events.push(singleEvent);
// }
const services = [
["ecommerce", "webhosts", "database", "storage", "SSO", "network", "telecom", "site builder", "email", "pki" ],
["monitoring", "hadoop", "webhosts", "database", "security", "SEO", "site builder", "billing", "Kafka", "pki"],
["monitoring", "hadoop", "webhosts", "database", "security", "SEO", "site builder", "billing", "Kafka", "pki"],
["hadoop", "ecommerce", "webhosts", "Cloudwatch", "database", "security", "SSO", "network", "Mongodb", "gateway"],
["database", "site builder", "Kafka", "Oncall", "pki", "Firewall", "Load Balancer", "Proxy", "Metrics"],
["SEO", "site builder", "Kafka", "pki", "EKS", "EMR", "Load Balancer", "ECS", "Aurora"],
];
const checks = ['cpu', 'disk', 'switch'];
const usbankTags = [
'rtamnaj9c01337.us.bank-dns.comBGPADJCHANGE*10.99.66.144',
'rtamnaj9c01337.us.bank-dns.comBGPADJCHANGE*10.99.71.17',
'rtamnaj9c01337.us.bank-dns.comBGPADJCHANGE*10.99.84.114',
];
const send = () => {
const events = [];
for (let i = 0; i < numEvents; i += 1) {
const words = Math.floor(Math.random() * 100) + 5;
const tags = {
'animal': 'cow',
'noise': randomWords(),
'www': 'www.mywwwurl.com',
'http': 'http://moogsoft.com',
'camelCase': 'cc',
'under_score': 'underscore',
// labels: ['l1', 'l2'],
// Identifier: usbankTags[i],
// 'amex.spike.broke.es': 'abc'
// 'html': '<script>alert("hey")</script>'
};
// In case needing to add lots of tags
// const onekTags = randomWords(1000);
// onekTags.forEach((t) => tags[t] = t);
const location = {
street: 'battery st',
city: 'SF',
region: 'us-west-2',
postcode: 'AB12 CDE'
};
const singleEvent = {
source: randomWords(),
description: randomWords({exactly: 1, wordsPerString: words }).toString(),
check: checks[i] || 'test',
severity: severities[Math.floor(Math.random() * 4)],
service: [randomWords()],
tags,
location,
}
events.push(singleEvent);
}
events.forEach(evt => sendFn(evt));
console.log(`Batch of ${count} events sent to MOC`);
}
send();
setInterval(() => send(), 10000);
}