Skip to content
Snippets Groups Projects
registerSender.pl 3.28 KiB
#!/usr/bin/perl -w
#
# registerSender.pl
#
# Copyright (C) 2011-2012 Cesnet z.s.p.o
#
# Use of this source is governed by a BSD-style license, see LICENSE file.

use strict;
use Getopt::Std;
use Switch;
use File::Basename;

our $VERSION = "2.0";

my $warden_path = '/opt/warden-server';
require $warden_path . '/lib/WardenReg.pm';
my $filename = basename($0);

#-------------------------------------------------------------------------------
#				Functions
#-------------------------------------------------------------------------------
sub usage {
  print "Usage: $filename [-h -n <hostname> -r <requestor> -s <service> -d <description_tags> -i <ip_net_client>]\n";
  exit 1;
}

sub help {
  print "$filename [-h -n <hostname> -r <requestor> -s <service> -d <description_tags> -i <ip_net_client>]\n";
  print "-h 	print this text and exit\n";
  print "-n 	hostname of sender\n";
  print "-r 	client registration requestor\n";
  print "-s 	name of service which sent events\n";
  print "-d 	description tags of send events\n";
  print "-i 	CIDR of sender\n";
  exit 0;
}


#-------------------------------------------------------------------------------
# errMsg - print error message and die
#-------------------------------------------------------------------------------
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


#-------------------------------------------------------------------------------
#				MAIN
#-------------------------------------------------------------------------------
our ($opt_n, $opt_r, $opt_s, $opt_d, $opt_i, $opt_h);

if ($#ARGV == -1) {usage}