Skip to content
Snippets Groups Projects
WardenCommon.pm 2.19 KiB
#!/usr/bin/perl -w
#
# WardenCommon.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 WardenCommon;

use strict;
use File::Basename;
use Sys::Syslog qw(:DEFAULT setlogsock);
Sys::Syslog::setlogsock('unix');
use Carp;

our $VERSION = "2.2";

#-------------------------------------------------------------------------------
# succMsg - print message and exit seccessfully
#-------------------------------------------------------------------------------
sub succMsg
{
  my $msg = shift;
  $msg = trim($msg);
  print $msg . "\n";
  exit 0;
} # End of succMsg


#-------------------------------------------------------------------------------
# errMsg - print error message and exit unsuccessfully
#-------------------------------------------------------------------------------
sub errMsg
{
  my $msg = shift;
  $msg = trim($msg);
  print $msg . "\n";
  exit 1;
} # End of errMsg


#-------------------------------------------------------------------------------
# trim - remove whitespace from the start and end of the string
#-------------------------------------------------------------------------------
sub trim
{
  my $string = shift;
  $string =~ s/^\s+//;
  $string =~ s/\s+$//;
  return $string;
} # End of trim


#-------------------------------------------------------------------------------
# sendMsg - sent message via syslog (SYS::Syslog) and to client (SOAP::Fault)
#-------------------------------------------------------------------------------
sub sendMsg
{
  my $syslog            = shift;
  my $syslog_verbose    = shift;
  my $syslog_facility   = shift;
  my $severity          = shift;
  my $syslog_msg        = shift;
  my $soap_msg          = shift;
  my $filename          = shift;

  if ($syslog_verbose == 1 && ($severity eq "err" || $severity eq "debug")) {
    $syslog_msg .= "\nStack info: " . Carp::longmess();
  }