clever-tools 2.8.1 → 2.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -1
- package/README.md +11 -0
- package/package.json +1 -1
- package/src/models/drain.js +33 -7
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -320,6 +320,7 @@ Where `DRAIN-TYPE` is one of:
|
|
|
320
320
|
- `HTTP`: for TCP syslog endpoint (note that this endpoint has optional username/passwordparameters as HTTP Basic Authentication);
|
|
321
321
|
- `ElasticSearch`: for ElasticSearch endpoint (note that this endpoint requires username/password parameters as HTTP Basic Authentication);
|
|
322
322
|
- `DatadogHTTP`: for Datadog endpoint (note that this endpoint needs your Datadog API Key).
|
|
323
|
+
- `NewRelicHTTP`: for NewRelic endpoint (note that this endpoint needs your NewRelic API Key).
|
|
323
324
|
|
|
324
325
|
#### ElasticSearch logs drains
|
|
325
326
|
|
|
@@ -337,6 +338,16 @@ clever drain create DatadogHTTP "https://http-intake.logs.datadoghq.com/v1/input
|
|
|
337
338
|
|
|
338
339
|
Please note that the `host` query parameter is not mandatory: in the Datadog pipeline configuration, you can map `@source_host` which is the host provided by Clever Cloud in logs as `host` property.
|
|
339
340
|
|
|
341
|
+
#### NewRelic logs drains
|
|
342
|
+
|
|
343
|
+
NewRelic has two zones, EU and US. An account on one zone is not available on the other, make sure to target the good EU or US intake endpoint.
|
|
344
|
+
|
|
345
|
+
To create a [NewRelic](https://docs.newrelic.com/docs/logs/log-api/introduction-log-api/) drain, you just need to use:
|
|
346
|
+
|
|
347
|
+
```sh
|
|
348
|
+
clever drain create NewRelicHTTP "https://log-api.eu.newrelic.com/log/v1" --api-key <API_KEY>
|
|
349
|
+
```
|
|
350
|
+
|
|
340
351
|
### Display help
|
|
341
352
|
|
|
342
353
|
You can display help about each command with `clever help`.
|
package/package.json
CHANGED
package/src/models/drain.js
CHANGED
|
@@ -8,12 +8,13 @@ const DRAIN_TYPES = [
|
|
|
8
8
|
{ id: 'HTTP', credentials: 'OPTIONAL' },
|
|
9
9
|
{ id: 'ElasticSearch', credentials: 'MANDATORY' },
|
|
10
10
|
{ id: 'DatadogHTTP' },
|
|
11
|
+
{ id: 'NewRelicHTTP', apiKey: 'MANDATORY' },
|
|
11
12
|
];
|
|
12
13
|
|
|
13
14
|
function createDrainBody (appId, drainTargetURL, drainTargetType, drainTargetCredentials, drainTargetConfig) {
|
|
14
15
|
|
|
15
|
-
if (!authorizeDrainCreation(drainTargetType, drainTargetCredentials)) {
|
|
16
|
-
throw new Error("Credentials are: optional for HTTP, mandatory for ElasticSearch and TCPSyslog/UDPSyslog don't need them.");
|
|
16
|
+
if (!authorizeDrainCreation(drainTargetType, drainTargetCredentials, drainTargetConfig)) {
|
|
17
|
+
throw new Error("Credentials are: optional for HTTP, mandatory for ElasticSearch, NewRelicHTTP and TCPSyslog/UDPSyslog don't need them.");
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
const body = {
|
|
@@ -26,20 +27,37 @@ function createDrainBody (appId, drainTargetURL, drainTargetType, drainTargetCre
|
|
|
26
27
|
password: drainTargetCredentials.password || '',
|
|
27
28
|
};
|
|
28
29
|
}
|
|
30
|
+
if (keyExist(drainTargetConfig)) {
|
|
31
|
+
body.APIKey = drainTargetConfig.apiKey;
|
|
32
|
+
}
|
|
29
33
|
return body;
|
|
30
34
|
}
|
|
31
35
|
|
|
32
|
-
function authorizeDrainCreation (drainTargetType, drainTargetCredentials) {
|
|
36
|
+
function authorizeDrainCreation (drainTargetType, drainTargetCredentials, drainTargetConfig) {
|
|
33
37
|
if (drainTypeExists(drainTargetType)) {
|
|
34
38
|
// retrieve creds for drain type ('mandatory', 'optional', undefined)
|
|
35
|
-
const
|
|
36
|
-
|
|
39
|
+
const credStatus = credentialsStatus(drainTargetType).credentials;
|
|
40
|
+
const keyStatus = credentialsStatus(drainTargetType).apiKey;
|
|
41
|
+
|
|
42
|
+
if (credStatus === 'MANDATORY') {
|
|
37
43
|
return credentialsExist(drainTargetCredentials);
|
|
38
44
|
}
|
|
39
|
-
if (
|
|
45
|
+
if (credStatus === 'OPTIONAL') {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
if (!credStatus && !keyStatus) {
|
|
49
|
+
return credentialsEmpty(drainTargetCredentials);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (keyStatus === 'MANDATORY') {
|
|
53
|
+
return keyExist(drainTargetConfig);
|
|
54
|
+
}
|
|
55
|
+
if (keyStatus === 'OPTIONAL') {
|
|
40
56
|
return true;
|
|
41
57
|
}
|
|
42
|
-
|
|
58
|
+
if (!keyStatus) {
|
|
59
|
+
return keyEmpty(drainTargetConfig);
|
|
60
|
+
}
|
|
43
61
|
}
|
|
44
62
|
}
|
|
45
63
|
|
|
@@ -59,6 +77,14 @@ function credentialsEmpty ({ username, password }) {
|
|
|
59
77
|
return username == null && password == null;
|
|
60
78
|
}
|
|
61
79
|
|
|
80
|
+
function keyExist ({ apiKey }) {
|
|
81
|
+
return apiKey != null;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function keyEmpty ({ apiKey }) {
|
|
85
|
+
return apiKey == null;
|
|
86
|
+
}
|
|
87
|
+
|
|
62
88
|
function listDrainTypes () {
|
|
63
89
|
return autocomplete.words(DRAIN_TYPES.map((type) => type.id));
|
|
64
90
|
}
|