Let's get right to it. The core of the file is all built around this aws cli command:
/usr/bin/aws rds download-db-log-file-portion --region $region --db-instance-identifier $instanceName --log-file-name trace/alert_$sid.log > $logfileThat downloads the current alert log for the specified RDS instance. That's all you really need to get started on a script of your own. Fill in the $variables with whatever values apply to your instance.
If you want to get actual alerting on the alert log, this is the script I setup to run every 5 minutes. It determines where it left off in the log using readPos() and writePos(). If it finds a trace file, it also downloads that and emails it to $mailRecipient. Downloading a trace file is the same as downloading the alert log.
Another thing to note are the .ignore and .trigger files, this is how I determine what lines are worth alerting on. I'd recommend alerting on everything at first, and then adding stuff to the ignore file as it comes up. Right now since this is for an RDS instance in AWS most of what we are ignoring we have little/no control over.
I don't recommend copying this directly, but rather using it to give you an idea on
analyze_log.pl
#!/usr/bin/perl # # Title: analyze_log.pl # Date: Sep 17 2010 # Purpose: Check for new "Tracefile" entries in the alert.log file # Hisory: 1.0 09/17/2010 * Initial version # 2.0 08/08/2015 * Updated to pull from AWS use Carp qw( confess ); $SIG{__DIE__} = \&confess; $SIG{__WARN__} = \&confess; use strict; use File::Basename; use Sys::Syslog qw(:standard :macros); # Configuration Vars my $myName = basename($0); my $myPath = dirname($0); my $POS_DIR = $myPath . "/../var"; my $TRIGGER_FILE = $myPath . "/../conf/analyze_log.trigger"; my $IGNORE_FILE = $myPath . "/../conf/analyze_log.ignore"; my $mailRecipient = "to\@whoever.whatever";; my $FROM_EMAIL = "from\@whoever.whatever"; my $alertRecipient = "to\@whoever.whatever"; #we send this to datadog for alerting my $sendmail="/usr/sbin/sendmail -t -f$FROM_EMAIL"; my $extraLines = 5; # Number of lines included around error. my $traceMaxLen = 1000; # Max number of lines included in email my $true = 1; my $false = 0; # Global Vars my @triggerRules; my @ignoreRules; my @traceFiles; my $lastErrCursor;
No comments:
Post a Comment