Skip to content

Commit

Permalink
Merge pull request #12 from silinternational/sentry-notification
Browse files Browse the repository at this point in the history
Added Sentry Notification
  • Loading branch information
Praveenraj-K authored Jan 31, 2025
2 parents 851b079 + 8af4464 commit 096d8e0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ FROM alpine:3
# Variables set with ARG can be overridden at image build time with
# "--build-arg var=value". They are not available in the running container.
ARG B2_VERSION=v3.10.0
ARG SENTRY_CLI_VERSION=2.41.1

# Install b2, curl, perl, jq
# Install b2, curl, perl, jq and sentry-cli
RUN cd /tmp \
&& wget -O /usr/local/bin/b2 \
https://github.com/Backblaze/B2_Command_Line_Tool/releases/download/${B2_VERSION}/b2-linux \
&& chmod +x /usr/local/bin/b2 \
&& apk update \
&& apk add --no-cache curl perl jq \
&& curl -sL https://downloads.sentry-cdn.com/sentry-cli/${SENTRY_CLI_VERSION}/sentry-cli-Linux-x86_64 -o /usr/local/bin/sentry-cli \
&& chmod +x /usr/local/bin/sentry-cli \
&& rm -rf /var/cache/apk/*

COPY ./youtrack-backup.pl /usr/local/bin/youtrack-backup.pl
Expand Down
15 changes: 15 additions & 0 deletions youtrack-backup.pl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@
use File::Temp;
use POSIX qw(strftime);

# Add Sentry notification function
sub error_to_sentry {
my ($error_message) = @_;
return unless $ENV{SENTRY_DSN};

my $sentry_cmd = sprintf(
'sentry-cli send-event --message "%s" --level error --tag backup_type=youtrack',
$error_message
);
system($sentry_cmd);
}

sub tstamp()
{
return strftime "%H:%M:%S", gmtime;
Expand Down Expand Up @@ -98,6 +110,7 @@ ()

chomp($result);
if ($result ne "null") {
error_to_sentry("Database backup failed: $result");
die "Database backup failed: $result\n";
}

Expand Down Expand Up @@ -161,6 +174,7 @@ ()
printf "%s: Downloading file $download_path\n", tstamp() if (! $quiet);
$result = system($curl_cmd);
if ($result != 0) {
error_to_sentry("Download failed: $result");
die "Download failed: $result\n";
}

Expand All @@ -182,6 +196,7 @@ ()
my $cmd = "b2 upload-file --noProgress $b2_bucket $download_path $file_name > $tmpfile";
$result = system($cmd);
if ($result != 0) {
error_to_sentry("Upload failed: $result");
`cat $tmpfile`;
unlink($download_path);
die "Upload failed: $result\n";
Expand Down

0 comments on commit 096d8e0

Please sign in to comment.