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

Naparuba naparuba at gmail.com
Tue Feb 28 22:12:06 UTC 2012


The following commit has been merged in the debian/master branch:
commit 58fa4f2a864b24661755f9c12930375d8f222cfb
Author: Naparuba <naparuba at gmail.com>
Date:   Thu Jan 5 16:59:54 2012 +0100

    *Add : new way for nmap discovery output. Now there is no more a big mapping pass. It will output what it can, and it's for the discovery_rule do do this job now, it's far more flexible (and need far less code!)
    a BIG thanks to all folks that send me sample xml output :)

diff --git a/etc/discovery_rules.cfg b/etc/discovery_rules.cfg
index 42c06e7..b3ffb1a 100644
--- a/etc/discovery_rules.cfg
+++ b/etc/discovery_rules.cfg
@@ -137,30 +137,51 @@ define discoveryrule {
        +use                     windows
 }
 
+# windows 2000 tag...
+# Yes, there are still some outside!
+define discoveryrule {
+       discoveryrule_name       Windows2000
+       creation_type            host
+       os                       windows
+       osversion		2000
+       +use                     windows2000
+}
+
+
 # windows 2003 tag
 define discoveryrule {
-       discoveryrule_name       Windows
+       discoveryrule_name       Windows2003
        creation_type            host
        os                       windows
        osversion		2003
        +use                     windows2003
 }
 
-#windows 2008 is return as 7 by nmap...
+#windows 2008 is return as vista by nmap...
 define discoveryrule {
-       discoveryrule_name       Windows
+       discoveryrule_name       Windows2008
        creation_type            host
        os                       windows
-       osversion                7
+       osversion                vista
        +use                     windows2008
 }
 
 
+#windows 2008 is return as vista by nmap...
+define discoveryrule {
+       discoveryrule_name       Windows2008r2
+       creation_type            host
+       os                       windows
+       osversion                7
+       +use                     windows2008,windows2008r2
+}
+
+
 # HPUX part
 define discoveryrule {
-       discoveryrule_name       Windows
+       discoveryrule_name       HpUx
        creation_type            host
-       os                       hpux
+       os                       hp-ux
        +use                     hpux
 }
 
@@ -177,6 +198,63 @@ define discoveryrule {
 
 
 
+# Network Equipements Now
+
+# Generic tags
+# Switch
+define discoveryrule {
+       discoveryrule_name       Switch
+       creation_type            host
+       ostype			switch
+       +use                     switch
+}
+
+# Generic router
+define discoveryrule {
+       discoveryrule_name       Router
+       creation_type            host
+       ostype                   router
+       +use                     router
+}
+
+
+# Fortinate firewalls
+define discoveryrule {
+       discoveryrule_name       Fortinate
+       creation_type            host
+       macvendor		fortinet
+       +use                     fortinet
+}
+
+# Cisco equipements
+define discoveryrule {
+       discoveryrule_name       Cisco
+       creation_type            host
+       osvendor			cisco
+       +use                     cisco
+}
+
+# Nortel equipements
+define discoveryrule {
+       discoveryrule_name       Nortel
+       creation_type            host
+       osvendor                 nortel
+       +use                     nortel
+}
+
+
+# Procurve
+define discoveryrule {
+       discoveryrule_name       Procurve
+       creation_type            host
+       ostype			switch
+       osvendor			hp
+       +use                     procurve
+}
+
+
+
+
 
 
 
diff --git a/libexec/nmap_discovery_runner.py b/libexec/nmap_discovery_runner.py
index dd7a003..c86d055 100755
--- a/libexec/nmap_discovery_runner.py
+++ b/libexec/nmap_discovery_runner.py
@@ -136,8 +136,8 @@ class DetectedHost:
 
 
     # Fill the different os possibilities
-    def add_os_possibility(self, os, osgen, accuracy):
-        self.os_possibilities.append( (os, osgen, accuracy) )
+    def add_os_possibility(self, os, osgen, accuracy, os_type, vendor):
+        self.os_possibilities.append( (os, osgen, accuracy, os_type, vendor) )
 
 
     # We search if our potential parent is present in the
@@ -163,48 +163,35 @@ class DetectedHost:
     def compute_os(self):
         self.os_name = 'Unknown OS'
         self.os_version = 'Unknown Version'
+        self.os_type = 'Unknown Type'
+        self.os_vendor = 'Unknown Vendor'
 
-        # bailout if we got no os :(
+        # Bailout if we got no os :(
         if len(self.os_possibilities) == 0:
             return
 
         max_accuracy = 0
-        for (os, osgen, accuracy) in self.os_possibilities:
+        for (os, osgen, accuracy , os_type, vendor) in self.os_possibilities:
             if accuracy > max_accuracy:
                 max_accuracy = accuracy
 
-        # now get the entry with the max value
-        for (os, osgen, accuracy) in self.os_possibilities:
-            print "Can be", (os, osgen, accuracy)
+        # now get the entry with the max value, the first one
+        for (os, osgen, accuracy, os_type, vendor) in self.os_possibilities:
+            print "Can be", (os, osgen, accuracy, os_type, vendor)
             if accuracy == max_accuracy:
-                self.os = (os, osgen)
+                self.os = (os, osgen, os_type, vendor)
+                break
 
-        print "Try to match", self.os
+        print "Will dump", self.os
 
-        #Ok, unknown os... not good
-        if self.os == ('', ''):
-            return
-
-        map = {('Windows', '2000') : 'windows',
-               ('Windows', '2003') : 'windows',
-               ('Windows', '7') : 'windows',
-               ('Windows', 'XP') : 'windows',
-               # ME? you are a stupid moron!
-               ('Windows', 'Me') : 'windows',
-               ('Windows', '2008') : 'windows',
-               # that's a good boy :)
-               ('Linux', '2.6.X') : 'linux',
-               ('Linux', '2.4.X') : 'linux',
-               # HPUX? I think you didn't choose...
-               ('HP-UX', '11.X') : 'hpux',
-               ('HP-UX', '10.X') : 'hpux',
-               }
-
-        if self.os not in map:
+        # Ok, unknown os... not good
+        if self.os == ('', '', '', ''):
             return
         
-        self.os_name = map[self.os]
-        self.os_version = self.os[1]
+        self.os_name = self.os[0].lower()
+        self.os_version = self.os[1].lower()
+        self.os_type = self.os[2].lower()
+        self.os_vendor = self.os[3].lower()
 
 
     # Return the string of the 'discovery' items
@@ -231,7 +218,9 @@ class DetectedHost:
     # for system output
     def get_discovery_system(self):
         r = '%s::os=%s' % (self.get_name(), self.os_name)+'\n'
-        r += '%s::osversion=%s' % (self.get_name(), self.os_version)
+        r += '%s::osversion=%s' % (self.get_name(), self.os_version)+'\n'
+        r += '%s::ostype=%s' % (self.get_name(), self.os_type)+'\n'
+        r += '%s::osvendor=%s' % (self.get_name(), self.os_vendor)
         return r
         
     def get_discovery_macvendor(self):
@@ -318,7 +307,7 @@ for h in hosts:
             dh.ip = addr.attrib['addr']
         if addrtype == "mac":
             if 'vendor' in addr.attrib:
-                dh.mac_vendor = addr.attrib['vendor']
+                dh.mac_vendor = addr.attrib['vendor'].lower()
 
 
     # Now we've got the hostnames
@@ -361,12 +350,11 @@ for h in hosts:
         #print "Class", c.__dict__
         family = c.attrib['osfamily']
         accuracy = c.attrib['accuracy']
-        if 'osgen' in c.attrib:
-            osgen = c.attrib['osgen']
-        else:
-            osgen = None
+        osgen = c.attrib.get('osgen', '')
+        os_type = c.attrib.get('type', '')
+        vendor = c.attrib.get('vendor', '')
         #print "Type:", family, osgen, accuracy
-        dh.add_os_possibility(family, osgen, accuracy)
+        dh.add_os_possibility(family, osgen, accuracy, os_type, vendor)
     # Ok we can compute our OS now :)
     dh.compute_os()
 

-- 
UNNAMED PROJECT



More information about the Pkg-nagios-changes mailing list