Skip to content

Implemented the Monitorv2 crud into cli#12

Open
obs-gh-joedarling wants to merge 14 commits into
mainfrom
joedarling/monitor_cli
Open

Implemented the Monitorv2 crud into cli#12
obs-gh-joedarling wants to merge 14 commits into
mainfrom
joedarling/monitor_cli

Conversation

@obs-gh-joedarling

@obs-gh-joedarling obs-gh-joedarling commented Jun 24, 2026

Copy link
Copy Markdown

Observe Monitor CLI — feature demo

0. Experimental gate

observe --helpmonitor absent from top-level commands

$ observe --help
USAGE
observe help <command>...
observe auth configure|login|logout|status ...
observe tag-value list ...
observe tag-key list ...
observe dataset list|view ...
observe metric list|view ...
observe query (--input value)... [--pipeline value] [--start value] [--end value] [--interval value] [--limit value] [--format json|csv] [--json]
observe skill list|view ...
observe alert list|view ...
observe datastream create|view|list|update ...
observe datastream-token check-status ...
observe cli install|uninstall|upgrade ...
observe --help
observe --version

observe is a command-line interface for interacting with Observe Inc. It provides commands for configuration, querying datasets, and more.

FLAGS
-h --help Print help information and exit
-v --version Print version information and exit

COMMANDS
help Display help for a command
auth Authenticate with Observe
tag-value Search and view tag values
tag-key Search and view tag keys
dataset View observe datasets
metric View observe metrics
query Execute an OPAL query
skill View AI agent skills
alert View observe alerts
datastream Manage datastreams
datastream-token Inspect datastream tokens
cli CLI management commands

export OBSERVE_CLI_EXPERIMENTAL=1 — unlock experimental commands

$ export OBSERVE_CLI_EXPERIMENTAL=1

observe --helpmonitor [experimental] now visible

$ observe --help
USAGE
observe help <command>...
observe auth configure|login|logout|status ...
observe tag-value list ...
observe tag-key list ...
observe dataset list|view ...
observe metric list|view ...
observe query (--input value)... [--pipeline value] [--start value] [--end value] [--interval value] [--limit value] [--format json|csv] [--json]
observe skill list|view ...
observe alert list|view ...
observe monitor list|view|create|update|delete|enable|disable ...
observe content host|kubernetes|tracing ...
observe ingest-token create|view|list|update ...
observe datasource create|update ...
observe data-connection create|generate-stack-url|list|view ...
observe datastream create|view|list|update ...
observe datastream-token check-status ...
observe cli install|uninstall|upgrade ...
observe --help
observe --version

observe is a command-line interface for interacting with Observe Inc. It provides commands for configuration, querying datasets, and more.

FLAGS
-h --help Print help information and exit
-v --version Print version information and exit

COMMANDS
help Display help for a command
auth Authenticate with Observe
tag-value Search and view tag values
tag-key Search and view tag keys
dataset View observe datasets
metric View observe metrics
query Execute an OPAL query
skill View AI agent skills
alert View observe alerts
monitor [experimental] Manage observe monitors
content [experimental] Manage installed content
ingest-token [experimental] Manage ingest tokens
datasource [experimental] Manage datasources
data-connection [experimental] Manage data connections
datastream Manage datastreams
datastream-token Inspect datastream tokens
cli CLI management commands

1. Help (with experimental flag)

monitor --help — available subcommands

$ observe monitor --help
USAGE
observe monitor list [--match value] [--kind value] [--disabled] [--sort id|name|kind|disabled] [--format json|csv] [--json] [--fields value] [--limit value] [--offset value]
observe monitor view [--format json|csv] [--json] <arg1>
observe monitor create (--file value) [--json]
observe monitor update (--file value) [--json] <arg1>
observe monitor delete [--yes] <arg1>
observe monitor enable [--json] <arg1>
observe monitor disable [--json] <arg1>
observe monitor --help

View and manage monitors in Observe

Commands:
list Search and list monitors in Observe
view View details of a specific monitor
create Create a new monitor
update Update a monitor
delete Delete a monitor
enable Enable a monitor
disable Disable a monitor

FLAGS
-h --help Print help information and exit

COMMANDS
list [experimental] Search and list monitors in Observe
view [experimental] View details of a monitor
create [experimental] Create a monitor
update [experimental] Update a monitor
delete [experimental] Delete a monitor
enable [experimental] Enable a monitor
disable [experimental] Disable a monitor

monitor create --help — single --file flag

Full schema reference: [Observe API Reference](https://developer.observeinc.com/#model/monitorv2definition).

$ observe monitor create --help
USAGE
observe monitor create (--file value) [--json]
observe monitor create --help

Create a new MonitorV2 monitor from a JSON file.

Required fields in the JSON file:
name (string) Monitor name
ruleKind (Count | Promote | Threshold)
definition (object) MonitorV2Definition

Optional fields:
actionRules (array) Array<MonitorV2ActionRule>

Full schema reference: https://developer.observeinc.com/#model/monitorv2definition

Minimal definition example:
{"inputQuery":{"outputStage":"main","stages":[{"stageID":"main","pipeline":"filter true"}]},"rules":[]}

FLAGS
--file Path to JSON file containing the monitor to create
[--json/--no-json] Output the created monitor as JSON
-h --help Print help information and exit

2. monitor list

list — all monitors (IDs and names redacted)

$ observe monitor list
Found 100 monitor(s):

ID NAME KIND DISABLED
XXXXXXXX Monitor 1 Threshold No
XXXXXXXX Monitor 2 Count No
XXXXXXXX Monitor 3 Count No
XXXXXXXX Monitor 4 Count Yes
XXXXXXXX Monitor 5 Promote No
[Truncated]

list --kind Count — filter by rule kind

$ observe monitor list --kind Count
Found 100 monitor(s):

ID NAME KIND DISABLED
XXXXXXXX Monitor 1 Count No
XXXXXXXX Monitor 2 Count No
XXXXXXXX Monitor 3 Count Yes
XXXXXXXX Monitor 4 Count No
XXXXXXXX Monitor 5 Count Yes
[Truncated]

list --no-disabled — only enabled monitors

$ observe monitor list --no-disabled
Found 100 monitor(s):

ID NAME KIND DISABLED
XXXXXXXX Monitor 1 Threshold No
XXXXXXXX Monitor 2 Count No
XXXXXXXX Monitor 3 Count No
XXXXXXXX Monitor 4 Promote No
XXXXXXXX Monitor 5 Count No
[Truncated]

list --sort name — sorted alphabetically

$ observe monitor list --sort name
Found 100 monitor(s):

ID NAME KIND DISABLED
XXXXXXXX Monitor 1 Threshold No
XXXXXXXX Monitor 2 Threshold Yes
XXXXXXXX Monitor 3 Threshold No
XXXXXXXX Monitor 4 Threshold No
XXXXXXXX Monitor 5 Promote Yes
[Truncated]

list --limit 5 — client-side pagination (first page)

$ observe monitor list --limit 5
Found 5 monitor(s):

ID NAME KIND DISABLED
XXXXXXXX Monitor 1 Threshold No
XXXXXXXX Monitor 2 Count No
XXXXXXXX Monitor 3 Count No
XXXXXXXX Monitor 4 Count Yes
XXXXXXXX Monitor 5 Promote No

list --limit 5 --offset 5 — second page

$ observe monitor list --limit 5 --offset 5
Found 5 monitor(s):

ID NAME KIND DISABLED
XXXXXXXX Monitor 1 Promote Yes
XXXXXXXX Monitor 2 Count No
XXXXXXXX Monitor 3 Threshold No
XXXXXXXX Monitor 4 Threshold No
XXXXXXXX Monitor 5 Threshold No

list --json — machine-readable output

[
  {
    "id": "XXXXXXXX",
    "name": "Monitor N",
    "ruleKind": "Threshold",
    "disabled": false
  },
  {
    "id": "XXXXXXXX",
    "name": "Monitor N",
    "ruleKind": "Count",
    "disabled": false
  },
  {
    "id": "XXXXXXXX",
    "name": "Monitor N",
    "ruleKind": "Count",
    "disabled": false
  }
]

3. monitor view

view <id> — human-readable output including definition

$ observe monitor view 41076897
Fetching monitor...

Monitor 41076897
Count DISABLED
Details
------------------------------------------------------------
Id 41076897
Name Joe - Test Monitor
Disabled Yes
Rule Kind Count

Scheduling
------------------------------------------------------------


Definition:
{
"customVariables": {
"message": "",
"title": ""
},
"dataStabilizationDelay": "180000000000",
"groupings": [
{
"columnPath": {
"name": "iris_id",
"path": ""
},
"correlationTag": null,
"linkColumn": null
}
],
"inputQuery": {
"outputStage": "stage-29n3w48x",
"stages": [
{
"id": "stage-29n3w48x",
"input": [
{
"datasetId": "41076895",
"datasetPath": null,
"inputName": "Reference Tables/Joe - Test Iris Dataset",
"inputRole": "Data",
"stageId": ""
}
],
"pipeline": ""
}
]
},
"lookbackTime": "600000000000",
"maxAlertsPerHour": null,
"rules": [
{
"count": {
"compareGroups": null,
"compareValues": [
{
"compareFn": "Greater",
"compareValue": {
"int64": "0"
}
}
]
},
"level": "Informational",
"promote": null,
"threshold": null
}
],
"scheduling": {
"scheduled": {
"alarmMode": null,
"cronConfig": "0 11 * * *",
"timezone": "America/Los_Angeles"
},
"transform": null
}
}

view <id> --json — full monitor JSON

{
  "id": "41076897",
  "name": "Joe - Test Monitor",
  "ruleKind": "Count",
  "disabled": true,
  "description": "This is just a test monitor used to test monitor cli commands."
}

4. monitor create

create --file — from JSON file

{
  "id": "41077231",
  "name": "CLI Demo Monitor",
  "ruleKind": "Count",
  "disabled": false
}
$ observe monitor create --file monitor-create.json --json

5. monitor update

update --file — full round-trip edit (view → edit → update)

$ observe monitor view 41077231 --json > monitor.json

$ # edit monitor.json

$ observe monitor update 41077231 --file monitor.json --json
{
"id": "41077231",
"name": "CLI Demo Monitor (edited)",
"description": "Updated via --file round-trip"
}

6. monitor disable

disable <id>

$ observe monitor disable 41077231
Disabling monitor...
✓ Monitor 41077231 disabled.

disable <id> --json

{
  "id": "41077231",
  "name": "CLI Demo Monitor (edited)",
  "disabled": true
}

7. monitor enable

enable <id>

$ observe monitor enable 41077231
Enabling monitor...
✓ Monitor 41077231 enabled.

enable <id> --json

{
  "id": "41077231",
  "name": "CLI Demo Monitor (edited)",
  "disabled": false
}

8. monitor delete

delete without --yes — confirmation prompt (type n to cancel)

$ observe monitor delete 41077231
Are you sure you want to delete monitor "CLI Demo Monitor (edited)"? This action is irreversible. [y/N]: n
✗ Deletion cancelled.

delete --yes — confirmed deletion

$ observe monitor delete 41077231 --yes
Deleting monitor...
✓ Monitor 41077231 deleted.

view after delete — confirms not found

$ observe monitor view 41077231
Fetching monitor...
✗ Monitor not found: 41077231

9. Error handling

non-integer ID

$ observe monitor view abc
✗ Invalid monitor ID: "abc". Must be a positive integer.

float ID

$ observe monitor view 41076897.5
✗ Invalid monitor ID: "41076897.5". Must be a positive integer.

zero ID

$ observe monitor view 0
✗ Invalid monitor ID: "0". Must be a positive integer.

create with missing required field in --file

$ observe monitor create --file <(echo '{"ruleKind":"Count","definition":{}}')
Creating monitor...
✗ --file must contain a "name" field (string).

create with invalid JSON in --file

$ observe monitor create --file <(echo '{ not valid json }')
Creating monitor...
✗ Error: Failed to parse --file: JSON Parse error: Expected '}'

view non-existent monitor

$ observe monitor view 9999999
Fetching monitor...
✗ Error: HTTP 400 Bad Request: Input: monitorV2 permission check failed for monitor:view on monitor 9999999

Demo complete

All demo-created monitors were cleaned up.


Joe Darling and others added 4 commits June 25, 2026 08:12
- Restore skill/KG source files to proper generated imports (our stubs
  caused CI typecheck failures when codegen regenerated correct types)
- Extract createApiConfiguration helper to src/rest/api-config.ts so
  monitor REST wrappers can use MonitorApi directly without pulling in
  ObserveRestSDK (which imports SkillsApi/V2KnowledgeGraphApi absent
  from the local dev spec)
- Fix MonitorV2RuleKind enum values in create/update commands (string
  literals → enum constants)
- Fix MonitorV2CronSchedule.interval reference in view (field is
  cronConfig in current schema)
- Fix test Parameters<fn>[N] indices (off-by-one: commands with a
  positional arg use [2] not [3]; commands without use [1] not [2])
- Add noUncheckedIndexedAccess-safe ! assertions on mock.calls[0]
- Add required outputStage field to MultiStageQuery test fixtures

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Comment thread src/commands/monitor/create.ts Outdated
Comment thread src/commands/monitor/list.ts Outdated
Comment thread src/commands/monitor/list.ts
Comment thread src/commands/monitor/view.ts
Comment thread src/commands/monitor/index.ts Outdated
Comment thread src/commands/monitor/create.ts Outdated
Comment thread src/commands/monitor/enable.ts Outdated
Comment thread src/commands/monitor/view.ts Outdated
Comment thread src/commands/monitor/list.ts
Comment thread src/commands/monitor/delete.ts Outdated
Comment thread src/commands/monitor/create.ts Outdated
Joe Darling and others added 3 commits June 26, 2026 19:13
- delete: require --force flag to prevent accidental deletions
- create: add fullDescription with MonitorV2Definition schema link and
  minimal JSON example in help text
- list: add client-side pagination (--limit, --offset) with default
  limit of 100, consistent with alert list and metric list

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Rename --rule-kind → --kind in create and update for consistency with list
- Extract shared ruleKindColor to monitor-utils.ts; fix Count color blue → green
- Add --definition inline JSON flag to create and update (mutex with --definition-file)
- Show definition section in monitor view human-readable output
- Update index.ts brief: "View" → "Manage observe monitors"

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@obs-gh-abhinavpappu obs-gh-abhinavpappu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Would you mind also updating this PR to use the newly added experimental option (#14). Gives us some flexibility to change the schema after merging this in for a short while before we make it fixed.

Essentially just switch to defineCommand instead of buildCommand and add experimental: true to each of the commands. Also use defineRoutes instead of buildRouteMap.

Comment thread src/commands/monitor/delete.ts Outdated
Comment thread src/commands/monitor/view.ts
@obs-gh-joedarling obs-gh-joedarling force-pushed the joedarling/monitor_cli branch 2 times, most recently from 94abeeb to 151f9f6 Compare June 29, 2026 22:40
… round 3

- Merge origin/main: adds defineCommand/defineRoutes wrappers and
  OBSERVE_CLI_EXPERIMENTAL gating (PR #14)
- Convert all monitor commands to defineCommand({ experimental: true })
  and monitorRoutes to defineRoutes
- Replace --force with --yes on delete; add interactive readline
  confirmation prompt when stdin is a TTY
- Strip layout fields from monitor view human-readable output
- Update delete tests: force → yes, add confirmFn injection tests

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Comment thread src/rest/api-config.ts
Joe Darling and others added 4 commits June 29, 2026 23:36
- Refactor all monitor rest helpers to use ObserveRestSDK instead of
  directly instantiating MonitorApi with createApiConfiguration, matching
  the pattern used by all other rest files
- Add --file flag to monitor update supporting the edit flow:
    observe monitor view <id> --json > monitor.json
    # edit monitor.json
    observe monitor update <id> --file monitor.json
  --file is mutually exclusive with all other update flags

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Remove unnecessary optional chain and fix conditional operator
to satisfy @typescript-eslint/no-unnecessary-condition.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@obs-gh-abhinavpappu obs-gh-abhinavpappu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Vikram actually suggested keeping it simple initially with just a single --file flag similar to the other CLIs, and then we can add the other top-level flags later as an alternative option if desired. And for consistency, we should probably have --file on create as well instead of the current flags.

Comment thread src/commands/monitor/update.ts Outdated
Remove individual field flags (--name, --kind, --definition, etc.) from
both create and update in favour of a single --file flag, matching the
pattern used by other CLIs. Also fix update to use !== undefined instead
of != null when building the patch, preserving explicit null values per
JSON merge-patch semantics.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

observe monitor view <id> --json # full monitor definition

observe monitor create --name "My Monitor" \

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

update this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants