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

Pavel Vinogradov blaze-guest at alioth.debian.org
Tue Sep 16 17:57:21 UTC 2008


Author: blaze-guest
Date: 2008-09-16 17:57:21 +0000 (Tue, 16 Sep 2008)
New Revision: 372

Modified:
   trunk/oval-monitor/manager.py
   trunk/oval-monitor/reporter.py
Log:
Update grid implementation

Modified: trunk/oval-monitor/manager.py
===================================================================
--- trunk/oval-monitor/manager.py	2008-09-15 17:06:39 UTC (rev 371)
+++ trunk/oval-monitor/manager.py	2008-09-16 17:57:21 UTC (rev 372)
@@ -11,12 +11,48 @@
 ID_BUTTON1=wx.NewId()
 ID_EXIT=wx.NewId()
 
+class MyGridTable(wx.grid.PyGridTableBase):
+    
+    cols = ["ID", "IP", "Affected", "Not Tested"]
+    
+    def __init__(self, reporter):
+        wx.grid.PyGridTableBase.__init__(self)
+        self.reporter = reporter
+        self.data = self.reporter.reportStd()
+        
+    def GetNumberRows(self):
+        """Return the number of rows in the grid"""
+        return len(self.data)
+
+    def GetNumberCols(self):
+        """Return the number of columns in the grid"""
+        return 4
+
+    def IsEmptyCell(self, row, col):
+        """Return True if the cell is empty"""
+        return False
+
+    def GetTypeName(self, row, col):
+        """Return the name of the data type of the value in the cell"""
+        return None
+
+    def GetValue(self, row, col):
+        """Return the value of a cell"""
+        return self.data[row][col]
+
+    def SetValue(self, row, col, value):
+        """Set the value of a cell"""
+        pass
+    
+    def GetColLabelValue(self, col):
+        return self.cols[col]
+
 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.grid = wx.grid.Grid(self) #wx.TextCtrl(self, 1, style=wx.TE_MULTILINE)
-        self.grid.CreateGrid(5,5)
+        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
@@ -48,23 +84,41 @@
         
         self.sizer2 = wx.BoxSizer(wx.HORIZONTAL)
         self.tabs=[]
-        self.tabs.append(wx.Button(self, wx.NewId(), "Current status"))
-        self.tabs.append(wx.Button(self, wx.NewId(), "Statistic"))
+        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)
-            wx.EVT_BUTTON(self, self.tabs[i].GetId(), self.OnClick)
+            
         
         # 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.log,2,wx.EXPAND)
                 
         #Layout sizers
         self.SetSizer(self.sizer)
         self.SetAutoLayout(1)
         self.sizer.Fit(self)
         self.Show(1)
+
+    def __initGrid(self):
+        newGrid = wx.grid.Grid(self)        
+        table = MyGridTable(Report ("./oval-server.db"))
+        newGrid.SetTable(table, True)
+        self.table = table
+        wx.grid.EVT_GRID_CELL_LEFT_DCLICK(self, self.OnStatus)
+
+        return newGrid
         
+    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)
@@ -74,42 +128,27 @@
     def OnExit(self,e):
         self.Close(True)  # Close the frame.
 
-#    def OnOpen(self,e):
-#        """ Open a file"""
-#        dlg = wx.FileDialog(self, "Choose a file", self.dirname, "", "*.*", wx.OPEN)
-#        if dlg.ShowModal() == wx.ID_OK:
-#            self.filename=dlg.GetFilename()
-#            self.dirname=dlg.GetDirectory()
-#            f=open(os.path.join(self.dirname, self.filename),'r')
-#            self.control.SetValue(f.read())
-#            f.close()
-#        dlg.Destroy()
+    def addRow(self):
+        msg = wx.grid.GridTableMessage(self.table, wx.grid.GRIDTABLE_NOTIFY_ROWS_APPENDED, 1)        
+        self.grid.ProcessTableMessage(msg)
+        self.grid.ForceRefresh()
 
-    def OnClick(self,event):
-        result = " Click on object with Id %d\n" %event.GetId() 
-        try:
-            reporter = Report ("./oval-server.db")
-            #self.grid.CreateGrid(5,5)
-            #self.grid.SetRowHeight(4, 45)
-            self.grid.SetCellValue("First cell", 0, 0)
-            self.grid.SetCellValue("Another cell", 1, 1)
-            self.grid.SetCellValue("Yet another cell", 2, 2)
-            #grid.SetCellTextFont(wxTheFontList->FindOrCreateFont(12, wxROMAN, wxITALIC, wxNORMAL), 0, 0);
-            self.grid.SetCellTextColour(wx.wxRED, 1, 1)
-            self.grid.SetCellBackgroundColour(wx.wxCYAN, 2, 2)
-            self.grid.UpdateDimensions()
-            
-            #grid.SetCellRenderer(0,0,reporter.reportFull ())
-            #grid.SetColSize(0,img.GetWidth()+2)
-            #grid.SetRowSize(0,img.GetHeight()+2)
-            #result = reporter.reportFull ()
+    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 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))
+
+    def OnStatistic(self, event):
+        result = " Click on object with Id %d\n" %event.GetId()
+        #self.addRow()
+        self.__appendLog(result)
         
-        except Exception, e:
-            sys.stderr.write('ERROR: Unhandled error during execution: %s : %s.\n' % (e.__class__, str(e)))
-            traceback.print_exc()
-        
-        #self.control.AppendText(result)
-
 if __name__ == "__main__":
     app = wx.PySimpleApp()
     frame = MainWindow(None, -1, "OVAL status monitor")

Modified: trunk/oval-monitor/reporter.py
===================================================================
--- trunk/oval-monitor/reporter.py	2008-09-15 17:06:39 UTC (rev 371)
+++ trunk/oval-monitor/reporter.py	2008-09-16 17:57:21 UTC (rev 372)
@@ -137,4 +137,60 @@
         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    
+            
         return result
\ No newline at end of file




More information about the Oval-commits mailing list