Skip to content

Commit

Permalink
Merge branch 'main' into ops
Browse files Browse the repository at this point in the history
  • Loading branch information
ezhil56x authored Jan 23, 2025
2 parents 7a65666 + 7aafdf1 commit 907f896
Show file tree
Hide file tree
Showing 6 changed files with 434 additions and 322 deletions.
36 changes: 36 additions & 0 deletions examples/workflows/create_alert_from_vm_metric.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
workflow:
id: query-victoriametrics
name: victoriametrics-alert-example
description: victoriametrics
triggers:
- type: manual
steps:
- name: victoriametrics-step
provider:
config: "{{ providers.vm }}"
type: victoriametrics
with:
query: avg(rate(process_cpu_seconds_total))
queryType: query

actions:
- name: create-alert
alias:
# assign the value of the query result to the alias `cpu`
# so we can use it anywhere in the action
cpu: "{{ steps.victoriametrics-step.results.data.result.0.value.1 }}"
# only create an alert if the CPU usage is greater than 0.005
if: "{{ aliases.cpu }} > 0.005 "
provider:
type: keep
# create an alert with the following details
with:
name: "High CPU Usage"
description: "CPU usage is high on the VM (created from VM metric)"
severity: '{{ aliases.cpu }} > 0.9 ? "critical" : {{ aliases.cpu }} > 0.7 ? "warning" : "info"'
labels:
environment: production
app: myapp
service: api
team: devops
owner: alice
7 changes: 6 additions & 1 deletion keep/contextmanager/contextmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def __init__(
}
self.consts_context = {}
self.current_step_vars = {}
self.current_step_aliases = {}
# cli context
try:
self.click_context = click.get_current_context()
Expand Down Expand Up @@ -162,6 +163,7 @@ def get_full_context(self, exclude_providers=False, exclude_env=False):
"incident": self.incident_context, # this is an alias so workflows will be able to use alert.source
"consts": self.consts_context,
"vars": self.current_step_vars,
"aliases": self.current_step_aliases,
}

if not exclude_providers:
Expand Down Expand Up @@ -248,16 +250,19 @@ def set_step_context(self, step_id, results, foreach=False):
self.steps_context["this"] = self.steps_context[step_id]
self.steps_context_size = asizeof(self.steps_context)

def set_step_vars(self, step_id, _vars):
def set_step_vars(self, step_id, _vars, _aliases):
if step_id not in self.steps_context:
self.steps_context[step_id] = {
"provider_parameters": {},
"results": [],
"vars": {},
"aliases": {},
}

self.current_step_vars = _vars
self.current_step_aliases = _aliases
self.steps_context[step_id]["vars"] = _vars
self.steps_context[step_id]["aliases"] = _aliases

def get_last_workflow_run(self, workflow_id):
return get_last_workflow_execution_by_workflow_id(self.tenant_id, workflow_id)
Expand Down
Loading

0 comments on commit 907f896

Please sign in to comment.