summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2013-09-30 17:40:20 +0200
committerDaniel Friesel <derf@finalrewind.org>2013-09-30 17:40:20 +0200
commite3ce3a77fccdd9377b0e3023f1f38ef86201aa45 (patch)
tree396af7e9beaf115c15f3203597f019595318f12c
parentf77c71dec31f5a416757a313e1f9e6cfd891ad48 (diff)
allow build-time specification of icinga paths
-rw-r--r--Build.PL66
-rw-r--r--README18
-rwxr-xr-xbin/icli16
3 files changed, 86 insertions, 14 deletions
diff --git a/Build.PL b/Build.PL
index a16e7c3..5ef3691 100644
--- a/Build.PL
+++ b/Build.PL
@@ -4,11 +4,7 @@ use strict;
use warnings;
use Module::Build;
-my $build = Module::Build->subclass(
- code => q(
- sub ACTION_testauthor { shift->generic_task(type => 'author') }
- )
-)->new(
+my $build = Module::Build->new(
build_requires => {
'Test::More' => 0,
'Test::Compile' => 0,
@@ -18,9 +14,15 @@ my $build = Module::Build->subclass(
configure_requires => {
'Module::Build' => 0,
},
+ config_data => {
+ object_file => '/var/cache/icinga/objects.cache',
+ status_file => '/var/lib/icinga/status.dat',
+ command_file => '/var/lib/icinga/rw/icinga.cmd',
+ },
dist_name => 'icli',
dist_version_from => 'bin/icli',
license => 'unrestricted',
+ module_name => 'App::Icli',
requires => {
'perl' => '5.10.0',
'autodie' => 0,
@@ -37,4 +39,58 @@ my $build = Module::Build->subclass(
author => '.at',
},
);
+
+print <<'EOF';
+
+-----------------------------------------------------------------------
+
+Note: To work with an Icinga installation, icli needs to know the path to
+three files:
+* objects.cache (icinga.cfg object_cache_file)
+* status.dat (icinga.cfg status_file)
+* icinga.cmd (icinga.cfg command_file)
+
+If you are building interactively and the default values for these paths
+do not exist, you will be asked for them -- hit return to keep the default.
+In a non-interactive build, the defaults will be used (unless changed using
+an option, see below).
+
+If you need to set them regardless of the build host, do not wish to be
+promited at all, or are using a non-interactive build process (perhaps even
+for a whole distribution), you can set them using the following options:
+perl Build.PL --icli-object-file=.../objects.cache \
+ --icli-status-file=.../status.dat \
+ --icli-command-file=.../icinga.cmd
+
+-----------------------------------------------------------------------
+
+EOF
+
+if ($build->args('icli-object-file')) {
+ $build->config_data(object_file => $build->args('icli-object-file'));
+}
+elsif (not -e $build->config_data('object_file')) {
+ my $reply = $build->prompt('Enter location of Icinga objects.cache',
+ $build->config_data('object_file'));
+ $build->config_data(object_file => $reply);
+}
+
+if ($build->args('icli-status-file')) {
+ $build->config_data(status_file => $build->args('icli-status-file'));
+}
+elsif (not -e $build->config_data('status_file')) {
+ my $reply = $build->prompt('Enter location of Icinga status.dat',
+ $build->config_data('status_file'));
+ $build->config_data(status_file => $reply);
+}
+
+if ($build->args('icli-command-file')) {
+ $build->config_data(command_file => $build->args('icli-command-file'));
+}
+elsif (not -e $build->config_data('command_file')) {
+ my $reply = $build->prompt('Enter location of Icinga command pipe',
+ $build->config_data('command_file'));
+ $build->config_data(command_file => $reply);
+}
+
$build->create_build_script();
diff --git a/README b/README
index c71ddc8..7dddf74 100644
--- a/README
+++ b/README
@@ -20,5 +20,23 @@ Extra modules required for testing:
* Test::Pod
* Test::Command
+Note: To work with an Icinga installation, icli needs to know the path to
+three files:
+* objects.cache (icinga.cfg object_cache_file)
+* status.dat (icinga.cfg status_file)
+* icinga.cmd (icinga.cfg command_file)
+
+If you are building interactively and the default values for these paths
+do not exist, you will be asked for them -- hit return to keep the default.
+In a non-interactive build, the defaults will be used (unless changed using
+an option, see below).
+
+If you need to set them regardless of the build host, do not wish to be
+promited at all, or are using a non-interactive build process (perhaps even
+for a whole distribution), you can set them using the following options:
+
+> perl Build.PL --icli-object-file=.../objects.cache \
+ --icli-status-file=.../status.dat \
+ --icli-command-file=.../icinga.cmd
http://finalrewind.org/projects/icli
diff --git a/bin/icli b/bin/icli
index 88a37df..07577b6 100755
--- a/bin/icli
+++ b/bin/icli
@@ -9,6 +9,7 @@ use 5.010;
no if $] >= 5.018, warnings => "experimental::smartmatch";
+use App::Icli::ConfigData;
use Carp qw(croak);
use Getopt::Long qw/:config bundling/;
use List::MoreUtils qw(any firstval);
@@ -19,9 +20,9 @@ use Term::Size;
our $VERSION = '0.46';
my ( $cache, $config, $data, $extra );
-my $config_file = '/var/cache/icinga/objects.cache';
-my $status_file = '/var/lib/icinga/status.dat';
-my $rw_file = '/var/lib/icinga/rw/icinga.cmd';
+my $config_file = App::Icli::ConfigData->config('object_file');
+my $status_file = App::Icli::ConfigData->config('status_file');
+my $rw_file = App::Icli::ConfigData->config('command_file');
my $context;
my $colours = 1;
my $list_type = 's';
@@ -1080,8 +1081,7 @@ Note: Acknowledgement of host problems is not yet supported.
=item B<-c>|B<--config> I<config>
-Read config from I<file> instead of the default
-F</var/cache/icinga/objects.cache>
+Read config from I<file>
=item B<-C>|B<--no-colours>
@@ -1089,13 +1089,11 @@ Disable colours in output
=item B<-f>|B<--status-file> I<file>
-Read the status from I<file> instead of the default
-F</var/lib/icinga/status.dat>
+Read the status from I<file>
=item B<-F>|B<--rw-file> I<file>
-Use I<file> as external commands file. Default:
-F</var/lib/icinga/rw/icinga.cmd>
+Use I<file> as external commands file.
=item B<-g>|B<--hostgroup> I<hostgroup>