[Oval-commits] r370 - trunk/oval-monitor

Pavel Vinogradov blaze-guest at alioth.debian.org
Mon Sep 15 17:04:57 UTC 2008


Author: blaze-guest
Date: 2008-09-15 17:04:56 +0000 (Mon, 15 Sep 2008)
New Revision: 370

Added:
   trunk/oval-monitor/reporter.py
Removed:
   trunk/oval-monitor/db.py
Log:
Rename db module to reporter

Deleted: trunk/oval-monitor/db.py
===================================================================
--- trunk/oval-monitor/db.py	2008-09-14 15:54:55 UTC (rev 369)
+++ trunk/oval-monitor/db.py	2008-09-15 17:04:56 UTC (rev 370)
@@ -1,211 +0,0 @@
-#!/usr/bin/python
-# -*- coding: utf-8 -*-
-#                                                                                                   # Written by Pavel Vinogradov
-# Licensed under the GNU General Public License version 2.
-
-from ConfigParser import SafeConfigParser
-from dba import dba, dbaNotAccesible
-import os, sys, time, getopt
-import traceback, exceptions
-sys.path = ['/usr/share/oval-server'] + sys.path
-
-assert sys.version_info >= (2,4), 'Requires Python 2.4 or better'
-
-class configNotFoundError (Exception):
-    pass
-
-def usage (prog = 'oval-monitor.py'):
-    """Print information about script flags and options"""
-
-    print """usage: python %s [-h] [-c <config>] [-a <agent ip>] [-d <dsa id>]
-\t-h\tthis help
-\t-c\tpath to config file (by default /etc/oval/server.conf
-\t-a\tagent id
-\t-d\tDebian Security Annnounce id
-""" % prog
-
-class Report:
-    
-    config = SafeConfigParser()
-
-    def __init__(self, cfgfile):
-        try:
-            # Read global server config
-            if not self.config.read(cfgfile):
-                raise configNotFoundError, 'Config file %s not found.\n' % cfgfile 
-
-            self.dbPath = self.config.get ('general', 'db')
-            #Init static fields in dba and Dsa2Oval classes
-            dba.dbPath = "/tmp/oval-server.db"#self.dbPath
-            self.db = dba ()
-        except Exception, e:
-            raise e
-
-    def getAgentAffectedVuln (self, agentID):
-        """ Return list of affected DSA for certain agent
-
-        Return list of DSA numbers which affected host for certain agent.
-
-        @type agentID: C(integer)
-        @param agentID: Identificator of inspected agent
-        @rtype: C(list)
-        @return: list of DSA numbers
-        """
-
-        cursor = self.db.getCursor()
-
-        cursor.execute ('SELECT vulnDSA from affected WHERE agentID = %d and status = 1' % agentID)
-        result = cursor.fetchall()
-        return result
-
-    def getAgentNottestedVuln (self, agentID):
-        """ Return list of not tested DSA for certain agent
-
-        Return list of DSA numbers which not tested again host for certain agent.
-
-        @type agentID: C(integer)
-        @param agentID: Identificator of inspected agent
-        @rtype: C(list)
-        @return: list of DSA numbers
-        """
-
-        cursor = self.db.getCursor()
-        
-        cursor.execute ("""SELECT vulnDSA FROM vulnerabilities 
-            WHERE vulnDSA NOT IN (
-                SELECT vulnDSA FROM affected where agentID = %d);
-                """ % agentID)
-        result = cursor.fetchall()
-        return result
-
-    def reportAgent (self, agentID):
-        """Generate report for certain agent.
-
-        Generate report, which include list of affected and not tested DSA.
-        Also contain number of not affected DSA.
-
-        @type agentID: C(integer)
-        @param agentID: Identificator of inspected agent
-        """
-
-        cursor = self.db.getCursor()
-
-        cursor.execute ('SELECT vulnDSA, status from affected WHERE agentID = %d' % agentID)
-        dsas = cursor.fetchall()
-        count = 0
-
-        print 'Agent %d:' % agentID
-        for dsa in dsas:
-            if dsa[1] == 1:
-                print '\tAffected to DSA ID %s' % dsa[0]
-            else:
-                count += 1
-        print '\tNot affected to %d DSA' % count
-
-        print '--------------------------'
-        cursor.execute ("""SELECT vulnerabilities.vulnDSA FROM vulnerabilities 
-            OUTER JOIN affected
-            ON vulnerabilities.vulnDSA = affected.vulnDSA
-            WHERE affected.agentID = %d AND vulnerabilities.vulnTimestamp > affected.vulnTimestamp OR affected.vulnTimestamp IS NULL;""" % agentID)
-
-        dsas = cursor.fetchall()
-        count = 0
-        for dsa in dsas:
-            print 'Not tested again DSA ID %s' %dsa[0]
-            count += 1    
-            
-    def reportDSA (self, dsaID):
-        """Generate report for certain DSA.
-
-        Generate report, which include list of affected and not tested agents 
-        again certain DSA.
-
-        @type agentID: C(integer)
-        @param agentID: Identificator of inspected DSA
-        """
-        
-        cursor = self.db.getCursor()
-        cursor.execute ('SELECT affected.agentID, agents.agentName from affected JOIN agents on affected.agentID = agents.agentID WHERE vulnDSA = %d and status = 1' % dsaID)
-        agents = cursor.fetchall ()
-        print 'Agents affected to DSA %d:' % dsaID
-        for agent in agents:
-            print '\t%d \t %s' % (agent[0], agent[1])
-
-        print '------------------------------'
-        cursor.execute ("""
-            SELECT agentID, agentName from agents 
-                WHERE agentID NOT IN (
-                    SELECT agentID FROM affected WHERE vulnDSA = %d);""" % dsaID)
-        agents = cursor.fetchall ()
-        print 'Agents not tested to DSA %d:' % dsaID
-        for agent in agents:
-            print '\t%d \t %s' % (agent[0], agent[1])    
-
-    def reportFull (self):
-        """Generate full report about status of all agents.
-
-        Generate report, which include list of all registered agents with:
-        ID, IP, number of affected and not tested DSA.
-        """
-        result = ""
-        
-        cursor = self.db.getCursor()
-
-        cursor.execute ("SELECT * FROM agents;")
-        agents = cursor.fetchall()
-
-        result += 'Agents: (ID \t IP \t\t Aff \tNot tested)\n'
-        for agent in agents:
-            result += '\t %d \t %s \t %s \t %s\n' % (agent[0], agent[1], len(self.getAgentAffectedVuln(agent[0])), len(self.getAgentNottestedVuln(agent[0])))
-    
-        cursor.execute ("SELECT count(*) from vulnerabilities;")
-        dsas = cursor.fetchall()[0][0]
-        result += 'DSA in repository: %d\n' % dsas
-        
-        return result
-
-if __name__ == "__main__":
-    #Parse command line options. 
-    #By default we search for config file in global etc directory 
-    opts = {'-c' : '/etc/oval/server.conf'}
-    
-    try:
-        opt, args = getopt.getopt (sys.argv[1:], 'hc:a:d:')
-    except getopt.GetoptError:
-        usage (sys.argv[0])
-        sys.exit(1)
-    
-    for key, value in opt: 
-        opts[key] = value
-
-    if opts.has_key ('-h'):
-        usage(sys.argv[0])
-        sys.exit(0)
-
-    try:
-        reporter = Report (opts['-c'])
-    
-        if opts.has_key ('-a'):
-            try:
-                reporter.reportAgent (int(opts['-a']))
-            except ValueError:
-                print 'Please enter numeric agent ID'
-        else:
-            if opts.has_key ('-d'):
-                try:
-                    reporter.reportDSA (int(opts['-d']))
-                except ValueError:
-                    print 'Please enter numeric DSA id'
-            else:
-                reporter.reportFull ()
-    
-    except configNotFoundError, e:
-        sys.stderr.write (str(e))
-    except dbaNotAccesible, e:
-        sys.stderr.write ("ERROR: Can't access to database file\n")
-        usage(sys.argv[0])
-    except exceptions.SystemExit, e:
-        raise e
-    except Exception, e:
-        sys.stderr.write('ERROR: Unhandled error during execution: %s : %s.\n' % (e.__class__, str(e)))
-        traceback.print_exc()
\ No newline at end of file

Copied: trunk/oval-monitor/reporter.py (from rev 369, trunk/oval-monitor/db.py)
===================================================================
--- trunk/oval-monitor/reporter.py	                        (rev 0)
+++ trunk/oval-monitor/reporter.py	2008-09-15 17:04:56 UTC (rev 370)
@@ -0,0 +1,211 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+#                                                                                                   # Written by Pavel Vinogradov
+# Licensed under the GNU General Public License version 2.
+
+from ConfigParser import SafeConfigParser
+from dba import dba, dbaNotAccesible
+import os, sys, time, getopt
+import traceback, exceptions
+sys.path = ['/usr/share/oval-server'] + sys.path
+
+assert sys.version_info >= (2,4), 'Requires Python 2.4 or better'
+
+class configNotFoundError (Exception):
+    pass
+
+def usage (prog = 'oval-monitor.py'):
+    """Print information about script flags and options"""
+
+    print """usage: python %s [-h] [-c <config>] [-a <agent ip>] [-d <dsa id>]
+\t-h\tthis help
+\t-c\tpath to config file (by default /etc/oval/server.conf
+\t-a\tagent id
+\t-d\tDebian Security Annnounce id
+""" % prog
+
+class Report:
+    
+    config = SafeConfigParser()
+
+    def __init__(self, cfgfile):
+        try:
+            # Read global server config
+            if not self.config.read(cfgfile):
+                raise configNotFoundError, 'Config file %s not found.\n' % cfgfile 
+
+            self.dbPath = self.config.get ('general', 'db')
+            #Init static fields in dba and Dsa2Oval classes
+            dba.dbPath = "/tmp/oval-server.db"#self.dbPath
+            self.db = dba ()
+        except Exception, e:
+            raise e
+
+    def getAgentAffectedVuln (self, agentID):
+        """ Return list of affected DSA for certain agent
+
+        Return list of DSA numbers which affected host for certain agent.
+
+        @type agentID: C(integer)
+        @param agentID: Identificator of inspected agent
+        @rtype: C(list)
+        @return: list of DSA numbers
+        """
+
+        cursor = self.db.getCursor()
+
+        cursor.execute ('SELECT vulnDSA from affected WHERE agentID = %d and status = 1' % agentID)
+        result = cursor.fetchall()
+        return result
+
+    def getAgentNottestedVuln (self, agentID):
+        """ Return list of not tested DSA for certain agent
+
+        Return list of DSA numbers which not tested again host for certain agent.
+
+        @type agentID: C(integer)
+        @param agentID: Identificator of inspected agent
+        @rtype: C(list)
+        @return: list of DSA numbers
+        """
+
+        cursor = self.db.getCursor()
+        
+        cursor.execute ("""SELECT vulnDSA FROM vulnerabilities 
+            WHERE vulnDSA NOT IN (
+                SELECT vulnDSA FROM affected where agentID = %d);
+                """ % agentID)
+        result = cursor.fetchall()
+        return result
+
+    def reportAgent (self, agentID):
+        """Generate report for certain agent.
+
+        Generate report, which include list of affected and not tested DSA.
+        Also contain number of not affected DSA.
+
+        @type agentID: C(integer)
+        @param agentID: Identificator of inspected agent
+        """
+
+        cursor = self.db.getCursor()
+
+        cursor.execute ('SELECT vulnDSA, status from affected WHERE agentID = %d' % agentID)
+        dsas = cursor.fetchall()
+        count = 0
+
+        print 'Agent %d:' % agentID
+        for dsa in dsas:
+            if dsa[1] == 1:
+                print '\tAffected to DSA ID %s' % dsa[0]
+            else:
+                count += 1
+        print '\tNot affected to %d DSA' % count
+
+        print '--------------------------'
+        cursor.execute ("""SELECT vulnerabilities.vulnDSA FROM vulnerabilities 
+            OUTER JOIN affected
+            ON vulnerabilities.vulnDSA = affected.vulnDSA
+            WHERE affected.agentID = %d AND vulnerabilities.vulnTimestamp > affected.vulnTimestamp OR affected.vulnTimestamp IS NULL;""" % agentID)
+
+        dsas = cursor.fetchall()
+        count = 0
+        for dsa in dsas:
+            print 'Not tested again DSA ID %s' %dsa[0]
+            count += 1    
+            
+    def reportDSA (self, dsaID):
+        """Generate report for certain DSA.
+
+        Generate report, which include list of affected and not tested agents 
+        again certain DSA.
+
+        @type agentID: C(integer)
+        @param agentID: Identificator of inspected DSA
+        """
+        
+        cursor = self.db.getCursor()
+        cursor.execute ('SELECT affected.agentID, agents.agentName from affected JOIN agents on affected.agentID = agents.agentID WHERE vulnDSA = %d and status = 1' % dsaID)
+        agents = cursor.fetchall ()
+        print 'Agents affected to DSA %d:' % dsaID
+        for agent in agents:
+            print '\t%d \t %s' % (agent[0], agent[1])
+
+        print '------------------------------'
+        cursor.execute ("""
+            SELECT agentID, agentName from agents 
+                WHERE agentID NOT IN (
+                    SELECT agentID FROM affected WHERE vulnDSA = %d);""" % dsaID)
+        agents = cursor.fetchall ()
+        print 'Agents not tested to DSA %d:' % dsaID
+        for agent in agents:
+            print '\t%d \t %s' % (agent[0], agent[1])    
+
+    def reportFull (self):
+        """Generate full report about status of all agents.
+
+        Generate report, which include list of all registered agents with:
+        ID, IP, number of affected and not tested DSA.
+        """
+        result = ""
+        
+        cursor = self.db.getCursor()
+
+        cursor.execute ("SELECT * FROM agents;")
+        agents = cursor.fetchall()
+
+        result += 'Agents: (ID \t IP \t\t Aff \tNot tested)\n'
+        for agent in agents:
+            result += '\t %d \t %s \t %s \t %s\n' % (agent[0], agent[1], len(self.getAgentAffectedVuln(agent[0])), len(self.getAgentNottestedVuln(agent[0])))
+    
+        cursor.execute ("SELECT count(*) from vulnerabilities;")
+        dsas = cursor.fetchall()[0][0]
+        result += 'DSA in repository: %d\n' % dsas
+        
+        return result
+
+if __name__ == "__main__":
+    #Parse command line options. 
+    #By default we search for config file in global etc directory 
+    opts = {'-c' : '/etc/oval/server.conf'}
+    
+    try:
+        opt, args = getopt.getopt (sys.argv[1:], 'hc:a:d:')
+    except getopt.GetoptError:
+        usage (sys.argv[0])
+        sys.exit(1)
+    
+    for key, value in opt: 
+        opts[key] = value
+
+    if opts.has_key ('-h'):
+        usage(sys.argv[0])
+        sys.exit(0)
+
+    try:
+        reporter = Report (opts['-c'])
+    
+        if opts.has_key ('-a'):
+            try:
+                reporter.reportAgent (int(opts['-a']))
+            except ValueError:
+                print 'Please enter numeric agent ID'
+        else:
+            if opts.has_key ('-d'):
+                try:
+                    reporter.reportDSA (int(opts['-d']))
+                except ValueError:
+                    print 'Please enter numeric DSA id'
+            else:
+                reporter.reportFull ()
+    
+    except configNotFoundError, e:
+        sys.stderr.write (str(e))
+    except dbaNotAccesible, e:
+        sys.stderr.write ("ERROR: Can't access to database file\n")
+        usage(sys.argv[0])
+    except exceptions.SystemExit, e:
+        raise e
+    except Exception, e:
+        sys.stderr.write('ERROR: Unhandled error during execution: %s : %s.\n' % (e.__class__, str(e)))
+        traceback.print_exc()
\ No newline at end of file


Property changes on: trunk/oval-monitor/reporter.py
___________________________________________________________________
Name: svn:mergeinfo
   + 




More information about the Oval-commits mailing list