Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/services-logs-drains.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ You can use Clever Tools to control logs drains, through following commands. Eac
```
clever drain
clever drain -F json
clever drain --type <DRAIN-TYPE>
clever drain create <DRAIN-TYPE> <DRAIN-URL>
clever drain get <DRAIN-ID>
clever drain get <DRAIN-ID> --format json
Expand Down
1 change: 1 addition & 0 deletions skills/clever-tools/references/full-documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,7 @@ clever drain [options]
-a, --alias <alias> Short name for the application
--app <app-id|app-name> Application to manage by its ID (or name, if unambiguous)
-F, --format <format> Output format (human, json) (default: human)
--type <drain-type> Only list drains of this type (betterstack, datadog, elasticsearch, newrelic, ovh-tcp, raw-http, splunk, syslog-tcp, syslog-udp)
```

### drain check
Expand Down
22 changes: 18 additions & 4 deletions src/commands/drain/drain.command.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { z } from 'zod';
import { getDrains } from '../../clever-client/drains.js';
import { defineCommand } from '../../lib/define-command.js';
import { defineOption } from '../../lib/define-option.js';
import { Logger } from '../../logger.js';
import { formatDrain, resolveDrainResource } from '../../models/drain.js';
import { DRAIN_TYPE_CLI_CODES, DRAIN_TYPES, formatDrain, resolveDrainResource } from '../../models/drain.js';
import { sendToApi } from '../../models/send-to-api.js';
import {
addonIdOrRealIdOption,
Expand All @@ -17,14 +19,25 @@ export const drainCommand = defineCommand({
alias: aliasOption,
appIdOrName: appIdOrNameOption,
addonIdOrRealId: addonIdOrRealIdOption,
type: defineOption({
name: 'type',
schema: z.enum(DRAIN_TYPE_CLI_CODES).optional(),
description: 'Only list drains of this type',
placeholder: 'drain-type',
}),
format: humanJsonOutputFormatOption,
},
args: [],
async handler(options) {
const { alias, appIdOrName, addonIdOrRealId, format } = options;
const { alias, appIdOrName, addonIdOrRealId, type, format } = options;
const { ownerId, resourceId } = await resolveDrainResource(alias, appIdOrName, addonIdOrRealId);

const drains = await getDrains({ ownerId, resourceId }).then(sendToApi);
const allDrains = await getDrains({ ownerId, resourceId }).then(sendToApi);

// The resource scoped endpoint only filters on status, so the type filter is applied here.
// The list is bounded by the number of drains of a single resource, it never paginates.
const drainType = Object.values(DRAIN_TYPES).find((drainType) => drainType.cliCode === type);
const drains = drainType == null ? allDrains : allDrains.filter((d) => d.recipient.type === drainType.apiCode);

switch (format) {
case 'json': {
Expand All @@ -35,7 +48,8 @@ export const drainCommand = defineCommand({
default: {
if (drains.length === 0) {
const resourceLabel = addonIdOrRealId ?? appIdOrName ?? resourceId;
Logger.println(`There are no drains for ${resourceLabel}`);
const drainsLabel = drainType == null ? 'drains' : `${drainType.label} drains`;
Logger.println(`There are no ${drainsLabel} for ${resourceLabel}`);
return;
}

Expand Down
1 change: 1 addition & 0 deletions src/commands/drain/drain.docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ clever drain [options]
|`-a`, `--alias` `<alias>`|Short name for the application|
|`--app` `<app-id\|app-name>`|Application to manage by its ID (or name, if unambiguous)|
|`-F`, `--format` `<format>`|Output format (human, json) (default: human)|
|`--type` `<drain-type>`|Only list drains of this type (betterstack, datadog, elasticsearch, newrelic, ovh-tcp, raw-http, splunk, syslog-tcp, syslog-udp)|

## ➡️ `clever drain check` <kbd>Since 4.11.0</kbd>

Expand Down
Loading