App-Sysadmin-Log-Simple

 view release on metacpan or  search on metacpan

bin/sysadmin-log  view on Meta::CPAN

#!/usr/bin/env perl
use strict;
use warnings;
use v5.10.1;
use Getopt::Long;
use Pod::Usage;
use File::HomeDir;
use App::Sysadmin::Log::Simple;

# PODNAME: sysadmin-log
# ABSTRACT: maintain a single-host system administration log
our $VERSION = '0.009'; # VERSION

my %opts = (
    user        => $ENV{SUDO_USER} || $ENV{USER},
    do_udp      => 1,
    do_file     => 1,
    do_http     => 0,
    do_twitter  => 0,
);
my $HOME = File::HomeDir->users_home($opts{user});
$opts{logdir} = "$HOME/sysadmin-log";
$opts{index_preamble} = <<'END';
INDEX
=====

This page indexes all the logs. For each line, you see a timestamp
for the line, the user who added the line, and then the comments.
This method of logging is less transparent than logging to the
wiki, but is more reliable:

* We can't rely on having apache and MySQL available, especially
  since logging is often due to issues with those.
* In fact, all that's needed is filesystem access.
* Shell access is required to log, so there probably aren't bogus
  log entries.
END

GetOptions( \%opts,
    'help|?',
    'version',
    'view',
    'date:s',
    'logdir:s',
    'refresh-index',
    'udp!',
    'twitter!',
    'file!',
    'http!',
) or exit;

$opts{do_udp}     = delete $opts{udp};
$opts{do_file}    = delete $opts{file};
$opts{do_http}    = delete $opts{http};
$opts{do_twitter} = delete $opts{twitter};

my %udp_data = ( irc => 1, port => 9002, host => 'localhost' );
GetOptions( 'udp-data=s' => \%udp_data) or exit;
$opts{udp} = \%udp_data if $opts{do_udp};

my %http_data = ( http => 1, method => 'post', uri => 'http://localhost' );
GetOptions( 'http-data=s' => \%http_data) or exit;
$opts{http} = \%http_data if $opts{do_http};


pod2usage(
    -verbose => 2,
) if $opts{help};


if ($opts{version}) {
    say "$0 version " . (defined __PACKAGE__->VERSION ? __PACKAGE__->VERSION : 'dev');
    exit 0;
}


my $mode = delete $opts{view}
    ? 'view'
    : delete $opts{'refresh-index'} ? 'refresh-index' : 'log';

$opts{read_from} = \*STDIN;

App::Sysadmin::Log::Simple->new(%opts)->run($mode);

__END__

=pod

=encoding utf-8



( run in 0.734 second using v1.01-cache-2.11-cpan-39bf76dae61 )