App-Sysadmin-Log-Simple
view release on metacpan or search on metacpan
If you need more than a single line of text, you may wish to use that
line to point to a pastebin - you can easily create and retrieve them
from the command line with App::Pastebin::sprunge.
There is also no way to audit that the logs are correct. It can be
incorrect in a number of ways:
* SUDO_USER or USER can be spoofed
* The files can be edited at any time, they are chmod 644 and owned by
an unprivileged user
* The timestamp depends on the system clock
* ...etc
Nonetheless, this is a simple, easy, and fast way to get a useful script
for managing a simple sysadmin log. We believe the 80/20 rule applies:
You can get 80% of the functionality with only 20% of a "real" solution.
In the future, each log entry might be committed to a git repository for
README.mkdn view on Meta::CPAN
modern drop-in replacement) and served on the web.
If you need more than a single line of text, you may wish to use that
line to point to a pastebin - you can easily create and retrieve them
from the command line with [App::Pastebin::sprunge](http://search.cpan.org/perldoc?App::Pastebin::sprunge).
There is also no way to audit that the logs are correct. It can be
incorrect in a number of ways:
- SUDO\_USER or USER can be spoofed
- The files can be edited at any time, they are chmod 644 and
owned by an unprivileged user
- The timestamp depends on the system clock
- ...etc
Nonetheless, this is a simple, easy, and __fast__ way to get a useful
script for managing a simple sysadmin log. We believe the 80/20 rule
applies: You can get 80% of the functionality with only 20% of a
"real" solution. In the future, each log entry might be committed to
a git repository for additional tracking.
lib/App/Sysadmin/Log/Simple.pm view on Meta::CPAN
line to point to a pastebin - you can easily create and retrieve them
from the command line with L<App::Pastebin::sprunge>.
There is also no way to audit that the logs are correct. It can be
incorrect in a number of ways:
=over 4
=item * SUDO_USER or USER can be spoofed
=item * The files can be edited at any time, they are chmod 644 and
owned by an unprivileged user
=item * The timestamp depends on the system clock
=item * ...etc
=back
Nonetheless, this is a simple, easy, and B<fast> way to get a useful
script for managing a simple sysadmin log. We believe the 80/20 rule
lib/App/Sysadmin/Log/Simple/File.pm view on Meta::CPAN
open my $logfh, '>>', $logfile;
my $timestamp = $self->{date}->hms;
my $user = $ENV{SUDO_USER} || $ENV{USER}; # We need to know who wrote this
say $logfh " $timestamp $user:\t$line";
# This might be run as root, so fix up ownership and
# permissions so mortals can log to files root started
my ($uid, $gid) = (getpwnam($self->{user}))[2,3];
chown $uid, $gid, $logfile;
chmod 0644, $logfile;
return "Logged to $logfile";
}
sub _generate_index {
my $self = shift;
require File::Find::Rule;
my $indexfh = path($self->{logdir}, 'index.log')->openw_utf8; # clobbers the file
say $indexfh $self->{index_preamble} if defined $self->{index_preamble};
lib/App/Sysadmin/Log/Simple/Twitter.pm view on Meta::CPAN
sub log {
my $self = shift;
my $logentry = shift;
return unless $self->{do_twitter};
require Net::Twitter::Lite::WithAPIv1_1;
warn "You should do: chmod 600 $self->{oauth_file}\n"
if ($self->{oauth_file}->stat->mode & 07777) != 0600; ## no critic (ValuesAndExpressions::ProhibitLeadingZeros)
my $conf = Config::General->new($self->{oauth_file});
my %oauth = $conf->getall();
my $ua = __PACKAGE__
. '/' . (defined __PACKAGE__->VERSION ? __PACKAGE__->VERSION : 'dev');
my $t = Net::Twitter::Lite::WithAPIv1_1->new(
consumer_key => $oauth{consumer_key},
consumer_secret => $oauth{consumer_secret},
access_token => $oauth{oauth_token},
lib/App/Sysadmin/Log/Simple/Twitter.pm view on Meta::CPAN
=head2 new
This creates a new App::Sysadmin::Log::Simple::Twitter object.
You're required to register this application at L<https://dev.twitter.com>, and
provide the consumer key, consumer secret, access token, and access token
secret. Upon registering the application, get the consumer key and secret from
the app details view. To get the I<access> key and secret, click "My Access
Token" on the right sidebar.
These data should be placed in a private (C<chmod 600>) file in
F<$HOME/.sysadmin-log-twitter-oauth>:
consumer_key = ...
consumer_secret = ...
oauth_token = ...
oauth_token_secret = ...
Or, you can provide a different location for the file:
my $logger = App::Sysadmin::Log::Simple::Twitter->new(
( run in 0.400 second using v1.01-cache-2.11-cpan-496ff517765 )