[icinga-checkins] icinga.org: icinga2/feature/configconvert-2743: configconvert: add support for * as service host_name next to comma seperated list

git at icinga.org git at icinga.org
Tue May 28 14:55:02 CEST 2013


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

Author: Michael Friedrich <michael.friedrich at netways.de>
Date:   Tue May 28 14:52:33 2013 +0200

configconvert: add support for * as service host_name next to comma seperated list

this is currently a proof of concept for services only, but should
target all the object tricks later on. this will be done on host_name
lookup and stored as array.

http://docs.icinga.org/latest/en/objecttricks.html

refs #4010

---

 contrib/configconvert/Icinga2/Convert.pm |   30 +++++++++++++++++++++++++++++-
 1 files changed, 29 insertions(+), 1 deletions(-)

diff --git a/contrib/configconvert/Icinga2/Convert.pm b/contrib/configconvert/Icinga2/Convert.pm
index 6e78a89..ac39b17 100644
--- a/contrib/configconvert/Icinga2/Convert.pm
+++ b/contrib/configconvert/Icinga2/Convert.pm
@@ -289,6 +289,27 @@ sub obj_get_usernames_arr_by_usergroup_name {
     return @user_names;
 }
 
+sub obj_1x_get_all_hostnames_arr {
+    my $objs = shift;
+    my $obj_type = 'host';
+    my $obj_attr = 'host_name';
+    my $obj_val = '*';
+    my @host_names = ();
+
+    #debug("My objects hive: ".Dumper($objs));
+
+    #debug("Checking for type=$obj_type attr=$obj_attr val=$obj_val ");
+    foreach my $obj_key (keys %{@$objs{$obj_type}}) {
+        my $obj = @$objs{$obj_type}->{$obj_key};
+        next if !defined($obj->{$obj_attr});
+        #debug("Getting attr $obj_attr and val $obj_val");
+
+        push @host_names, $obj->{$obj_attr};
+    }
+
+    return @host_names;
+}
+
 
 
 # get host_name from object
@@ -359,7 +380,14 @@ sub obj_1x_get_service_host_name_arr {
 
         # convert to array
         delete($obj_1x->{'__I2CONVERT_HOSTNAMES'});
-        @host_name = sort (map { s/^\s+//; s/\s+$//; $_ } split (/,/, $obj_1x->{'host_name'}) );
+
+        # check if host_name is a wildcard, or a possible comma seperated list
+        # using object tricks - http://docs.icinga.org/latest/en/objecttricks.html#objecttricks-service
+        if ($obj_1x->{'host_name'} =~ /^\*$/) {
+            @host_name = obj_1x_get_all_hostnames_arr($objs_1x);
+        } else {
+            @host_name = sort (map { s/^\s+//; s/\s+$//; $_ } split (/,/, $obj_1x->{'host_name'}) );
+        }
         push @{$obj_1x->{'__I2CONVERT_HOSTNAMES'}}, @host_name;
 
         #print "DEBUG: @{$obj_1x->{'__I2CONVERT_HOSTNAMES'}}"; 





More information about the icinga-checkins mailing list