Skip to content

Commit

Permalink
Merge pull request #114 from bcgov/pg-duty-error
Browse files Browse the repository at this point in the history
send error logs to pager duty endpoint
  • Loading branch information
WadeBarnes authored Oct 3, 2023
2 parents 7e46504 + cf8f72e commit a54f013
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 11 deletions.
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,18 @@ The following environment variables are defaults used by the `backup` app.
| DATABASE_NAME | my_postgres_db | Used for backward compatibility only. The name of the _default_ database target; the name of the database you want to backup. |
| DATABASE_USER | _wired to a secret_ | The username for the database(s) hosted by the database server. The deployment configuration makes the assumption you have your database credentials stored in secrets (which you should), and the key for the username is `database-user`. The name of the secret must be provided as the `DATABASE_DEPLOYMENT_NAME` parameter to the deployment configuration template. |
| DATABASE_PASSWORD | _wired to a secret_ | The password for the database(s) hosted by the database server. The deployment configuration makes the assumption you have your database credentials stored in secrets (which you should), and the key for the username is `database-password`. The name of the secret must be provided as the `DATABASE_DEPLOYMENT_NAME` parameter to the deployment configuration template. |
| FTP_URL | | The FTP server URL. If not specified, the FTP backup feature is disabled. The default value in the deployment configuration is an empty value - not specified. |
| FTP_USER | _wired to a secret_ | The username for the FTP server. The deployment configuration creates a secret with the name specified in the FTP_SECRET_KEY parameter (default: `ftp-secret`). The key for the username is `ftp-user` and the value is an empty value by default. |
| FTP_PASSWORD | _wired to a secret_ | The password for the FTP server. The deployment configuration creates a secret with the name specified in the FTP_SECRET_KEY parameter (default: `ftp-secret`). The key for the password is `ftp-password` and the value is an empty value by default. |
| S3_USER | No Default | The username for the S3 compatible object store. This may also be referred to as the "Access key" in AWS S3. |
| S3_PASSWORD | No Default | The password for the S3 compatible object store. This may also be referred to as the "Secret key" in AWS. |
| S3_ENDPOINT | None | The AWS endpoint to use for S3 compatible object storage. For OpenShift minio use `http://minio-service:9000` |
| S3_BUCKET | None | The bucket where you backups will be transferd to. |
| WEBHOOK_URL | | The URL of the webhook endpoint to use for notifications. If not specified, the webhook integration feature is disabled. The default value in the deployment configuration is an empty value - not specified. |
| ENVIRONMENT_FRIENDLY_NAME | | A friendly (human readable) name of the environment. This variable is used by the webhook integration to identify the environment from which the backup notifications originate. The default value in the deployment configuration is an empty value - not specified. |
| ENVIRONMENT_NAME | | A name or ID of the environment. This variable is used by the webhook integration to identify the environment from which the backup notifications originate. The default value in the deployment configuration is an empty value - not specified. |
| FTP_URL | | The FTP server URL. If not specified, the FTP backup feature is disabled. The default value in the deployment configuration is an empty value - not specified. |
| FTP_USER | _wired to a secret_ | The username for the FTP server. The deployment configuration creates a secret with the name specified in the FTP_SECRET_KEY parameter (default: `ftp-secret`). The key for the username is `ftp-user` and the value is an empty value by default. |
| FTP_PASSWORD | _wired to a secret_ | The password for the FTP server. The deployment configuration creates a secret with the name specified in the FTP_SECRET_KEY parameter (default: `ftp-secret`). The key for the password is `ftp-password` and the value is an empty value by default. |
| S3_USER | No Default | The username for the S3 compatible object store. This may also be referred to as the "Access key" in AWS S3. |
| S3_PASSWORD | No Default | The password for the S3 compatible object store. This may also be referred to as the "Secret key" in AWS. |
| S3_ENDPOINT | None | The AWS endpoint to use for S3 compatible object storage. For OpenShift minio use `http://minio-service:9000` |
| S3_BUCKET | None | The bucket where you backups will be transferd to. |
| PGDUTY_SVC_KEY | | PagerDuty service integration key. |
| PGDUTY_URL | | PagerDuty events API url, the default url (the default url is https://events.pagerduty.com/generic/2010-04-15/create_event.json) |
| WEBHOOK_URL | | The URL of the webhook endpoint to use for notifications. If not specified, the webhook integration feature is disabled. The default value in the deployment configuration is an empty value - not specified. |
| ENVIRONMENT_FRIENDLY_NAME | | A friendly (human readable) name of the environment. This variable is used by the webhook integration to identify the environment from which the backup notifications originate. The default value in the deployment configuration is an empty value - not specified. |
| ENVIRONMENT_NAME | | A name or ID of the environment. This variable is used by the webhook integration to identify the environment from which the backup notifications originate. The default value in the deployment configuration is an empty value - not specified. |

### backup.conf

Expand Down
29 changes: 28 additions & 1 deletion docker/backup.logging
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ function logError(){
"${ENVIRONMENT_NAME}" \
"ERROR" \
"${errorMsg}"
postMsgToPagerDuty "${errorMsg}"
)
}

Expand All @@ -98,4 +99,30 @@ function postMsgToWebhook(){
"${WEBHOOK_URL}" > /dev/null
)
}
# =================================================================================================================

function postMsgToPagerDuty(){
(
if [ -z "${PGDUTY_SVC_KEY}" ]; then
echo "Missing PagerDuty service key"
return 0
fi

if [ -z "${PGDUTY_URL}" ]; then
echo "Missing PagerDuty API url"
return 0
fi

message=$(echo -e "${1}" | tr '\n' ' ')

curl -s \
-X POST \
-H "Content-type: application/json" \
-d "{
\"service_key\": \"${PGDUTY_SVC_KEY}\",
\"event_type\": \"trigger\",
\"description\": \"${message}\"
}" \
"${PGDUTY_URL}" > /dev/null
)
}
# =================================================================================================================

0 comments on commit a54f013

Please sign in to comment.