-
Tomáš Plesník authoredTomáš Plesník authored
WardenWatchdog.pm 10.52 KiB
# WardenWatchdog.pm
#
# Copyright (C) 2011-2014 Cesnet z.s.p.o
#
# Use of this source is governed by a BSD-style license, see LICENSE file.
package WardenWatchdog;
use strict;
use warnings;
use DBI;
use DBD::mysql;
use DateTime;
use Email::Simple;
use Sys::Hostname;
#-------------------------------------------------------------------------------
# sendmailWrapper
#
# Simple wrapper function for an mailserver.
#
# Input:
# message = prepared message
# email_conf = configuration of a mailserver
#
# Output: -
#
# Return:
# On Success (1)
# On Failure (0, 'Error message')
#-------------------------------------------------------------------------------
sub sendmailWrapper
{
my $message = shift;
my $email_conf = shift;
if(open(my $sendmail, $email_conf)) {
print $sendmail $message;
close $sendmail;
return (1);
} else {
return (0, "Sending email failed: $!");
}
}
# Array of hashes
#{query => ; text => ; contact => }
#-------------------------------------------------------------------------------
# sendReport
#
# Function for creating and sending of an Watchdog status report via email to
# administrators of an clients.
#
# Input:
# Hash of parameters:
# contact => email address of a message recipient
# domain => domain name of server where script runs
# subject => subject of an email
# text => body of an email
# email_conf => configuration of a mailserver
#
# Output: -
#
# Return:
# On Success (1)
# On Failure (0, 'Error message')