Skip to content

Commit

Permalink
Merge pull request #2879 from flexera-public/task/update-meta-parent-…
Browse files Browse the repository at this point in the history
…policy-templates

Co-authored-by: bryankaraffa <[email protected]>
  • Loading branch information
bryankaraffa and bryankaraffa authored Dec 11, 2024
2 parents 47d261f + 1d7d7cf commit f85894d
Show file tree
Hide file tree
Showing 3 changed files with 345 additions and 21 deletions.
123 changes: 115 additions & 8 deletions cost/aws/schedule_instance/aws_schedule_instance_meta_parent.pt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ category "Meta"
default_frequency "15 minutes"
info(
provider: "AWS",
version: "7.0.3", # This version of the Meta Parent Policy Template should match the version of the Child Policy Template as it appears in the Catalog for best reliability
version: "7.1.0", # This version of the Meta Parent Policy Template should match the version of the Child Policy Template as it appears in the Catalog for best reliability
publish: "true",
deprecated: "false",
hide_skip_approvals: "true"
Expand Down Expand Up @@ -117,8 +117,8 @@ parameter "param_automatic_action" do
category "Actions"
label "Automatic Actions"
description "When this value is set, this policy will automatically take the selected action(s)"
allowed_values ["Execute Schedules"]
default ["Execute Schedules"]
allowed_values ["Execute Schedules", "Start Notification", "Stop Notification", "Error Notification"]
default ["Execute Schedules", "Start Notification", "Stop Notification", "Error Notification"] # Schedules enabled by default because resource label required to action. Can be disabled by removing from list which is helpful for debugging / manual triggers.
end

###############################################################################
Expand Down Expand Up @@ -847,6 +847,72 @@ datasource "ds_child_incident_details" do
end
end

datasource "ds_policy_incident_action_failed_details_combined_incidents" do
run_script $js_ds_policy_incident_action_failed_details_combined_incidents, $ds_child_incident_details
end

script "js_ds_policy_incident_action_failed_details_combined_incidents", type: "javascript" do
parameters "ds_child_incident_details"
result "result"
code <<-EOS
result = []
_.each(ds_child_incident_details, function(incident) {
s = incident["summary"];
// If the incident summary contains "Failed Actions" then include it in the filter result
if (s.indexOf("Failed Actions") > -1) {
_.each(incident["violation_data"], function(violation) {
violation["incident_id"] = incident["id"];
result.push(violation);
});
}
});
EOS
end

datasource "ds_instances_schedule_result_action_start_combined_incidents" do
run_script $js_ds_instances_schedule_result_action_start_combined_incidents, $ds_child_incident_details
end

script "js_ds_instances_schedule_result_action_start_combined_incidents", type: "javascript" do
parameters "ds_child_incident_details"
result "result"
code <<-EOS
result = []
_.each(ds_child_incident_details, function(incident) {
s = incident["summary"];
// If the incident summary contains "Starting Instances" then include it in the filter result
if (s.indexOf("Starting Instances") > -1) {
_.each(incident["violation_data"], function(violation) {
violation["incident_id"] = incident["id"];
result.push(violation);
});
}
});
EOS
end

datasource "ds_instances_schedule_result_action_stop_combined_incidents" do
run_script $js_ds_instances_schedule_result_action_stop_combined_incidents, $ds_child_incident_details
end

script "js_ds_instances_schedule_result_action_stop_combined_incidents", type: "javascript" do
parameters "ds_child_incident_details"
result "result"
code <<-EOS
result = []
_.each(ds_child_incident_details, function(incident) {
s = incident["summary"];
// If the incident summary contains "Stopping Instances" then include it in the filter result
if (s.indexOf("Stopping Instances") > -1) {
_.each(incident["violation_data"], function(violation) {
violation["incident_id"] = incident["id"];
result.push(violation);
});
}
});
EOS
end

datasource "ds_instances_schedule_result_combined_incidents" do
run_script $js_ds_instances_schedule_result_combined_incidents, $ds_child_incident_details
end
Expand All @@ -858,8 +924,8 @@ script "js_ds_instances_schedule_result_combined_incidents", type: "javascript"
result = []
_.each(ds_child_incident_details, function(incident) {
s = incident["summary"];
// If the incident summary contains "AWS Scheduled EC2 Instances" then include it in the filter result
if (s.indexOf("AWS Scheduled EC2 Instances") > -1) {
// If the incident summary contains "Scheduled Instances" then include it in the filter result
if (s.indexOf("Scheduled Instances") > -1) {
_.each(incident["violation_data"], function(violation) {
violation["incident_id"] = incident["id"];
result.push(violation);
Expand Down Expand Up @@ -967,11 +1033,52 @@ end
# Could also just have one incident and use meta_status to determine which escalation happens
policy "policy_scheduled_report" do
# Consolidated Incident Check(s)
# Consolidated incident for AWS Scheduled EC2 Instances
validate $ds_instances_schedule_result_combined_incidents do
summary_template "Consolidated Incident: {{ len data }} AWS Scheduled EC2 Instances"
# Consolidated incident for Failed Actions
validate $ds_policy_incident_action_failed_details_combined_incidents do
summary_template "Consolidated Incident: {{ len data }} Failed Actions"
escalate $esc_email

check eq(size(data), 0)
export do
resource_level true
field "incident_id" do
label "Child Incident ID"
end
end
end

# Consolidated incident for Starting Instances
validate $ds_instances_schedule_result_action_start_combined_incidents do
summary_template "Consolidated Incident: {{ len data }} Starting Instances"
escalate $esc_email
escalate $esc_execute_schedules
check eq(size(data), 0)
export do
resource_level true
field "incident_id" do
label "Child Incident ID"
end
end
end

# Consolidated incident for Stopping Instances
validate $ds_instances_schedule_result_action_stop_combined_incidents do
summary_template "Consolidated Incident: {{ len data }} Stopping Instances"
escalate $esc_email
escalate $esc_execute_schedules
check eq(size(data), 0)
export do
resource_level true
field "incident_id" do
label "Child Incident ID"
end
end
end

# Consolidated incident for Scheduled Instances
validate $ds_instances_schedule_result_combined_incidents do
summary_template "Consolidated Incident: {{ len data }} Scheduled Instances"
escalate $esc_email
escalate $esc_update_schedules
escalate $esc_delete_schedules
escalate $esc_start_instances
Expand Down
126 changes: 118 additions & 8 deletions cost/azure/schedule_instance/azure_schedule_instance_meta_parent.pt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ category "Meta"
default_frequency "15 minutes"
info(
provider: "Azure",
version: "6.0.2", # This version of the Meta Parent Policy Template should match the version of the Child Policy Template as it appears in the Catalog for best reliability
version: "6.1.0", # This version of the Meta Parent Policy Template should match the version of the Child Policy Template as it appears in the Catalog for best reliability
publish: "true",
deprecated: "false",
hide_skip_approvals: "true"
Expand Down Expand Up @@ -134,8 +134,8 @@ parameter "param_automatic_action" do
category "Actions"
label "Automatic Actions"
description "When this value is set, this policy will automatically take the selected action."
allowed_values ["Execute Schedules"]
default ["Execute Schedules"]
allowed_values ["Execute Schedules", "Start Notification", "Stop Notification", "Error Notification"]
default ["Execute Schedules", "Start Notification", "Stop Notification", "Error Notification"] # Schedules enabled by default because resource label required to action. Can be disabled by removing from list which is helpful for debugging / manual triggers.
end

###############################################################################
Expand Down Expand Up @@ -874,6 +874,72 @@ datasource "ds_child_incident_details" do
end
end

datasource "ds_policy_incident_action_failed_details_combined_incidents" do
run_script $js_ds_policy_incident_action_failed_details_combined_incidents, $ds_child_incident_details
end

script "js_ds_policy_incident_action_failed_details_combined_incidents", type: "javascript" do
parameters "ds_child_incident_details"
result "result"
code <<-EOS
result = []
_.each(ds_child_incident_details, function(incident) {
s = incident["summary"];
// If the incident summary contains "Failed Actions" then include it in the filter result
if (s.indexOf("Failed Actions") > -1) {
_.each(incident["violation_data"], function(violation) {
violation["incident_id"] = incident["id"];
result.push(violation);
});
}
});
EOS
end

datasource "ds_instances_schedule_result_action_start_combined_incidents" do
run_script $js_ds_instances_schedule_result_action_start_combined_incidents, $ds_child_incident_details
end

script "js_ds_instances_schedule_result_action_start_combined_incidents", type: "javascript" do
parameters "ds_child_incident_details"
result "result"
code <<-EOS
result = []
_.each(ds_child_incident_details, function(incident) {
s = incident["summary"];
// If the incident summary contains "Starting Instances" then include it in the filter result
if (s.indexOf("Starting Instances") > -1) {
_.each(incident["violation_data"], function(violation) {
violation["incident_id"] = incident["id"];
result.push(violation);
});
}
});
EOS
end

datasource "ds_instances_schedule_result_action_stop_combined_incidents" do
run_script $js_ds_instances_schedule_result_action_stop_combined_incidents, $ds_child_incident_details
end

script "js_ds_instances_schedule_result_action_stop_combined_incidents", type: "javascript" do
parameters "ds_child_incident_details"
result "result"
code <<-EOS
result = []
_.each(ds_child_incident_details, function(incident) {
s = incident["summary"];
// If the incident summary contains "Stopping Instances" then include it in the filter result
if (s.indexOf("Stopping Instances") > -1) {
_.each(incident["violation_data"], function(violation) {
violation["incident_id"] = incident["id"];
result.push(violation);
});
}
});
EOS
end

datasource "ds_instances_schedule_result_combined_incidents" do
run_script $js_ds_instances_schedule_result_combined_incidents, $ds_child_incident_details
end
Expand All @@ -885,8 +951,8 @@ script "js_ds_instances_schedule_result_combined_incidents", type: "javascript"
result = []
_.each(ds_child_incident_details, function(incident) {
s = incident["summary"];
// If the incident summary contains "Azure Scheduled Instances" then include it in the filter result
if (s.indexOf("Azure Scheduled Instances") > -1) {
// If the incident summary contains "Scheduled Instances" then include it in the filter result
if (s.indexOf("Scheduled Instances") > -1) {
_.each(incident["violation_data"], function(violation) {
violation["incident_id"] = incident["id"];
result.push(violation);
Expand Down Expand Up @@ -994,11 +1060,52 @@ end
# Could also just have one incident and use meta_status to determine which escalation happens
policy "policy_scheduled_report" do
# Consolidated Incident Check(s)
# Consolidated incident for Azure Scheduled Instances
validate $ds_instances_schedule_result_combined_incidents do
summary_template "Consolidated Incident: {{ len data }} Azure Scheduled Instances"
# Consolidated incident for Failed Actions
validate $ds_policy_incident_action_failed_details_combined_incidents do
summary_template "Consolidated Incident: {{ len data }} Failed Actions"
escalate $esc_email

check eq(size(data), 0)
export do
resource_level true
field "incident_id" do
label "Child Incident ID"
end
end
end

# Consolidated incident for Starting Instances
validate $ds_instances_schedule_result_action_start_combined_incidents do
summary_template "Consolidated Incident: {{ len data }} Starting Instances"
escalate $esc_email
escalate $esc_execute_schedules
check eq(size(data), 0)
export do
resource_level true
field "incident_id" do
label "Child Incident ID"
end
end
end

# Consolidated incident for Stopping Instances
validate $ds_instances_schedule_result_action_stop_combined_incidents do
summary_template "Consolidated Incident: {{ len data }} Stopping Instances"
escalate $esc_email
escalate $esc_execute_schedules
check eq(size(data), 0)
export do
resource_level true
field "incident_id" do
label "Child Incident ID"
end
end
end

# Consolidated incident for Scheduled Instances
validate $ds_instances_schedule_result_combined_incidents do
summary_template "Consolidated Incident: {{ len data }} Scheduled Instances"
escalate $esc_email
escalate $esc_update_schedules
escalate $esc_delete_schedules
escalate $esc_start_instances
Expand All @@ -1007,6 +1114,9 @@ policy "policy_scheduled_report" do
check eq(size(data), 0)
export do
resource_level true
field "tenantId" do
label "Tenant ID"
end
field "accountID" do
label "Subscription ID"
end
Expand Down
Loading

0 comments on commit f85894d

Please sign in to comment.