diff --git a/software-development-optimization-terraform/outputs.tf b/software-development-optimization-terraform/outputs.tf index be2f8eb3..44fa7109 100644 --- a/software-development-optimization-terraform/outputs.tf +++ b/software-development-optimization-terraform/outputs.tf @@ -53,8 +53,20 @@ output "circleci_orb_workflow_source_id" { # value = sumologic_folder.folder.path # } -output "sumo_pagerduty_webhook_id" { - value = sumologic_connection.pagerduty_connection.*.id +output "sumo_pagerduty_v2_webhook_id" { + value = sumologic_connection.pagerduty_v2_connection.*.id +} + +output "sumo_pagerduty_v3_webhook_id" { + value = sumologic_connection.pagerduty_v3_connection.*.id +} + +output "sumo_pagerduty_v2_webhook_integration_key" { + value = pagerduty_service_integration.sumologic_v2_service.*.integration_key +} + +output "sumo_pagerduty_v3_webhook_integration_key" { + value = pagerduty_service_integration.sumologic_v3_service.*.integration_key } output "sumo_opsgenie_webhook_id" { @@ -81,10 +93,22 @@ output "opsgenie_webhook_id" { value = restapi_object.ops_to_sumo_webhook.*.id } -output "pagerduty_webhook_id" { +output "pagerduty_v2_webhook_id" { value = pagerduty_extension.sumologic_extension.*.id } +output "pagerduty_v3_service_webhook_id" { + value = pagerduty_webhook_subscription.service_webhook.*.id +} + +output "pagerduty_v3_account_webhook_id" { + value = pagerduty_webhook_subscription.account_webhook.*.id +} + +output "pagerduty_v3_team_webhook_id" { + value = pagerduty_webhook_subscription.team_webhook.*.id +} + # output "github_repo_webhook_id" { # value = "${zipmap(github_repository_webhook.github_sumologic_repo_webhook.*.repository, github_repository_webhook.github_sumologic_repo_webhook.*.id)}" # } @@ -121,8 +145,12 @@ output "jira_issues_fer_id" { value = sumologic_field_extraction_rule.jira_issues_fer.*.id } -output "pagerduty_alerts_fer_id" { - value = sumologic_field_extraction_rule.pagerduty_alerts_fer.*.id +output "pagerduty_alerts_v2_fer_id" { + value = sumologic_field_extraction_rule.pagerduty_alerts_v2_fer.*.id +} + +output "pagerduty_alerts_v3_fer_id" { + value = sumologic_field_extraction_rule.pagerduty_alerts_v3_fer.*.id } output "github_pr_fer_id" { diff --git a/software-development-optimization-terraform/pagerduty.tf b/software-development-optimization-terraform/pagerduty.tf index 26a3ebf7..f9fe696a 100644 --- a/software-development-optimization-terraform/pagerduty.tf +++ b/software-development-optimization-terraform/pagerduty.tf @@ -1,37 +1,6 @@ -# Sumo Logic - SDO Terraform - -# This script creates Webhooks to Sumo Logic in Pagerduty Services. -# Configure the Pagerduty credentials in the pagerduty.auto.tfvars. - # Configure the Pagerduty Provider + provider "pagerduty" { skip_credentials_validation = "true" - token = var.pagerduty_api_key -} - -data "pagerduty_extension_schema" "webhook" { - count = "${var.install_pagerduty}" == "collection" || "${var.install_pagerduty}" == "all" ? length(var.pagerduty_services_pagerduty_webhooks) : 0 - name = "Generic V2 Webhook" + token = var.pagerduty_api_key } - -# Create Webhook in Pagerduty -resource "pagerduty_extension" "sumologic_extension" { - count = length(data.pagerduty_extension_schema.webhook) > 0 && "${var.install_pagerduty}" == "collection" || "${var.install_pagerduty}" == "all" ? length(var.pagerduty_services_pagerduty_webhooks) : 0 - name = "Sumo Logic Webhook" - endpoint_url = sumologic_http_source.pagerduty[0].url - extension_schema = data.pagerduty_extension_schema.webhook[0].id - extension_objects = [var.pagerduty_services_pagerduty_webhooks[count.index]] -} - -data "pagerduty_vendor" "sumologic" { - count = "${var.install_pagerduty}" == "collection" || "${var.install_pagerduty}" == "all" ? length(var.pagerduty_services_pagerduty_webhooks) : 0 - name = "Sumo Logic" -} - -# We need to create Service Key for each service for Sumo Logic to Pagerduty Webhook -resource "pagerduty_service_integration" "sumologic_service" { - count = length(data.pagerduty_vendor.sumologic) > 0 && "${var.install_sumo_to_pagerduty_webhook}" ? length(var.pagerduty_services_sumo_webhooks) : 0 - name = data.pagerduty_vendor.sumologic[0].name - service = var.pagerduty_services_sumo_webhooks[count.index] - vendor = data.pagerduty_vendor.sumologic[0].id -} \ No newline at end of file diff --git a/software-development-optimization-terraform/pagerduty.auto.tfvars b/software-development-optimization-terraform/pagerdutyv2.auto.tfvars similarity index 90% rename from software-development-optimization-terraform/pagerduty.auto.tfvars rename to software-development-optimization-terraform/pagerdutyv2.auto.tfvars index c91d667e..6edca1ff 100644 --- a/software-development-optimization-terraform/pagerduty.auto.tfvars +++ b/software-development-optimization-terraform/pagerdutyv2.auto.tfvars @@ -2,7 +2,7 @@ # Configure Pagerduty credentials and parameters. # Please replace (including brackets) with your Pagerduty key, to generate the key, refer: https://support.pagerduty.com/docs/generating-api-keys#section-generating-a-general-access-rest-api-key -pagerduty_api_key = "" +pagerduty_api_key = "" # Please replace and (including > brackets) with your Pagerduty service IDs. You can get these from the URL after opening a specific service. These are used for Pagerduty to Sumo Logic webhooks. # Examples: ["P6HHD","PHGBUY"] or ["P76GFB"] pagerduty_services_pagerduty_webhooks = ["", ""] \ No newline at end of file diff --git a/software-development-optimization-terraform/pagerdutyv2.tf b/software-development-optimization-terraform/pagerdutyv2.tf new file mode 100644 index 00000000..4bb3ca1c --- /dev/null +++ b/software-development-optimization-terraform/pagerdutyv2.tf @@ -0,0 +1,31 @@ +# Sumo Logic - SDO Terraform + +# This script creates WebhooksV2 to Sumo Logic in Pagerduty Services. +# Configure the Pagerduty credentials in the pagerdutyv2.auto.tfvars. + +data "pagerduty_extension_schema" "webhook" { + count = ("${var.install_pagerduty}" == "collection" || "${var.install_pagerduty}" == "all") && "${var.install_pagerduty_version}" == "v2" ? length(var.pagerduty_services_pagerduty_webhooks) : 0 + name = "Generic V2 Webhook" +} + +# Create Webhook in Pagerduty +resource "pagerduty_extension" "sumologic_extension" { + count = length(data.pagerduty_extension_schema.webhook) > 0 && ("${var.install_pagerduty}" == "collection" || "${var.install_pagerduty}" == "all") ? length(var.pagerduty_services_pagerduty_webhooks) : 0 + name = "Sumo Logic Webhook" + endpoint_url = sumologic_http_source.pagerduty[0].url + extension_schema = data.pagerduty_extension_schema.webhook[0].id + extension_objects = [var.pagerduty_services_pagerduty_webhooks[count.index]] +} + +data "pagerduty_vendor" "sumologic" { + count = ("${var.install_pagerduty}" == "collection" || "${var.install_pagerduty}" == "all") && "${var.install_pagerduty_version}" == "v2" ? length(var.pagerduty_services_pagerduty_webhooks) : 0 + name = "Sumo Logic" +} + +# We need to create Service Key for each service for Sumo Logic to Pagerduty Webhook +resource "pagerduty_service_integration" "sumologic_v2_service" { + count = length(data.pagerduty_vendor.sumologic) > 0 && "${var.install_sumo_to_pagerduty_webhook}" ? length(var.pagerduty_services_sumo_webhooks) : 0 + name = data.pagerduty_vendor.sumologic[0].name + service = var.pagerduty_services_sumo_webhooks[count.index] + vendor = data.pagerduty_vendor.sumologic[0].id +} \ No newline at end of file diff --git a/software-development-optimization-terraform/pagerdutyv3.auto.tfvars b/software-development-optimization-terraform/pagerdutyv3.auto.tfvars new file mode 100644 index 00000000..92ef1467 --- /dev/null +++ b/software-development-optimization-terraform/pagerdutyv3.auto.tfvars @@ -0,0 +1,12 @@ +# Sumo Logic - SDO Terraform +# Configure Pagerduty credentials and parameters. + +# Please replace (including brackets) with your Pagerduty key, to generate the key, refer: https://support.pagerduty.com/docs/generating-api-keys#section-generating-a-general-access-rest-api-key +pagerduty_api_key = "" +# Please replace and (including > brackets) with your Pagerduty service IDs. You can get these from the URL after opening a specific service. These are used for Pagerduty to Sumo Logic webhooks. +# Examples: ["P6HHD","PHGBUY"] or ["P76GFB"] +create_services_webhooks = ["", ""] +# Please replace blank string with true so as to send Pagerduty account events via the webhook to Sumo. +create_account_webhook = false +# Please replace and (including > brackets) with your Pagerduty team IDs. +create_teams_webhooks = ["", ""] \ No newline at end of file diff --git a/software-development-optimization-terraform/pagerdutyv3.tf b/software-development-optimization-terraform/pagerdutyv3.tf new file mode 100644 index 00000000..eca2645c --- /dev/null +++ b/software-development-optimization-terraform/pagerdutyv3.tf @@ -0,0 +1,131 @@ +# Sumo Logic - SDO Terraform + +# This script creates WebhooksV3 to Sumo Logic in Pagerduty Services, Account and Teams. +# Configure the Pagerduty credentials in the pagerdutyv3.auto.tfvars. + +# Create v3 webhook for service/services in PagerDuty +resource "pagerduty_webhook_subscription" "service_webhook" { + count = (("${var.install_pagerduty}" == "collection" || "${var.install_pagerduty}" == "all") && "${var.install_pagerduty_version}" == "v3") ? length(var.create_services_webhooks) : 0 + delivery_method { + type = "http_delivery_method" + url = sumologic_http_source.pagerduty[0].url + } + description = "Sends PagerDuty v3 webhook events to Sumo" + events = [ + "incident.acknowledged", + "incident.annotated", + "incident.delegated", + "incident.escalated", + "incident.priority_updated", + "incident.reassigned", + "incident.reopened", + "incident.resolved", + "incident.responder.added", + "incident.responder.replied", + "incident.status_update_published", + "incident.triggered", + "incident.unacknowledged", + "service.created", + "service.deleted", + "service.updated" + ] + active = true + filter { + id = var.create_services_webhooks[count.index] + type = "service_reference" + } + type = "webhook_subscription" +} + +# Send service level alerts to PagerDuty +data "pagerduty_vendor" "v3_service_sumologic" { + count = (("${var.install_pagerduty}" == "collection" || "${var.install_pagerduty}" == "all") && "${var.install_pagerduty_version}" == "v3") ? length(var.create_services_webhooks) : 0 + name = "Sumo Logic" +} + +# We need to create Service Key for each service for Sumo Logic to Pagerduty Webhook +resource "pagerduty_service_integration" "sumologic_v3_service" { + count = length(data.pagerduty_vendor.v3_service_sumologic) > 0 && "${var.install_sumo_to_pagerduty_webhook}" ? length(var.pagerduty_services_sumo_webhooks) : 0 + name = data.pagerduty_vendor.v3_service_sumologic[0].name + service = var.pagerduty_services_sumo_webhooks[count.index] + vendor = data.pagerduty_vendor.v3_service_sumologic[0].id +} + +# Create v3 webhook for account in PagerDuty +resource "pagerduty_webhook_subscription" "account_webhook" { + count = (("${var.install_pagerduty}" == "collection" || "${var.install_pagerduty}" == "all") && "${var.install_pagerduty_version}" == "v3") ? ("${var.create_account_webhook}" == true ? 1 : 0) : 0 + delivery_method { + type = "http_delivery_method" + url = sumologic_http_source.pagerduty[0].url + } + description = "Sends PagerDuty v3 webhook events to Sumo" + events = [ + "incident.acknowledged", + "incident.annotated", + "incident.delegated", + "incident.escalated", + "incident.priority_updated", + "incident.reassigned", + "incident.reopened", + "incident.resolved", + "incident.responder.added", + "incident.responder.replied", + "incident.status_update_published", + "incident.triggered", + "incident.unacknowledged", + "service.created", + "service.deleted", + "service.updated" + ] + active = true + filter { + type = "account_reference" + } + type = "webhook_subscription" +} + +# TODO for account level alerts +# data "pagerduty_vendor" "v3_account_sumologic" { +# count = (("${var.install_pagerduty}" == "collection" || "${var.install_pagerduty}" == "all") && "${var.install_pagerduty_version}" == "v3" && "${var.create_account_webhook}") == "yes" ? 1 : 0 +# name = "Sumo Logic" +# } + +# Create v3 webhook for team/teams in PagerDuty +resource "pagerduty_webhook_subscription" "team_webhook" { + count = (("${var.install_pagerduty}" == "collection" || "${var.install_pagerduty}" == "all") && "${var.install_pagerduty_version}" == "v3") ? length(var.create_teams_webhooks) : 0 + delivery_method { + type = "http_delivery_method" + url = sumologic_http_source.pagerduty[0].url + } + description = "Sends PagerDuty v3 webhook events to Sumo" + events = [ + "incident.acknowledged", + "incident.annotated", + "incident.delegated", + "incident.escalated", + "incident.priority_updated", + "incident.reassigned", + "incident.reopened", + "incident.resolved", + "incident.responder.added", + "incident.responder.replied", + "incident.status_update_published", + "incident.triggered", + "incident.unacknowledged", + "service.created", + "service.deleted", + "service.updated" + ] + active = true + filter { + id = var.create_teams_webhooks[count.index] + type = "team_reference" + } + type = "webhook_subscription" +} + +# TODO for team level alerts +# data "pagerduty_vendor" "v3_team_sumologic" { +# count = (("${var.install_pagerduty}" == "collection" || "${var.install_pagerduty}" == "all") && "${var.install_pagerduty_version}" == "v3") ? length(var.create_teams_webhooks) : 0 +# name = "Sumo Logic" +# } diff --git a/software-development-optimization-terraform/providers.tf b/software-development-optimization-terraform/providers.tf index 4eaf996f..5bf08ae9 100644 --- a/software-development-optimization-terraform/providers.tf +++ b/software-development-optimization-terraform/providers.tf @@ -6,8 +6,8 @@ terraform { template = "~> 2.1" # jira = "~> 0.1.11" github = "~> 2.8" - pagerduty = "~> 1.7" + pagerduty = "~> 2.3" sumologic = "~> 2.1.0" - gitlab ="3.6.0" + gitlab = "3.6.0" } } \ No newline at end of file diff --git a/software-development-optimization-terraform/sdo_app_artifacts/sdo_fer.txt b/software-development-optimization-terraform/sdo_app_artifacts/sdo_fer.txt index 0df6d3dd..071c9f77 100644 --- a/software-development-optimization-terraform/sdo_app_artifacts/sdo_fer.txt +++ b/software-development-optimization-terraform/sdo_app_artifacts/sdo_fer.txt @@ -205,7 +205,7 @@ commit_id, reviewers, updated_date, head_commit_id nodrop | if (alert_type matches "*Create", "alert_created", if(alert_type matches "*Close", "alert_closed", "other") ) as event_type " }, - "PagerDuty": { + "PagerDutyV2": { "Scope": "_sourcecategory=Labs/pagerduty_v2 ("incident.trigger" or "incident.resolve" )", "Parse": "parse regex "(?\{\"event\":\"incident\..+?\}(?=,\{\"event\":\"incident\..+|\]\}$))" |json field=event "event", "created_on", "incident" as alert_type, @@ -220,6 +220,18 @@ link | if (alert_type matches "*trigger", "alert_created", if(alert_type matches "*resolve", "alert_closed", "other") ) as event_type " } + "PagerDutyV3":{ + "Scope": "_sourceCategory=Labs/pagerduty_v3 ("incident.triggered" or "incident.resolved")", + "Parse": "json "event.event_type","event.data","event.occurred_at" as alert_type,incident,closeddate nodrop +| json field=incident "id", "service.summary" , "urgency", +"teams[*].summary", "html_url","created_at" as alert_id, service, priority, team, +link,dateTime nodrop +| where alert_type in ("incident.triggered", "incident.resolved") +| parseDate(closeddate, "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'","etc/utc") as closeddate_epoch +| parse regex field=dateTime "(?.{19})" +| parseDate(dateTime,"yyyy-MM-dd'T'HH:mm:ss","etc/utc") as dateTime_epoch +| if (alert_type matches "*triggered", "alert_created", if(alert_type matches "*resolved", "alert_closed", "other") ) as event_type" + } } }, { diff --git a/software-development-optimization-terraform/sumologic.auto.tfvars b/software-development-optimization-terraform/sumologic.auto.tfvars index 1e69f359..513ceec8 100644 --- a/software-development-optimization-terraform/sumologic.auto.tfvars +++ b/software-development-optimization-terraform/sumologic.auto.tfvars @@ -28,6 +28,7 @@ install_jira_server = "all" install_bitbucket_cloud = "all" install_opsgenie = "all" install_pagerduty = "all" +install_pagerduty_version = "v3" install_github = "all" install_gitlab = "all" install_jenkins = "all" diff --git a/software-development-optimization-terraform/sumologic_collection_content.tf b/software-development-optimization-terraform/sumologic_collection_content.tf index bb318105..fb23de4e 100644 --- a/software-development-optimization-terraform/sumologic_collection_content.tf +++ b/software-development-optimization-terraform/sumologic_collection_content.tf @@ -132,7 +132,7 @@ locals { resource "null_resource" "create_folder" { depends_on = [sumologic_collector.sdo_collector] triggers = { - version = var.folder_version + version = var.folder_version } provisioner "local-exec" { command = <.+?)\\\",\\\"\" \n| \"n/a\" as team\n| json \"issue.fields.resolutiondate\", \"issue.fields.created\" as closedDate, dateTime \n| parseDate(dateTime, \"yyyy-MM-dd'T'HH:mm:ss.SSSZ\") as datetime_epoch\n| if (isNull(closeddate) , 00000000000, parseDate(closedDate, \"yyyy-MM-dd'T'HH:mm:ss.SSSZ\") ) as closeddate_epoch\n| toLong(closeddate_epoch)\n| \"issue\" as event_type\n" -pagerduty_alerts_fer_scope = "(\"incident.trigger\" or \"incident.resolve\" )" -pagerduty_alerts_fer_parse = "parse regex \"(?\\{\\\"event\\\":\\\"incident\\..+?\\}(?=,\\{\\\"event\\\":\\\"incident\\..+|\\]\\}$))\" \n|json field=event \"event\", \"created_on\", \"incident\" as alert_type,\ndateTime, incident\n|json field=incident \"id\", \"service.name\" , \"urgency\",\n\"teams[0].summary\", \"html_url\" as alert_id, service, priority, team,\nlink\n|json field=incident \"created_at\" as closeddate nodrop\n| where alert_type in (\"incident.trigger\", \"incident.resolve\")\n| parseDate(dateTime, \"yyyy-MM-dd'T'HH:mm:ss'Z'\") as dateTime_epoch\n| parseDate(closeddate, \"yyyy-MM-dd'T'HH:mm:ss'Z'\") as closeddate_epoch\n| if (alert_type matches \"*trigger\", \"alert_created\", if(alert_type matches \"*resolve\", \"alert_closed\", \"other\") ) as event_type\n" +pagerduty_alerts_v2_fer_scope = "(\"incident.trigger\" or \"incident.resolve\" )" +pagerduty_alerts_v2_fer_parse = "parse regex \"(?\\{\\\"event\\\":\\\"incident\\..+?\\}(?=,\\{\\\"event\\\":\\\"incident\\..+|\\]\\}$))\" \n|json field=event \"event\", \"created_on\", \"incident\" as alert_type,\ndateTime, incident\n|json field=incident \"id\", \"service.name\" , \"urgency\",\n\"teams[0].summary\", \"html_url\" as alert_id, service, priority, team,\nlink\n|json field=incident \"created_at\" as closeddate nodrop\n| where alert_type in (\"incident.trigger\", \"incident.resolve\")\n| parseDate(dateTime, \"yyyy-MM-dd'T'HH:mm:ss'Z'\") as dateTime_epoch\n| parseDate(closeddate, \"yyyy-MM-dd'T'HH:mm:ss'Z'\") as closeddate_epoch\n| if (alert_type matches \"*trigger\", \"alert_created\", if(alert_type matches \"*resolve\", \"alert_closed\", \"other\") ) as event_type\n" + +pagerduty_alerts_v3_fer_scope = "(\"incident.triggered\" or \"incident.resolved\")" +pagerduty_alerts_v3_fer_parse = "json \"event.event_type\",\"event.data\",\"event.occurred_at\" as alert_type,incident,closeddate nodrop\n| json field=incident \"id\", \"service.summary\" , \"urgency\",\n\"teams[*].summary\", \"html_url\",\"created_at\" as alert_id, service, priority, team,\nlink,dateTime nodrop\n| where alert_type in (\"incident.triggered\", \"incident.resolved\")\n| parseDate(closeddate, \"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'\",\"etc/utc\") as closeddate_epoch\n| parse regex field=dateTime \"(?.{19})\"\n| parseDate(dateTime,\"yyyy-MM-dd'T'HH:mm:ss\",\"etc/utc\") as dateTime_epoch\n| if (alert_type matches \"*triggered\", \"alert_created\", if(alert_type matches \"*resolved\", \"alert_closed\", \"other\") ) as event_type\n" gitlab_pull_request_fer_scope = " %\"x-gitlab-event\"=\"Merge Request Hook\" " gitlab_pull_request_fer_parse = "json \"object_attributes.action\",\"object_attributes.state\" ,\"object_attributes.title\", \"object_attributes.created_at\",\"object_attributes.updated_at\",\"user.name\",\"project.name\",\"object_attributes.target_branch\" ,\"object_attributes.url\",\"assignees[*].name\",\"object_attributes.merge_commit_sha\",\"repository.name\",\"project.path_with_namespace\",\"object_attributes.last_commit.id\" as action,status, title,createddatetime, updateddatetime_epoch,user,project_name,target_branch,link,reviewers,commit_id,repository_name,team, head_commit_id nodrop\n| parse regex field=team \"(?.+)\\/.+\" \n| if (status matches \"opened\", \"created\", if(status matches \"merged\", \"merged\", if(status matches \"closed\", \"declined\", \"other\"))) as status\n| parseDate(createddatetime, \"yyyy-MM-dd HH:mm:ss\",\"etc/utc\") as datetime_epoch\n| parseDate(updateddatetime_epoch, \"yyyy-MM-dd HH:mm:ss\",\"etc/utc\") as updateddatetime_epoch\n|if(status in (\"declined\",\"merged\") ,updateddatetime_epoch,000000000)as closeddate_epoch\n| project_name as service\n| toLong(datetime_epoch)\n| toLong(closeddate_epoch)\n| \"pull_request\" as event_type\n" @@ -48,11 +51,11 @@ gitlab_deploy_request_fer_parse = "json \"deployment_id\",\"status\",\"status_ch gitlab_issue_request_fer_scope = " %\"x-gitlab-event\"=\"Issue Hook\" " gitlab_issue_request_fer_parse = "json \"user.name\",\"project.name\",\"object_attributes.created_at\",\"object_attributes.url\",\"labels[*].title\",\"object_attributes.state\",\"object_attributes.severity\",\"object_attributes.action\",\"repository.name\",\"assignees[*].name\",\"object_attributes.id\",\"object_attributes.closed_at\",\"project.path_with_namespace\" as user,project_name,dateTime,link,issue_type,issue_status,priority,issue_event_type,repository,assignees,issue_key,closedDate,team nodrop\n| parse regex field=team \"(?.+)\\/.+\" \n| project_name as service\n| substring(issue_type,1,length(issue_type)-1) as issue_type\n|if (issue_type matches \"*incident*\",\"incident\",\"issue\") as issue_type\n| parseDate(datetime, \"yyyy-MM-dd HH:mm:ss\",\"etc/utc\") as datetime_epoch\n| if (isNull(closeddate) , 00000000000, parseDate(closedDate, \"yyyy-MM-dd HH:mm:ss\",\"etc/utc\")) as closeddate_epoch\n| if(issue_status matches \"opened\",\"To Do\",if(issue_status matches \"closed\",\"Complete\",issue_status)) as issue_status\n| toLong(datetime_epoch) as datetime_epoch\n| toLong(closeddate_epoch) as closeddate_epoch\n| \"issue\" as event_type\n" -gitlab_push_fer_scope = " %\"x-gitlab-event\" = \"Push Hook\"" +gitlab_push_fer_scope = " %\"x-gitlab-event\" = \"Push Hook\"" gitlab_push_fer_parse = "json \"commits[(@.length-2)].id\" as head_commit_id\n| json \"commits[(@.length-2)].timestamp\" as head_commit_datetime\n| json \"commits[(@.length-2)].message\" as head_commit_message\n| parseDate(head_commit_datetime, \"yyyy-MM-dd'T'HH:mm:ssXXX\",\"etc/utc\") as head_commit_epoch\n| json \"commits[0].id\" as base_commit_id\n| json \"commits[0].timestamp\" as base_commit_datetime\n| json \"commits[0].message\" as base_commit_message\n| parseDate(base_commit_datetime, \"yyyy-MM-dd'T'HH:mm:ssXXX\",\"etc/utc\") as base_commit_epoch\n| json \"repository.name\",\"user_name\" as repository_name,user\n| \"push\" as event_type\n" circleci_build_fer_scope = "circleci/job-collector\n" circleci_build_fer_parse = "json \"workflows.job_name\" as job_type\n|where toLowerCase(job_type) matches \"BUILDJOBNAME\" \n|json \"custom_data.env\",\"custom_data.team\",\"custom_data.service\",\"workflows.job_id\",\"user.login\",\"build_url\",\"start_time\",\"branch\",\"outcome\",\"reponame\",\"vcs_revision\",\"job_name\",\"build_num\",\"messages\" as environment_name,team,service,trace_id,user,link,datetime,target_branch,job_status,repository_name,commit_id,job_name,build_number,message nodrop\n| if(job_status == \"success\", \"Success\", \"Failed\") as status\n| toLong(parseDate(datetime, \"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'\")) as datetime_epoch\n| concat(job_type, \" # \",build_number) as title\n|\"build\" as event_type" circleci_deploy_fer_scope = "circleci/job-collector\n" -circleci_deploy_fer_parse = "json \"workflows.job_name\" as job_type\n|where toLowerCase(job_type) matches (\"DEPLOYJOBNAME\")\n|json \"custom_data.env\",\"custom_data.team\",\"custom_data.service\",\"workflows.job_id\",\"user.login\",\"build_url\",\"start_time\",\"branch\",\"outcome\",\"reponame\",\"vcs_revision\",\"job_name\",\"messages\",\"build_num\" as environment_name,team,service,trace_id,user,link,datetime,target_branch,job_status,repository_name,commit_id,job_name,message,job_num nodrop\n| if(job_status == \"success\", \"Success\", \"Failed\") as status\n| toLong(parseDate(datetime, \"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'\",\"etc/utc\")) as datetime_epoch\n| concat(job_type, \" # \",job_num) as title\n|\"deploy\" as event_type\n" +circleci_deploy_fer_parse = "json \"workflows.job_name\" as job_type\n|where toLowerCase(job_type) matches (\"DEPLOYJOBNAME\")\n|json \"custom_data.env\",\"custom_data.team\",\"custom_data.service\",\"workflows.job_id\",\"user.login\",\"build_url\",\"start_time\",\"branch\",\"outcome\",\"reponame\",\"vcs_revision\",\"job_name\",\"messages\",\"build_num\" as environment_name,team,service,trace_id,user,link,datetime,target_branch,job_status,repository_name,commit_id,job_name,message,job_num nodrop\n| if(job_status == \"success\", \"Success\", \"Failed\") as status\n| toLong(parseDate(datetime, \"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'\",\"etc/utc\")) as datetime_epoch\n| concat(job_type, \" # \",job_num) as title\n|\"deploy\" as event_type\n" diff --git a/software-development-optimization-terraform/sumologic_fer.tf b/software-development-optimization-terraform/sumologic_fer.tf index abdf23fa..94836d56 100644 --- a/software-development-optimization-terraform/sumologic_fer.tf +++ b/software-development-optimization-terraform/sumologic_fer.tf @@ -2,7 +2,7 @@ resource "sumologic_field_extraction_rule" "github_pr_fer" { count = "${var.install_github}" == "fer" || "${var.install_github}" == "collection" || "${var.install_github}" == "all" ? 1 : 0 - depends_on = [sumologic_http_source.github,restapi_object.github_field] + depends_on = [sumologic_http_source.github, restapi_object.github_field] name = "SDO - Github Pull Request" scope = "_sourceCategory=${var.github_sc} ${var.github_pull_request_fer_scope}" parse_expression = var.github_pull_request_fer_parse @@ -11,7 +11,7 @@ resource "sumologic_field_extraction_rule" "github_pr_fer" { resource "sumologic_field_extraction_rule" "github_push_fer" { count = "${var.install_github}" == "fer" || "${var.install_github}" == "collection" || "${var.install_github}" == "all" ? 1 : 0 - depends_on = [sumologic_http_source.github,restapi_object.github_field] + depends_on = [sumologic_http_source.github, restapi_object.github_field] name = "SDO - Github Push" scope = "_sourceCategory=${var.github_sc} ${var.github_push_fer_scope}" parse_expression = var.github_push_fer_parse @@ -55,7 +55,7 @@ resource "sumologic_field_extraction_rule" "opsgenie_alerts_fer" { resource "sumologic_field_extraction_rule" "bitbucket_pr_fer" { count = "${var.install_bitbucket_cloud}" == "fer" || "${var.install_bitbucket_cloud}" == "collection" || "${var.install_bitbucket_cloud}" == "all" ? 1 : 0 - depends_on = [sumologic_http_source.bitbucket_cloud,restapi_object.bitbucket_field] + depends_on = [sumologic_http_source.bitbucket_cloud, restapi_object.bitbucket_field] name = "SDO - Bitbucket Pull Request" scope = "_sourceCategory=${var.bitbucket_sc} ${var.bitbucket_pull_request_fer_scope}" parse_expression = var.bitbucket_pull_request_fer_parse @@ -64,7 +64,7 @@ resource "sumologic_field_extraction_rule" "bitbucket_pr_fer" { resource "sumologic_field_extraction_rule" "bitbucket_build_fer" { count = "${var.install_bitbucket_cloud}" == "fer" || "${var.install_bitbucket_cloud}" == "collection" || "${var.install_bitbucket_cloud}" == "all" ? 1 : 0 - depends_on = [sumologic_http_source.bitbucket_cloud,restapi_object.bitbucket_field] + depends_on = [sumologic_http_source.bitbucket_cloud, restapi_object.bitbucket_field] name = "SDO - Bitbucket Build" scope = "_sourceCategory=${var.bitbucket_sc} ${var.bitbucket_build_fer_scope}" parse_expression = var.bitbucket_build_fer_parse @@ -73,7 +73,7 @@ resource "sumologic_field_extraction_rule" "bitbucket_build_fer" { resource "sumologic_field_extraction_rule" "bitbucket_deploy_fer" { count = "${var.install_bitbucket_cloud}" == "fer" || "${var.install_bitbucket_cloud}" == "collection" || "${var.install_bitbucket_cloud}" == "all" ? 1 : 0 - depends_on = [sumologic_http_source.bitbucket_cloud,restapi_object.bitbucket_field] + depends_on = [sumologic_http_source.bitbucket_cloud, restapi_object.bitbucket_field] name = "SDO - Bitbucket Deploy" scope = "_sourceCategory=${var.bitbucket_sc} ${var.bitbucket_deploy_fer_scope}" parse_expression = var.bitbucket_deploy_fer_parse @@ -82,7 +82,7 @@ resource "sumologic_field_extraction_rule" "bitbucket_deploy_fer" { resource "sumologic_field_extraction_rule" "bitbucket_push_fer" { count = "${var.install_bitbucket_cloud}" == "fer" || "${var.install_bitbucket_cloud}" == "collection" || "${var.install_bitbucket_cloud}" == "all" ? 1 : 0 - depends_on = [sumologic_http_source.bitbucket_cloud,restapi_object.bitbucket_field] + depends_on = [sumologic_http_source.bitbucket_cloud, restapi_object.bitbucket_field] name = "SDO - Bitbucket Push" scope = "_sourceCategory=${var.bitbucket_sc} ${var.bitbucket_push_fer_scope}" parse_expression = var.bitbucket_push_fer_parse @@ -97,18 +97,27 @@ resource "sumologic_field_extraction_rule" "jira_issues_fer" { enabled = true } -resource "sumologic_field_extraction_rule" "pagerduty_alerts_fer" { - count = "${var.install_pagerduty}" == "fer" || "${var.install_pagerduty}" == "collection" || "${var.install_pagerduty}" == "all" ? 1 : 0 +resource "sumologic_field_extraction_rule" "pagerduty_alerts_v2_fer" { + count = ("${var.install_pagerduty}" == "fer" || "${var.install_pagerduty}" == "collection" || "${var.install_pagerduty}" == "all") && "${var.install_pagerduty_version}" == "v2" ? 1 : 0 depends_on = [sumologic_http_source.pagerduty] - name = "SDO - Pagerduty Alerts" - scope = "_sourceCategory=${var.pagerduty_sc} ${var.pagerduty_alerts_fer_scope}" - parse_expression = var.pagerduty_alerts_fer_parse + name = "SDO - Pagerduty V2 Alerts" + scope = "_sourceCategory=${var.pagerduty_sc} ${var.pagerduty_alerts_v2_fer_scope}" + parse_expression = var.pagerduty_alerts_v2_fer_parse + enabled = true +} + +resource "sumologic_field_extraction_rule" "pagerduty_alerts_v3_fer" { + count = ("${var.install_pagerduty}" == "fer" || "${var.install_pagerduty}" == "collection" || "${var.install_pagerduty}" == "all") && "${var.install_pagerduty_version}" == "v3" ? 1 : 0 + depends_on = [sumologic_http_source.pagerduty] + name = "SDO - Pagerduty V3 Alerts" + scope = "_sourceCategory=${var.pagerduty_sc} ${var.pagerduty_alerts_v3_fer_scope}" + parse_expression = var.pagerduty_alerts_v3_fer_parse enabled = true } resource "sumologic_field_extraction_rule" "gitlab_pr_fer" { count = "${var.install_gitlab}" == "fer" || "${var.install_gitlab}" == "collection" || "${var.install_gitlab}" == "all" ? 1 : 0 - depends_on = [sumologic_http_source.gitlab,restapi_object.gitlab_field] + depends_on = [sumologic_http_source.gitlab, restapi_object.gitlab_field] name = "SDO - Gitlab Pull Request" scope = "_sourceCategory=${var.gitlab_sc} ${var.gitlab_pull_request_fer_scope}" parse_expression = var.gitlab_pull_request_fer_parse @@ -116,18 +125,18 @@ resource "sumologic_field_extraction_rule" "gitlab_pr_fer" { } resource "sumologic_field_extraction_rule" "gitlab_build_fer" { - count = "${var.install_gitlab}" == "fer" || "${var.install_gitlab}" == "collection" || "${var.install_gitlab}" == "all" ? 1 : 0 - depends_on = [sumologic_http_source.gitlab,restapi_object.gitlab_field] - name = "SDO - Gitlab Build" - scope = "_sourceCategory=${var.gitlab_sc} ${var.gitlab_build_request_fer_scope}" + count = "${var.install_gitlab}" == "fer" || "${var.install_gitlab}" == "collection" || "${var.install_gitlab}" == "all" ? 1 : 0 + depends_on = [sumologic_http_source.gitlab, restapi_object.gitlab_field] + name = "SDO - Gitlab Build" + scope = "_sourceCategory=${var.gitlab_sc} ${var.gitlab_build_request_fer_scope}" #parse_expression = var.gitlab_build_request_fer_parse - parse_expression = replace(var.gitlab_build_request_fer_parse,"Gitlab_Build_Job_Name",var.gitlab_build_jobname) + parse_expression = replace(var.gitlab_build_request_fer_parse, "Gitlab_Build_Job_Name", var.gitlab_build_jobname) enabled = true } resource "sumologic_field_extraction_rule" "gitlab_deploy_fer" { count = "${var.install_gitlab}" == "fer" || "${var.install_gitlab}" == "collection" || "${var.install_gitlab}" == "all" ? 1 : 0 - depends_on = [sumologic_http_source.gitlab,restapi_object.gitlab_field] + depends_on = [sumologic_http_source.gitlab, restapi_object.gitlab_field] name = "SDO - Gitlab Deploy" scope = "_sourceCategory=${var.gitlab_sc} ${var.gitlab_deploy_request_fer_scope}" parse_expression = var.gitlab_deploy_request_fer_parse @@ -136,7 +145,7 @@ resource "sumologic_field_extraction_rule" "gitlab_deploy_fer" { resource "sumologic_field_extraction_rule" "gitlab_issue_fer" { count = "${var.install_gitlab}" == "fer" || "${var.install_gitlab}" == "collection" || "${var.install_gitlab}" == "all" ? 1 : 0 - depends_on = [sumologic_http_source.gitlab,restapi_object.gitlab_field] + depends_on = [sumologic_http_source.gitlab, restapi_object.gitlab_field] name = "SDO - Gitlab Issue" scope = "_sourceCategory=${var.gitlab_sc} ${var.gitlab_issue_request_fer_scope}" parse_expression = var.gitlab_issue_request_fer_parse @@ -145,7 +154,7 @@ resource "sumologic_field_extraction_rule" "gitlab_issue_fer" { resource "sumologic_field_extraction_rule" "gitlab_push_fer" { count = "${var.install_gitlab}" == "fer" || "${var.install_gitlab}" == "collection" || "${var.install_gitlab}" == "all" ? 1 : 0 - depends_on = [sumologic_http_source.gitlab,restapi_object.gitlab_field] + depends_on = [sumologic_http_source.gitlab, restapi_object.gitlab_field] name = "SDO - Gitlab Push" scope = "_sourceCategory=${var.gitlab_sc} ${var.gitlab_push_fer_scope}" parse_expression = var.gitlab_push_fer_parse @@ -157,7 +166,7 @@ resource "sumologic_field_extraction_rule" "circleci_orb_build_fer" { depends_on = [sumologic_http_source.circleci_orb_job] name = "SDO - CircleCi Build " scope = "_sourceCategory=${var.circleci_build_fer_scope}" - parse_expression = replace(var.circleci_build_fer_parse,"BUILDJOBNAME",var.circleci_build_jobname) + parse_expression = replace(var.circleci_build_fer_parse, "BUILDJOBNAME", var.circleci_build_jobname) enabled = true } @@ -166,6 +175,6 @@ resource "sumologic_field_extraction_rule" "circleci_orb_deploy_fer" { depends_on = [sumologic_http_source.circleci_orb_job] name = "SDO - CircleCi Deploy " scope = "_sourceCategory=${var.circleci_deploy_fer_scope}" - parse_expression = replace(var.circleci_deploy_fer_parse,"DEPLOYJOBNAME",var.circleci_deploy_jobname) + parse_expression = replace(var.circleci_deploy_fer_parse, "DEPLOYJOBNAME", var.circleci_deploy_jobname) enabled = true } \ No newline at end of file diff --git a/software-development-optimization-terraform/sumologic_webhooks.tf b/software-development-optimization-terraform/sumologic_webhooks.tf index 29912ba5..4feef8fe 100644 --- a/software-development-optimization-terraform/sumologic_webhooks.tf +++ b/software-development-optimization-terraform/sumologic_webhooks.tf @@ -2,7 +2,7 @@ # Configure the Sumo Logic credentials in the sumologic.auto.tvars and other system credentials in respective files. # Create/Delete Sumo Logic to Pagerduty Webhook -resource "sumologic_connection" "pagerduty_connection" { +resource "sumologic_connection" "pagerduty_v2_connection" { count = length(data.pagerduty_vendor.sumologic) > 0 && "${var.install_sumo_to_pagerduty_webhook}" ? length(var.pagerduty_services_sumo_webhooks) : 0 type = "WebhookConnection" name = "Pagerduty Connection for Service - ${var.pagerduty_services_sumo_webhooks[count.index]}" @@ -14,7 +14,29 @@ resource "sumologic_connection" "pagerduty_connection" { default_payload = < 0 && "${var.install_sumo_to_pagerduty_webhook}" ? length(var.pagerduty_services_sumo_webhooks) : 0 + type = "WebhookConnection" + name = "Pagerduty Connection for Service - ${var.pagerduty_services_sumo_webhooks[count.index]}" + description = "Created via Sumo Logic SDO Terraform Script." + url = "https://events.pagerduty.com/generic/2010-04-15/create_event.json" + headers = { + "X-Header" : "Token token=${var.pagerduty_api_key}" + } + + default_payload = <