[Oval-commits] r373 - trunk/oval-monitor
Pavel Vinogradov
blaze-guest at alioth.debian.org
Mon Sep 22 16:05:33 UTC 2008
Author: blaze-guest
Date: 2008-09-22 16:05:33 +0000 (Mon, 22 Sep 2008)
New Revision: 373
Modified:
trunk/oval-monitor/manager.py
trunk/oval-monitor/reporter.py
Log:
New updates in UI
Modified: trunk/oval-monitor/manager.py
===================================================================
--- trunk/oval-monitor/manager.py 2008-09-16 17:57:21 UTC (rev 372)
+++ trunk/oval-monitor/manager.py 2008-09-22 16:05:33 UTC (rev 373)
@@ -6,19 +6,22 @@
from reporter import Report
ID_ABOUT=wx.NewId()
-ID_OPEN=wx.NewId()
+ID_REFRESH=wx.NewId()
ID_PREFERENCES=wx.NewId()
ID_BUTTON1=wx.NewId()
ID_EXIT=wx.NewId()
-class MyGridTable(wx.grid.PyGridTableBase):
+class AgentsGridTable(wx.grid.PyGridTableBase):
- cols = ["ID", "IP", "Affected", "Not Tested"]
+ cols = ["ID", "IP", "Affected", "Not Affected", "Not Tested"]
def __init__(self, reporter):
wx.grid.PyGridTableBase.__init__(self)
self.reporter = reporter
- self.data = self.reporter.reportStd()
+ self.data = self.reporter.reportGeneral()
+
+ def Update(self):
+ self.data = self.reporter.reportGeneral()
def GetNumberRows(self):
"""Return the number of rows in the grid"""
@@ -26,7 +29,7 @@
def GetNumberCols(self):
"""Return the number of columns in the grid"""
- return 4
+ return len(AgentsGridTable.cols)
def IsEmptyCell(self, row, col):
"""Return True if the cell is empty"""
@@ -47,58 +50,135 @@
def GetColLabelValue(self, col):
return self.cols[col]
+class MonitorConfig():
+
+ def __init__(self):
+ self._readConf()
+
+ def _readConf(self):
+ self.cfg = wx.Config('monitor')
+ if self.cfg.Exists('AutoRefresh'):
+ self.refrAuto = self.cfg.ReadBool('AutoRefresh');
+ else:
+ self.refrAuto = True
+
+ if self.cfg.Exists('RefreshRate'):
+ self.refrRate = self.cfg.ReadInt('RefreshRate');
+ else:
+ self.refrRate = 10
+
+ if self.cfg.Exists('DbPath'):
+ self.dbPath = self.cfg.Read('DbPath');
+ else:
+ self.dbPath = "./oval-server.db"
+
+ def updateConf(self, auto, rate, path):
+ self.refrAuto = auto
+ self.refrRate = rate
+ self.dbPath = path
+ self.writeConf()
+
+ def writeConf(self):
+ self.cfg.WriteBool("AutoRefresh", self.refrAuto)
+ self.cfg.WriteInt("RefreshRate", self.refrRate)
+ self.cfg.Write("DbPath", self.dbPath)
+
+class MonitorPrefBox(wx.Dialog):
+ def __init__(self, parent, id, title):
+ wx.Dialog.__init__(self, parent, id, title, size=(360, 190))
+
+ self.conf = MonitorConfig()
+ wx.StaticBox(self, -1, 'Settings', (5, 5), size=(340, 120))
+
+ self.cb = wx.CheckBox(self, -1 ,'Auto-refresh', (15, 30))
+ self.cb.SetValue(self.conf.refrAuto)
+
+ wx.EVT_CHECKBOX(self, self.cb.GetId(), self.OnToggleRateSpin)
+
+ wx.StaticText(self, -1, 'Refresh rate', (30, 55))
+ self.sp = wx.SpinCtrl(self, -1, str(self.conf.refrRate), (105, 55), (50, -1), min=1, max=120)
+
+ wx.StaticText(self, -1, 'Path to db', (15, 95))
+ self.tc = wx.TextCtrl(self, -1, self.conf.dbPath, size=(230, 25), pos=(100, 85))
+
+ wx.Button(self, 1, 'Ok', (150, 130), (60, -1))
+
+ self.Bind(wx.EVT_BUTTON, self.OnClose, id=1)
+
+ self.Centre()
+ self.ShowModal()
+ self.Destroy()
+
+
+ def OnToggleRateSpin(self, event):
+ if self.sp.IsEnabled():
+ self.sp.Disable()
+ else:
+ self.sp.Enable()
+
+ def OnClose(self, event):
+ self.conf.updateConf(self.cb.GetValue(), self.sp.GetValue(), self.tc.GetValue())
+ self.Close()
+
+class AgentPopupMenu(wx.Menu):
+ def __init__(self, parent):
+ wx.Menu.__init__(self)
+
+ self.parent = parent
+
+ query = wx.MenuItem(self, wx.NewId(), 'Query')
+ self.AppendItem(query)
+ self.Bind(wx.EVT_MENU, self.OnQuery, id=query.GetId())
+
+ detail = wx.MenuItem(self, wx.NewId(), 'Detail')
+ self.AppendItem(detail)
+ self.Bind(wx.EVT_MENU, self.OnDetail, id=detail.GetId())
+
+
+ def OnQuery(self, event):
+ pass
+
+ def OnDetail(self, event):
+ pass
+
class MainWindow(wx.Frame):
def __init__(self,parent,id,title):
- #self.dirname=''
+
wx.Frame.__init__(self, parent, wx.ID_ANY, title, pos=(150, 150), size=(350, 200))
+
+ self.conf = MonitorConfig()
self.grid = self.__initGrid()
self.log = wx.TextCtrl(self, 1, size=(10, 10), style=wx.TE_AUTO_SCROLL | wx.TE_READONLY | wx.TE_AUTO_URL | wx.TE_MULTILINE)
- # Setting statusbar
- self.CreateStatusBar() # A Statusbar in the bottom of the window
+ # A Statusbar in the bottom of the window
+ self.CreateStatusBar()
+ # Adding the MenuBar to the Frame content.
+ self.SetMenuBar(self.__createMenu())
- # Setting up the filemenu.
- filemenu=wx.Menu()
- #filemenu.Append(ID_OPEN, "&Open"," Open a file to edit")
- filemenu.AppendSeparator()
- filemenu.Append(ID_EXIT,"E&xit"," Terminate the program")
-
- # Setting up the aboutmenu.
- aboutmenu=wx.Menu()
- aboutmenu.Append(ID_ABOUT, "&About"," Information about this program")
-
- # Setting up the settingsmenu.
- settingsmenu=wx.Menu()
- settingsmenu.Append(ID_PREFERENCES, "&Preferences"," OVAL monitor preferences ")
-
- # Creating the menubar.
- menuBar = wx.MenuBar()
- menuBar.Append(filemenu,"&File") # Adding the "filemenu" to the MenuBar
- menuBar.Append(settingsmenu,"&Settings") # Adding the "settingsmenu" to the MenuBar
- menuBar.Append(aboutmenu,"&Help") # Adding the "aboutmenu" to the MenuBar
- self.SetMenuBar(menuBar) # Adding the MenuBar to the Frame content.
-
wx.EVT_MENU(self, ID_ABOUT, self.OnAbout)
+ wx.EVT_MENU(self, ID_REFRESH, self.OnRefresh)
wx.EVT_MENU(self, ID_EXIT, self.OnExit)
- #wx.EVT_MENU(self, ID_OPEN, self.OnOpen)
+ wx.EVT_MENU(self, ID_PREFERENCES, self.OnPref)
- self.sizer2 = wx.BoxSizer(wx.HORIZONTAL)
- self.tabs=[]
- statusButton = wx.Button(self, wx.NewId(), "Current status")
- statisticButton = wx.Button(self, wx.NewId(), "Statistic")
- wx.EVT_BUTTON(self, statusButton.GetId(), self.OnStatus)
- wx.EVT_BUTTON(self, statisticButton.GetId(), self.OnStatistic)
+# self.sizerButtons = wx.BoxSizer(wx.HORIZONTAL)
+# self.tabs=[]
+# statusButton = wx.Button(self, wx.NewId(), "Current status")
+# statisticButton = wx.Button(self, wx.NewId(), "Statistic")
+# wx.EVT_BUTTON(self, statusButton.GetId(), self.OnStatus)
+# wx.EVT_BUTTON(self, statisticButton.GetId(), self.OnStatistic)
- self.tabs.append(statusButton)
- self.tabs.append(statisticButton)
- for i in range(len(self.tabs)):
- self.sizer2.Add(self.tabs[i],1,wx.EXPAND)
+# self.tabs.append(statusButton)
+# self.tabs.append(statisticButton)
+# for i in range(len(self.tabs)):
+# self.sizerButtons.Add(self.tabs[i],1,wx.EXPAND)
+ self.sizerGrid = wx.BoxSizer(wx.HORIZONTAL)
+ self.sizerGrid.Add(self.grid, 1, wx.EXPAND)
# Use some sizers to see layout options
self.sizer=wx.BoxSizer(wx.VERTICAL)
- self.sizer.Add(self.sizer2,0,wx.EXPAND)
- self.sizer.Add(self.grid,1,wx.EXPAND)
+# self.sizer.Add(self.sizerButtons,0,wx.EXPAND)
+ self.sizer.Add(self.sizerGrid,1,wx.EXPAND)
self.sizer.Add(self.log,2,wx.EXPAND)
#Layout sizers
@@ -106,48 +186,116 @@
self.SetAutoLayout(1)
self.sizer.Fit(self)
self.Show(1)
+
+ def __createMenu(self):
+ # Setting up the filemenu.
+ menuFile=wx.Menu()
+ menuFile.AppendSeparator()
+ menuFile.Append(ID_EXIT,"E&xit"," Terminate the program")
+
+ # Setting up the actions menu
+ menuActions=wx.Menu()
+ menuActions.Append(ID_REFRESH, "&Refresh"," Refresh Agents info ")
+
+ # Setting up the settingsmenu.
+ menuSettings=wx.Menu()
+ menuSettings.Append(ID_PREFERENCES, "&Preferences"," OVAL monitor preferences ")
+ # Setting up the aboutmenu.
+ menuAbout=wx.Menu()
+ menuAbout.Append(ID_ABOUT, "&About"," Information about this program")
+
+ # Creating the menubar.
+ menuBar = wx.MenuBar()
+ menuBar.Append(menuFile,"&File") # Adding the "filemenu" to the MenuBar
+ menuBar.Append(menuActions, "Actions")
+ menuBar.Append(menuSettings,"&Settings") # Adding the "settingsmenu" to the MenuBar
+ menuBar.Append(menuAbout,"&Help") # Adding the "aboutmenu" to the MenuBar
+
+ return menuBar
+
def __initGrid(self):
newGrid = wx.grid.Grid(self)
- table = MyGridTable(Report ("./oval-server.db"))
+ table = AgentsGridTable(Report (self.conf.dbPath))
newGrid.SetTable(table, True)
self.table = table
wx.grid.EVT_GRID_CELL_LEFT_DCLICK(self, self.OnStatus)
+ wx.grid.EVT_GRID_CELL_RIGHT_CLICK(self, self.OnAgentContext)
return newGrid
+
+ def __updateGrid(self):
+ self.log.AppendText("Updating agent grid\n")
+ self.table.Update()
+ self.grid.Refresh()
def __appendLog(self, message):
self.log.AppendText(message)
def OnAbout(self,e):
- d= wx.MessageDialog( self, " OVAL status monitor \n"
- " alpha version","OVAL monitor", wx.OK)
- d.ShowModal() # Shows it
- d.Destroy() # finally destroy it when finished.
+ description = """Oval Monitor is an advanced GUI tool for monitoring status of Oval agents.
+Features include agents list, full network status, detailed agent status, manual agent control
+and much more."""
+ licence = """File Hunter is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the Free Software Foundation;
+either version 2 of the License, or (at your option) any later version.
+
+File Hunter is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+See the GNU General Public License for more details. You should have received a copy of
+the GNU General Public License along with File Hunter; if not, write to
+the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA"""
+
+ info = wx.AboutDialogInfo()
+
+ #info.SetIcon(wx.Icon('icons/hunter.png', wx.BITMAP_TYPE_PNG))
+ info.SetName('Oval Monitor')
+ info.SetVersion('0.1.0')
+ info.SetDescription(description)
+ info.SetCopyright('(C) 2008 Pavel Vinogradov')
+ info.SetWebSite('http://www.nixdev.net')
+ info.SetLicence(licence)
+ info.AddDeveloper('Pavel Vinogradov')
+ info.AddDeveloper('Javier Fernandez-Sanguino')
+ wx.AboutBox(info)
+
+ def OnRefresh(self, e):
+ self.__updateGrid()
+
+ def OnPref(self, e):
+ MonitorPrefBox(self, wx.NewId(), 'Monitor preference')
+
def OnExit(self,e):
self.Close(True) # Close the frame.
- def addRow(self):
- msg = wx.grid.GridTableMessage(self.table, wx.grid.GRIDTABLE_NOTIFY_ROWS_APPENDED, 1)
- self.grid.ProcessTableMessage(msg)
- self.grid.ForceRefresh()
+# def addRow(self):
+# msg = wx.grid.GridTableMessage(self.table, wx.grid.GRIDTABLE_NOTIFY_ROWS_APPENDED, 1)
+# self.grid.ProcessTableMessage(msg)
+# self.grid.ForceRefresh()
+#
+# def delRow(self):
+# msg = wx.grid.GridTableMessage(self.table, wx.grid.GRIDTABLE_NOTIFY_ROWS_DELETED, self.grid.GetNumberRows(), 1)
+# self.grid.ProcessTableMessage(msg)
+# self.grid.ForceRefresh()
- def delRow(self):
- msg = wx.grid.GridTableMessage(self.table, wx.grid.GRIDTABLE_NOTIFY_ROWS_DELETED, self.grid.GetNumberRows(), 1)
- self.grid.ProcessTableMessage(msg)
- self.grid.ForceRefresh()
+ def OnAgentContext(self, event):
+ self.PopupMenu(AgentPopupMenu(self), event.GetPosition())
+ self.__appendLog(str(event))
def OnStatus(self, event):
- result = " Click on object with Id %d\n" %event.GetId()
- #self.delRow()
- self.__appendLog(result)
- self.__appendLog(Report ("./oval-server.db").reportStdAgent(event.Row+1))
-
+ self.grid.Show()
+# result = " Click on object with Id %d\n" %event.GetId()
+# #self.delRow()
+# self.__appendLog(result)
+# self.__appendLog(Report (self.conf.dbPath).reportStdAgent(event.Row+1))
+ self.__updateGrid()
+
def OnStatistic(self, event):
- result = " Click on object with Id %d\n" %event.GetId()
- #self.addRow()
- self.__appendLog(result)
+ self.grid.Hide()
+# result = " Click on object with Id %d\n" %event.GetId()
+# #self.addRow()
+# self.__appendLog(result)
if __name__ == "__main__":
app = wx.PySimpleApp()
Modified: trunk/oval-monitor/reporter.py
===================================================================
--- trunk/oval-monitor/reporter.py 2008-09-16 17:57:21 UTC (rev 372)
+++ trunk/oval-monitor/reporter.py 2008-09-22 16:05:33 UTC (rev 373)
@@ -1,196 +1,191 @@
-#!/usr/bin/python
-# -*- coding: utf-8 -*-
-# # Written by Pavel Vinogradov
-# Licensed under the GNU General Public License version 2.
-
-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 Report:
-
- def __init__(self, dbfile):
- dba.dbPath = dbfile
- self.db = dba ()
-
- 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
-
- def reportStd (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()
-
- for agent in agents:
- result.append([agent[0], agent[1], len(self.getAgentAffectedVuln(agent[0])), len(self.getAgentNottestedVuln(agent[0]))])
-
- return result
-
- def reportStdAgent (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
- """
- result = ""
- cursor = self.db.getCursor()
-
- cursor.execute ('SELECT vulnDSA, status from affected WHERE agentID = %d' % agentID)
- dsas = cursor.fetchall()
- count = 0
-
- result += 'Agent %d:\n' % agentID
- for dsa in dsas:
- if dsa[1] == 1:
- result += '\tAffected to DSA ID %s\n' % dsa[0]
- else:
- count += 1
- result += '\tNot affected to %d DSA\n' % count
-
- result += '--------------------------\n'
- 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:
- result += 'Not tested again DSA ID %s\n' %dsa[0]
- count += 1
-
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+# # Written by Pavel Vinogradov
+# Licensed under the GNU General Public License version 2.
+
+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 Report:
+
+ def __init__(self, dbfile):
+ dba.dbPath = dbfile
+ self.db = dba ()
+
+ 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 __getAgentNotAffectedVuln (self, agentID):
+ """ Return list of not affected DSA for certain agent
+
+ Return list of DSA numbers which not 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 = 0' % 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 reportGeneral (self):
+ """Generate full report about status of all agents.
+
+ Generate report, which include list of all registered agents with:
+ ID, IP, number of affected, not affected and not tested DSA.
+ """
+ result = []
+
+ cursor = self.db.getCursor()
+
+ cursor.execute ("SELECT * FROM agents;")
+ agents = cursor.fetchall()
+
+ for agent in agents:
+ #ID, IP, AFF, NotAFF, NotTested
+ result.append([agent[0], agent[1], len(self.__getAgentAffectedVuln(agent[0])), len(self.__getAgentNotAffectedVuln (agent[0])), len(self.__getAgentNotTestedVuln (agent[0]))])
+
+ 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 reportStdAgent (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
+ """
+ result = ""
+ cursor = self.db.getCursor()
+
+ cursor.execute ('SELECT vulnDSA, status from affected WHERE agentID = %d' % agentID)
+ dsas = cursor.fetchall()
+ count = 0
+
+ result += 'Agent %d:\n' % agentID
+ for dsa in dsas:
+ if dsa[1] == 1:
+ result += '\tAffected to DSA ID %s\n' % dsa[0]
+ else:
+ count += 1
+ result += '\tNot affected to %d DSA\n' % count
+
+ result += '--------------------------\n'
+ 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:
+ result += 'Not tested again DSA ID %s\n' %dsa[0]
+ count += 1
+
return result
\ No newline at end of file
More information about the Oval-commits
mailing list