### Install yaml.v3 Package Source: https://github.com/chronosphereio/chronoctl-core/blob/main/src/thirdparty/yaml/README.md Use 'go get' to install the yaml.v3 package for use in your Go projects. ```bash go get gopkg.in/yaml.v3 ``` -------------------------------- ### Example Notifier Configurations Source: https://context7.com/chronosphereio/chronoctl-core/llms.txt YAML examples for configuring Slack, PagerDuty, and Webhook notifiers. Ensure API URLs and credentials are set correctly. ```yaml # Example Slack notifier api_version: v1/config kind: Notifier spec: slug: slack-alerts name: Slack Alerts Channel slack: api_url: https://hooks.slack.com/services/T00000/B00000/XXXXXXXX channel: "#alerts" username: Chronosphere title: "{{ .Status }}: {{ .CommonAnnotations.summary }}" text: | {{ range .Alerts }} *Alert:* {{ .Annotations.summary }} *Description:* {{ .Annotations.description }} *Severity:* {{ .Labels.severity }} {{ end }} --- ``` ```yaml # Example PagerDuty notifier api_version: v1/config kind: Notifier spec: slug: pagerduty-oncall name: PagerDuty On-Call pagerduty: routing_key: your-pagerduty-integration-key severity: "{{ .CommonLabels.severity }}" description: "{{ .CommonAnnotations.summary }}" --- ``` ```yaml # Example Webhook notifier api_version: v1/config kind: Notifier spec: slug: custom-webhook name: Custom Webhook webhook: url: https://api.example.com/alerts http_config: basic_auth: username: alertuser password: secretpassword ``` -------------------------------- ### Team Configuration Example Source: https://context7.com/chronosphereio/chronoctl-core/llms.txt Example YAML configuration for a Team. This defines a team with a slug and name. ```yaml api_version: v1/config kind: Team spec: slug: platform-team name: Platform Engineering ``` -------------------------------- ### Resource Pool Configuration Example Source: https://context7.com/chronosphereio/chronoctl-core/llms.txt Example YAML configuration for a ResourcePool. This defines a pool named 'Production Resource Pool' with specific allocation percentages and priority thresholds. ```yaml api_version: v1/config kind: ResourcePool spec: slug: production-pool name: Production Resource Pool pool: allocation: percent_of_license: 60 priority_thresholds: - priority: 1 threshold_percent: 80 ``` -------------------------------- ### Service Account Configuration Example Source: https://context7.com/chronosphereio/chronoctl-core/llms.txt Example YAML configuration for a ServiceAccount. This defines a service account with a slug and name. ```yaml api_version: v1/config kind: ServiceAccount spec: slug: ci-pipeline name: CI/CD Pipeline Service Account ``` -------------------------------- ### Recording Rule Configuration Example Source: https://context7.com/chronosphereio/chronoctl-core/llms.txt Example YAML configuration for a RecordingRule. This defines a rule to calculate API error rates over a 5-minute interval. ```yaml api_version: v1/config kind: RecordingRule spec: slug: api-error-rate name: API Error Rate metric_name: api:error_rate:5m prometheus_expr: | sum(rate(http_requests_total{status=~"5.."}[5m])) by (service) / sum(rate(http_requests_total[5m])) by (service) interval_secs: 60 execution_group: default label_policy: add: aggregation: 5m ``` -------------------------------- ### Example Collection Configuration Source: https://context7.com/chronosphereio/chronoctl-core/llms.txt A YAML configuration for a collection, specifying its slug, name, and associated team. ```yaml # Example collection.yml api_version: v1/config kind: Collection spec: slug: infrastructure name: Infrastructure Monitoring team_slug: platform-team ``` -------------------------------- ### Create Drop Rule Configuration Source: https://context7.com/chronosphereio/chronoctl-core/llms.txt Example YAML configuration for a DropRule. Use this to define metrics that should be dropped based on specified filters. ```yaml api_version: v1/config kind: DropRule spec: slug: debug-metrics name: Drop Debug Metrics filters: - __name__=~"debug_.*" - environment="development" ``` -------------------------------- ### Example Notification Policy Configuration Source: https://context7.com/chronosphereio/chronoctl-core/llms.txt A YAML configuration for a notification policy, including default routes and overrides based on alert labels. ```yaml # Example notification-policy.yml api_version: v1/config kind: NotificationPolicy spec: slug: default name: Default Notification Policy routes: defaults: critical: notifier_slugs: - pagerduty-oncall - slack-alerts repeat_interval_secs: 3600 warn: notifier_slugs: - slack-alerts repeat_interval_secs: 14400 overrides: - alert_label_matchers: - name: team type: EXACT value: platform notifiers: critical: Notifier_slugs: - platform-pagerduty warn: notifier_slugs: - platform-slack - alert_label_matchers: - name: environment type: REGEX value: "staging|dev" notifiers: critical: notifier_slugs: - slack-non-prod warn: notifier_slugs: - slack-non-prod ``` -------------------------------- ### Muting Rule Configuration Example Source: https://context7.com/chronosphereio/chronoctl-core/llms.txt Example YAML configuration for a MutingRule. This rule suppresses alerts for the 'staging' environment during a specified maintenance window. ```yaml api_version: v1/config kind: MutingRule spec: slug: scheduled-maintenance name: Scheduled Maintenance Window label_matchers: - name: environment type: EXACT value: staging starts_at: "2024-01-15T00:00:00Z" ends_at: "2024-01-15T06:00:00Z" comment: Scheduled database maintenance ``` -------------------------------- ### Example Rollup Rule Configuration Source: https://context7.com/chronosphereio/chronoctl-core/llms.txt A YAML configuration for a rollup rule, defining aggregation, metric type, interval, and labels to keep. ```yaml # Example rollup-rule.yml api_version: v1/config kind: RollupRule spec: slug: http-requests-rollup name: HTTP Requests Rollup filter: __name__="http_requests_total" aggregation: SUM metric_type: COUNTER interval: 1m new_metric: http_requests_total:1m label_policy: keep: - service - method - status_code ``` -------------------------------- ### Generate Recording Rule Scaffold Source: https://context7.com/chronosphereio/chronoctl-core/llms.txt Generates a scaffold YAML file for a recording rule, which can be used as a starting point for creating new rules. ```bash chronoctl recording-rules scaffold ``` -------------------------------- ### Apply Multiple Resources Source: https://context7.com/chronosphereio/chronoctl-core/llms.txt Manage resource lifecycle using batch operations from configuration files. ```bash # Apply resources from a YAML file chronoctl apply -f resources.yml # Dry run to validate resources without applying chronoctl apply -f resources.yml -d # Apply resources from stdin cat resources.yml | chronoctl apply -f - ``` ```yaml # Example resources.yml with multiple resources api_version: v1/config kind: Monitor spec: slug: high-cpu-usage name: High CPU Usage Alert collection_slug: infrastructure prometheus_query: avg(cpu_usage) by (host) > 80 series_conditions: defaults: critical: conditions: - op: GT value: 90 sustain_secs: 300 warn: conditions: - op: GT value: 80 sustain_secs: 300 --- api_version: v1/config kind: NotificationPolicy spec: slug: default name: Default routes: defaults: critical: notifier_slugs: - pagerduty-oncall warn: notifier_slugs: - slack-alerts ``` -------------------------------- ### List Teams Source: https://context7.com/chronosphereio/chronoctl-core/llms.txt Lists all configured teams. ```bash chronoctl teams list ``` -------------------------------- ### List Resource Pools Source: https://context7.com/chronosphereio/chronoctl-core/llms.txt Lists all configured resource pools. ```bash chronoctl resource-pools list ``` -------------------------------- ### List Recording Rules Source: https://context7.com/chronosphereio/chronoctl-core/llms.txt Lists all configured recording rules. ```bash chronoctl recording-rules list ``` -------------------------------- ### List Service Accounts Source: https://context7.com/chronosphereio/chronoctl-core/llms.txt Lists all configured service accounts. ```bash chronoctl service-accounts list ``` -------------------------------- ### Read Team Source: https://context7.com/chronosphereio/chronoctl-core/llms.txt Reads the configuration of a specific team by its slug. Replace 'platform-team' with the actual slug. ```bash chronoctl teams read platform-team ``` -------------------------------- ### List Metric Usages by Label Name Source: https://context7.com/chronosphereio/chronoctl-core/llms.txt Queries the current state of the system to list metric usages, grouped by label name. ```bash chronoctl metric-usages-by-label-name list ``` -------------------------------- ### Create, Read, List, and Delete Notifiers Source: https://context7.com/chronosphereio/chronoctl-core/llms.txt Use these commands to manage notification channels. Configuration is typically done via YAML files. ```bash # Create a notifier chronoctl notifiers create -f notifier.yml ``` ```bash # Read a notifier chronoctl notifiers read slack-alerts ``` ```bash # List all notifiers chronoctl notifiers list ``` ```bash # Delete a notifier chronoctl notifiers delete old-webhook ``` -------------------------------- ### List Metric Usages by Metric Name Source: https://context7.com/chronosphereio/chronoctl-core/llms.txt Queries the current state of the system to list metric usages, grouped by metric name. ```bash chronoctl metric-usages-by-metric-name list ``` -------------------------------- ### Manage Collections Source: https://context7.com/chronosphereio/chronoctl-core/llms.txt Commands for creating, listing, reading, and deleting collections. Collections help organize monitors and dashboards. ```bash # Create a collection chronoctl collections create -f collection.yml ``` ```bash # List collections chronoctl collections list ``` ```bash # Read collection chronoctl collections read infrastructure ``` ```bash # Delete collection chronoctl collections delete old-collection ``` -------------------------------- ### Create Service Account Source: https://context7.com/chronosphereio/chronoctl-core/llms.txt Use this command to create a new service account from a YAML file. Service accounts manage programmatic API access. ```bash chronoctl service-accounts create -f service-account.yml ``` -------------------------------- ### Configure Authentication via Environment Variables Source: https://context7.com/chronosphereio/chronoctl-core/llms.txt Set environment variables for non-interactive authentication in CI/CD pipelines. ```bash # Set API token for authentication (required if not using browser login) export CHRONOSPHERE_API_TOKEN="your-api-token-here" # Set organization name (optional if using default org) export CHRONOSPHERE_ORG_NAME="mycompany" # Set entity namespace for multi-tenant environments (optional) export CHRONOSPHERE_ENTITY_NAMESPACE="production" # Set actor name for audit logging in Version History (optional) export CHRONOSPHERE_ACTOR="ci-pipeline" ``` -------------------------------- ### Create Recording Rule Source: https://context7.com/chronosphereio/chronoctl-core/llms.txt Use this command to create a new recording rule from a YAML file. Recording rules precompute expensive PromQL queries as new time series. ```bash chronoctl recording-rules create -f recording-rule.yml ``` -------------------------------- ### Create Team Source: https://context7.com/chronosphereio/chronoctl-core/llms.txt Use this command to create a new team from a YAML file. Teams are used for organizing resources and permissions. ```bash chronoctl teams create -f team.yml ``` -------------------------------- ### Authenticate with Chronoctl Source: https://context7.com/chronosphereio/chronoctl-core/llms.txt Manage session credentials and organization settings using browser-based login. ```bash # Login to your Chronosphere organization chronoctl auth login --org-name mycompany # Set a default organization for all future commands chronoctl auth set-default-org mycompany # List all authenticated organizations chronoctl auth list # Check currently authenticated user chronoctl auth whoami # Logout from the session chronoctl auth logout ``` -------------------------------- ### Set Output Format to YAML Source: https://context7.com/chronosphereio/chronoctl-core/llms.txt Configures the command output to be in YAML format. This is the default format. ```bash chronoctl monitors list -o yaml ``` -------------------------------- ### Create Resource Pool Source: https://context7.com/chronosphereio/chronoctl-core/llms.txt Use this command to create a new resource pool from a YAML file. Resource pools manage capacity allocation and quota management. ```bash chronoctl resource-pools create -f pool.yml ``` -------------------------------- ### Manage Dashboards Source: https://context7.com/chronosphereio/chronoctl-core/llms.txt Commands for creating, reading, listing, updating, and deleting dashboards. Dashboards visualize metrics and monitoring data. ```bash # Create dashboard chronoctl dashboards create -f dashboard.yml ``` ```bash # Read dashboard by slug chronoctl dashboards read my-service-dashboard ``` ```bash # List all dashboards chronoctl dashboards list --collection-slugs my-collection ``` ```bash # Update dashboard chronoctl dashboards update -f dashboard.yml ``` ```bash # Delete dashboard chronoctl dashboards delete old-dashboard ``` ```bash # Generate scaffold chronoctl dashboards scaffold ``` -------------------------------- ### Manage Notification Policies Source: https://context7.com/chronosphereio/chronoctl-core/llms.txt Commands for creating, reading, listing, and scaffolding notification policies. Policies define how alerts are routed to notifiers. ```bash # Create notification policy chronoctl notification-policies create -f policy.yml ``` ```bash # Read policy chronoctl notification-policies read default ``` ```bash # List policies chronoctl notification-policies list ``` ```bash # Generate scaffold chronoctl notification-policies scaffold ``` -------------------------------- ### List All Rule Evaluations Source: https://context7.com/chronosphereio/chronoctl-core/llms.txt Queries the current state of the system to list all rule evaluations. ```bash chronoctl rule-evaluations list ``` -------------------------------- ### Manage Monitors via CRUD Operations Source: https://context7.com/chronosphereio/chronoctl-core/llms.txt Perform CRUD operations on monitors and generate scaffold configurations. ```bash # Create a monitor from file chronoctl monitors create -f monitor.yml # Read a monitor by slug chronoctl monitors read high-cpu-usage # Update an existing monitor chronoctl monitors update -f monitor.yml # Update or create if missing chronoctl monitors update -f monitor.yml --create-if-missing # Delete a monitor by slug chronoctl monitors delete high-cpu-usage # List all monitors chronoctl monitors list # List monitors with filters chronoctl monitors list --collection-slugs infrastructure --team-slugs platform # List with pagination chronoctl monitors list --limit 50 --page-max-size 25 # Output in JSON format chronoctl monitors list -o json # Generate scaffold YAML with all fields chronoctl monitors scaffold ``` ```yaml # Example monitor.yml api_version: v1/config kind: Monitor spec: slug: high-memory-usage name: High Memory Usage collection_slug: infrastructure labels: service: backend environment: production annotations: runbook: https://wiki.example.com/runbooks/memory description: "Memory usage exceeded threshold on {{ $labels.host }}" prometheus_query: | (node_memory_MemTotal_bytes - node_memory_MemAvailable_bytes) / node_memory_MemTotal_bytes * 100 interval_secs: 60 notification_policy_slug: default signal_grouping: label_names: - host - environment series_conditions: defaults: critical: conditions: - op: GEQ value: 95 sustain_secs: 300 resolve_sustain_secs: 60 warn: conditions: - op: GEQ value: 85 sustain_secs: 300 ``` -------------------------------- ### Output to Directory with File Per Object Source: https://context7.com/chronosphereio/chronoctl-core/llms.txt Exports command output to a specified directory, creating a separate file for each object. The `--create-file-per-object` flag ensures this behavior. ```bash chronoctl monitors list --output-dir ./exported-monitors --create-file-per-object ``` -------------------------------- ### List Muting Rules Source: https://context7.com/chronosphereio/chronoctl-core/llms.txt Lists all configured muting rules. ```bash chronoctl muting-rules list ``` -------------------------------- ### Manage Drop Rules Source: https://context7.com/chronosphereio/chronoctl-core/llms.txt Commands for creating, listing, and deleting drop rules. These rules drop unwanted metrics before storage. ```bash # Create drop rule chronoctl drop-rules create -f drop-rule.yml ``` ```bash # List drop rules chronoctl drop-rules list ``` ```bash # Delete drop rule chronoctl drop-rules delete debug-metrics ``` -------------------------------- ### Unmarshal and Marshal YAML Data in Go Source: https://github.com/chronosphereio/chronoctl-core/blob/main/src/thirdparty/yaml/README.md Demonstrates how to unmarshal YAML data into a Go struct and a map, and then marshal them back into YAML format. Ensure struct fields are public for correct unmarshaling. The 'yaml:"c"' tag renames a field during marshaling/unmarshaling, and 'yaml:",flow"' formats a slice in flow style. ```Go package main import ( "fmt" "log" "gopkg.in/yaml.v3" ) var data = ` a: Easy! b: c: 2 d: [3, 4] ` // Note: struct fields must be public in order for unmarshal to // correctly populate the data. type T struct { A string B struct { RenamedC int `yaml:"c"` D []int `yaml:",flow"` } } func main() { t := T{} err := yaml.Unmarshal([]byte(data), &t) if err != nil { log.Fatalf("error: %v", err) } fmt.Printf("--- t:\n%v\n\n", t) d, err := yaml.Marshal(&t) if err != nil { log.Fatalf("error: %v", err) } fmt.Printf("--- t dump:\n%s\n\n", string(d)) m := make(map[interface{}]interface{}) err = yaml.Unmarshal([]byte(data), &m) if err != nil { log.Fatalf("error: %v", err) } fmt.Printf("--- m:\n%v\n\n", m) d, err = yaml.Marshal(&m) if err != nil { log.Fatalf("error: %v", err) } fmt.Printf("--- m dump:\n%s\n\n", string(d)) } ``` -------------------------------- ### Manage Rollup Rules Source: https://context7.com/chronosphereio/chronoctl-core/llms.txt Commands for creating, listing, reading, and scaffolding rollup rules. These rules aggregate metrics to reduce cardinality and storage costs. ```bash # Create rollup rule chronoctl rollup-rules create -f rollup.yml ``` ```bash # List rollup rules chronoctl rollup-rules list ``` ```bash # Read specific rule chronoctl rollup-rules read http-requests-rollup ``` ```bash # Generate scaffold chronoctl rollup-rules scaffold ``` -------------------------------- ### Convert Prometheus and Alertmanager configurations to Chronosphere entities Source: https://context7.com/chronosphereio/chronoctl-core/llms.txt Uses the converter package to transform YAML configurations into Chronosphere monitors, receivers, and notification policies. Requires the converter package import and valid YAML input strings. ```go import "github.com/chronosphereio/chronoctl-core/src/cmd/pkg/converter" // Convert Prometheus rules and Alertmanager config to Chronosphere entities opts := converter.Opts{ MonitorSignalPerSeries: false, SeverityLabelName: "severity", InferMonitorSignals: true, AddGroupByToNotificationPolicies: false, } result, warnings, err := converter.ConvertPrometheus( rulesYAML, // Prometheus alerting rules YAML alertManagerYAML, // Alertmanager configuration YAML opts, ) if err != nil { log.Fatalf("Conversion failed: %v", err) } // Access converted entities for _, monitor := range result.Monitors { fmt.Printf("Converted monitor: %s\n", monitor.Name) } for _, receiver := range result.Receivers { fmt.Printf("Converted notifier: %s\n", receiver.Name) } if result.NotificationPolicy != nil { fmt.Printf("Generated notification policy: %s\n", result.NotificationPolicy.Slug) } ``` -------------------------------- ### Read Resource Pool Source: https://context7.com/chronosphereio/chronoctl-core/llms.txt Reads the configuration of a specific resource pool by its slug. Replace 'default-pool' with the actual slug. ```bash chronoctl resource-pools read default-pool ``` -------------------------------- ### Set Output Format to Table Source: https://context7.com/chronosphereio/chronoctl-core/llms.txt Configures the command output to be in a table format, where supported by the specific command. ```bash chronoctl monitors list -o table ``` -------------------------------- ### Set Output Format to JSON Source: https://context7.com/chronosphereio/chronoctl-core/llms.txt Configures the command output to be in JSON format, specifically as an array. ```bash chronoctl monitors list -o json ``` -------------------------------- ### Set Output Format to JSON Lines Source: https://context7.com/chronosphereio/chronoctl-core/llms.txt Configures the command output to be in JSON Lines format, where each line is a valid JSON object. ```bash chronoctl monitors list -o jsonl ``` -------------------------------- ### Dry Run Monitor Creation Source: https://context7.com/chronosphereio/chronoctl-core/llms.txt Validates that a monitor can be created without actually applying the changes. Use the `-d` or `--dry-run` flag for validation. ```bash chronoctl monitors create -f monitor.yml -d ``` -------------------------------- ### Create Muting Rule Source: https://context7.com/chronosphereio/chronoctl-core/llms.txt Use this command to create a new muting rule from a YAML file. Muting rules suppress alerts during maintenance windows or known outages. ```bash chronoctl muting-rules create -f muting-rule.yml ``` -------------------------------- ### Dry Run Apply Multiple Resources Source: https://context7.com/chronosphereio/chronoctl-core/llms.txt Validates multiple resources defined in a YAML file without applying any changes. Use the `--dry-run` flag for validation. ```bash chronoctl apply -f resources.yml --dry-run ``` -------------------------------- ### Delete Service Account Source: https://context7.com/chronosphereio/chronoctl-core/llms.txt Deletes a service account by its slug. Replace 'ci-pipeline' with the actual slug. ```bash chronoctl service-accounts delete ci-pipeline ``` -------------------------------- ### Add JSON struct tag support Source: https://github.com/chronosphereio/chronoctl-core/blob/main/src/thirdparty/yaml/FORK.md This patch enables the library to respect json struct tags when yaml tags are missing. ```text 548a548,550 > if tag == "" { > tag = field.Tag.Get("json") > } ``` -------------------------------- ### Dry Run Monitor Update Source: https://context7.com/chronosphereio/chronoctl-core/llms.txt Validates that a monitor can be updated without actually applying the changes. Use the `-d` or `--dry-run` flag for validation. ```bash chronoctl monitors update -f monitor.yml -d ``` -------------------------------- ### Delete Muting Rule Source: https://context7.com/chronosphereio/chronoctl-core/llms.txt Deletes a muting rule by its slug. Replace 'maintenance-window' with the actual slug of the rule to delete. ```bash chronoctl muting-rules delete maintenance-window ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.