File: rolllog

package info (click to toggle)
dnssec-tools 1.13-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 16,064 kB
  • sloc: perl: 44,399; ansic: 31,547; cpp: 21,306; sh: 15,813; xml: 2,113; makefile: 1,390; pascal: 836; python: 290; csh: 11
file content (196 lines) | stat: -rwxr-xr-x 4,055 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/usr/bin/perl
#
# Copyright 2006-2012 SPARTA, Inc.  All rights reserved.  See the COPYING
# file distributed with this software for details.
#
#
# rolllog
#
#	This script writes log messages in the rollover manager's log file.
#

use strict;

use Getopt::Long qw(:config no_ignore_case_always);

use Net::DNS::SEC::Tools::rollmgr;

#
# Version information.
#
my $NAME   = "rolllog";  
my $VERS   = "$NAME version: 1.13.0";
my $DTVERS = "DNSSEC-Tools Version: 1.13";

#######################################################################

#
# Data required for command line options.
#
my $loglevel;				# Logging level.

my $OPT_HELP	 = "help";
my $OPT_LOGLEVEL = "loglevel";
my $OPT_VERSION	 = "Version";

my %opts = ();				# Filled option array.
my @opts =
(
	"loglevel=s",			# Logging level.
	"help",				# Give a usage message and exit.
        "Version",			# Display the version number.
);

#######################################################################

my $ret;				# Return code from main().

$ret = main();
exit($ret);

#-----------------------------------------------------------------------------
# Routine:	main()
#
# Purpose:	Main controller routine.
#
sub main
{
	my $logmsg = "";			# The constructed log message.
	my $ret;				# Return code from rollerd.
	my $resp;				# Return message from rollerd.

	#
	# Check our arguments.
	#
	optsandargs();
	usage() if(@ARGV == 0);

	#
	# Build our log message from the remaining arguments.
	#
	$logmsg = join(" ",@ARGV);

	#
	# Send the logging command to rollerd.
	#
	if(rollmgr_sendcmd(CHANNEL_WAIT,ROLLCMD_LOGMSG,"($loglevel)$logmsg") == 0)
	{
		print STDERR "rolllog:  unable to send command to rollerd\n";
		exit(1);
	}

	#
	# Give an error message if rollerd didn't like something. 
	# 
	($ret, $resp) = rollmgr_getresp();
	if($ret != ROLLCMD_RC_OKAY)
	{
		print STDERR "rolllog:  rollerd was unable to write message to log file:  \"$resp\"\n";
	}
}

#-----------------------------------------------------------------------------
# Routine:	optsandargs()
#
# Purpose:	Check for arguments.
#
sub optsandargs
{
	my $argc = @ARGV;				# Number of arguments.
	my $dir;					# Execution directory.

	#
	# Check our options.
	#
	GetOptions(\%opts,@opts) || usage();
	usage()   if(defined($opts{$OPT_HELP}));
	version() if(defined($opts{$OPT_VERSION}));

	$loglevel  = $opts{$OPT_LOGLEVEL} || usage();

}

#-----------------------------------------------------------------------------
# Routine:	usage()
#
sub usage
{
	print STDERR "usage:  rolllog [-loglevel <level> <log_message> | -help | -Version]\n";
	exit(0);
}

#-----------------------------------------------------------------------------
# Routine:	version()
#
# Purpose:      Print the version number(s) and exit.
#
sub version
{
        print STDERR "$VERS\n";
	print STDERR "$DTVERS\n";

	exit(0);
}

1;

##############################################################################
#

=pod

=head1 NAME

rolllog - DNSSEC-Tools utility to write messages to the DNSSEC rollover
log file

=head1 SYNOPSIS

  rolllog -loglevel <level> <log_message>

=head1 DESCRIPTION

The B<rolllog> program writes log messages to the DNSSEC rollover log file.
B<rolllog> does not actually write the messages itself; rather, it sends them
to the B<rollerd> rollover daemon to write the messages.  B<rollerd> keeps
track of a logging level, and only messages of that level or higher are
written to the log file.

=head1 OPTIONS

The following options are recognized:

=over 4

=item B<-loglevel level>

Logging level of this message.  The valid levels are defined in
B<rollmgr.pm>(3).   This option is required.

=item B<-help>

Display a usage message.

=item B<-Version>

Displays the version information for B<rolllog> and the DNSSEC-Tools package.

=back

=head1 COPYRIGHT

Copyright 2006-2012 SPARTA, Inc.  All rights reserved.
See the COPYING file included with the DNSSEC-Tools package for details.

=head1 AUTHOR

Wayne Morrison, tewok@tislabs.com

=head1 SEE ALSO

B<rollctl(8)>,
B<rollerd(8)>

B<Net::DNS::SEC::Tools::rollmgr.pm(3)>

=cut