Skip to content
Snippets Groups Projects
Forked from 713 / Warden / Warden - archive
368 commits behind the upstream repository.
Warden.pm 18.35 KiB
# Warden.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 Warden;

use strict;
use warnings;

use DBI;
use DBD::mysql;
use Sys::Syslog qw(:DEFAULT setlogsock);
Sys::Syslog::setlogsock('unix');
use Net::CIDR::Lite;
use DateTime;
use MIME::Base64;
use Crypt::X509;
use SOAP::Lite;
use Carp;
use File::Basename;

my $lib = File::Basename::dirname(__FILE__);
use lib $lib;
use WardenCommon;



################################################################################
#				VARIABLES
################################################################################
our $VERSION = "2.2";
our $FILENAME = File::Basename::basename(__FILE__);
my $etc = "$lib/../etc";



################################################################################
#			READING OF CONFIGURATION VARIABLES
################################################################################
# load server configuration
my $conf_file = "$etc/warden-server.conf";
WardenCommon::loadConf($conf_file);



################################################################################
#				DB CONNECT
################################################################################
# create database handler
our $DBH = DBI->connect("DBI:mysql:database=$WardenCommon::DB_NAME;host=$WardenCommon::DB_HOST", $WardenCommon::DB_USER, $WardenCommon::DB_PASS, {RaiseError => 1, mysql_auto_reconnect => 1})
           || die "Could not connect to database '$WardenCommon::DB_NAME' at '$WardenCommon::DB_HOST': $DBI::errstr";



################################################################################
#				FUNCTIONS
################################################################################

#-------------------------------------------------------------------------------
# sendMsg - wrapper for more complex WardenCommon::sendMsg function
#-------------------------------------------------------------------------------
sub sendMsg
{
  my $severity   = shift;
  my $syslog_msg = shift;
  my $soap_msg   = shift;

  # send message via syslog