Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling group alerts and mail to different mailing groups #16

Open
reeshnar opened this issue Nov 18, 2014 · 2 comments
Open

Handling group alerts and mail to different mailing groups #16

reeshnar opened this issue Nov 18, 2014 · 2 comments

Comments

@reeshnar
Copy link

Hi,

Trying out different ways to handle alerting in Production environment. This is to handle
grouping alerts and mail to different mailing groups ie basically grouping Includes and Excludes for certain Email ids. This way the config1.txt would handle multiple lines of EMAIL and its corresponding Includes/Excludes, even in case a null value is passed for EMAIL.

Following where done to achieve the same:

@@ -404,7 +404,8 @@ my $fileinfo = $opt{file}[$filenumber];
}

We're done parsing the message, send an email if needed

-process_report() if $opt{grand_total} or $arg{mailzero} or $opt{mailzero};
+#process_report() if $opt{grand_total} or $arg{mailzero} or $opt{mailzero};
+invoke_process_report() if $opt{grand_total} or $arg{mailzero} or $opt{mailzero};

@@ -614,6 +615,8 @@ sub parse_config_file {
## Store locally so we can easily populate %opt at the end
my %localopt;

  • my $mail; # variable to keep the email for each section, parse from EMAIL: (mailid)
  • my %seen_mailid; # to avoid duplicate (mailid + entry)

@@ -629,6 +632,8 @@ sub parse_config_file {
$in_standard_comments = 0;
}

  •    $mail = $1 if (/^EMAIL: (.+)/); # parsing mailid whenever we read a new section
    

@@ -637,7 +642,8 @@ sub parse_config_file {

     ## If the exact same line shows up more than once ignore it.
     ## Failing to do so will confuse the comment hash
  •    if (/^[\w]/ and $seenit{$_}++) {
    
  •    $seen_mailid{$mail}++ if $mail;
    
  •    if (/^[\w]/ and $seenit{$_}++ and !$seen_mailid{$mail}++) {
    

@@ -718,7 +724,11 @@ sub parse_config_file {
}
## Who to send emails to for this file
elsif (/^EMAIL:\s_(.+?)\s_$/) {

  •        push @{$localopt{email}}, $1;
    
  •    #    push @{$localopt{email}}, $1;
    
  •            my $m = $1;
    
  •        $localopt{email_hash}{$m} = {};
    
  •            @{$localopt{include}} = ();
    
  •            @{$localopt{exclude}} = ();
    

@@ -774,7 +784,8 @@ sub parse_config_file {
}
## Which lines to exclude from the report
elsif (/^EXCLUDE:\s_(.+?)\s_$/) {

  •        push @{$localopt{exclude}}, $1;
    
  •        #push @{$localopt{exclude}}, $1;
    
  •        push @{$localopt{email_hash}{$mail}->{exclude}}, $1 if $mail;              # global exclude --> mailid based exclude
    
    
     ## Which lines to include in the report
     elsif (/^INCLUDE:\s*(.+)/) {
    
  •        push @{$localopt{include}}, $1;
    
  •        #push @{$localopt{include}}, $1;
    
  •        push @{$localopt{email_hash}{$mail}->{include}}, $1 if $mail;              # global include --> mailid based include
    

@@ -1981,6 +1993,22 @@ sub process_line {

} ## end of process_line

+# Invoke_process_report
+# invoking process_report subroutine for each sections separately
+# ie: looping through email_hash and get each emailids and corresponding includes and excludes,
+# make a call to the original process_report after overriding global include/exclude with mailid specific include/exclude
+sub invoke_process_report {

  •    foreach my $e(keys %{$opt{email_hash}}) {
    
  •            @{$opt{include}} = @{$opt{email_hash}{$e}->{include}};
    
  •            @{$opt{exclude}} = @{$opt{email_hash}{$e}->{exclude}};
    
  •            $opt{email} = [];
    
  •            push @{$opt{email}}, split(/,/,$e);
    
  •            process_report();
    
  •    }
    
  •    return;
    
    +}

@@ -2414,10 +2447,10 @@ sub lines_of_interest {
|| ($a->{line} <=> $b->{line});
}
elsif ($sorttype eq 'count') {

  •        return ($b->{count} <=> $a->{count})
    
  •                || ($fileorder{$a->{filename}} <=> $fileorder{$b->{filename}})
    
  •                || ($a->{line} <=> $b->{line});
    
  •    }
    
  •                return ($b->{count} cmp $a->{count})
    
  •                        || ($fileorder{$a->{filename}} cmp $fileorder{$b->{filename}})
    
  •                        || ($a->{line} cmp $b->{line});
    
  •            }
    

@@ -2780,16 +2813,29 @@ sub final_cleanup {
add_comments("INHERIT: $inherit");
print "INHERIT: $inherit\n";
}

  • for my $include (@{$opt{include}}) {
  •    next if ! exists $opt{configfile}{"include.$include"};
    
  •    add_comments("INCLUDE: $include");
    
  •    print "INCLUDE: $include\n";
    
  • }
  • for my $exclude (@{$opt{exclude}}) {
  •    next if ! exists $opt{configfile}{"exclude.$exclude"};
    
  •    add_comments("EXCLUDE: $exclude");
    
  •    print "EXCLUDE: $exclude\n";
    
  • }
  • for my $m (keys %{$opt{email_hash}}) {
  •    add_comments("EMAIL: $m");
    
  •    print "\nEMAIL: $m\n";
    
  •    for my $include (@{$opt{email_hash}->{$m}->{include}}) {
    
  •            add_comments("INCLUDE: $include");
    
  •            print "INCLUDE: $include\n";
    
  •    }
    
  •    for my $exclude (@{$opt{email_hash}->{$m}->{exclude}}) {
    
  •            add_comments("EXCLUDE: $exclude");
    
  •            print "EXCLUDE: $exclude\n";
    
  •    }
    
  • }
    +# for my $include (@{$opt{include}}) {
    +# next if ! exists $opt{configfile}{"include.$include"};
    +# add_comments("INCLUDE: $include");
    +# print "INCLUDE: $include\n";
    +# }
    +# for my $exclude (@{$opt{exclude}}) {
    +# next if ! exists $opt{configfile}{"exclude.$exclude"};
    +# add_comments("EXCLUDE: $exclude");
    +# print "EXCLUDE: $exclude\n";
    +# }

This works as expected but downside is it parses through the pg_logs every time line EMAIL is mentioned in the cfg file. Please let me know if this can be avoided.

Regards

@reeshnar
Copy link
Author

Could you please include this change in the next version.

@turnstep
Copy link
Contributor

Any chance you could reformat this and/or turn it into a real patch?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants