[Oval-commits] r226 - trunk/oval-server
Pavel Vinogradov
blaze-guest at alioth.debian.org
Thu Aug 23 20:07:19 UTC 2007
Author: blaze-guest
Date: 2007-08-23 20:07:19 +0000 (Thu, 23 Aug 2007)
New Revision: 226
Added:
trunk/oval-server/oval-monitor.py
Log:
First version of monitor
Added: trunk/oval-server/oval-monitor.py
===================================================================
--- trunk/oval-server/oval-monitor.py (rev 0)
+++ trunk/oval-server/oval-monitor.py 2007-08-23 20:07:19 UTC (rev 226)
@@ -0,0 +1,136 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# # Written by Pavel Vinogradov
+# Licensed under the GNU General Public License version 2.
+
+from ConfigParser import SafeConfigParser
+from oval.dba.dba import dba
+import os, sys, time, getopt
+import traceback, exceptions
+
+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 oval-server.cfg
+\t-a\tagent ip address
+\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 = self.dbPath
+ self.db = dba ()
+ except:
+ pass
+
+ def reportAgent (self, agentID):
+ cursor = self.db.getCursor()
+
+ cursor.execute ('SELECT vulnDSA, status from affected WHERE agentID = %d' % agentID)
+ dsas = cursor.fetchall()
+ count = 0
+
+ print 'Agent %d\n' % agentID
+ for dsa in dsas:
+ if dsa[1] == 1:
+ print 'Affected to DSA ID %s' % dsa[0]
+ else:
+ count += 1
+ print 'Not affected to %d DSA' % count
+
+ print '--------------------------'
+# cursor.execute ("""SELECT vulnerabilities.vulnDSA FROM vulnerabilities
+# LEFT 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):
+ 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 agents.agentID from agents LEFT JOIN affected ON agents.agentID = affected.agentID WHERE vulnDSA = %d' % dsaID)
+# agents = cursor.fetchall ()
+# print 'Agents not tested to DSA %d:' % dsaID
+# for agent in agents:
+# print '\t%d' % agent[0]
+
+
+
+ def reportFull (self):
+ cursor = self.db.getCursor()
+
+ cursor.execute ("SELECT * FROM agents;")
+ agents = cursor.fetchall()
+
+ print 'Agents: (ID, \t IP)'
+ for agent in agents:
+ print '\t %d \t %s ' % (agent[0], agent[1])
+
+ cursor.execute ("SELECT count(*) from vulnerabilities;")
+ dsas = cursor.fetchall()[0][0]
+ print 'DSA in repository: %d' % dsas
+
+if __name__ == "__main__":
+ #Parse command line options.
+ #By default we search for config file in current directory
+ opts = {'-c' : 'oval-server.cfg'}
+
+ 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'):
+ reporter.reportAgent (int(opts['-a']))
+ else:
+ if opts.has_key ('-d'):
+ reporter.reportDSA (int(opts['-d']))
+ else:
+ reporter.reportFull ()
+
+ except configNotFoundError, e:
+ sys.stderr.write (str(e))
+ except KeyboardInterrupt, e:
+ sys.stderr.write ('Execution interrupted by keyboard.')
+ except exceptions.SystemExit, e:
+ raise e
+ except Exception, e:
+ sys.stderr.write('Unhandled error during execution: %s : %s.\n' % (e.__class__, str(e)))
+ traceback.print_exc()
Property changes on: trunk/oval-server/oval-monitor.py
___________________________________________________________________
Name: svn:executable
+ *
More information about the Oval-commits
mailing list