Advertisement
Guest User

Untitled

a guest
Mar 20th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.73 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5. use Data::Dumper;
  6. use Switch;
  7. use 5.010;
  8. use File::Path qw( make_path rmtree );
  9. use File::Find;
  10. use File::Slurp qw( read_dir );
  11. use File::Spec::Functions qw( catfile catdir );
  12.  
  13. my $dh; # handle
  14.  
  15.  
  16. while (1){
  17.  
  18.   our %threshold = ();
  19.  
  20.   my $path = "check";
  21.   my @sub_dirs = grep { -d } map { catdir $path, $_ } read_dir $path;
  22.  
  23.   for my $subdir (@sub_dirs){
  24.  
  25.     if ( !opendir ($dh, $subdir)) {
  26.          warn "Unable to open $subdir: $!\n";
  27.          return;
  28.      }
  29.  
  30.     my @files = grep { $_ ne '.' && $_ ne '..' } readdir($dh);
  31.  
  32.     my %readdir_map = map { $_ => 1 } @files;
  33.  
  34.     foreach (keys %threshold) {
  35.             if (! exists $readdir_map{$_}) {
  36.                delete $threshold{$_};
  37.                my $site = "$_";
  38.          #      RVBDCC::hipchat::recover($config, $site);
  39.                print "$_ has been deleted\n";
  40.             }
  41.           }
  42.  
  43.      my $count = scalar (@files);
  44.  
  45.      if ( $count > 0 ) {
  46.        for my $file (@files) {
  47.          $threshold{$file} +=1;
  48.           #         #$scm_config->{site} = $file;
  49.  
  50.          switch ($threshold{$file})
  51.          {
  52.            case 1    {print "Alert Detected for $file\n"}#{get_alert($file)}
  53.            case 5    {print "Hipchat message for $file\n"} #{RVBDCC::hipchat::alert($config, $scm_config, $file)}
  54.            case 10   {print "Sending mail notification for $file to rlaborius\@riverbed.com\n"}#{RVBDCC::email::mail($config, $scm_config, $file)}
  55.            case 15   {print "Sending mail notification for $file to roc\@riverbed.com\n"}
  56.           }
  57.           sleep 1;
  58.         }
  59.       }
  60.         else{
  61.                  #RVBDCC::hipchat::self_check($config);
  62.           sleep 3;
  63.         }
  64.     }
  65.  
  66.  
  67.  
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement