-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdrbd-status-emailer.pl
More file actions
executable file
·72 lines (59 loc) · 1.47 KB
/
drbd-status-emailer.pl
File metadata and controls
executable file
·72 lines (59 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/perl
my $old_problem_file = "/var/run/drbd.problem";
use strict;
use warnings;
use Mail::Sendmail;
use File::Slurper 'write_text';
use File::Slurper 'read_text';
use Sys::Hostname;
my $noisy = 0;
if (@ARGV && $ARGV[0] eq 'noisy') {
$noisy = 1;
}
my %found;
my @problem;
my $copy;
my $hostname = hostname();
my %totallygood;
my %connected;
open my $drbd, "<", "/proc/drbd" or die;
while (<$drbd>) {
$copy .= $_;
next unless /^\s*(\d+):\s/;
my $r = $1;
$found{$r}++;
if (m{cs:(Connected|SyncTarget|SyncSource)}) {
$connected{$r} = 1;
} else {
if (m{ro:Primary}) {
push(@problem, "r$r is unconnected primary")
} else {
push(@problem, "r$r not connected");
}
}
if (m{ds:UpToDate/UpToDate}) {
$totallygood{$r} = 1;
next;
}
push(@problem, "r$r not up-to-date");
}
if (!%found) {
push(@problem, "no resources found")
}
push(@problem, "no drbd issues, all is good") unless @problem;
my $old_problem = -e $old_problem_file ? read_text($old_problem_file) : '';
my $new_problem = join("\n", @problem);
if ($new_problem ne $old_problem || $noisy) {
my $body = join("\n", @problem, "", "", $copy);
sendmail(
Smtp => '127.0.0.1',
From => "Root Guy <root\@$hostname>",
To => "root\@$hostname",
Subject => "$hostname: drbd status",
Message => $body,
) or die "could not send: $Mail::Sendmail::error";
write_text($old_problem_file, $new_problem);
print "SENDING MESSAGE\n$body" if -t STDOUT;
} else {
print "Not sending: @problem\n" if -t STDOUT;
}