Skip to content
Snippets Groups Projects
Forked from 713 / Warden / Warden
758 commits behind the upstream repository.
Warden.pm 25.95 KiB
#!/usr/bin/perl -w
#
# Warden.pm
#
# Copyright (C) 2011-2013 Cesnet z.s.p.o
#
# Use of this source is governed by a BSD-style license, see LICENSE file.

package Warden;

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

our $VERSION = "2.2";


################################################################################
#			READING OF CONFIGURATION VARIABLES
################################################################################

my $conf_file = "/opt/warden-server/etc/warden-server.conf"; # path is updated by install.sh
our $SYSLOG		= undef;
our $SYSLOG_VERBOSE	= undef;
our $SYSLOG_FACILITY	= undef;
our $DB_NAME		= undef;
our $DB_USER		= undef;
our $DB_PASS		= undef;
our $DB_HOST		= undef;
our $MAX_EVENTS_LIMIT	= 1000000; # default value
our %VALID_STRINGS	= undef;

# load set variables by user
unless (do $conf_file) {
  die("Errors in config file '$conf_file': $@") if $@;
  die("Can't read config file '$conf_file': $!") unless defined $_;
  # if $_ defined, it's retvalue of last statement of conf, for which we don't care
}


################################################################################
#				VARIABLES
################################################################################

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


################################################################################
#				LOCAL FUNCTIONS
################################################################################

#-------------------------------------------------------------------------------
# sendMsg - sent message to syslog (SYS::Syslog) and to client (SOAP::Fault)
#
# Args:	(SYSLOG severity, SYSLOG msg, SOAP msg)
#-------------------------------------------------------------------------------
sub sendMsg
{
  my $severity		= shift;
  my $syslog_msg 	= shift;
  my $soap_msg		= shift;