Skip to content

Commit ad21cc1

Browse files
authored
Merge pull request #15 from eginnovations/add-eginnovations-plugin
Descriptor drop down for Live Mesaure and Historical Data data streams
2 parents 63a3c2a + 447a31e commit ad21cc1

File tree

9 files changed

+410
-104
lines changed

9 files changed

+410
-104
lines changed

plugins/eginnovations/v1/data_streams.json

Lines changed: 243 additions & 91 deletions
Large diffs are not rendered by default.

plugins/eginnovations/v1/handlerConfig.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { getLiveMeasure } from './readDataSource/getLiveMeasure.js';
1010
import { getMeasureForTest } from './readDataSource/getMeasureForTest.js';
1111
import { getTestForType } from './readDataSource/getTestForType.js';
1212
import { getUserComponentsForType } from './readDataSource/getUserComponentsForType.js';
13+
import { getDescriptorForComponentTestLive } from './readDataSource/getDescriptorForComponentTestLive.js';
14+
import { getDescriptorForComponentTestHistorical } from './readDataSource/getDescriptorForComponentTestHistorical.js';
1315

1416
// ============================================================================
1517

@@ -165,5 +167,7 @@ export const dataSourceFns = {
165167
getComponentsByType,
166168
getUserComponentsForType,
167169
getTestForType,
168-
getMeasureForTest
170+
getMeasureForTest,
171+
getDescriptorForComponentTestLive,
172+
getDescriptorForComponentTestHistorical
169173
};

plugins/eginnovations/v1/metadata.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "eGInnovations",
33
"displayName": "eG Enterprise",
4-
"version": "1.1.6",
4+
"version": "1.1.9",
55
"author": "eG Innovations Pvt Ltd",
66
"description": "Monitor key application metrics from your eG environment",
77
"category": "APM",
@@ -72,6 +72,17 @@
7272
"connector": "nodejs",
7373
"version": "2.0.0",
7474
"config": { "scriptPath": "handler.js", "entryPoint": "readDataSource" }
75+
},
76+
"getDescriptorForComponentTestLive": {
77+
"connector": "nodejs",
78+
"version": "2.0.0",
79+
"config": { "scriptPath": "handler.js", "entryPoint": "readDataSource" }
80+
},
81+
"getDescriptorForComponentTestHistorical": {
82+
"connector": "nodejs",
83+
"version": "2.0.0",
84+
"config": { "scriptPath": "handler.js", "entryPoint": "readDataSource" }
7585
}
86+
7687
}
7788
}

plugins/eginnovations/v1/readDataSource/alarmCount.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export async function getAlarmCount(context) {
55
const serverUrl = context.pluginConfig.serverUrl;
66
const url = `${serverUrl}/api/eg/analytics/getAlarmCount`;
77
context.log.info(url);
8-
8+
99
const agent = new https.Agent({
1010
rejectUnauthorized: false
1111
});

plugins/eginnovations/v1/readDataSource/alerts.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export async function getAlerts(context) {
3939
if (!response.ok) {
4040
throw new Error(`HTTP error! status: ${response.status}`);
4141
}
42+
4243

4344
// Check if response is JSON
4445
const contentType = response.headers.get('content-type');
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// import _ from 'lodash';
2+
import https from 'https';
3+
import fetch from 'node-fetch';
4+
5+
export async function getDescriptorForComponentTestHistorical(context) {
6+
const serverUrl = context.pluginConfig.serverUrl;
7+
const url = `${serverUrl}/api/eg/analytics/getDescriptorForComponentTest`;
8+
context.log.info(url);
9+
const agent = new https.Agent({
10+
rejectUnauthorized: false
11+
});
12+
13+
// Define the body of the request
14+
const body = {
15+
componentName: context.dataSourceConfig.componentName, //'172.16.8.112:7077',
16+
componentType: context.dataSourceConfig.componentType,
17+
test: context.dataSourceConfig.test,
18+
from: 'squaredup',
19+
dataMode:'historical'
20+
};
21+
context.log.info(JSON.stringify(context.dataSourceConfig));
22+
const headers = {
23+
'Content-Type': 'application/json',
24+
user: context.pluginConfig.user,
25+
pwd: Buffer.from(context.pluginConfig.pwd).toString('base64'),
26+
managerurl: `${serverUrl}`,
27+
accessID: context.pluginConfig.accessID
28+
};
29+
30+
try {
31+
// Await the fetch request
32+
const response = await fetch(url, {
33+
method: 'POST',
34+
body: JSON.stringify(body),
35+
headers: headers,
36+
agent: agent
37+
});
38+
39+
// Check if the response is OK
40+
if (!response.ok) {
41+
throw new Error(`HTTP error! status: ${response.status}`);
42+
}
43+
44+
// Check if response is JSON
45+
const contentType = response.headers.get('content-type');
46+
if (!contentType || !contentType.includes('application/json')) {
47+
throw new Error('Response is not JSON');
48+
}
49+
50+
let data = await response.json();
51+
52+
return data;
53+
} catch (error) {
54+
// Catch and log any errors
55+
context.log.error(`Error in getDescriptorForComponentTestHistorical: ${error.message}`);
56+
throw new Error(`HTTP error! status: ${error.message}`);
57+
}
58+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// import _ from 'lodash';
2+
import https from 'https';
3+
import fetch from 'node-fetch';
4+
5+
export async function getDescriptorForComponentTestLive(context) {
6+
const serverUrl = context.pluginConfig.serverUrl;
7+
const url = `${serverUrl}/api/eg/analytics/getDescriptorForComponentTest`;
8+
context.log.info(url);
9+
const agent = new https.Agent({
10+
rejectUnauthorized: false
11+
});
12+
13+
// Define the body of the request
14+
const body = {
15+
componentName: context.dataSourceConfig.componentName, //'172.16.8.112:7077',
16+
componentType: context.dataSourceConfig.componentType,
17+
test: context.dataSourceConfig.test,
18+
from: 'squaredup',
19+
dataMode:'live'
20+
};
21+
context.log.info(JSON.stringify(context.dataSourceConfig));
22+
const headers = {
23+
'Content-Type': 'application/json',
24+
user: context.pluginConfig.user,
25+
pwd: Buffer.from(context.pluginConfig.pwd).toString('base64'),
26+
managerurl: `${serverUrl}`,
27+
accessID: context.pluginConfig.accessID
28+
};
29+
30+
try {
31+
// Await the fetch request
32+
const response = await fetch(url, {
33+
method: 'POST',
34+
body: JSON.stringify(body),
35+
headers: headers,
36+
agent: agent
37+
});
38+
39+
// Check if the response is OK
40+
if (!response.ok) {
41+
throw new Error(`HTTP error! status: ${response.status}`);
42+
}
43+
44+
// Check if response is JSON
45+
const contentType = response.headers.get('content-type');
46+
if (!contentType || !contentType.includes('application/json')) {
47+
throw new Error('Response is not JSON');
48+
}
49+
50+
let data = await response.json();
51+
52+
return data;
53+
} catch (error) {
54+
// Catch and log any errors
55+
context.log.error(`Error in getDescriptorForComponentTestLive: ${error.message}`);
56+
throw new Error(`HTTP error! status: ${error.message}`);
57+
}
58+
}

plugins/eginnovations/v1/readDataSource/getHistoricalData.js

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,38 @@ import fetch from 'node-fetch';
44

55
export async function getHistoricalData(context) {
66
const serverUrl = context.pluginConfig.serverUrl;
7+
var info = '';
78
const url = `${serverUrl}/api/eg/analytics/getHistoricalData`;
89
context.log.info(url);
910
context.log.info(JSON.stringify(context.dataSourceConfig));
11+
1012
const agent = new https.Agent({
1113
rejectUnauthorized: false
1214
});
13-
14-
15+
if (context.dataSourceConfig.descriptor != 'Not Applicable') {
16+
if (Array.isArray(context.dataSourceConfig.descriptor)) {
17+
info =
18+
context.dataSourceConfig.descriptor.length > 0
19+
? context.dataSourceConfig.descriptor.join(',') // or [0]
20+
: '';
21+
} else {
22+
info = context.dataSourceConfig.descriptor;
23+
}
24+
} else {
25+
info = '';
26+
}
1527

1628
// Define the body of the request
1729
const body = {
18-
timeline: context.dataSourceConfig.timeline,//'1 hour',
19-
componentName:context.dataSourceConfig.componentName, //'172.16.8.112:7077',
30+
timeline: context.dataSourceConfig.timeline, //'1 hour',
31+
componentName: context.dataSourceConfig.componentName, //'172.16.8.112:7077',
2032
componentType: context.dataSourceConfig.componentType, //'eG Manager',
21-
test: context.dataSourceConfig.test, //'Network',
22-
measure: context.dataSourceConfig.measure,//'Packet Loss',
33+
test: context.dataSourceConfig.test, //'HTTP',
34+
info: info, //'HomePage',
35+
measure: context.dataSourceConfig.measure, //'web availability',
2336
from: 'squaredup'
2437
};
38+
context.log.info(JSON.stringify(body));
2539

2640
const headers = {
2741
'Content-Type': 'application/json',
@@ -52,9 +66,8 @@ export async function getHistoricalData(context) {
5266
}
5367

5468
let data = await response.json();
55-
const dynamicKey = Object.keys(data)[0];
56-
context.log.info(dynamicKey);
57-
return data[dynamicKey];
69+
70+
return data.data;
5871
} catch (error) {
5972
// Catch and log any errors
6073
context.log.error(`Error in getHistoricalData: ${error.message}`);

plugins/eginnovations/v1/readDataSource/getLiveMeasure.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,30 @@ import fetch from 'node-fetch';
55
export async function getLiveMeasure(context) {
66
const serverUrl = context.pluginConfig.serverUrl;
77
const url = `${serverUrl}/api/eg/analytics/getLiveMeasure`;
8+
var info = '';
89
context.log.info(url);
910

1011
const agent = new https.Agent({
1112
rejectUnauthorized: false
1213
});
1314

15+
if (context.dataSourceConfig.descriptor != 'All' && context.dataSourceConfig.descriptor != 'Not Applicable') {
16+
info = context.dataSourceConfig.descriptor;
17+
}else{
18+
info = '';
19+
}
20+
1421
// Define the body of the request
1522
const body = {
1623
componentName: context.dataSourceConfig.componentName, //'172.16.8.112:7077',
1724
componentType: context.dataSourceConfig.componentType,
1825
test: context.dataSourceConfig.test,
19-
measure: context.dataSourceConfig.measure, //'eG Manager'
26+
measure: context.dataSourceConfig.measure,
27+
info: info, //'eG Manager'
2028
from: 'squaredup'
2129
};
2230
context.log.info(JSON.stringify(context.dataSourceConfig));
31+
context.log.info(JSON.stringify(body));
2332
const headers = {
2433
'Content-Type': 'application/json',
2534
user: context.pluginConfig.user,

0 commit comments

Comments
 (0)