Net-NSCA-Client

 view release on metacpan or  search on metacpan

bin/send_nsca  view on Meta::CPAN


	# Close the file
	close $file
		or confess sprintf 'Unable to close %s: %s',
			$file_name, $ERRNO;

	# Key-value pairs found in the file will be stored here
	my %config_info;

	# Process each line of the file looking for a key-value pair
	LINE: foreach my $line (@lines) {
		chomp $line;

		# Skip comments and blank lines
		next LINE if $line =~ m{\A [#\000] | \A \z}msx;

		if ($line =~ m{\A ([^=]+) = (.+) \z}msx) {
			# Found a key-value pair
			my ($key, $value) = ($1, $2);

			if (!exists $config_info{$key}) {
				# Add the key-value pair if it was not added already
				$config_info{$key} = $value;
			}
		}
	}

	if (!exists $config_info{password}) {
		# The password is missing from the configuration file
		confess sprintf 'Missing password from the configuration file %s',
			$file_name;
	}

	if (!exists $config_info{encryption_method}) {
		# The encryption method is missing from the configuration file
		confess sprintf 'Missing encryption method from the configuration file %s',
			$file_name;
	}
	elsif (!exists $ENCRYPTION_METHOD{$config_info{encryption_method}}) {
		# The encryption method is unsupported
		confess sprintf 'The encryption method %s in %s is unsupported at this time',
			$config_info{encryption_method}, $file_name;
	}

	# Return the password and encryption method
	return $config_info{password}, $ENCRYPTION_METHOD{$config_info{encryption_method}};
}

sub _parse_line_to_send_report_options {
	my ($line, %args) = @_;

	# Get the input delimiter
	my $delimiter = $args{input_delimiter};

	if (!defined $delimiter) {
		confess 'An input delimiter must be provided to read_stdin()';
	}

	# Get the different values from the line
	my ($hostname, $service, $status, $message)
		= split m{$delimiter}msx, $line, $INPUT_FIELD_COUNT;

	# Return a HASH of the format for Net::NSCA::Client->send_report
	return (
		hostname => $hostname,
		message  => $message,
		service  => $service,
		status   => $status,
	);
}

__END__

=head1 NAME

send_nsca - Send reports to NSCA just like send_nsca in NSCA 2.7.2

=head1 VERSION

This documentation refers to version 0.009002

=head1 DESCRIPTION

This utility is made to mimic the functionality and usage of the send_nsca
program distributed with NSCA 2.7.2, but use the L<Net::NSCA::Client|Net::NSCA::Client>
Perl library.

=head1 USAGE

  ./send_nsca [-H host_name] [-p port] [-to timeout] [-d delim] [-c config_file]

  Options:
    -H         The host name of the NSCA server (default to localhost)
    -p         The port number of the NSCA server (defaults to 5667)
    -to        The timeout when talking to the NSCA server in seconds (defaults to 10)
    -d         The input delimiter (defaults to tab)
    -c         The path to the configuration file
    --help     Usage message
    --version  Display version of the program

  The program then waits for input on STDIN until the first new line character.
  The input should be in the following format:

    Nagios Service Host<TAB>Nagios Service Description<TAB>Status Number<TAB>Plugin Output

  The <TAB> represents the tab character and should be change to which ever
  dimilimter is specified.

=head1 OPTIONS

=head2 C<-H>

This switch takes the host name of the NSCA server. If not specified, then
C<localhost> is used.

=head2 C<-p>

This switch takes the port number of the NSCA server. If not specified, then
the default NSCA port 5667 is used.

=head2 C<-to>



( run in 0.549 second using v1.01-cache-2.11-cpan-71847e10f99 )