summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorTobi Oetiker <tobi@oetiker.ch>2005-02-12 10:58:20 +0100
committerTobi Oetiker <tobi@oetiker.ch>2005-02-12 10:58:20 +0100
commit3247e9cd78e6bfbea9e3e18805ea6c930b04aee5 (patch)
treefeb33232476206ac4271a46915f2ec44ad801b80 /lib
parent3d62610c70896af4fef67480965898533a68e839 (diff)
downloadsmokeping-3247e9cd78e6bfbea9e3e18805ea6c930b04aee5.tar.gz
smokeping-3247e9cd78e6bfbea9e3e18805ea6c930b04aee5.tar.xz
be more careful after seting up Net::SMTP and Net::SNPP only use the handle
if we got one ...
Diffstat (limited to 'lib')
-rw-r--r--lib/Smokeping.pm30
1 files changed, 17 insertions, 13 deletions
diff --git a/lib/Smokeping.pm b/lib/Smokeping.pm
index e8a59d7..0606467 100644
--- a/lib/Smokeping.pm
+++ b/lib/Smokeping.pm
@@ -144,29 +144,33 @@ sub sendmail ($$$){
my $to = shift;
$to = $1 if $to =~ /<(.*?)>/;
my $body = shift;
- if ($cfg->{General}{mailhost}){
- my $smtp = Net::SMTP->new($cfg->{General}{mailhost});
- $smtp->mail($from);
- $smtp->to(split(/\s*,\s*/, $to));
- $smtp->data();
- $smtp->datasend($body);
- $smtp->dataend();
- $smtp->quit;
+ if ($cfg->{General}{mailhost} and
+ my $smtp = Net::SMTP->new($cfg->{General}{mailhost})){
+ $smtp->mail($from);
+ $smtp->to(split(/\s*,\s*/, $to));
+ $smtp->data();
+ $smtp->datasend($body);
+ $smtp->dataend();
+ $smtp->quit;
} elsif ($cfg->{General}{sendmail} or -x "/usr/lib/sendmail"){
- open (M, "|-") || exec (($cfg->{General}{sendmail} || "/usr/lib/sendmail"),"-f",$from,$to);
- print M $body;
- close M;
+ open (M, "|-") || exec (($cfg->{General}{sendmail} || "/usr/lib/sendmail"),"-f",$from,$to);
+ print M $body;
+ close M;
+ } else {
+ warn "ERROR: not sending mail to $to, as all methodes failed\n";
}
}
sub sendsnpp ($$){
my $to = shift;
my $msg = shift;
- if ($cfg->{General}{snpphost}){
- my $snpp = Net::SNPP->new($cfg->{General}{snpphost}, Timeout => 60);
+ if ($cfg->{General}{snpphost} and
+ my $snpp = Net::SNPP->new($cfg->{General}{snpphost}, Timeout => 60)){
$snpp->send( Pager => $to,
Message => $msg) || do_debuglog("ERROR - ". $snpp->message);
$snpp->quit;
+ } else {
+ warn "ERROR: not sending page to $to, as all SNPP setup faild\n";
}
}