diff --git a/executor/playbook_result_conditional_evaluators/global_variable_evaluators/__init__.py b/executor/playbook_result_conditional_evaluators/global_variable_evaluators/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/executor/playbook_result_conditional_evaluators/global_variable_evaluators/compare_global_variable_evaluator.py b/executor/playbook_result_conditional_evaluators/global_variable_evaluators/compare_global_variable_evaluator.py new file mode 100644 index 000000000..55a9d1f53 --- /dev/null +++ b/executor/playbook_result_conditional_evaluators/global_variable_evaluators/compare_global_variable_evaluator.py @@ -0,0 +1,57 @@ +from executor.playbook_result_conditional_evaluators.global_variable_evaluators.global_variable_evaluator import \ + GlobalVariableEvaluator +from protos.base_pb2 import Operator +from protos.playbooks.playbook_pb2 import PlaybookTaskExecutionLog +from protos.playbooks.playbook_global_variable_evaluator_pb2 import GlobalVariableResultRule, CompareGlobalVariable +from utils.proto_utils import proto_to_dict +from utils.dict_utils import get_nested_value + +class CompareGlobalVariableEvaluator(GlobalVariableEvaluator): + + def evaluate(self, rule: GlobalVariableResultRule, playbook_task_execution_log: [PlaybookTaskExecutionLog]) -> bool: + if rule.type != GlobalVariableResultRule.Type.COMPARE_GLOBAL_VARIABLE: + raise ValueError(f'Rule type {GlobalVariableResultRule.Type.Name(rule.type)} not supported') + + compare_global_variable: CompareGlobalVariable = rule.compare_global_variable + operator = compare_global_variable.operator + variable_name = compare_global_variable.variable_name.value + threshold = compare_global_variable.threshold.value + + global_variable_set = next( + (tr.execution_global_variable_set for tr in playbook_task_execution_log), None) + global_variable_set_dict = proto_to_dict(global_variable_set) if global_variable_set else {} + value = get_nested_value(global_variable_set_dict, variable_name) + + # compare current time with first member of cron schedules + if operator == Operator.EQUAL_O: + return value == threshold + elif operator == Operator.GREATER_THAN_O: + try: + value = int(value) + threshold = int(threshold) + except ValueError: + return False + return value > threshold + elif operator == Operator.GREATER_THAN_EQUAL_O: + try: + value = int(value) + threshold = int(threshold) + except ValueError: + return False + return value >= threshold + elif operator == Operator.LESS_THAN_O: + try: + value = int(value) + threshold = int(threshold) + except ValueError: + return False + return value < threshold + elif operator == Operator.LESS_THAN_EQUAL_O: + try: + value = int(value) + threshold = int(threshold) + except ValueError: + return False + return value <= threshold + else: + raise ValueError(f'Operator {Operator.Name(operator)} not supported') diff --git a/executor/playbook_result_conditional_evaluators/global_variable_evaluators/global_variable_evaluator.py b/executor/playbook_result_conditional_evaluators/global_variable_evaluators/global_variable_evaluator.py new file mode 100644 index 000000000..505699ff1 --- /dev/null +++ b/executor/playbook_result_conditional_evaluators/global_variable_evaluators/global_variable_evaluator.py @@ -0,0 +1,8 @@ +from protos.playbooks.playbook_pb2 import PlaybookTaskExecutionLog +from protos.playbooks.playbook_global_variable_evaluator_pb2 import GlobalVariableResultRule + + +class GlobalVariableEvaluator: + + def evaluate(self, rule: GlobalVariableResultRule, playbook_task_execution_log: [PlaybookTaskExecutionLog]) -> bool: + pass diff --git a/executor/playbook_result_conditional_evaluators/step_condition_evaluator.py b/executor/playbook_result_conditional_evaluators/step_condition_evaluator.py index 82a00b9ac..3a9d57d44 100644 --- a/executor/playbook_result_conditional_evaluators/step_condition_evaluator.py +++ b/executor/playbook_result_conditional_evaluators/step_condition_evaluator.py @@ -12,11 +12,14 @@ TimeseriesResultEvaluator from executor.playbook_result_conditional_evaluators.task_result_evalutors.bash_command_result_evaluator import \ BashCommandOutputResultEvaluator +from executor.playbook_result_conditional_evaluators.global_variable_evaluators.compare_global_variable_evaluator import \ + CompareGlobalVariableEvaluator from protos.base_pb2 import LogicalOperator from protos.playbooks.playbook_commons_pb2 import PlaybookTaskResultType from protos.playbooks.playbook_pb2 import PlaybookStepResultCondition, PlaybookTaskResultRule, \ PlaybookTaskExecutionLog from protos.playbooks.playbook_step_result_evaluator_pb2 import PlaybookStepResultRule +from protos.playbooks.playbook_global_variable_evaluator_pb2 import GlobalVariableResultRule class StepConditionEvaluator: @@ -24,6 +27,7 @@ class StepConditionEvaluator: def __init__(self): self._task_rule_map = {} self._step_rule_map = {} + self._variable_rule_map = {} def register_task_result_evaluator(self, result_type: PlaybookTaskResultType, task_result_evaluator: TaskResultEvaluator): @@ -33,6 +37,10 @@ def register_step_result_evaluator(self, step_rule_type: PlaybookStepResultRule. step_result_evaluator: StepResultEvaluator): self._step_rule_map[step_rule_type] = step_result_evaluator + def register_variable_evaluator(self, variable_rule_type: GlobalVariableResultRule.Type, + variable_evaluator: TaskResultEvaluator): + self._variable_rule_map[variable_rule_type] = variable_evaluator + def evaluate(self, condition: PlaybookStepResultCondition, playbook_task_execution_log: [PlaybookTaskExecutionLog]) -> (bool, Dict): if not condition.rule_sets: @@ -63,6 +71,15 @@ def evaluate(self, condition: PlaybookStepResultCondition, raise ValueError(f"Step result type {PlaybookStepResultRule.Type.Name(sr.type)} not supported") evaluation = step_result_evaluator.evaluate(sr, playbook_task_execution_log) all_evaluations.append(evaluation) + + variable_rules: [PlaybookTaskResultRule] = rs.variable_rules + for vr in variable_rules: + variable_evaluator = self._variable_rule_map.get(vr.type) + if not variable_evaluator: + raise ValueError(f"Task result type {task_result.type} not supported") + evaluation = variable_evaluator.evaluate(vr, playbook_task_execution_log) + all_evaluations.append(evaluation) + logical_operator = rs.logical_operator if logical_operator == LogicalOperator.AND_LO: all_rs_evaluations.append(all(all_evaluations)) @@ -99,3 +116,5 @@ def evaluate(self, condition: PlaybookStepResultCondition, step_condition_evaluator.register_step_result_evaluator(PlaybookStepResultRule.Type.COMPARE_TIME_WITH_CRON, CompareTimeWithCronEvaluator()) +step_condition_evaluator.register_variable_evaluator(GlobalVariableResultRule.Type.COMPARE_GLOBAL_VARIABLE, + CompareGlobalVariableEvaluator()) diff --git a/executor/tasks.py b/executor/tasks.py index eaf7c09df..fde4cf387 100644 --- a/executor/tasks.py +++ b/executor/tasks.py @@ -77,6 +77,10 @@ def execute_playbook_step_impl(tr: TimeRange, account: Account, step: PlaybookSt execution_global_variable_set = Struct() if global_variable_set and global_variable_set.items(): execution_global_variable_set.CopyFrom(global_variable_set) + + task_execution_global_variable_set = Struct() + if global_variable_set and global_variable_set.items(): + task_execution_global_variable_set.CopyFrom(global_variable_set) for task_proto in tasks: if not execution_global_variable_set or not execution_global_variable_set.items(): if task_proto.global_variable_set and task_proto.global_variable_set.items(): @@ -123,9 +127,9 @@ def execute_playbook_step_impl(tr: TimeRange, account: Account, step: PlaybookSt continue for bev in bulk_execution_var_values: if is_bulk_execution and bulk_task_var: - execution_global_variable_set[bulk_task_var] = bev + task_execution_global_variable_set[bulk_task_var] = bev try: - task_result = playbook_source_facade.execute_task(account.id, tr, execution_global_variable_set, + task_result = playbook_source_facade.execute_task(account.id, tr, task_execution_global_variable_set, task_proto) task_interpretation: InterpretationProto = task_result_interpret(interpreter_type, task_proto, task_result) diff --git a/protos/playbooks/playbook.proto b/protos/playbooks/playbook.proto index 11e43188b..c3ac1408c 100644 --- a/protos/playbooks/playbook.proto +++ b/protos/playbooks/playbook.proto @@ -9,6 +9,7 @@ import "protos/playbooks/intelligence_layer/interpreter.proto"; import "protos/playbooks/playbook_task_result_evaluator.proto"; import "protos/playbooks/playbook_step_result_evaluator.proto"; +import "protos/playbooks/playbook_global_variable_evaluator.proto"; import "protos/playbooks/source_task_definitions/cloudwatch_task.proto"; import "protos/playbooks/source_task_definitions/grafana_task.proto"; @@ -118,6 +119,7 @@ message PlaybookStepResultCondition { LogicalOperator logical_operator = 1; repeated PlaybookTaskResultRule rules = 2; repeated PlaybookStepResultRule step_rules = 3; + repeated GlobalVariableResultRule variable_rules = 4; } LogicalOperator logical_operator = 1; repeated RuleSet rule_sets = 2; diff --git a/protos/playbooks/playbook_commons.proto b/protos/playbooks/playbook_commons.proto index 501877b75..2a0dc4109 100644 --- a/protos/playbooks/playbook_commons.proto +++ b/protos/playbooks/playbook_commons.proto @@ -22,6 +22,7 @@ enum PlaybookTaskResultType { BASH_COMMAND_OUTPUT = 4; TEXT = 5; LOGS = 6; + GLOBAL_VARIABLE = 7; } message ExternalLink { diff --git a/protos/playbooks/playbook_commons_pb2.py b/protos/playbooks/playbook_commons_pb2.py index ca57d0bc9..f429d2f96 100644 --- a/protos/playbooks/playbook_commons_pb2.py +++ b/protos/playbooks/playbook_commons_pb2.py @@ -17,7 +17,7 @@ from google.protobuf import struct_pb2 as google_dot_protobuf_dot_struct__pb2 -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\'protos/playbooks/playbook_commons.proto\x12\x10protos.playbooks\x1a\x11protos/base.proto\x1a\x1aprotos/ui_definition.proto\x1a\x1egoogle/protobuf/wrappers.proto\x1a\x1cgoogle/protobuf/struct.proto\"e\n\x0c\x45xternalLink\x12*\n\x04name\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12)\n\x03url\x18\x02 \x01(\x0b\x32\x1c.google.protobuf.StringValue\"i\n\x0eLabelValuePair\x12*\n\x04name\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12+\n\x05value\x18\x02 \x01(\x0b\x32\x1c.google.protobuf.StringValue\"\x8b\x04\n\x10TimeseriesResult\x12\x31\n\x0bmetric_name\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12\x37\n\x11metric_expression\x18\x02 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12]\n\x19labeled_metric_timeseries\x18\x03 \x03(\x0b\x32:.protos.playbooks.TimeseriesResult.LabeledMetricTimeseries\x1a\xab\x02\n\x17LabeledMetricTimeseries\x12=\n\x13metric_label_values\x18\x01 \x03(\x0b\x32 .protos.playbooks.LabelValuePair\x12*\n\x04unit\x18\x02 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12X\n\ndatapoints\x18\x03 \x03(\x0b\x32\x44.protos.playbooks.TimeseriesResult.LabeledMetricTimeseries.Datapoint\x1aK\n\tDatapoint\x12\x11\n\ttimestamp\x18\x01 \x01(\x10\x12+\n\x05value\x18\x02 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\"\xdf\x03\n\x0bTableResult\x12/\n\traw_query\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12\x31\n\x0btotal_count\x18\x02 \x01(\x0b\x32\x1c.google.protobuf.UInt64Value\x12+\n\x05limit\x18\x03 \x01(\x0b\x32\x1c.google.protobuf.UInt64Value\x12,\n\x06offset\x18\x04 \x01(\x0b\x32\x1c.google.protobuf.UInt64Value\x12\x34\n\x04rows\x18\x05 \x03(\x0b\x32&.protos.playbooks.TableResult.TableRow\x1a\x92\x01\n\x0bTableColumn\x12*\n\x04name\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12*\n\x04type\x18\x02 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12+\n\x05value\x18\x03 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x1a\x46\n\x08TableRow\x12:\n\x07\x63olumns\x18\x01 \x03(\x0b\x32).protos.playbooks.TableResult.TableColumn\"\xe9\x02\n\x11\x41piResponseResult\x12\x34\n\x0erequest_method\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12\x31\n\x0brequest_url\x18\x02 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12\x35\n\x0fresponse_status\x18\x03 \x01(\x0b\x32\x1c.google.protobuf.UInt64Value\x12\x31\n\x10response_headers\x18\x04 \x01(\x0b\x32\x17.google.protobuf.Struct\x12.\n\rresponse_body\x18\x05 \x01(\x0b\x32\x17.google.protobuf.Struct\x12&\n\x05\x65rror\x18\x06 \x01(\x0b\x32\x17.google.protobuf.Struct\x12)\n\x08metadata\x18\x07 \x01(\x0b\x32\x17.google.protobuf.Struct\"\xd9\x01\n\x17\x42\x61shCommandOutputResult\x12P\n\x0f\x63ommand_outputs\x18\x01 \x03(\x0b\x32\x37.protos.playbooks.BashCommandOutputResult.CommandOutput\x1al\n\rCommandOutput\x12-\n\x07\x63ommand\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12,\n\x06output\x18\x02 \x01(\x0b\x32\x1c.google.protobuf.StringValue\":\n\nTextResult\x12,\n\x06output\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.StringValue\"\xfd\x04\n\x12PlaybookTaskResult\x12+\n\x05\x65rror\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12\x36\n\x04type\x18\x02 \x01(\x0e\x32(.protos.playbooks.PlaybookTaskResultType\x12\x1e\n\x06source\x18\x03 \x01(\x0e\x32\x0e.protos.Source\x12\x38\n\x17task_local_variable_set\x18\x04 \x01(\x0b\x32\x17.google.protobuf.Struct\x12P\n/result_transformer_lambda_function_variable_set\x18\x05 \x01(\x0b\x32\x17.google.protobuf.Struct\x12\x38\n\ntimeseries\x18\x65 \x01(\x0b\x32\".protos.playbooks.TimeseriesResultH\x00\x12.\n\x05table\x18\x66 \x01(\x0b\x32\x1d.protos.playbooks.TableResultH\x00\x12;\n\x0c\x61pi_response\x18g \x01(\x0b\x32#.protos.playbooks.ApiResponseResultH\x00\x12H\n\x13\x62\x61sh_command_output\x18h \x01(\x0b\x32).protos.playbooks.BashCommandOutputResultH\x00\x12,\n\x04text\x18i \x01(\x0b\x32\x1c.protos.playbooks.TextResultH\x00\x12-\n\x04logs\x18j \x01(\x0b\x32\x1d.protos.playbooks.TableResultH\x00\x42\x08\n\x06result\"\x87\x07\n\x15PlaybookSourceOptions\x12\x1e\n\x06source\x18\x01 \x01(\x0e\x32\x0e.protos.Source\x12\x32\n\x0c\x64isplay_name\x18\x02 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12[\n\x1bsupported_task_type_options\x18\x03 \x03(\x0b\x32\x36.protos.playbooks.PlaybookSourceOptions.TaskTypeOption\x12R\n\x11\x63onnector_options\x18\x04 \x03(\x0b\x32\x37.protos.playbooks.PlaybookSourceOptions.ConnectorOption\x1ay\n\x0f\x43onnectorOption\x12\x32\n\x0c\x63onnector_id\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.UInt64Value\x12\x32\n\x0c\x64isplay_name\x18\x02 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x1a\xed\x03\n\x0eTaskTypeOption\x12\x32\n\x0c\x64isplay_name\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12/\n\ttask_type\x18\x02 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12.\n\x08\x63\x61tegory\x18\x03 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12h\n\x15supported_model_types\x18\x04 \x03(\x0b\x32I.protos.playbooks.PlaybookSourceOptions.TaskTypeOption.SourceModelTypeMap\x12=\n\x0bresult_type\x18\x05 \x01(\x0e\x32(.protos.playbooks.PlaybookTaskResultType\x12&\n\x0b\x66orm_fields\x18\x06 \x03(\x0b\x32\x11.protos.FormField\x1au\n\x12SourceModelTypeMap\x12+\n\nmodel_type\x18\x01 \x01(\x0e\x32\x17.protos.SourceModelType\x12\x32\n\x0c\x64isplay_name\x18\x02 \x01(\x0b\x32\x1c.google.protobuf.StringValue*e\n\x1bPlaybookExecutionStatusType\x12\x12\n\x0eUNKNOWN_STATUS\x10\x00\x12\x0b\n\x07\x43REATED\x10\x01\x12\x0b\n\x07RUNNING\x10\x02\x12\x0c\n\x08\x46INISHED\x10\x03\x12\n\n\x06\x46\x41ILED\x10\x04*\x7f\n\x16PlaybookTaskResultType\x12\x0b\n\x07UNKNOWN\x10\x00\x12\x0e\n\nTIMESERIES\x10\x01\x12\t\n\x05TABLE\x10\x02\x12\x10\n\x0c\x41PI_RESPONSE\x10\x03\x12\x17\n\x13\x42\x41SH_COMMAND_OUTPUT\x10\x04\x12\x08\n\x04TEXT\x10\x05\x12\x08\n\x04LOGS\x10\x06\x62\x06proto3') +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\'protos/playbooks/playbook_commons.proto\x12\x10protos.playbooks\x1a\x11protos/base.proto\x1a\x1aprotos/ui_definition.proto\x1a\x1egoogle/protobuf/wrappers.proto\x1a\x1cgoogle/protobuf/struct.proto\"e\n\x0c\x45xternalLink\x12*\n\x04name\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12)\n\x03url\x18\x02 \x01(\x0b\x32\x1c.google.protobuf.StringValue\"i\n\x0eLabelValuePair\x12*\n\x04name\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12+\n\x05value\x18\x02 \x01(\x0b\x32\x1c.google.protobuf.StringValue\"\x8b\x04\n\x10TimeseriesResult\x12\x31\n\x0bmetric_name\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12\x37\n\x11metric_expression\x18\x02 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12]\n\x19labeled_metric_timeseries\x18\x03 \x03(\x0b\x32:.protos.playbooks.TimeseriesResult.LabeledMetricTimeseries\x1a\xab\x02\n\x17LabeledMetricTimeseries\x12=\n\x13metric_label_values\x18\x01 \x03(\x0b\x32 .protos.playbooks.LabelValuePair\x12*\n\x04unit\x18\x02 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12X\n\ndatapoints\x18\x03 \x03(\x0b\x32\x44.protos.playbooks.TimeseriesResult.LabeledMetricTimeseries.Datapoint\x1aK\n\tDatapoint\x12\x11\n\ttimestamp\x18\x01 \x01(\x10\x12+\n\x05value\x18\x02 \x01(\x0b\x32\x1c.google.protobuf.DoubleValue\"\xdf\x03\n\x0bTableResult\x12/\n\traw_query\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12\x31\n\x0btotal_count\x18\x02 \x01(\x0b\x32\x1c.google.protobuf.UInt64Value\x12+\n\x05limit\x18\x03 \x01(\x0b\x32\x1c.google.protobuf.UInt64Value\x12,\n\x06offset\x18\x04 \x01(\x0b\x32\x1c.google.protobuf.UInt64Value\x12\x34\n\x04rows\x18\x05 \x03(\x0b\x32&.protos.playbooks.TableResult.TableRow\x1a\x92\x01\n\x0bTableColumn\x12*\n\x04name\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12*\n\x04type\x18\x02 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12+\n\x05value\x18\x03 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x1a\x46\n\x08TableRow\x12:\n\x07\x63olumns\x18\x01 \x03(\x0b\x32).protos.playbooks.TableResult.TableColumn\"\xe9\x02\n\x11\x41piResponseResult\x12\x34\n\x0erequest_method\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12\x31\n\x0brequest_url\x18\x02 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12\x35\n\x0fresponse_status\x18\x03 \x01(\x0b\x32\x1c.google.protobuf.UInt64Value\x12\x31\n\x10response_headers\x18\x04 \x01(\x0b\x32\x17.google.protobuf.Struct\x12.\n\rresponse_body\x18\x05 \x01(\x0b\x32\x17.google.protobuf.Struct\x12&\n\x05\x65rror\x18\x06 \x01(\x0b\x32\x17.google.protobuf.Struct\x12)\n\x08metadata\x18\x07 \x01(\x0b\x32\x17.google.protobuf.Struct\"\xd9\x01\n\x17\x42\x61shCommandOutputResult\x12P\n\x0f\x63ommand_outputs\x18\x01 \x03(\x0b\x32\x37.protos.playbooks.BashCommandOutputResult.CommandOutput\x1al\n\rCommandOutput\x12-\n\x07\x63ommand\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12,\n\x06output\x18\x02 \x01(\x0b\x32\x1c.google.protobuf.StringValue\":\n\nTextResult\x12,\n\x06output\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.StringValue\"\xfd\x04\n\x12PlaybookTaskResult\x12+\n\x05\x65rror\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12\x36\n\x04type\x18\x02 \x01(\x0e\x32(.protos.playbooks.PlaybookTaskResultType\x12\x1e\n\x06source\x18\x03 \x01(\x0e\x32\x0e.protos.Source\x12\x38\n\x17task_local_variable_set\x18\x04 \x01(\x0b\x32\x17.google.protobuf.Struct\x12P\n/result_transformer_lambda_function_variable_set\x18\x05 \x01(\x0b\x32\x17.google.protobuf.Struct\x12\x38\n\ntimeseries\x18\x65 \x01(\x0b\x32\".protos.playbooks.TimeseriesResultH\x00\x12.\n\x05table\x18\x66 \x01(\x0b\x32\x1d.protos.playbooks.TableResultH\x00\x12;\n\x0c\x61pi_response\x18g \x01(\x0b\x32#.protos.playbooks.ApiResponseResultH\x00\x12H\n\x13\x62\x61sh_command_output\x18h \x01(\x0b\x32).protos.playbooks.BashCommandOutputResultH\x00\x12,\n\x04text\x18i \x01(\x0b\x32\x1c.protos.playbooks.TextResultH\x00\x12-\n\x04logs\x18j \x01(\x0b\x32\x1d.protos.playbooks.TableResultH\x00\x42\x08\n\x06result\"\x87\x07\n\x15PlaybookSourceOptions\x12\x1e\n\x06source\x18\x01 \x01(\x0e\x32\x0e.protos.Source\x12\x32\n\x0c\x64isplay_name\x18\x02 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12[\n\x1bsupported_task_type_options\x18\x03 \x03(\x0b\x32\x36.protos.playbooks.PlaybookSourceOptions.TaskTypeOption\x12R\n\x11\x63onnector_options\x18\x04 \x03(\x0b\x32\x37.protos.playbooks.PlaybookSourceOptions.ConnectorOption\x1ay\n\x0f\x43onnectorOption\x12\x32\n\x0c\x63onnector_id\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.UInt64Value\x12\x32\n\x0c\x64isplay_name\x18\x02 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x1a\xed\x03\n\x0eTaskTypeOption\x12\x32\n\x0c\x64isplay_name\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12/\n\ttask_type\x18\x02 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12.\n\x08\x63\x61tegory\x18\x03 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12h\n\x15supported_model_types\x18\x04 \x03(\x0b\x32I.protos.playbooks.PlaybookSourceOptions.TaskTypeOption.SourceModelTypeMap\x12=\n\x0bresult_type\x18\x05 \x01(\x0e\x32(.protos.playbooks.PlaybookTaskResultType\x12&\n\x0b\x66orm_fields\x18\x06 \x03(\x0b\x32\x11.protos.FormField\x1au\n\x12SourceModelTypeMap\x12+\n\nmodel_type\x18\x01 \x01(\x0e\x32\x17.protos.SourceModelType\x12\x32\n\x0c\x64isplay_name\x18\x02 \x01(\x0b\x32\x1c.google.protobuf.StringValue*e\n\x1bPlaybookExecutionStatusType\x12\x12\n\x0eUNKNOWN_STATUS\x10\x00\x12\x0b\n\x07\x43REATED\x10\x01\x12\x0b\n\x07RUNNING\x10\x02\x12\x0c\n\x08\x46INISHED\x10\x03\x12\n\n\x06\x46\x41ILED\x10\x04*\x94\x01\n\x16PlaybookTaskResultType\x12\x0b\n\x07UNKNOWN\x10\x00\x12\x0e\n\nTIMESERIES\x10\x01\x12\t\n\x05TABLE\x10\x02\x12\x10\n\x0c\x41PI_RESPONSE\x10\x03\x12\x17\n\x13\x42\x41SH_COMMAND_OUTPUT\x10\x04\x12\x08\n\x04TEXT\x10\x05\x12\x08\n\x04LOGS\x10\x06\x12\x13\n\x0fGLOBAL_VARIABLE\x10\x07\x62\x06proto3') _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals()) _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'protos.playbooks.playbook_commons_pb2', globals()) @@ -26,8 +26,8 @@ DESCRIPTOR._options = None _PLAYBOOKEXECUTIONSTATUSTYPE._serialized_start=3578 _PLAYBOOKEXECUTIONSTATUSTYPE._serialized_end=3679 - _PLAYBOOKTASKRESULTTYPE._serialized_start=3681 - _PLAYBOOKTASKRESULTTYPE._serialized_end=3808 + _PLAYBOOKTASKRESULTTYPE._serialized_start=3682 + _PLAYBOOKTASKRESULTTYPE._serialized_end=3830 _EXTERNALLINK._serialized_start=170 _EXTERNALLINK._serialized_end=271 _LABELVALUEPAIR._serialized_start=273 diff --git a/protos/playbooks/playbook_commons_pb2.pyi b/protos/playbooks/playbook_commons_pb2.pyi index 3e82fc6e3..5f2d08c37 100644 --- a/protos/playbooks/playbook_commons_pb2.pyi +++ b/protos/playbooks/playbook_commons_pb2.pyi @@ -56,6 +56,7 @@ class _PlaybookTaskResultTypeEnumTypeWrapper(google.protobuf.internal.enum_type_ BASH_COMMAND_OUTPUT: _PlaybookTaskResultType.ValueType # 4 TEXT: _PlaybookTaskResultType.ValueType # 5 LOGS: _PlaybookTaskResultType.ValueType # 6 + GLOBAL_VARIABLE: _PlaybookTaskResultType.ValueType # 7 class PlaybookTaskResultType(_PlaybookTaskResultType, metaclass=_PlaybookTaskResultTypeEnumTypeWrapper): ... @@ -66,6 +67,7 @@ API_RESPONSE: PlaybookTaskResultType.ValueType # 3 BASH_COMMAND_OUTPUT: PlaybookTaskResultType.ValueType # 4 TEXT: PlaybookTaskResultType.ValueType # 5 LOGS: PlaybookTaskResultType.ValueType # 6 +GLOBAL_VARIABLE: PlaybookTaskResultType.ValueType # 7 global___PlaybookTaskResultType = PlaybookTaskResultType @typing_extensions.final diff --git a/protos/playbooks/playbook_global_variable_evaluator.proto b/protos/playbooks/playbook_global_variable_evaluator.proto new file mode 100644 index 000000000..37d43f492 --- /dev/null +++ b/protos/playbooks/playbook_global_variable_evaluator.proto @@ -0,0 +1,23 @@ +syntax = "proto3"; +package protos.playbooks; + +import "protos/base.proto"; +import "google/protobuf/wrappers.proto"; + +message CompareGlobalVariable { + google.protobuf.StringValue variable_name = 1; + Operator operator = 2; + google.protobuf.StringValue threshold = 3; +} + +message GlobalVariableResultRule { + enum Type { + UNKOWN = 0; + COMPARE_GLOBAL_VARIABLE = 1; + } + + Type type = 1; + oneof rule { + CompareGlobalVariable compare_global_variable = 101; + } +} diff --git a/protos/playbooks/playbook_global_variable_evaluator_pb2.py b/protos/playbooks/playbook_global_variable_evaluator_pb2.py new file mode 100644 index 000000000..c9a1f4ff6 --- /dev/null +++ b/protos/playbooks/playbook_global_variable_evaluator_pb2.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: protos/playbooks/playbook_global_variable_evaluator.proto +"""Generated protocol buffer code.""" +from google.protobuf.internal import builder as _builder +from google.protobuf import descriptor as _descriptor +from google.protobuf import descriptor_pool as _descriptor_pool +from google.protobuf import symbol_database as _symbol_database +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + +from protos import base_pb2 as protos_dot_base__pb2 +from google.protobuf import wrappers_pb2 as google_dot_protobuf_dot_wrappers__pb2 + + +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n9protos/playbooks/playbook_global_variable_evaluator.proto\x12\x10protos.playbooks\x1a\x11protos/base.proto\x1a\x1egoogle/protobuf/wrappers.proto\"\xa1\x01\n\x15\x43ompareGlobalVariable\x12\x33\n\rvariable_name\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12\"\n\x08operator\x18\x02 \x01(\x0e\x32\x10.protos.Operator\x12/\n\tthreshold\x18\x03 \x01(\x0b\x32\x1c.google.protobuf.StringValue\"\xde\x01\n\x18GlobalVariableResultRule\x12=\n\x04type\x18\x01 \x01(\x0e\x32/.protos.playbooks.GlobalVariableResultRule.Type\x12J\n\x17\x63ompare_global_variable\x18\x65 \x01(\x0b\x32\'.protos.playbooks.CompareGlobalVariableH\x00\"/\n\x04Type\x12\n\n\x06UNKOWN\x10\x00\x12\x1b\n\x17\x43OMPARE_GLOBAL_VARIABLE\x10\x01\x42\x06\n\x04ruleb\x06proto3') + +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals()) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'protos.playbooks.playbook_global_variable_evaluator_pb2', globals()) +if _descriptor._USE_C_DESCRIPTORS == False: + + DESCRIPTOR._options = None + _COMPAREGLOBALVARIABLE._serialized_start=131 + _COMPAREGLOBALVARIABLE._serialized_end=292 + _GLOBALVARIABLERESULTRULE._serialized_start=295 + _GLOBALVARIABLERESULTRULE._serialized_end=517 + _GLOBALVARIABLERESULTRULE_TYPE._serialized_start=462 + _GLOBALVARIABLERESULTRULE_TYPE._serialized_end=509 +# @@protoc_insertion_point(module_scope) diff --git a/protos/playbooks/playbook_global_variable_evaluator_pb2.pyi b/protos/playbooks/playbook_global_variable_evaluator_pb2.pyi new file mode 100644 index 000000000..c527001f2 --- /dev/null +++ b/protos/playbooks/playbook_global_variable_evaluator_pb2.pyi @@ -0,0 +1,77 @@ +""" +@generated by mypy-protobuf. Do not edit manually! +isort:skip_file +""" +import builtins +import google.protobuf.descriptor +import google.protobuf.internal.enum_type_wrapper +import google.protobuf.message +import google.protobuf.wrappers_pb2 +import protos.base_pb2 +import sys +import typing + +if sys.version_info >= (3, 10): + import typing as typing_extensions +else: + import typing_extensions + +DESCRIPTOR: google.protobuf.descriptor.FileDescriptor + +@typing_extensions.final +class CompareGlobalVariable(google.protobuf.message.Message): + DESCRIPTOR: google.protobuf.descriptor.Descriptor + + VARIABLE_NAME_FIELD_NUMBER: builtins.int + OPERATOR_FIELD_NUMBER: builtins.int + THRESHOLD_FIELD_NUMBER: builtins.int + @property + def variable_name(self) -> google.protobuf.wrappers_pb2.StringValue: ... + operator: protos.base_pb2.Operator.ValueType + @property + def threshold(self) -> google.protobuf.wrappers_pb2.StringValue: ... + def __init__( + self, + *, + variable_name: google.protobuf.wrappers_pb2.StringValue | None = ..., + operator: protos.base_pb2.Operator.ValueType = ..., + threshold: google.protobuf.wrappers_pb2.StringValue | None = ..., + ) -> None: ... + def HasField(self, field_name: typing_extensions.Literal["threshold", b"threshold", "variable_name", b"variable_name"]) -> builtins.bool: ... + def ClearField(self, field_name: typing_extensions.Literal["operator", b"operator", "threshold", b"threshold", "variable_name", b"variable_name"]) -> None: ... + +global___CompareGlobalVariable = CompareGlobalVariable + +@typing_extensions.final +class GlobalVariableResultRule(google.protobuf.message.Message): + DESCRIPTOR: google.protobuf.descriptor.Descriptor + + class _Type: + ValueType = typing.NewType("ValueType", builtins.int) + V: typing_extensions.TypeAlias = ValueType + + class _TypeEnumTypeWrapper(google.protobuf.internal.enum_type_wrapper._EnumTypeWrapper[GlobalVariableResultRule._Type.ValueType], builtins.type): # noqa: F821 + DESCRIPTOR: google.protobuf.descriptor.EnumDescriptor + UNKOWN: GlobalVariableResultRule._Type.ValueType # 0 + COMPARE_GLOBAL_VARIABLE: GlobalVariableResultRule._Type.ValueType # 1 + + class Type(_Type, metaclass=_TypeEnumTypeWrapper): ... + UNKOWN: GlobalVariableResultRule.Type.ValueType # 0 + COMPARE_GLOBAL_VARIABLE: GlobalVariableResultRule.Type.ValueType # 1 + + TYPE_FIELD_NUMBER: builtins.int + COMPARE_GLOBAL_VARIABLE_FIELD_NUMBER: builtins.int + type: global___GlobalVariableResultRule.Type.ValueType + @property + def compare_global_variable(self) -> global___CompareGlobalVariable: ... + def __init__( + self, + *, + type: global___GlobalVariableResultRule.Type.ValueType = ..., + compare_global_variable: global___CompareGlobalVariable | None = ..., + ) -> None: ... + def HasField(self, field_name: typing_extensions.Literal["compare_global_variable", b"compare_global_variable", "rule", b"rule"]) -> builtins.bool: ... + def ClearField(self, field_name: typing_extensions.Literal["compare_global_variable", b"compare_global_variable", "rule", b"rule", "type", b"type"]) -> None: ... + def WhichOneof(self, oneof_group: typing_extensions.Literal["rule", b"rule"]) -> typing_extensions.Literal["compare_global_variable"] | None: ... + +global___GlobalVariableResultRule = GlobalVariableResultRule diff --git a/protos/playbooks/playbook_pb2.py b/protos/playbooks/playbook_pb2.py index 9651edb23..621cc9931 100644 --- a/protos/playbooks/playbook_pb2.py +++ b/protos/playbooks/playbook_pb2.py @@ -18,6 +18,7 @@ from protos.playbooks.intelligence_layer import interpreter_pb2 as protos_dot_playbooks_dot_intelligence__layer_dot_interpreter__pb2 from protos.playbooks import playbook_task_result_evaluator_pb2 as protos_dot_playbooks_dot_playbook__task__result__evaluator__pb2 from protos.playbooks import playbook_step_result_evaluator_pb2 as protos_dot_playbooks_dot_playbook__step__result__evaluator__pb2 +from protos.playbooks import playbook_global_variable_evaluator_pb2 as protos_dot_playbooks_dot_playbook__global__variable__evaluator__pb2 from protos.playbooks.source_task_definitions import cloudwatch_task_pb2 as protos_dot_playbooks_dot_source__task__definitions_dot_cloudwatch__task__pb2 from protos.playbooks.source_task_definitions import grafana_task_pb2 as protos_dot_playbooks_dot_source__task__definitions_dot_grafana__task__pb2 from protos.playbooks.source_task_definitions import new_relic_task_pb2 as protos_dot_playbooks_dot_source__task__definitions_dot_new__relic__task__pb2 @@ -42,47 +43,47 @@ from protos.playbooks.source_task_definitions import argocd_task_pb2 as protos_dot_playbooks_dot_source__task__definitions_dot_argocd__task__pb2 -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1fprotos/playbooks/playbook.proto\x12\x10protos.playbooks\x1a\x11protos/base.proto\x1a\x1egoogle/protobuf/wrappers.proto\x1a\x1cgoogle/protobuf/struct.proto\x1a\'protos/playbooks/playbook_commons.proto\x1a\x35protos/playbooks/intelligence_layer/interpreter.proto\x1a\x35protos/playbooks/playbook_task_result_evaluator.proto\x1a\x35protos/playbooks/playbook_step_result_evaluator.proto\x1a>protos/playbooks/source_task_definitions/cloudwatch_task.proto\x1a;protos/playbooks/source_task_definitions/grafana_task.proto\x1a=protos/playbooks/source_task_definitions/new_relic_task.proto\x1a;protos/playbooks/source_task_definitions/datadog_task.proto\x1a\x37protos/playbooks/source_task_definitions/eks_task.proto\x1a\x42protos/playbooks/source_task_definitions/sql_data_fetch_task.proto\x1a\x37protos/playbooks/source_task_definitions/api_task.proto\x1a\x38protos/playbooks/source_task_definitions/bash_task.proto\x1a\x41protos/playbooks/source_task_definitions/documentation_task.proto\x1a:protos/playbooks/source_task_definitions/promql_task.proto\x1a\x39protos/playbooks/source_task_definitions/azure_task.proto\x1a\x37protos/playbooks/source_task_definitions/gke_task.proto\x1a\x42protos/playbooks/source_task_definitions/elastic_search_task.proto\x1a@protos/playbooks/source_task_definitions/grafana_loki_task.proto\x1a;protos/playbooks/source_task_definitions/kubectl_task.proto\x1a\x37protos/playbooks/source_task_definitions/gcm_task.proto\x1a\x39protos/playbooks/source_task_definitions/email_task.proto\x1a\x43protos/playbooks/source_task_definitions/lambda_function_task.proto\x1a\x39protos/playbooks/source_task_definitions/slack_task.proto\x1a=protos/playbooks/source_task_definitions/big_query_task.proto\x1a\x38protos/playbooks/source_task_definitions/jira_task.proto\x1a:protos/playbooks/source_task_definitions/argocd_task.proto\"\x94\x11\n\x0cPlaybookTask\x12(\n\x02id\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.UInt64Value\x12\x1e\n\x06source\x18\x02 \x01(\x0e\x32\x0e.protos.Source\x12\x32\n\x0creference_id\x18\x03 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12*\n\x04name\x18\x04 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12\x31\n\x0b\x64\x65scription\x18\x05 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12+\n\x05notes\x18\x06 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12\x30\n\ncreated_by\x18\x07 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12\x34\n\x13global_variable_set\x18\x08 \x01(\x0b\x32\x17.google.protobuf.Struct\x12;\n\x10interpreter_type\x18\t \x01(\x0e\x32!.protos.playbooks.InterpreterType\x12Z\n\x16task_connector_sources\x18\n \x03(\x0b\x32:.protos.playbooks.PlaybookTask.PlaybookTaskConnectorSource\x12V\n\x17\x65xecution_configuration\x18\x0b \x01(\x0b\x32\x35.protos.playbooks.PlaybookTask.ExecutionConfiguration\x12\x38\n\rdocumentation\x18\x65 \x01(\x0b\x32\x1f.protos.playbooks.DocumentationH\x00\x12\x32\n\ncloudwatch\x18\x66 \x01(\x0b\x32\x1c.protos.playbooks.CloudwatchH\x00\x12,\n\x07grafana\x18g \x01(\x0b\x32\x19.protos.playbooks.GrafanaH\x00\x12/\n\tnew_relic\x18h \x01(\x0b\x32\x1a.protos.playbooks.NewRelicH\x00\x12,\n\x07\x64\x61tadog\x18i \x01(\x0b\x32\x19.protos.playbooks.DatadogH\x00\x12\x34\n\nclickhouse\x18j \x01(\x0b\x32\x1e.protos.playbooks.SqlDataFetchH\x00\x12\x32\n\x08postgres\x18k \x01(\x0b\x32\x1e.protos.playbooks.SqlDataFetchH\x00\x12$\n\x03\x65ks\x18l \x01(\x0b\x32\x15.protos.playbooks.EksH\x00\x12\x41\n\x17sql_database_connection\x18m \x01(\x0b\x32\x1e.protos.playbooks.SqlDataFetchH\x00\x12$\n\x03\x61pi\x18n \x01(\x0b\x32\x15.protos.playbooks.ApiH\x00\x12&\n\x04\x62\x61sh\x18o \x01(\x0b\x32\x16.protos.playbooks.BashH\x00\x12\x31\n\rgrafana_mimir\x18p \x01(\x0b\x32\x18.protos.playbooks.PromQlH\x00\x12(\n\x05\x61zure\x18q \x01(\x0b\x32\x17.protos.playbooks.AzureH\x00\x12$\n\x03gke\x18r \x01(\x0b\x32\x15.protos.playbooks.GkeH\x00\x12\x39\n\x0e\x65lastic_search\x18s \x01(\x0b\x32\x1f.protos.playbooks.ElasticSearchH\x00\x12\x35\n\x0cgrafana_loki\x18t \x01(\x0b\x32\x1d.protos.playbooks.GrafanaLokiH\x00\x12/\n\nkubernetes\x18u \x01(\x0b\x32\x19.protos.playbooks.KubectlH\x00\x12$\n\x03gcm\x18v \x01(\x0b\x32\x15.protos.playbooks.GcmH\x00\x12&\n\x04smtp\x18w \x01(\x0b\x32\x16.protos.playbooks.SMTPH\x00\x12(\n\x05slack\x18x \x01(\x0b\x32\x17.protos.playbooks.SlackH\x00\x12/\n\tbig_query\x18y \x01(\x0b\x32\x1a.protos.playbooks.BigQueryH\x00\x12,\n\njira_cloud\x18z \x01(\x0b\x32\x16.protos.playbooks.JiraH\x00\x12*\n\x06\x61rgocd\x18{ \x01(\x0b\x32\x18.protos.playbooks.ArgoCDH\x00\x1a\x93\x01\n\x1bPlaybookTaskConnectorSource\x12(\n\x02id\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.UInt64Value\x12\x1e\n\x06source\x18\x02 \x01(\x0e\x32\x0e.protos.Source\x12*\n\x04name\x18\x03 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x1a\xbd\x02\n\x16\x45xecutionConfiguration\x12\x35\n\x11is_bulk_execution\x18\x01 \x01(\x0b\x32\x1a.google.protobuf.BoolValue\x12>\n\x18\x62ulk_execution_var_field\x18\x02 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12\x1a\n\x12timeseries_offsets\x18\x03 \x03(\r\x12\x41\n\x1dis_result_transformer_enabled\x18\x04 \x01(\x0b\x32\x1a.google.protobuf.BoolValue\x12M\n\"result_transformer_lambda_function\x18\x05 \x01(\x0b\x32!.protos.playbooks.Lambda.FunctionB\x06\n\x04task\"\xf9\x02\n\x16PlaybookTaskResultRule\x12\x36\n\x04type\x18\x01 \x01(\x0e\x32(.protos.playbooks.PlaybookTaskResultType\x12,\n\x04task\x18\x02 \x01(\x0b\x32\x1e.protos.playbooks.PlaybookTask\x12<\n\ntimeseries\x18\x65 \x01(\x0b\x32&.protos.playbooks.TimeseriesResultRuleH\x00\x12\x32\n\x05table\x18\x66 \x01(\x0b\x32!.protos.playbooks.TableResultRuleH\x00\x12\x31\n\x04logs\x18g \x01(\x0b\x32!.protos.playbooks.TableResultRuleH\x00\x12L\n\x13\x62\x61sh_command_output\x18h \x01(\x0b\x32-.protos.playbooks.BashCommandOutputResultRuleH\x00\x42\x06\n\x04rule\"\x8e\x03\n\x18PlaybookTaskExecutionLog\x12(\n\x02id\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.UInt64Value\x12\x11\n\ttimestamp\x18\x02 \x01(\x10\x12,\n\x04task\x18\x03 \x01(\x0b\x32\x1e.protos.playbooks.PlaybookTask\x12\x34\n\x06result\x18\x04 \x01(\x0b\x32$.protos.playbooks.PlaybookTaskResult\x12\x38\n\x0einterpretation\x18\x05 \x01(\x0b\x32 .protos.playbooks.Interpretation\x12%\n\ntime_range\x18\x06 \x01(\x0b\x32\x11.protos.TimeRange\x12\x30\n\ncreated_by\x18\x07 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12>\n\x1d\x65xecution_global_variable_set\x18\x08 \x01(\x0b\x32\x17.google.protobuf.Struct\"\xd0\x02\n\x1bPlaybookStepResultCondition\x12\x31\n\x10logical_operator\x18\x01 \x01(\x0e\x32\x17.protos.LogicalOperator\x12H\n\trule_sets\x18\x02 \x03(\x0b\x32\x35.protos.playbooks.PlaybookStepResultCondition.RuleSet\x1a\xb3\x01\n\x07RuleSet\x12\x31\n\x10logical_operator\x18\x01 \x01(\x0e\x32\x17.protos.LogicalOperator\x12\x37\n\x05rules\x18\x02 \x03(\x0b\x32(.protos.playbooks.PlaybookTaskResultRule\x12<\n\nstep_rules\x18\x03 \x03(\x0b\x32(.protos.playbooks.PlaybookStepResultRule\"\xd6\x03\n\x0cPlaybookStep\x12(\n\x02id\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.UInt64Value\x12\x32\n\x0creference_id\x18\x02 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12*\n\x04name\x18\x03 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12\x31\n\x0b\x64\x65scription\x18\x04 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12+\n\x05notes\x18\x05 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12\x36\n\x0e\x65xternal_links\x18\x06 \x03(\x0b\x32\x1e.protos.playbooks.ExternalLink\x12;\n\x10interpreter_type\x18\x07 \x01(\x0e\x32!.protos.playbooks.InterpreterType\x12-\n\x05tasks\x18\x08 \x03(\x0b\x32\x1e.protos.playbooks.PlaybookTask\x12\x38\n\x08\x63hildren\x18\t \x03(\x0b\x32&.protos.playbooks.PlaybookStepRelation\"\x90\x02\n\x14PlaybookStepRelation\x12(\n\x02id\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.UInt64Value\x12.\n\x06parent\x18\x02 \x01(\x0b\x32\x1e.protos.playbooks.PlaybookStep\x12-\n\x05\x63hild\x18\x03 \x01(\x0b\x32\x1e.protos.playbooks.PlaybookStep\x12@\n\tcondition\x18\x04 \x01(\x0b\x32-.protos.playbooks.PlaybookStepResultCondition\x12-\n\tis_active\x18\x05 \x01(\x0b\x32\x1a.google.protobuf.BoolValue\"\xb9\x02\n PlaybookStepRelationExecutionLog\x12(\n\x02id\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.UInt64Value\x12\x38\n\x08relation\x18\x02 \x01(\x0b\x32&.protos.playbooks.PlaybookStepRelation\x12\x35\n\x11\x65valuation_result\x18\x03 \x01(\x0b\x32\x1a.google.protobuf.BoolValue\x12\x32\n\x11\x65valuation_output\x18\x04 \x01(\x0b\x32\x17.google.protobuf.Struct\x12\x46\n\x1cstep_relation_interpretation\x18\x05 \x01(\x0b\x32 .protos.playbooks.Interpretation\"\xf2\x03\n\x18PlaybookStepExecutionLog\x12(\n\x02id\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.UInt64Value\x12\x11\n\ttimestamp\x18\x02 \x01(\x10\x12\x35\n\x0fplaybook_run_id\x18\x03 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12,\n\x04step\x18\x04 \x01(\x0b\x32\x1e.protos.playbooks.PlaybookStep\x12G\n\x13task_execution_logs\x18\x05 \x03(\x0b\x32*.protos.playbooks.PlaybookTaskExecutionLog\x12S\n\x17relation_execution_logs\x18\x06 \x03(\x0b\x32\x32.protos.playbooks.PlaybookStepRelationExecutionLog\x12=\n\x13step_interpretation\x18\x07 \x01(\x0b\x32 .protos.playbooks.Interpretation\x12%\n\ntime_range\x18\x08 \x01(\x0b\x32\x11.protos.TimeRange\x12\x30\n\ncreated_by\x18\t \x01(\x0b\x32\x1c.google.protobuf.StringValue\"\x81\x04\n\x08Playbook\x12(\n\x02id\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.UInt64Value\x12*\n\x04name\x18\x02 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12\x31\n\x0b\x64\x65scription\x18\x03 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12\x34\n\x13global_variable_set\x18\x04 \x01(\x0b\x32\x17.google.protobuf.Struct\x12\x30\n\ncreated_by\x18\x05 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12-\n\tis_active\x18\x06 \x01(\x0b\x32\x1a.google.protobuf.BoolValue\x12\x12\n\ncreated_at\x18\x07 \x01(\x10\x12\x13\n\x0blast_run_at\x18\x08 \x01(\x10\x12=\n\x06status\x18\t \x01(\x0e\x32-.protos.playbooks.PlaybookExecutionStatusType\x12-\n\x05steps\x18\n \x03(\x0b\x32\x1e.protos.playbooks.PlaybookStep\x12>\n\x0estep_relations\x18\x0b \x03(\x0b\x32&.protos.playbooks.PlaybookStepRelation\"\x80\x04\n\x11PlaybookExecution\x12(\n\x02id\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.UInt64Value\x12\x35\n\x0fplaybook_run_id\x18\x02 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12,\n\x08playbook\x18\x03 \x01(\x0b\x32\x1a.protos.playbooks.Playbook\x12=\n\x06status\x18\x04 \x01(\x0e\x32-.protos.playbooks.PlaybookExecutionStatusType\x12\x12\n\ncreated_at\x18\x05 \x01(\x10\x12\x12\n\nstarted_at\x18\x06 \x01(\x10\x12\x13\n\x0b\x66inished_at\x18\x07 \x01(\x10\x12%\n\ntime_range\x18\x08 \x01(\x0b\x32\x11.protos.TimeRange\x12\x30\n\ncreated_by\x18\t \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12G\n\x13step_execution_logs\x18\x0b \x03(\x0b\x32*.protos.playbooks.PlaybookStepExecutionLog\x12>\n\x1d\x65xecution_global_variable_set\x18\x0c \x01(\x0b\x32\x17.google.protobuf.Struct\"\xf6\x04\n\x10UpdatePlaybookOp\x12\x31\n\x02op\x18\x01 \x01(\x0e\x32%.protos.playbooks.UpdatePlaybookOp.Op\x12U\n\x14update_playbook_name\x18\x02 \x01(\x0b\x32\x35.protos.playbooks.UpdatePlaybookOp.UpdatePlaybookNameH\x00\x12Y\n\x16update_playbook_status\x18\x03 \x01(\x0b\x32\x37.protos.playbooks.UpdatePlaybookOp.UpdatePlaybookStatusH\x00\x12L\n\x0fupdate_playbook\x18\x04 \x01(\x0b\x32\x31.protos.playbooks.UpdatePlaybookOp.UpdatePlaybookH\x00\x1a@\n\x12UpdatePlaybookName\x12*\n\x04name\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x1a\x45\n\x14UpdatePlaybookStatus\x12-\n\tis_active\x18\x01 \x01(\x0b\x32\x1a.google.protobuf.BoolValue\x1a>\n\x0eUpdatePlaybook\x12,\n\x08playbook\x18\x01 \x01(\x0b\x32\x1a.protos.playbooks.Playbook\"\\\n\x02Op\x12\x0b\n\x07UNKNOWN\x10\x00\x12\x18\n\x14UPDATE_PLAYBOOK_NAME\x10\x01\x12\x1a\n\x16UPDATE_PLAYBOOK_STATUS\x10\x02\x12\x13\n\x0fUPDATE_PLAYBOOK\x10\x03\x42\x08\n\x06updateb\x06proto3') +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1fprotos/playbooks/playbook.proto\x12\x10protos.playbooks\x1a\x11protos/base.proto\x1a\x1egoogle/protobuf/wrappers.proto\x1a\x1cgoogle/protobuf/struct.proto\x1a\'protos/playbooks/playbook_commons.proto\x1a\x35protos/playbooks/intelligence_layer/interpreter.proto\x1a\x35protos/playbooks/playbook_task_result_evaluator.proto\x1a\x35protos/playbooks/playbook_step_result_evaluator.proto\x1a\x39protos/playbooks/playbook_global_variable_evaluator.proto\x1a>protos/playbooks/source_task_definitions/cloudwatch_task.proto\x1a;protos/playbooks/source_task_definitions/grafana_task.proto\x1a=protos/playbooks/source_task_definitions/new_relic_task.proto\x1a;protos/playbooks/source_task_definitions/datadog_task.proto\x1a\x37protos/playbooks/source_task_definitions/eks_task.proto\x1a\x42protos/playbooks/source_task_definitions/sql_data_fetch_task.proto\x1a\x37protos/playbooks/source_task_definitions/api_task.proto\x1a\x38protos/playbooks/source_task_definitions/bash_task.proto\x1a\x41protos/playbooks/source_task_definitions/documentation_task.proto\x1a:protos/playbooks/source_task_definitions/promql_task.proto\x1a\x39protos/playbooks/source_task_definitions/azure_task.proto\x1a\x37protos/playbooks/source_task_definitions/gke_task.proto\x1a\x42protos/playbooks/source_task_definitions/elastic_search_task.proto\x1a@protos/playbooks/source_task_definitions/grafana_loki_task.proto\x1a;protos/playbooks/source_task_definitions/kubectl_task.proto\x1a\x37protos/playbooks/source_task_definitions/gcm_task.proto\x1a\x39protos/playbooks/source_task_definitions/email_task.proto\x1a\x43protos/playbooks/source_task_definitions/lambda_function_task.proto\x1a\x39protos/playbooks/source_task_definitions/slack_task.proto\x1a=protos/playbooks/source_task_definitions/big_query_task.proto\x1a\x38protos/playbooks/source_task_definitions/jira_task.proto\x1a:protos/playbooks/source_task_definitions/argocd_task.proto\"\x94\x11\n\x0cPlaybookTask\x12(\n\x02id\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.UInt64Value\x12\x1e\n\x06source\x18\x02 \x01(\x0e\x32\x0e.protos.Source\x12\x32\n\x0creference_id\x18\x03 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12*\n\x04name\x18\x04 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12\x31\n\x0b\x64\x65scription\x18\x05 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12+\n\x05notes\x18\x06 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12\x30\n\ncreated_by\x18\x07 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12\x34\n\x13global_variable_set\x18\x08 \x01(\x0b\x32\x17.google.protobuf.Struct\x12;\n\x10interpreter_type\x18\t \x01(\x0e\x32!.protos.playbooks.InterpreterType\x12Z\n\x16task_connector_sources\x18\n \x03(\x0b\x32:.protos.playbooks.PlaybookTask.PlaybookTaskConnectorSource\x12V\n\x17\x65xecution_configuration\x18\x0b \x01(\x0b\x32\x35.protos.playbooks.PlaybookTask.ExecutionConfiguration\x12\x38\n\rdocumentation\x18\x65 \x01(\x0b\x32\x1f.protos.playbooks.DocumentationH\x00\x12\x32\n\ncloudwatch\x18\x66 \x01(\x0b\x32\x1c.protos.playbooks.CloudwatchH\x00\x12,\n\x07grafana\x18g \x01(\x0b\x32\x19.protos.playbooks.GrafanaH\x00\x12/\n\tnew_relic\x18h \x01(\x0b\x32\x1a.protos.playbooks.NewRelicH\x00\x12,\n\x07\x64\x61tadog\x18i \x01(\x0b\x32\x19.protos.playbooks.DatadogH\x00\x12\x34\n\nclickhouse\x18j \x01(\x0b\x32\x1e.protos.playbooks.SqlDataFetchH\x00\x12\x32\n\x08postgres\x18k \x01(\x0b\x32\x1e.protos.playbooks.SqlDataFetchH\x00\x12$\n\x03\x65ks\x18l \x01(\x0b\x32\x15.protos.playbooks.EksH\x00\x12\x41\n\x17sql_database_connection\x18m \x01(\x0b\x32\x1e.protos.playbooks.SqlDataFetchH\x00\x12$\n\x03\x61pi\x18n \x01(\x0b\x32\x15.protos.playbooks.ApiH\x00\x12&\n\x04\x62\x61sh\x18o \x01(\x0b\x32\x16.protos.playbooks.BashH\x00\x12\x31\n\rgrafana_mimir\x18p \x01(\x0b\x32\x18.protos.playbooks.PromQlH\x00\x12(\n\x05\x61zure\x18q \x01(\x0b\x32\x17.protos.playbooks.AzureH\x00\x12$\n\x03gke\x18r \x01(\x0b\x32\x15.protos.playbooks.GkeH\x00\x12\x39\n\x0e\x65lastic_search\x18s \x01(\x0b\x32\x1f.protos.playbooks.ElasticSearchH\x00\x12\x35\n\x0cgrafana_loki\x18t \x01(\x0b\x32\x1d.protos.playbooks.GrafanaLokiH\x00\x12/\n\nkubernetes\x18u \x01(\x0b\x32\x19.protos.playbooks.KubectlH\x00\x12$\n\x03gcm\x18v \x01(\x0b\x32\x15.protos.playbooks.GcmH\x00\x12&\n\x04smtp\x18w \x01(\x0b\x32\x16.protos.playbooks.SMTPH\x00\x12(\n\x05slack\x18x \x01(\x0b\x32\x17.protos.playbooks.SlackH\x00\x12/\n\tbig_query\x18y \x01(\x0b\x32\x1a.protos.playbooks.BigQueryH\x00\x12,\n\njira_cloud\x18z \x01(\x0b\x32\x16.protos.playbooks.JiraH\x00\x12*\n\x06\x61rgocd\x18{ \x01(\x0b\x32\x18.protos.playbooks.ArgoCDH\x00\x1a\x93\x01\n\x1bPlaybookTaskConnectorSource\x12(\n\x02id\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.UInt64Value\x12\x1e\n\x06source\x18\x02 \x01(\x0e\x32\x0e.protos.Source\x12*\n\x04name\x18\x03 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x1a\xbd\x02\n\x16\x45xecutionConfiguration\x12\x35\n\x11is_bulk_execution\x18\x01 \x01(\x0b\x32\x1a.google.protobuf.BoolValue\x12>\n\x18\x62ulk_execution_var_field\x18\x02 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12\x1a\n\x12timeseries_offsets\x18\x03 \x03(\r\x12\x41\n\x1dis_result_transformer_enabled\x18\x04 \x01(\x0b\x32\x1a.google.protobuf.BoolValue\x12M\n\"result_transformer_lambda_function\x18\x05 \x01(\x0b\x32!.protos.playbooks.Lambda.FunctionB\x06\n\x04task\"\xf9\x02\n\x16PlaybookTaskResultRule\x12\x36\n\x04type\x18\x01 \x01(\x0e\x32(.protos.playbooks.PlaybookTaskResultType\x12,\n\x04task\x18\x02 \x01(\x0b\x32\x1e.protos.playbooks.PlaybookTask\x12<\n\ntimeseries\x18\x65 \x01(\x0b\x32&.protos.playbooks.TimeseriesResultRuleH\x00\x12\x32\n\x05table\x18\x66 \x01(\x0b\x32!.protos.playbooks.TableResultRuleH\x00\x12\x31\n\x04logs\x18g \x01(\x0b\x32!.protos.playbooks.TableResultRuleH\x00\x12L\n\x13\x62\x61sh_command_output\x18h \x01(\x0b\x32-.protos.playbooks.BashCommandOutputResultRuleH\x00\x42\x06\n\x04rule\"\x8e\x03\n\x18PlaybookTaskExecutionLog\x12(\n\x02id\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.UInt64Value\x12\x11\n\ttimestamp\x18\x02 \x01(\x10\x12,\n\x04task\x18\x03 \x01(\x0b\x32\x1e.protos.playbooks.PlaybookTask\x12\x34\n\x06result\x18\x04 \x01(\x0b\x32$.protos.playbooks.PlaybookTaskResult\x12\x38\n\x0einterpretation\x18\x05 \x01(\x0b\x32 .protos.playbooks.Interpretation\x12%\n\ntime_range\x18\x06 \x01(\x0b\x32\x11.protos.TimeRange\x12\x30\n\ncreated_by\x18\x07 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12>\n\x1d\x65xecution_global_variable_set\x18\x08 \x01(\x0b\x32\x17.google.protobuf.Struct\"\x94\x03\n\x1bPlaybookStepResultCondition\x12\x31\n\x10logical_operator\x18\x01 \x01(\x0e\x32\x17.protos.LogicalOperator\x12H\n\trule_sets\x18\x02 \x03(\x0b\x32\x35.protos.playbooks.PlaybookStepResultCondition.RuleSet\x1a\xf7\x01\n\x07RuleSet\x12\x31\n\x10logical_operator\x18\x01 \x01(\x0e\x32\x17.protos.LogicalOperator\x12\x37\n\x05rules\x18\x02 \x03(\x0b\x32(.protos.playbooks.PlaybookTaskResultRule\x12<\n\nstep_rules\x18\x03 \x03(\x0b\x32(.protos.playbooks.PlaybookStepResultRule\x12\x42\n\x0evariable_rules\x18\x04 \x03(\x0b\x32*.protos.playbooks.GlobalVariableResultRule\"\xd6\x03\n\x0cPlaybookStep\x12(\n\x02id\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.UInt64Value\x12\x32\n\x0creference_id\x18\x02 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12*\n\x04name\x18\x03 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12\x31\n\x0b\x64\x65scription\x18\x04 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12+\n\x05notes\x18\x05 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12\x36\n\x0e\x65xternal_links\x18\x06 \x03(\x0b\x32\x1e.protos.playbooks.ExternalLink\x12;\n\x10interpreter_type\x18\x07 \x01(\x0e\x32!.protos.playbooks.InterpreterType\x12-\n\x05tasks\x18\x08 \x03(\x0b\x32\x1e.protos.playbooks.PlaybookTask\x12\x38\n\x08\x63hildren\x18\t \x03(\x0b\x32&.protos.playbooks.PlaybookStepRelation\"\x90\x02\n\x14PlaybookStepRelation\x12(\n\x02id\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.UInt64Value\x12.\n\x06parent\x18\x02 \x01(\x0b\x32\x1e.protos.playbooks.PlaybookStep\x12-\n\x05\x63hild\x18\x03 \x01(\x0b\x32\x1e.protos.playbooks.PlaybookStep\x12@\n\tcondition\x18\x04 \x01(\x0b\x32-.protos.playbooks.PlaybookStepResultCondition\x12-\n\tis_active\x18\x05 \x01(\x0b\x32\x1a.google.protobuf.BoolValue\"\xb9\x02\n PlaybookStepRelationExecutionLog\x12(\n\x02id\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.UInt64Value\x12\x38\n\x08relation\x18\x02 \x01(\x0b\x32&.protos.playbooks.PlaybookStepRelation\x12\x35\n\x11\x65valuation_result\x18\x03 \x01(\x0b\x32\x1a.google.protobuf.BoolValue\x12\x32\n\x11\x65valuation_output\x18\x04 \x01(\x0b\x32\x17.google.protobuf.Struct\x12\x46\n\x1cstep_relation_interpretation\x18\x05 \x01(\x0b\x32 .protos.playbooks.Interpretation\"\xf2\x03\n\x18PlaybookStepExecutionLog\x12(\n\x02id\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.UInt64Value\x12\x11\n\ttimestamp\x18\x02 \x01(\x10\x12\x35\n\x0fplaybook_run_id\x18\x03 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12,\n\x04step\x18\x04 \x01(\x0b\x32\x1e.protos.playbooks.PlaybookStep\x12G\n\x13task_execution_logs\x18\x05 \x03(\x0b\x32*.protos.playbooks.PlaybookTaskExecutionLog\x12S\n\x17relation_execution_logs\x18\x06 \x03(\x0b\x32\x32.protos.playbooks.PlaybookStepRelationExecutionLog\x12=\n\x13step_interpretation\x18\x07 \x01(\x0b\x32 .protos.playbooks.Interpretation\x12%\n\ntime_range\x18\x08 \x01(\x0b\x32\x11.protos.TimeRange\x12\x30\n\ncreated_by\x18\t \x01(\x0b\x32\x1c.google.protobuf.StringValue\"\x81\x04\n\x08Playbook\x12(\n\x02id\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.UInt64Value\x12*\n\x04name\x18\x02 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12\x31\n\x0b\x64\x65scription\x18\x03 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12\x34\n\x13global_variable_set\x18\x04 \x01(\x0b\x32\x17.google.protobuf.Struct\x12\x30\n\ncreated_by\x18\x05 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12-\n\tis_active\x18\x06 \x01(\x0b\x32\x1a.google.protobuf.BoolValue\x12\x12\n\ncreated_at\x18\x07 \x01(\x10\x12\x13\n\x0blast_run_at\x18\x08 \x01(\x10\x12=\n\x06status\x18\t \x01(\x0e\x32-.protos.playbooks.PlaybookExecutionStatusType\x12-\n\x05steps\x18\n \x03(\x0b\x32\x1e.protos.playbooks.PlaybookStep\x12>\n\x0estep_relations\x18\x0b \x03(\x0b\x32&.protos.playbooks.PlaybookStepRelation\"\x80\x04\n\x11PlaybookExecution\x12(\n\x02id\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.UInt64Value\x12\x35\n\x0fplaybook_run_id\x18\x02 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12,\n\x08playbook\x18\x03 \x01(\x0b\x32\x1a.protos.playbooks.Playbook\x12=\n\x06status\x18\x04 \x01(\x0e\x32-.protos.playbooks.PlaybookExecutionStatusType\x12\x12\n\ncreated_at\x18\x05 \x01(\x10\x12\x12\n\nstarted_at\x18\x06 \x01(\x10\x12\x13\n\x0b\x66inished_at\x18\x07 \x01(\x10\x12%\n\ntime_range\x18\x08 \x01(\x0b\x32\x11.protos.TimeRange\x12\x30\n\ncreated_by\x18\t \x01(\x0b\x32\x1c.google.protobuf.StringValue\x12G\n\x13step_execution_logs\x18\x0b \x03(\x0b\x32*.protos.playbooks.PlaybookStepExecutionLog\x12>\n\x1d\x65xecution_global_variable_set\x18\x0c \x01(\x0b\x32\x17.google.protobuf.Struct\"\xf6\x04\n\x10UpdatePlaybookOp\x12\x31\n\x02op\x18\x01 \x01(\x0e\x32%.protos.playbooks.UpdatePlaybookOp.Op\x12U\n\x14update_playbook_name\x18\x02 \x01(\x0b\x32\x35.protos.playbooks.UpdatePlaybookOp.UpdatePlaybookNameH\x00\x12Y\n\x16update_playbook_status\x18\x03 \x01(\x0b\x32\x37.protos.playbooks.UpdatePlaybookOp.UpdatePlaybookStatusH\x00\x12L\n\x0fupdate_playbook\x18\x04 \x01(\x0b\x32\x31.protos.playbooks.UpdatePlaybookOp.UpdatePlaybookH\x00\x1a@\n\x12UpdatePlaybookName\x12*\n\x04name\x18\x01 \x01(\x0b\x32\x1c.google.protobuf.StringValue\x1a\x45\n\x14UpdatePlaybookStatus\x12-\n\tis_active\x18\x01 \x01(\x0b\x32\x1a.google.protobuf.BoolValue\x1a>\n\x0eUpdatePlaybook\x12,\n\x08playbook\x18\x01 \x01(\x0b\x32\x1a.protos.playbooks.Playbook\"\\\n\x02Op\x12\x0b\n\x07UNKNOWN\x10\x00\x12\x18\n\x14UPDATE_PLAYBOOK_NAME\x10\x01\x12\x1a\n\x16UPDATE_PLAYBOOK_STATUS\x10\x02\x12\x13\n\x0fUPDATE_PLAYBOOK\x10\x03\x42\x08\n\x06updateb\x06proto3') _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals()) _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'protos.playbooks.playbook_pb2', globals()) if _descriptor._USE_C_DESCRIPTORS == False: DESCRIPTOR._options = None - _PLAYBOOKTASK._serialized_start=1693 - _PLAYBOOKTASK._serialized_end=3889 - _PLAYBOOKTASK_PLAYBOOKTASKCONNECTORSOURCE._serialized_start=3414 - _PLAYBOOKTASK_PLAYBOOKTASKCONNECTORSOURCE._serialized_end=3561 - _PLAYBOOKTASK_EXECUTIONCONFIGURATION._serialized_start=3564 - _PLAYBOOKTASK_EXECUTIONCONFIGURATION._serialized_end=3881 - _PLAYBOOKTASKRESULTRULE._serialized_start=3892 - _PLAYBOOKTASKRESULTRULE._serialized_end=4269 - _PLAYBOOKTASKEXECUTIONLOG._serialized_start=4272 - _PLAYBOOKTASKEXECUTIONLOG._serialized_end=4670 - _PLAYBOOKSTEPRESULTCONDITION._serialized_start=4673 - _PLAYBOOKSTEPRESULTCONDITION._serialized_end=5009 - _PLAYBOOKSTEPRESULTCONDITION_RULESET._serialized_start=4830 - _PLAYBOOKSTEPRESULTCONDITION_RULESET._serialized_end=5009 - _PLAYBOOKSTEP._serialized_start=5012 - _PLAYBOOKSTEP._serialized_end=5482 - _PLAYBOOKSTEPRELATION._serialized_start=5485 - _PLAYBOOKSTEPRELATION._serialized_end=5757 - _PLAYBOOKSTEPRELATIONEXECUTIONLOG._serialized_start=5760 - _PLAYBOOKSTEPRELATIONEXECUTIONLOG._serialized_end=6073 - _PLAYBOOKSTEPEXECUTIONLOG._serialized_start=6076 - _PLAYBOOKSTEPEXECUTIONLOG._serialized_end=6574 - _PLAYBOOK._serialized_start=6577 - _PLAYBOOK._serialized_end=7090 - _PLAYBOOKEXECUTION._serialized_start=7093 - _PLAYBOOKEXECUTION._serialized_end=7605 - _UPDATEPLAYBOOKOP._serialized_start=7608 - _UPDATEPLAYBOOKOP._serialized_end=8238 - _UPDATEPLAYBOOKOP_UPDATEPLAYBOOKNAME._serialized_start=7935 - _UPDATEPLAYBOOKOP_UPDATEPLAYBOOKNAME._serialized_end=7999 - _UPDATEPLAYBOOKOP_UPDATEPLAYBOOKSTATUS._serialized_start=8001 - _UPDATEPLAYBOOKOP_UPDATEPLAYBOOKSTATUS._serialized_end=8070 - _UPDATEPLAYBOOKOP_UPDATEPLAYBOOK._serialized_start=8072 - _UPDATEPLAYBOOKOP_UPDATEPLAYBOOK._serialized_end=8134 - _UPDATEPLAYBOOKOP_OP._serialized_start=8136 - _UPDATEPLAYBOOKOP_OP._serialized_end=8228 + _PLAYBOOKTASK._serialized_start=1752 + _PLAYBOOKTASK._serialized_end=3948 + _PLAYBOOKTASK_PLAYBOOKTASKCONNECTORSOURCE._serialized_start=3473 + _PLAYBOOKTASK_PLAYBOOKTASKCONNECTORSOURCE._serialized_end=3620 + _PLAYBOOKTASK_EXECUTIONCONFIGURATION._serialized_start=3623 + _PLAYBOOKTASK_EXECUTIONCONFIGURATION._serialized_end=3940 + _PLAYBOOKTASKRESULTRULE._serialized_start=3951 + _PLAYBOOKTASKRESULTRULE._serialized_end=4328 + _PLAYBOOKTASKEXECUTIONLOG._serialized_start=4331 + _PLAYBOOKTASKEXECUTIONLOG._serialized_end=4729 + _PLAYBOOKSTEPRESULTCONDITION._serialized_start=4732 + _PLAYBOOKSTEPRESULTCONDITION._serialized_end=5136 + _PLAYBOOKSTEPRESULTCONDITION_RULESET._serialized_start=4889 + _PLAYBOOKSTEPRESULTCONDITION_RULESET._serialized_end=5136 + _PLAYBOOKSTEP._serialized_start=5139 + _PLAYBOOKSTEP._serialized_end=5609 + _PLAYBOOKSTEPRELATION._serialized_start=5612 + _PLAYBOOKSTEPRELATION._serialized_end=5884 + _PLAYBOOKSTEPRELATIONEXECUTIONLOG._serialized_start=5887 + _PLAYBOOKSTEPRELATIONEXECUTIONLOG._serialized_end=6200 + _PLAYBOOKSTEPEXECUTIONLOG._serialized_start=6203 + _PLAYBOOKSTEPEXECUTIONLOG._serialized_end=6701 + _PLAYBOOK._serialized_start=6704 + _PLAYBOOK._serialized_end=7217 + _PLAYBOOKEXECUTION._serialized_start=7220 + _PLAYBOOKEXECUTION._serialized_end=7732 + _UPDATEPLAYBOOKOP._serialized_start=7735 + _UPDATEPLAYBOOKOP._serialized_end=8365 + _UPDATEPLAYBOOKOP_UPDATEPLAYBOOKNAME._serialized_start=8062 + _UPDATEPLAYBOOKOP_UPDATEPLAYBOOKNAME._serialized_end=8126 + _UPDATEPLAYBOOKOP_UPDATEPLAYBOOKSTATUS._serialized_start=8128 + _UPDATEPLAYBOOKOP_UPDATEPLAYBOOKSTATUS._serialized_end=8197 + _UPDATEPLAYBOOKOP_UPDATEPLAYBOOK._serialized_start=8199 + _UPDATEPLAYBOOKOP_UPDATEPLAYBOOK._serialized_end=8261 + _UPDATEPLAYBOOKOP_OP._serialized_start=8263 + _UPDATEPLAYBOOKOP_OP._serialized_end=8355 # @@protoc_insertion_point(module_scope) diff --git a/protos/playbooks/playbook_pb2.pyi b/protos/playbooks/playbook_pb2.pyi index 07515e3ac..7067943f9 100644 --- a/protos/playbooks/playbook_pb2.pyi +++ b/protos/playbooks/playbook_pb2.pyi @@ -13,6 +13,7 @@ import google.protobuf.wrappers_pb2 import protos.base_pb2 import protos.playbooks.intelligence_layer.interpreter_pb2 import protos.playbooks.playbook_commons_pb2 +import protos.playbooks.playbook_global_variable_evaluator_pb2 import protos.playbooks.playbook_step_result_evaluator_pb2 import protos.playbooks.playbook_task_result_evaluator_pb2 import protos.playbooks.source_task_definitions.api_task_pb2 @@ -344,19 +345,23 @@ class PlaybookStepResultCondition(google.protobuf.message.Message): LOGICAL_OPERATOR_FIELD_NUMBER: builtins.int RULES_FIELD_NUMBER: builtins.int STEP_RULES_FIELD_NUMBER: builtins.int + VARIABLE_RULES_FIELD_NUMBER: builtins.int logical_operator: protos.base_pb2.LogicalOperator.ValueType @property def rules(self) -> google.protobuf.internal.containers.RepeatedCompositeFieldContainer[global___PlaybookTaskResultRule]: ... @property def step_rules(self) -> google.protobuf.internal.containers.RepeatedCompositeFieldContainer[protos.playbooks.playbook_step_result_evaluator_pb2.PlaybookStepResultRule]: ... + @property + def variable_rules(self) -> google.protobuf.internal.containers.RepeatedCompositeFieldContainer[protos.playbooks.playbook_global_variable_evaluator_pb2.GlobalVariableResultRule]: ... def __init__( self, *, logical_operator: protos.base_pb2.LogicalOperator.ValueType = ..., rules: collections.abc.Iterable[global___PlaybookTaskResultRule] | None = ..., step_rules: collections.abc.Iterable[protos.playbooks.playbook_step_result_evaluator_pb2.PlaybookStepResultRule] | None = ..., + variable_rules: collections.abc.Iterable[protos.playbooks.playbook_global_variable_evaluator_pb2.GlobalVariableResultRule] | None = ..., ) -> None: ... - def ClearField(self, field_name: typing_extensions.Literal["logical_operator", b"logical_operator", "rules", b"rules", "step_rules", b"step_rules"]) -> None: ... + def ClearField(self, field_name: typing_extensions.Literal["logical_operator", b"logical_operator", "rules", b"rules", "step_rules", b"step_rules", "variable_rules", b"variable_rules"]) -> None: ... LOGICAL_OPERATOR_FIELD_NUMBER: builtins.int RULE_SETS_FIELD_NUMBER: builtins.int diff --git a/protos/playbooks/playbook_task_result_evaluator.proto b/protos/playbooks/playbook_task_result_evaluator.proto index bfae29265..100985d82 100644 --- a/protos/playbooks/playbook_task_result_evaluator.proto +++ b/protos/playbooks/playbook_task_result_evaluator.proto @@ -51,4 +51,4 @@ message BashCommandOutputResultRule { google.protobuf.StringValue pattern = 3; google.protobuf.BoolValue case_sensitive = 4; google.protobuf.UInt64Value threshold = 5; -} \ No newline at end of file +} diff --git a/utils/dict_utils.py b/utils/dict_utils.py new file mode 100644 index 000000000..9bcdbae9e --- /dev/null +++ b/utils/dict_utils.py @@ -0,0 +1,39 @@ +import json + +def get_nested_value(dict, key): + # First, try to find the key as-is in the global dictionary + if key in dict: + return dict[key] + + keys = key.split('.') + + # Start with the first key in the global dictionary + value = dict.get(keys[0], None) + + # Loop over the remaining keys to access nested values + for key in keys[1:]: + if value is None: + return None + + # Try and convert to dict/list + try: + value = json.loads(value) + if isinstance(value, list) or isinstance(value, dict): + value = value + except Exception: + pass + + # If the key represents an integer index, try list access + if key.isdigit(): + try: + idx = int(key) + value = value[idx] + except (IndexError, TypeError): + return None + # Otherwise assume dictionary access + else: + try: + value = value.get(key, None) + except AttributeError: + return None + return value \ No newline at end of file diff --git a/web/src/components/AddVariableCondition/VariableCondition.tsx b/web/src/components/AddVariableCondition/VariableCondition.tsx new file mode 100644 index 000000000..962daa980 --- /dev/null +++ b/web/src/components/AddVariableCondition/VariableCondition.tsx @@ -0,0 +1,92 @@ +import CustomInput from "../Inputs/CustomInput"; +import { + InputTypes, + VariableConditionRule, + VariableRuleTypes, +} from "../../types"; +import useIsPrefetched from "../../hooks/playbooks/useIsPrefetched"; +import { useSelector } from "react-redux"; +import { currentPlaybookSelector } from "../../store/features/playbook/selectors"; +import { additionalStateSelector } from "../../store/features/drawers/selectors"; +import DeleteRuleButton from "../common/Conditions/DeleteRuleButton"; +import { RuleType } from "../common/Conditions/types"; +import { operationOptions } from "../../utils/conditionals/operationOptions"; +import useEdgeConditions from "../../hooks/playbooks/useEdgeConditions"; + +type VariableConditionProps = { + i: number; + showDelete?: boolean; + condition: VariableConditionRule; +}; + +function VariableCondition({ + i, + condition, + showDelete = true, +}: VariableConditionProps) { + const { id } = useSelector(additionalStateSelector); + const isPrefetched = useIsPrefetched(); + const currentPlaybook = useSelector(currentPlaybookSelector); + const { handleRule } = useEdgeConditions(id); + const ruleType = condition.type?.toLowerCase() as VariableRuleTypes; + const ruleData = condition?.[ruleType] ?? {}; + + const handleChange = (val: string, type: string) => { + handleRule(type, val, i, RuleType.VARIABLE_RULE); + }; + + return ( +
+

+ Variable Condition-{i + 1} +

+
+
+ ({ + id: key, + label: key, + }))} + value={ruleData.variable_name} + placeholder={`Variable Name`} + handleChange={(id: string) => + handleChange(id, `${ruleType}.variable_name`) + } + disabled={!!isPrefetched} + /> +
+
+ + handleChange(id, `${ruleType}.operator`) + } + /> + + handleChange(id, `${ruleType}.threshold`) + } + /> +
+ + {showDelete && ( + + )} +
+
+ ); +} + +export default VariableCondition; diff --git a/web/src/components/AddVariableCondition/index.tsx b/web/src/components/AddVariableCondition/index.tsx new file mode 100644 index 000000000..580133218 --- /dev/null +++ b/web/src/components/AddVariableCondition/index.tsx @@ -0,0 +1,36 @@ +import { useSelector } from "react-redux"; +import { additionalStateSelector } from "../../store/features/drawers/drawersSlice.ts"; +import CustomButton from "../common/CustomButton/index.tsx"; +import { Add } from "@mui/icons-material"; +import useEdgeConditions from "../../hooks/playbooks/useEdgeConditions.ts"; +import useIsPrefetched from "../../hooks/playbooks/useIsPrefetched.ts"; +import VariableCondition from "./VariableCondition.tsx"; + +function AddVariableCondition() { + const { id } = useSelector(additionalStateSelector); + const { variable_rules, addNewVariableRule } = useEdgeConditions(id); + const isPrefetched = useIsPrefetched(); + + return ( + <> +

+ Add Variable Conditions +

+
+ + {variable_rules?.map((condition, i) => ( + + ))} + + {!isPrefetched && ( + <> + + Add + + + )} + + ); +} + +export default AddVariableCondition; diff --git a/web/src/components/Playbooks/task/taskConfiguration/bulkTasks/ExecutionVarFieldSelection.tsx b/web/src/components/Playbooks/task/taskConfiguration/bulkTasks/ExecutionVarFieldSelection.tsx index 928787375..1313879b1 100644 --- a/web/src/components/Playbooks/task/taskConfiguration/bulkTasks/ExecutionVarFieldSelection.tsx +++ b/web/src/components/Playbooks/task/taskConfiguration/bulkTasks/ExecutionVarFieldSelection.tsx @@ -6,6 +6,7 @@ import { isCSV } from "../../../../../utils/common/isCSV"; import { updateCardById } from "../../../../../utils/execution/updateCardById"; import useCurrentTask from "../../../../../hooks/playbooks/task/useCurrentTask"; import useIsPrefetched from "../../../../../hooks/playbooks/useIsPrefetched"; +import isJSONString from "../../../../common/CodeAccordion/utils/isJSONString"; const key = "execution_configuration.bulk_execution_var_field"; @@ -20,7 +21,11 @@ function ExecutionVarFieldSelection({ id }: ExecutionVarFieldSelectionProps) { const global_variable_set = currentPlaybook?.global_variable_set ?? {}; const variableOptions = Object.entries(global_variable_set).reduce( (acc: any, [key, value]) => { - if (isCSV(value)) { + if ( + isCSV( + isJSONString(JSON.stringify(value)) ? JSON.stringify(value) : value, + ) + ) { acc.push({ id: key, label: key, diff --git a/web/src/components/common/Conditions/types/RuleTypes.ts b/web/src/components/common/Conditions/types/RuleTypes.ts index 41004f0fa..6e5e643df 100644 --- a/web/src/components/common/Conditions/types/RuleTypes.ts +++ b/web/src/components/common/Conditions/types/RuleTypes.ts @@ -1,4 +1,5 @@ export enum RuleType { RULE = "rules", STEP_RULE = "step_rules", + VARIABLE_RULE = "variable_rules", } diff --git a/web/src/components/common/Drawers/ConditionDrawer.tsx b/web/src/components/common/Drawers/ConditionDrawer.tsx index c77adbc04..6d278b7fb 100644 --- a/web/src/components/common/Drawers/ConditionDrawer.tsx +++ b/web/src/components/common/Drawers/ConditionDrawer.tsx @@ -1,5 +1,6 @@ import AddCondition from "../../AddCondition/index.tsx"; import AddStepCondition from "../../AddStepCondition/index.tsx"; +import AddVariableCondition from "../../AddVariableCondition/index.tsx"; import CommonConditionBottom from "../Conditions/CommonConditionBottom.tsx"; import CommonConditionTop from "../Conditions/CommonConditionTop.tsx"; @@ -9,6 +10,7 @@ function ConditionDrawer() { + ); diff --git a/web/src/hooks/playbooks/useEdgeConditions.ts b/web/src/hooks/playbooks/useEdgeConditions.ts index 3288762f2..fa116b9fb 100644 --- a/web/src/hooks/playbooks/useEdgeConditions.ts +++ b/web/src/hooks/playbooks/useEdgeConditions.ts @@ -1,9 +1,9 @@ -import { addRuleToRelationByIndex } from "../../utils/conditionals/addRuleToRelationByIndex.ts"; import { ruleOptions } from "../../utils/conditionals/ruleOptions.ts"; import { useDispatch, useSelector } from "react-redux"; import { addRule, addStepRule, + addVariableRule, currentPlaybookSelector, setCurrentPlaybookKey, } from "../../store/features/playbook/playbookSlice.ts"; @@ -29,6 +29,7 @@ function useEdgeConditions(id: string, ruleSetIndex: number = 0) { const condition = relation?.condition; const rules = ruleSet?.rules ?? []; const step_rules = ruleSet?.step_rules ?? []; + const variable_rules = ruleSet?.variable_rules ?? []; const globalRule = edge?.condition?.logical_operator ?? ruleOptions[0].id; const dispatch = useDispatch(); @@ -53,6 +54,11 @@ function useEdgeConditions(id: string, ruleSetIndex: number = 0) { dispatch(addStepRule({ id: relation?.id, ruleSetIndex })); }; + const addNewVariableRule = () => { + if (!relation?.id) return; + dispatch(addVariableRule({ id: relation?.id, ruleSetIndex })); + }; + const deleteRule = (conditionIndex: number) => { const temp = structuredClone(relations ?? []); const tempEdge = temp[edgeIndex]; @@ -75,6 +81,17 @@ function useEdgeConditions(id: string, ruleSetIndex: number = 0) { setPlaybookRelations(temp); }; + const deleteVariableRule = (conditionIndex: number) => { + const temp = structuredClone(relations ?? []); + const tempEdge = temp[edgeIndex]; + if (!tempEdge.condition) return; + const tempRuleSet = tempEdge.condition.rule_sets?.[ruleSetIndex]; + tempRuleSet.variable_rules = tempRuleSet?.variable_rules?.filter( + (_, i) => i !== conditionIndex, + ); + setPlaybookRelations(temp); + }; + const handleRule = ( key: string, value: any, @@ -107,6 +124,9 @@ function useEdgeConditions(id: string, ruleSetIndex: number = 0) { case RuleType.STEP_RULE: deleteStepRule(index); break; + case RuleType.VARIABLE_RULE: + deleteVariableRule(index); + break; default: return; } @@ -121,9 +141,11 @@ function useEdgeConditions(id: string, ruleSetIndex: number = 0) { condition, rules, step_rules, + variable_rules, handleRule, addNewStepRule, addNewRule, + addNewVariableRule, handleDeleteRule, handleGlobalRule, }; diff --git a/web/src/store/features/playbook/playbookSlice.ts b/web/src/store/features/playbook/playbookSlice.ts index 2e0197d86..0f16e9b40 100644 --- a/web/src/store/features/playbook/playbookSlice.ts +++ b/web/src/store/features/playbook/playbookSlice.ts @@ -49,6 +49,7 @@ export const playbookSlice = createSlice({ removeStepRuleSetForDynamicAlert: Actions.removeStepRuleSetForDynamicAlert, duplicateStep: Actions.duplicateStep, addRelationKey: Actions.addRelationKey, + addVariableRule: Actions.addVariableRuleAction, }, }); @@ -95,6 +96,7 @@ export const { removeStepRuleSetForDynamicAlert, duplicateStep, addRelationKey, + addVariableRule, } = playbookSlice.actions; export default playbookSlice.reducer; diff --git a/web/src/store/features/playbook/slices/relations/addVariableRule.ts b/web/src/store/features/playbook/slices/relations/addVariableRule.ts new file mode 100644 index 000000000..e1b38b30d --- /dev/null +++ b/web/src/store/features/playbook/slices/relations/addVariableRule.ts @@ -0,0 +1,38 @@ +import { PayloadAction } from "@reduxjs/toolkit"; +import { PlaybookUIState, VariableRuleTypes } from "../../../../../types"; +import { OperatorOptions } from "../../../../../utils/conditionals/types/operatorOptionTypes"; +import { playbookSlice } from "../../playbookSlice"; + +export const addVariableRuleAction = ( + state: PlaybookUIState, + { + payload, + }: PayloadAction<{ + id: string; + ruleSetIndex: number; + }>, +) => { + const { id, ruleSetIndex } = payload; + const relation = state.currentPlaybook?.step_relations.find( + (e) => e.id === id, + ); + if (!relation || !relation.condition) return; + if ( + !relation.condition.rule_sets || + (relation.condition.rule_sets?.length ?? 0) === 0 + ) + playbookSlice.caseReducers.addStepRuleSet(state, { + payload: { id }, + type: "", + }); + const ruleSet = relation.condition.rule_sets[ruleSetIndex]; + if (!ruleSet.variable_rules) ruleSet.variable_rules = []; + ruleSet.variable_rules.push({ + type: VariableRuleTypes.COMPARE_GLOBAL_VARIABLE, + compare_global_variable: { + operator: OperatorOptions.EQUAL_O, + variable_name: "", + threshold: "", + }, + }); +}; diff --git a/web/src/store/features/playbook/slices/relations/index.ts b/web/src/store/features/playbook/slices/relations/index.ts index 4fc952f5b..e37c38011 100644 --- a/web/src/store/features/playbook/slices/relations/index.ts +++ b/web/src/store/features/playbook/slices/relations/index.ts @@ -7,3 +7,4 @@ export * from "./addStepRuleSetForDynamicAlert"; export * from "./addRuleForDynamicAlert"; export * from "./removeStepRuleSetForDynamicAlert"; export * from "./addRelationKey"; +export * from "./addVariableRule"; diff --git a/web/src/types/common/lowercaseString.ts b/web/src/types/common/lowercaseString.ts index ef2826bf5..466523f2f 100644 --- a/web/src/types/common/lowercaseString.ts +++ b/web/src/types/common/lowercaseString.ts @@ -1,3 +1 @@ -export type LowercaseString = T extends `${infer F}${infer R}` - ? `${Lowercase}${R}` - : T; +export type LowercaseString = Lowercase; diff --git a/web/src/types/playbooks/stepRelations.ts b/web/src/types/playbooks/stepRelations.ts index 2ea94154c..e57befcac 100644 --- a/web/src/types/playbooks/stepRelations.ts +++ b/web/src/types/playbooks/stepRelations.ts @@ -12,6 +12,10 @@ export enum StepRuleTypes { COMPARE_TIME_WITH_CRON = "COMPARE_TIME_WITH_CRON", } +export enum VariableRuleTypes { + COMPARE_GLOBAL_VARIABLE = "COMPARE_GLOBAL_VARIABLE", +} + enum RuleType { TIMESERIES = "timeseries", TABLE = "table", @@ -37,6 +41,18 @@ export type ConditionRule = { [key in RuleType]?: any; }; +export type VariableConditionRuleType = { + [key in VariableRuleTypes as LowercaseString]: { + variable_name: string; + operator: OperatorOptionType; + threshold: string; + }; +}; + +export type VariableConditionRule = { + type: VariableRuleTypes; +} & VariableConditionRuleType; + export type StepRuleType = { [key in StepRuleTypes as LowercaseString]: { operator: OperatorOptionType; @@ -51,6 +67,7 @@ export type StepRule = { export type ConditionRuleSet = { rules: ConditionRule[]; + variable_rules?: VariableConditionRule[]; step_rules?: StepRule[]; logical_operator: LogicalOperator; }; diff --git a/web/src/utils/conditionals/addVariableRuleToRelationByIndex.ts b/web/src/utils/conditionals/addVariableRuleToRelationByIndex.ts new file mode 100644 index 000000000..c1329843f --- /dev/null +++ b/web/src/utils/conditionals/addVariableRuleToRelationByIndex.ts @@ -0,0 +1,35 @@ +import { store } from "../../store/index.ts"; +import { + currentPlaybookSelector, + setCurrentPlaybookKey, +} from "../../store/features/playbook/playbookSlice.ts"; +import setNestedValue from "../common/setNestedValue.ts"; + +const playbookKey = "step_relations"; + +export function addVariableRuleToRelationByIndex( + key: string, + value: any, + index: number, + ruleIndex: number, + ruleSetIndex: number = 0, +) { + const currentPlaybook = currentPlaybookSelector(store.getState()); + const relations = currentPlaybook?.[playbookKey]; + const edges = structuredClone(relations ?? []); + if (edges.length === 0) return; + if (!edges[index] || !edges[index].condition) return; + setNestedValue( + edges[index]?.condition?.rule_sets?.[ruleSetIndex]?.variable_rules?.[ + ruleIndex + ], + key, + value, + ); + store.dispatch( + setCurrentPlaybookKey({ + key: playbookKey, + value: edges, + }), + ); +} diff --git a/web/src/utils/conditionals/handleRelationRuleChange.ts b/web/src/utils/conditionals/handleRelationRuleChange.ts index 3e13228b2..df83501b3 100644 --- a/web/src/utils/conditionals/handleRelationRuleChange.ts +++ b/web/src/utils/conditionals/handleRelationRuleChange.ts @@ -1,6 +1,7 @@ import { RuleType } from "../../components/common/Conditions/types"; import { addRuleToRelationByIndex } from "./addRuleToRelationByIndex"; import { addStepRuleToRelationByIndex } from "./addStepRuleToRelationByIndex"; +import { addVariableRuleToRelationByIndex } from "./addVariableRuleToRelationByIndex"; export const handleRelationRuleChange = ( key: string, @@ -17,6 +18,15 @@ export const handleRelationRuleChange = ( case RuleType.STEP_RULE: addStepRuleToRelationByIndex(key, value, index, ruleIndex, ruleSetIndex); break; + case RuleType.VARIABLE_RULE: + addVariableRuleToRelationByIndex( + key, + value, + index, + ruleIndex, + ruleSetIndex, + ); + break; default: return; }