[icinga-checkins] icinga.org: icinga2/feature/configconvert-2743: configconvert: add getopts and pod2usage incl help

git at icinga.org git at icinga.org
Thu May 2 23:25:06 CEST 2013


Module: icinga2
Branch: feature/configconvert-2743
Commit: 302bf02fdd66a71e4272eb172baddf6655523bf5
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=302bf02fdd66a71e4272eb172baddf6655523bf5

Author: Michael Friedrich <michael.friedrich at netways.de>
Date:   Thu May  2 23:23:29 2013 +0200

configconvert: add getopts and pod2usage incl help

fixes #4041

---

 contrib/configconvert/Icinga2/ExportIcinga2Cfg.pm |    6 +-
 contrib/configconvert/README                      |    8 ++-
 contrib/configconvert/icinga2_convert_v1_v2.pl    |   76 +++++++++++++++++++--
 3 files changed, 81 insertions(+), 9 deletions(-)

diff --git a/contrib/configconvert/Icinga2/ExportIcinga2Cfg.pm b/contrib/configconvert/Icinga2/ExportIcinga2Cfg.pm
index ac5eabb..3a9cc53 100644
--- a/contrib/configconvert/Icinga2/ExportIcinga2Cfg.pm
+++ b/contrib/configconvert/Icinga2/ExportIcinga2Cfg.pm
@@ -34,7 +34,7 @@ use feature 'say';
 #use Icinga2;
 use Icinga2::Utils;
 
-our $dbg_lvl = 1;
+#our $dbg_lvl = 1;
 
 # XXX figure a better way for \t count printing, making dumps more modular
 # XXX sort macros and linked hostservices by name
@@ -72,7 +72,7 @@ sub add_header {
 sub dump_config_line {
     my $icinga2_cfg = shift;
     my $line = shift;
-    our $dbg_lvl;
+    my $dbg_lvl = $icinga2_cfg->{'__I2EXPORT_DEBUG'};
 
     if ($dbg_lvl) {
         print $line. "\n";
@@ -667,7 +667,7 @@ sub dump_notification_2x {
     my $object_type = "object"; # object or template
     my $notification_name = $notification_2x->{'__I2CONVERT_NOTIFICATION_NAME'}; # default, may be changed for templates
 
-    say Dumper($notification_2x);
+    #say Dumper($notification_2x);
     # XXX
     if ($notification_2x->{__I2CONVERT_IS_TEMPLATE} == 1) {
         $object_type = "template";
diff --git a/contrib/configconvert/README b/contrib/configconvert/README
index 403398a..a76620a 100644
--- a/contrib/configconvert/README
+++ b/contrib/configconvert/README
@@ -18,7 +18,13 @@ allowing to define notifications directly on the service definition then.
 All required templates will be inherited from Icinga2's Template Library (ITL).
 
 REQUIREMENTS
-- Perl: Data::Dumper, File::Find, Storable qw(dclone)
+- Perl:
+	Data::Dumper
+	File::Find
+	Storable qw(dclone)
+	Getopt::Long qw(:config no_ignore_case bundling)
+	Pod::Usage
+
 - Icinga2 ITL
 
 TODO
diff --git a/contrib/configconvert/icinga2_convert_v1_v2.pl b/contrib/configconvert/icinga2_convert_v1_v2.pl
old mode 100644
new mode 100755
index 3c582bf..ac28c3c
--- a/contrib/configconvert/icinga2_convert_v1_v2.pl
+++ b/contrib/configconvert/icinga2_convert_v1_v2.pl
@@ -21,6 +21,45 @@
  ******************************************************************************/
 =cut
 
+=head1 NAME
+
+icinga2_convert_v1_v2.pl - convert icinga 1.x config to icinga 2.x format
+
+=head1 SYNOPSIS
+
+icinga2_convert_v1_v2.pl -c <path to icinga.cfg>
+                         -o <output directory for icinga2 config>
+                         [-v]
+                         [-h]
+                         [-V]
+
+Convert Icinga 1.x configuration to new Icinga 2.x configuration format.
+
+=head1 OPTIONS
+
+=over
+
+=item -c|--icingacfgfile <path to icinga.cfg>
+
+Path to your Icinga 1.x main configuration file "icinga.cfg".
+
+=item -o|--outputcfgdir <output directory for icinga2 config>
+
+Directory to Icinga 2.x configuration output.
+
+=item -v|--verbose
+
+Verbose mode.
+
+=item -h|--help
+
+Print help page.
+
+=item -V|--version
+
+print version.
+
+=cut
 
 use warnings;
 use strict;
@@ -28,6 +67,8 @@ use strict;
 use Data::Dumper;
 use File::Find;
 use Storable qw(dclone);
+use Getopt::Long qw(:config no_ignore_case bundling);
+use Pod::Usage;
 
 use feature 'say';
 
@@ -37,10 +78,39 @@ use Icinga2::ExportIcinga2Cfg;
 use Icinga2::Convert;
 use Icinga2::Utils;
 
-# FIXME getopts
+my $version = "0.0.1";
+
+# get command-line parameters
+our $opt;
+GetOptions(
+    "c|icingacfgfile=s" => \$opt->{icinga1xcfg},
+    "o|outputcfgdir=s"  => \$opt->{icinga2xoutputprefix},
+    "v|verbose"         => \$opt->{verbose},
+    "h|help"            => \$opt->{help},
+    "V|version"         => \$opt->{version}
+);
+
 my $icinga1_cfg = "/etc/icinga/icinga.cfg";
 my $icinga2_cfg = {};
 my $conf_prefix = "./conf";
+my $verbose = 1;
+our $dbg_lvl = 1;
+$icinga2_cfg->{'__I2EXPORT_DEBUG'} = 0;
+
+if(defined($opt->{icinga1xcfg})) {
+    $icinga1_cfg = $opt->{icinga1xcfg};
+} 
+if(defined($opt->{icinga2xoutputprefix})) {
+    $conf_prefix = $opt->{icinga2xoutputprefix};
+}
+if(defined($opt->{verbose})) {
+    $verbose = $opt->{verbose};
+    $icinga2_cfg->{'__I2EXPORT_DEBUG'} = 1;
+}
+
+if (defined $opt->{version}) { print $version."\n"; exit 0; }
+if ($opt->{help}) { pod2usage(1); }
+
 $icinga2_cfg->{'main'}= "$conf_prefix/icinga2.conf";
 $icinga2_cfg->{'hosts'}= "$conf_prefix/icinga2-hosts.conf";
 $icinga2_cfg->{'services'}= "$conf_prefix/icinga2-services.conf";
@@ -56,10 +126,6 @@ $icinga2_cfg->{'itl'}->{'notification-template'} = "plugin-notification";
 $icinga2_cfg->{'itl'}->{'timeperiod-template'} = "legacy-timeperiod";
 
 
-my $verbose = 1;
-
-
-our $dbg_lvl = 1;
 my $type_cnt;
 
 ################################################################################





More information about the icinga-checkins mailing list