[Pkg-nagios-changes] [SCM] UNNAMED PROJECT branch, debian/master, updated. 810edbdd3feedbfe37f4a65bee50b57b2f60fa2a

Naparuba naparuba at gmail.com
Tue Feb 28 22:11:48 UTC 2012


The following commit has been merged in the debian/master branch:
commit 1807efcf86b6f9bfd6eab75789d75c63f13ac6c5
Author: Naparuba <naparuba at gmail.com>
Date:   Wed Jan 4 11:13:48 2012 +0100

    * Add : '+' in discovery rule management, so you can 'add' something, like a template.
    * Enh : change sample discovery rules into a host tag based instead of a service based one

diff --git a/bin/shinken-discovery b/bin/shinken-discovery
index 8b5e047..736fa64 100755
--- a/bin/shinken-discovery
+++ b/bin/shinken-discovery
@@ -578,7 +578,20 @@ class DiscoveryMerger:
         # now merge them
         d = {'host_name' : host}
         for r in host_rules:
-            d.update(r.writing_properties)
+            for k,v in r.writing_properties.iteritems():
+                # If it's a + (add) property, add with a ,
+                if k.startswith('+'):
+                    prop = k[1:]
+                    # If the d do not already have this prop,
+                    # just push it
+                    if not prop in d:
+                        d[prop] = v
+                    # oh, must add with a , so
+                    else:
+                        d[prop] = d[prop] + ',' + v
+                else:
+                    d[k] = v
+            print "current D", d
         print "Will generate", d
         self.write_host_config_to_file(host, d)
 
diff --git a/etc/discovery_rules.cfg b/etc/discovery_rules.cfg
index cb3f5c3..9633890 100644
--- a/etc/discovery_rules.cfg
+++ b/etc/discovery_rules.cfg
@@ -1,203 +1,153 @@
-##### Here are some rules for generating classic services for network
+##### Here are some rules for tagging hosts with classic templates
+
 define discoveryrule {
-       discoveryrule_name	HostGeneric
-       isup			1
-       use			generic-host
+       discoveryrule_name       Http
        creation_type		host
+       openports                ^80$
+       +use			http
 }
 
 
-
-##### Here are some rules for generating classic services for network
-define discoveryrule {
-       discoveryrule_name	Http
-       openports		^80$
-       check_command		check_http
-       service_description	Http
-       use			generic-service
-}
-
 define discoveryrule {
        discoveryrule_name       Https
+       creation_type		host
        openports                ^443$
-       check_command            check_https
-       service_description      Https
-       use                      generic-service
-}
-
-define discoveryrule {
-       discoveryrule_name       Https-Certificate
-       openports                ^443$
-       check_command            check_https_certificate
-       service_description      Https-Certificate
-       use                      generic-service
+       +use			https
 }
 
 define discoveryrule {
        discoveryrule_name       Ftp
+       creation_type            host
        openports                ^21$
-       check_command            check_ftp
-       service_description      Ftp
-       use                      generic-service
+       +use                     ftp
 }
 
 define discoveryrule {
        discoveryrule_name       Ssh
+       creation_type            host
        openports                ^22$
-       check_command            check_ssh
-       service_description      Ssh
-       use                      generic-service
+       +use                     ssh
 }
 
+
 define discoveryrule {
-       discoveryrule_name       DNS
+       discoveryrule_name       Ssh
+       creation_type            host
        openports                ^53$
-       check_command            check_dig
-       service_description      DNS
-       use                      generic-service
+       +use                     dns
 }
 
+
 define discoveryrule {
-       discoveryrule_name       SMTP
+       discoveryrule_name       Smtp
+       creation_type            host
        openports                ^25$
-       check_command            check_smtp
-       service_description      SMTP
-       use                      generic-service
+       +use                     smtp
 }
 
 define discoveryrule {
-       discoveryrule_name       SMTPS
+       discoveryrule_name       Smtps
+       creation_type            host
        openports                ^465$
-       check_command            check_smtps
-       service_description      SMTPS
-       use                      generic-service
+       +use                     smtps
 }
 
 
 define discoveryrule {
-       discoveryrule_name       LDAP
+       discoveryrule_name       Ldap
+       creation_type            host
        openports                ^389$
-       check_command            check_ldap
-       service_description      389
-       use                      generic-service
+       +use                     ldap
 }
 
 define discoveryrule {
-       discoveryrule_name       LDAPS
+       discoveryrule_name       Ldaps
+       creation_type            host
        openports                ^636$
-       check_command            check_ldaps
-       service_description      LDAPS
-       use                      generic-service
+       +use                     ldaps
 }
 
-## Printers
-# Nmap do nto find them good, so look at ports
 define discoveryrule {
        discoveryrule_name       HPPrinterState
+       creation_type            host
        openports                631,9100
-       check_command            check_hpjd
-       service_description      HPPrinterState
-       use                      generic-service
+       +use                     printer-hp
 }
 
-
-
-###Then some classic RDBMS connection
 define discoveryrule {
-       discoveryrule_name       Mysql-Connexion
+       discoveryrule_name       Mysql
+       creation_type            host
        openports                ^3306$
-       check_command            check_mysql_connection
-       service_description      Mysql-Connexion
-       use                      generic-service
+       +use                     mysql
 }
 
+
 define discoveryrule {
-       discoveryrule_name       Oracle-Listener
+       discoveryrule_name       Oracle
+       creation_type            host
        openports                ^1521$
-       check_command            check_oracle_listener
-       service_description      Oracle-Listener
-       use                      generic-service
+       +use                     oracle
 }
 
+
+
 define discoveryrule {
-       discoveryrule_name       MSSQL-Connexion
+       discoveryrule_name       Mssql
+       creation_type            host
        openports                ^1433$
-       check_command            check_mssql_connection
-       service_description      MSSQL-Connexion
-       use                      generic-service
+       +use                     mssql
 }
 
 
+
+
 ### Look for a VMWare Host
-# Here for CPU
 define discoveryrule {
-       discoveryrule_name       ESX-Host-Cpu
+       discoveryrule_name       ESX
+       creation_type            host
        isesxhost		1
-       check_command            check_esx_host!cpu
-       service_description      ESX-host-Cpu
-       use                      generic-service
+       +use                     esx
 }
 
-# Now Memory
-define discoveryrule {
-       discoveryrule_name       ESX-Host-Mem
-       isesxhost                1
-       check_command            check_esx_host!mem
-       service_description      ESX-host-Mem
-       use                      generic-service
-}
+#### And now look for VMware machines
 
-# Now I/O
 define discoveryrule {
-       discoveryrule_name       ESX-Host-IO
-       isesxhost                1
-       check_command            check_esx_host!io
-       service_description      ESX-host-IO
-       use                      generic-service
+       discoveryrule_name       VMware-VM
+       creation_type            host
+       isesxvm                  1
+       +use                     vmware-vm
 }
 
-# Now Network
-define discoveryrule {
-       discoveryrule_name       ESX-Host-Net
-       isesxhost                1
-       check_command            check_esx_host!net
-       service_description      ESX-host-Net
-       use                      generic-service
-}
 
-#### And now look for VMware machines
-# Now CPU
-define discoveryrule {
-       discoveryrule_name       ESX-VM-Cpu
-       isesxvm                  1
-       check_command            check_esx_vm!cpu
-       service_description      ESX-VM-Cpu
-       use                      generic-service
-}
 
-# Now Memory
-define discoveryrule {
-       discoveryrule_name       ESX-VM-Mem
-       isesxvm                  1
-       check_command            check_esx_vm!mem
-       service_description      ESX-VM-Mem
-       use                      generic-service
-}
 
-# Now IO
+
+
+
+
+
+
+# The generic-host should be AT THE END, because template are from more specific to
+# the msot generic one
 define discoveryrule {
-       discoveryrule_name       ESX-VM-IO
-       isesxvm                  1
-       check_command            check_esx_vm!io
-       service_description      ESX-VM-IO
-       use                      generic-service
+       discoveryrule_name	HostGeneric
+       creation_type		host
+       isup			1
+       +use			generic-host
 }
 
-# Now Network
+
+
+
+
+# Sample for service creation.
+# It's just a sample, because the 77777 port is not valid :)
+# but should how to create a service with a rule
+
 define discoveryrule {
-       discoveryrule_name       ESX-VM-Net
-       isesxvm                  1
-       check_command            check_esx_vm!net
-       service_description      ESX-VM-Net
+       discoveryrule_name       Sample-Service
+       openports                ^77777$
+       check_command            check_dummy
+       service_description      Sample-Service
        use                      generic-service
 }
diff --git a/etc/packs/vmware/vm/cpu.cfg b/etc/packs/vmware/vm/cpu.cfg
index d271404..9aee2bf 100644
--- a/etc/packs/vmware/vm/cpu.cfg
+++ b/etc/packs/vmware/vm/cpu.cfg
@@ -2,6 +2,6 @@ define service{
    name           Cpu
    use            generic-service
    register       0
-   host_name	  vm
+   host_name	  vmware-vm
    check_command  check_esx_vm_cpu
 }
diff --git a/etc/packs/vmware/vm/io.cfg b/etc/packs/vmware/vm/io.cfg
index 6cb44d3..6feec20 100644
--- a/etc/packs/vmware/vm/io.cfg
+++ b/etc/packs/vmware/vm/io.cfg
@@ -2,6 +2,6 @@ define service{
    name           Io
    use            generic-service
    register       0
-   host_name	  vm
+   host_name	  vmware-vm
    check_command  check_esx_vm_io
 }
diff --git a/etc/packs/vmware/vm/mem.cfg b/etc/packs/vmware/vm/mem.cfg
index 66ca8ff..416bf21 100644
--- a/etc/packs/vmware/vm/mem.cfg
+++ b/etc/packs/vmware/vm/mem.cfg
@@ -2,6 +2,6 @@ define service{
    name           Mem
    use            generic-service
    register       0
-   host_name	  vm
+   host_name	  vmware-vm
    check_command  check_esx_vm_mem
 }
diff --git a/etc/packs/vmware/vm/net.cfg b/etc/packs/vmware/vm/net.cfg
index 7aa79c0..251f8ad 100644
--- a/etc/packs/vmware/vm/net.cfg
+++ b/etc/packs/vmware/vm/net.cfg
@@ -2,6 +2,6 @@ define service{
    name           Net
    use            generic-service
    register       0
-   host_name	  vm
+   host_name	  vmware-vm
    check_command  check_esx_vm_net
 }
diff --git a/etc/packs/vmware/vm/templates.cfg b/etc/packs/vmware/vm/templates.cfg
index 02624f9..a8e7366 100644
--- a/etc/packs/vmware/vm/templates.cfg
+++ b/etc/packs/vmware/vm/templates.cfg
@@ -1,6 +1,6 @@
 # VM template
 define host{
-   name           vm
+   name           vmware-vm
    use            generic-host
    register       0
 }
diff --git a/shinken/objects/discoveryrule.py b/shinken/objects/discoveryrule.py
index 104d063..3ebf7bd 100644
--- a/shinken/objects/discoveryrule.py
+++ b/shinken/objects/discoveryrule.py
@@ -82,10 +82,13 @@ class Discoveryrule(Item):
         # if not, in matches or not match (if key starts
         # with a !, it's a not rule)
         # -> in self.matches or self.not_matches
+        # in writing properties if start with + (means 'add this')
         for key in params:
             # Some key are quite special
             if key in ['use']:
                 self.writing_properties[key] = params[key]
+            elif key.startswith('+'):
+                self.writing_properties[key] = params[key]
             elif key in cls.properties:
                 setattr(self, key, params[key])
             elif key in tcls.properties:
diff --git a/test/etc/discovery_def/discovery.cfg b/test/etc/discovery_def/discovery.cfg
index c2a90cb..351753d 100644
--- a/test/etc/discovery_def/discovery.cfg
+++ b/test/etc/discovery_def/discovery.cfg
@@ -29,3 +29,13 @@ define discoveryrule {
        service_description      Http
        use                      generic-service
 }
+
+
+
+# Test for host creation and tagging
+define discoveryrule {
+       discoveryrule_name	GenHttpHost
+       creation_type		host
+       openports                ^80$
+       +use			http
+}
\ No newline at end of file
diff --git a/test/test_discovery_def.py b/test/test_discovery_def.py
index 86d155b..e25a89b 100755
--- a/test/test_discovery_def.py
+++ b/test/test_discovery_def.py
@@ -50,7 +50,6 @@ class TestDiscoveryConf(ShinkenTest):
         value = '80'
         self.assert_(genhttp.is_matching(key, value) == True)
         
-        
         # Low look for a list of matchings
         l = [('openports', '80'), ('os', 'windows')]
         # should match this
@@ -89,7 +88,7 @@ class TestDiscoveryConf(ShinkenTest):
 
 
 
-    #Look for good definition and call of a discoveryrun
+    # Look for good definition and call of a discoveryrun
     def test_look_for_discorun(self):
         nmap = self.sched.conf.discoveryruns.find_by_name('nmap')
         self.assert_(nmap != None)
@@ -107,6 +106,38 @@ class TestDiscoveryConf(ShinkenTest):
         print "Output", nmap.current_launch.output
         print "LongOutput", nmap.current_launch.long_output
 
+
+    #Change ME :)
+    def test_look_for_host_discorule(self):
+        genhttp = self.sched.conf.discoveryrules.find_by_name('GenHttpHost')
+        self.assert_(genhttp != None)
+        self.assert_(genhttp.creation_type == 'host')
+        self.assert_(genhttp.matches['openports'] == '^80$')
+        
+        key = 'osversion'
+        value = '2003'
+        # Should not match this
+        self.assert_(genhttp.is_matching(key, value) == False)
+        # But should match this one
+        key = 'openports'
+        value = '80'
+        self.assert_(genhttp.is_matching(key, value) == True)
+        
+        # Low look for a list of matchings
+        l = [('openports', '80'), ('os', 'windows')]
+        # should match this
+        self.assert_(genhttp.is_matching_disco_datas(l) == True)
+        # Match this one too
+        l = [('openports', '80'), ('os', 'windows'), ('super', 'man')]
+        self.assert_(genhttp.is_matching_disco_datas(l) == True)
+        # And this last one
+        l = [('openports', '80')]
+        self.assert_(genhttp.is_matching_disco_datas(l) == True)
+
+        print "Writing properties"
+        print genhttp.writing_properties
+
+
 if __name__ == '__main__':
     unittest.main()
 

-- 
UNNAMED PROJECT



More information about the Pkg-nagios-changes mailing list