Permalink
Browse files

Use File::ShareDir

This commit makes this distribution use File::ShareDir.
  • Loading branch information...
1 parent a54c601 commit 525c8883b3fe2e42e783ad20939f2caeb4beaf36 @dominikschulz committed with Nov 25, 2012
View
@@ -0,0 +1,5 @@
+Revision history for Monitoring-Spooler
+
+0.01 2012-11-25
+ First public version, released on an unsuspecting world.
+
@@ -11,6 +11,6 @@ use Monitoring::Spooler::Web::API;
my $Frontend = Monitoring::Spooler::Web::API::->new();
my $app = sub {
my $env = shift;
-
+
return $Frontend->run($env);
};
@@ -7,19 +7,20 @@ use warnings;
use lib '../lib';
use Plack::Builder;
+use File::ShareDir;
use Monitoring::Spooler::Web::Frontend;
my $Frontend = Monitoring::Spooler::Web::Frontend::->new();
my $app = sub {
my $env = shift;
-
+
return $Frontend->run($env);
};
my $static_path = $Frontend->config()->get('Monitoring::Spooler::Frontend::StaticPath');
if(!-d $static_path) {
- # TODO use ShareDir ...
- $static_path = 'res/';
+ my $dist_dir = File::ShareDir::dist_dir('Monitoring-Spooler');
+ $static_path = $dist_dir.'/res';
}
builder {
View
@@ -11,10 +11,14 @@ exclude_filename = README.pod
exclude_match = ^doc.*
exclude_match = ^cover.*
+[ExecDir]
+[ShareDir]
+
[PruneCruft]
[Authority]
[PkgVersion]
[MetaJSON]
+
[ExtraTests]
[PodSyntaxTests]
[NoTabsTests]
@@ -1,5 +0,0 @@
-use strict;
-use warnings;
-package Monitoring::Spooler;
-
-1;
@@ -1,4 +1,5 @@
package Monitoring::Spooler::Cmd;
+# ABSTRACT: CLI for Monitoring::Spooler
use 5.010_000;
use mro 'c3';
@@ -14,8 +15,6 @@ use namespace::autoclean;
# use English qw( -no_match_vars );
# use Try::Tiny;
-our $VERSION = '@VERSION@';
-
# extends ...
extends 'MooseX::App::Cmd';
# has ...
@@ -33,7 +32,7 @@ __END__
=head1 NAME
-Monitoring::Spooler::Cmd - Command base class.
+Monitoring::Spooler::Cmd - CLI class.
=head1 SYNOPSIS
@@ -42,7 +41,7 @@ Monitoring::Spooler::Cmd - Command base class.
=head1 DESCRIPTION
-This class is the base class for any command implemented by its subclasses.
+This class is the CLI for Monitoring::Spooler.
It is a mere requirement by App::Cmd. Don't mess with it.
@@ -49,30 +49,30 @@ has '_dbh' => (
# initializers ...
sub _init_dbh {
my $self = shift;
-
+
my $DBH = Monitoring::Spooler::DB::->new({
- 'config' => $self->config(),
- 'logger' => $self->logger(),
+ 'config' => $self->config(),
+ 'logger' => $self->logger(),
});
-
+
return $DBH;
}
sub _init_config {
my $self = shift;
-
+
my $Config = Config::Tree::->new({
- 'locations' => [qw(conf /etc/mon-spooler)],
+ 'locations' => [qw(conf /etc/mon-spooler)],
});
-
+
return $Config;
}
sub _init_logger {
my $self = shift;
-
+
my $Logger = Log::Tree::->new('mon-spooler');
-
+
return $Logger;
}
@@ -89,17 +89,4 @@ __END__
Monitoring::Spooler::Cmd::Command - Base class for any command.
-=head1 SYNOPSIS
-
- use Monitoring::Spooler::App;
- my $Mod = Monitoring::Spooler::App::->new();
-
-=head1 DESCRIPTION
-
-Some description.
-
-=method _check_tables
-
-Create all necessary tables if they don't already exist.
-
=cut
@@ -37,22 +37,22 @@ Initializ a new installation
=cut
sub execute {
my $self = shift;
-
+
my $sql = 'SELECT COUNT(*) FROM groups';
my $sth = $self->dbh()->prepexec($sql);
my $cnt = $sth->fetchrow_array();
-
+
if($cnt > 0) {
- print "You can not use this command once there is already at least one group\n";
- return;
+ print "You can not use this command once there is already at least one group\n";
+ return;
}
-
+
$sql = 'INSERT INTO groups (name) VALUES (?)';
$sth = $self->dbh()->prepexec($sql,$self->name());
if($sth) {
- print "Created new group '".$self->name()."'\n";
+ print "Created new group '".$self->name()."'\n";
}
-
+
return 1;
}
@@ -1,4 +1,5 @@
package Monitoring::Spooler::Cmd::Command::create;
+# ABSTRACT: enqueue a new notification
use 5.010_000;
use mro 'c3';
@@ -49,12 +50,12 @@ has 'message' => (
# your code here ...
sub execute {
my $self = shift;
-
+
my $message = $self->message();
-
+
my $trigger_id = 0;
my $event = '';
-
+
# Handle negating triggers
if($self->type() eq 'text'
&& $self->config()->get('Monitoring::Spooler::NegatingTrigger')
@@ -65,7 +66,7 @@ sub execute {
$message =~ s/^\s*\d+\s+//g;
# remove any trailing spaces
$message =~ s/\s+$//;
-
+
# if we got an trigger id and this is a recovery message
# we look for any related down trigger and delete it
if($event =~ m/^(?:OK|UP)$/ && $trigger_id) {
@@ -77,19 +78,19 @@ sub execute {
}
}
}
-
+
# Do not insert new messages into queue for paused groups
if($self->type() eq 'phone') {
my $sql = 'SELECT COUNT(*) FROM paused_groups WHERE until > ? AND group_id = ?';
my $sth = $self->dbh()->prepexec($sql,time(),$self->group_id());
my $count = $sth->fetchrow_array();
-
+
if($count > 0) {
$self->logger()->log( message => 'Rejected new message "'.$self->message().'" to paused group', level => 'debug', );
return 1;
}
}
-
+
# create new message in queue
my $sql = 'INSERT INTO msg_queue (group_id,type,message,ts,event,trigger_id) VALUES(?,?,?,?,?,?)';
my $sth = $self->dbh()->prepare($sql);
@@ -1,4 +1,5 @@
package Monitoring::Spooler::Cmd::Command::flush;
+# ABSTRACT: remove all pending notifications
use 5.010_000;
use mro 'c3';
@@ -57,7 +58,7 @@ sub execute {
$self->logger()->log( message => 'Failed to execute statement: '.$sth->errstr, level => 'warning', );
}
$sth->finish();
-
+
if($self->all()) {
my $sql = 'DELETE FROM paused_groups';
my $sth = $self->dbh()->prepare($sql);
@@ -84,7 +85,7 @@ sub execute {
$self->logger()->log( message => 'Failed to prepare statement ('.$sql.'): '.$self->dbh()->errstr, level => 'warning', );
}
}
-
+
return 1;
}
@@ -1,4 +1,5 @@
package Monitoring::Spooler::Cmd::Command::list;
+# ABSTRACT: list all queued notifications
use 5.010_000;
use mro 'c3';
@@ -39,7 +40,7 @@ has 'group_id' => (
# your code here ...
sub execute {
my $self = shift;
-
+
# just print the queue content if invoked w/o options
# we may also print all tables if the user asks for them
my $sql = 'SELECT id, group_id, type, message, ts FROM msg_queue';
@@ -51,7 +52,7 @@ sub execute {
$sql .= ' ORDER BY id';
my $sth = $self->dbh()->prepare($sql);
$sth->execute(@args);
-
+
my $msg_ref = {};
while(my ($id, $group_id, $type, $message) = $sth->fetchrow_array()) {
push(@{$msg_ref->{$group_id}}, {
@@ -62,7 +63,7 @@ sub execute {
});
}
$sth->finish();
-
+
if(scalar(keys %$msg_ref)) {
foreach my $group_id (sort keys %$msg_ref) {
print "Messages waiting in Queue for Group ".$group_id."\n";
@@ -73,7 +74,7 @@ sub execute {
} else {
print "Queue is empty\n";
}
-
+
if($self->all()) {
my $sql = 'SELECT id, name FROM groups ORDER BY name';
my $sth = $self->dbh()->prepare($sql);
@@ -82,15 +83,15 @@ sub execute {
printf("%s (%i)\n", $name, $id);
}
$sth->finish();
-
+
$sql = 'SELECT group_id, until FROM paused_groups ORDER BY group_id';
$sth = $self->dbh()->prepare($sql);
$sth->execute();
while(my ($id, $until) = $sth->fetchrow_array()) {
printf("%i => %s\n", $id, localtime($until));
}
$sth->finish();
-
+
$sql = 'SELECT group_id,type,notify_from,notify_to FROM notify_interval ORDER BY group_id';
$sth = $self->dbh()->prepare($sql);
$sth->execute();
@@ -99,7 +100,7 @@ sub execute {
}
$sth->finish();
}
-
+
return 1;
}
Oops, something went wrong.

0 comments on commit 525c888

Please sign in to comment.