Skip to content
This repository was archived by the owner on Aug 11, 2025. It is now read-only.
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
6 changes: 6 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ The `--reg` argument allows bulk enable/disable of integrations, like this:
opsgenie integrations disable --reg=-core-prod-
```

opsgenie-cli uses `api.opsgenie.com` by default. If you want to override the domain (for example, if you are working with OpsGenie EU), you can override it with the `--domain <domain>` argument. For example:

```bash
opsgenie alerts --domain api.eu.opsgenie.com
```

Use the `--dry-run` argument to see what changes would be applied without actually changing them.

## Using jq for data transformations
Expand Down
11,136 changes: 11,117 additions & 19 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ export class Api {
name: "--debug",
description: "Enables debug logging.",
},
{
name: "--domain <domain>",
description: "Overrides the default domain to contact OpsGenie, for example to use OpsGenie EU endpoint.",
},
];

//
Expand Down
8 changes: 5 additions & 3 deletions src/commands/alerts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { OutputStream } from "../lib/output-stream";

const pageSize = 100; // The max.

async function listAlerts(query: string, offset: number, apiKey: string, options: any): Promise<any[]> {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apiKey was actually not used in the method (it is part of the Options argument).

async function listAlerts(query: string, offset: number, domain: string, options: any): Promise<any[]> {
try {
const listResponse = await axios.get(`https://api.opsgenie.com/v2/alerts?offset=${offset}&limit=${pageSize}&query=${query}`, options);
const listResponse = await axios.get(`https://${domain}/v2/alerts?offset=${offset}&limit=${pageSize}&query=${query}`, options);
return listResponse.data.data;
}
catch (err) {
Expand Down Expand Up @@ -47,8 +47,10 @@ export class AlertsCommand implements ICommand {

const maxAlerts = 20000;
let offset = 0;

const domain = this.configuration.getOpsGenieDomain();
while (true) {
const data = await listAlerts(query, offset, apiKey, options);
const data = await listAlerts(query, offset, domain, options);
if (data.length === 0) {
break;
}
Expand Down
8 changes: 6 additions & 2 deletions src/commands/integrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export class IntegrationsCommand implements ICommand {
const integrationId = this.configuration.getArg("id");
const integrationName = this.configuration.getArg("name");
const integrationRegex = this.configuration.getArg("reg");
const domain = this.configuration.getOpsGenieDomain();

if (!integrationId && !integrationName && !integrationRegex) {
throw new Error(`Please specify integration(s) using --id=<integration-id>, --name=<integration-name> or --reg=<name-regex>.`);
}
Expand Down Expand Up @@ -73,7 +75,7 @@ export class IntegrationsCommand implements ICommand {
}
else {
for (const integration of integrations) {
await axios.post(`https://api.opsgenie.com/v2/integrations/${integration.id}/${apiOperation}`, {}, options);
await axios.post(`https://${domain}/v2/integrations/${integration.id}/${apiOperation}`, {}, options);
}
}

Expand All @@ -84,7 +86,9 @@ export class IntegrationsCommand implements ICommand {
// Gets the list of all integrations.
//
private async listIntegrations(options: any): Promise<any[]> {
const listResponse = await axios.get(`https://api.opsgenie.com/v2/integrations`, options);
const domain = this.configuration.getOpsGenieDomain();

const listResponse = await axios.get(`https://${domain}/v2/integrations`, options);
const integrations = listResponse.data.data;
return integrations;
}
Expand Down
7 changes: 5 additions & 2 deletions src/commands/integrations/disable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export class IntegrationsDisableCommand implements ICommand {
const integrationId = this.configuration.getArg("id");
const integrationName = this.configuration.getArg("name");
const integrationRegex = this.configuration.getArg("reg");
const domain = this.configuration.getOpsGenieDomain();

if (!integrationId && !integrationName && !integrationRegex) {
throw new Error(`Please specify integration(s) using --id=<integration-id>, --name=<integration-name> or --reg=<name-regex>.`);
}
Expand Down Expand Up @@ -63,7 +65,7 @@ export class IntegrationsDisableCommand implements ICommand {
}
else {
for (const integration of integrations) {
await axios.post(`https://api.opsgenie.com/v2/integrations/${integration.id}/${apiOperation}`, {}, options);
await axios.post(`https://${domain}/v2/integrations/${integration.id}/${apiOperation}`, {}, options);
}
}

Expand All @@ -74,7 +76,8 @@ export class IntegrationsDisableCommand implements ICommand {
// Gets the list of all integrations.
//
private async listIntegrations(options: any): Promise<any[]> {
const listResponse = await axios.get(`https://api.opsgenie.com/v2/integrations`, options);
const domain = this.configuration.getOpsGenieDomain();
const listResponse = await axios.get(`https://${domain}/v2/integrations`, options);
const integrations = listResponse.data.data;
return integrations;
}
Expand Down
7 changes: 5 additions & 2 deletions src/commands/integrations/enable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export class IntegrationsEnableCommand implements ICommand {
const integrationId = this.configuration.getArg("id");
const integrationName = this.configuration.getArg("name");
const integrationRegex = this.configuration.getArg("reg");
const domain = this.configuration.getOpsGenieDomain();

if (!integrationId && !integrationName && !integrationRegex) {
throw new Error(`Please specify integration(s) using --id=<integration-id>, --name=<integration-name> or --reg=<name-regex>.`);
}
Expand Down Expand Up @@ -64,7 +66,7 @@ export class IntegrationsEnableCommand implements ICommand {
}
else {
for (const integration of integrations) {
await axios.post(`https://api.opsgenie.com/v2/integrations/${integration.id}/${apiOperation}`, {}, options);
await axios.post(`https://${domain}/v2/integrations/${integration.id}/${apiOperation}`, {}, options);
}
}

Expand All @@ -75,7 +77,8 @@ export class IntegrationsEnableCommand implements ICommand {
// Gets the list of all integrations.
//
private async listIntegrations(options: any): Promise<any[]> {
const listResponse = await axios.get(`https://api.opsgenie.com/v2/integrations`, options);
const domain = this.configuration.getOpsGenieDomain();
const listResponse = await axios.get(`https://${domain}/v2/integrations`, options);
const integrations = listResponse.data.data;
return integrations;
}
Expand Down
17 changes: 17 additions & 0 deletions src/services/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ export interface IConfiguration {
// Get the local path for the plugin, if specified.
//
getLocalPluginPath(): string | undefined;

//
// Get the OpsGenie domain to send commands to. This will be, by default, "api.opsgenie.com"
//
getOpsGenieDomain(): string;
}

@InjectableClass()
Expand All @@ -69,6 +74,7 @@ export class Configuration implements IConfiguration {
private projectType: string | undefined;
private localPluginPath: string | undefined;
private pluginUrl: string | undefined;
private opsGenieDomain: string | undefined;

//
// Command line arguments to the application.
Expand Down Expand Up @@ -181,4 +187,15 @@ export class Configuration implements IConfiguration {

return this.localPluginPath;
}

getOpsGenieDomain(): string {
if (!this.opsGenieDomain) {
this.opsGenieDomain = this.getArg<string>("domain");
if (!this.opsGenieDomain) {
this.opsGenieDomain = "api.opsgenie.com"
}
}

return this.opsGenieDomain;
}
}