Package zephir :: Package monitor :: Package agents :: Module patches
[hide private]
[frames] | no frames]

Source Code for Module zephir.monitor.agents.patches

  1  # -*- coding: UTF-8 -*- 
  2  ########################################################################### 
  3  # Eole NG - 2007 
  4  # Copyright Pole de Competence Eole  (Ministere Education - Academie Dijon) 
  5  # Licence CeCill  cf /root/LicenceEole.txt 
  6  # eole@ac-dijon.fr 
  7  ########################################################################### 
  8   
  9  """ 
 10  Agent zephir testant l'application des patches présents sur le serveur 
 11  """ 
 12   
 13  from twisted.python import log 
 14  from twisted.internet import defer 
 15  from twisted.internet.utils import getProcessOutput 
 16   
 17  from zephir.monitor.agentmanager.agent import Agent 
 18  from zephir.monitor.agentmanager import status 
 19  from zephir.monitor.agentmanager.util import status_to_img 
 20  from zephir.monitor.agentmanager.data import HTMLData, TableData 
 21   
 22  from glob import glob 
 23  from cgi import escape 
 24  import os 
 25   
26 -def verify_patch(filename):
27 """vérifie qu'un patch est bien appliqué""" 28 bad_patches = {} 29 patch_lines = open(filename).read().split('\n') 30 fic_dest = "" 31 for line in patch_lines: 32 if line.startswith('+++'): 33 dest_not_found = False 34 if os.path.exists('/etc/eole/template'): 35 fic_dest = os.path.join('/etc/eole/template',os.path.basename(line.split()[1])) 36 else: 37 fic_dest = os.path.join('/etc/eole',os.path.basename(line.split()[1])) 38 39 if not os.path.exists(fic_dest): 40 # pas de fichier dans /etc/eole : patch sur un fichier quelconque ? 41 fic_dest = line.split()[1] 42 if not os.path.exists(fic_dest): 43 # fichier de destination inexistant 44 dest_not_found = True 45 bad_patches[fic_dest] = [] 46 if dest_not_found: 47 bad_patches[fic_dest].append("Fichier de destination non trouvé !") 48 elif line.startswith('+') and not dest_not_found: 49 pattern = line[1:] 50 # recherche du pattern dans le fichier de destination 51 f_dest = open(fic_dest) 52 data = f_dest.read().split('\n') 53 f_dest.close() 54 if not pattern in data: 55 if len(pattern) > 40: 56 pattern = pattern[:40] 57 if bad_patches[fic_dest] == []: 58 bad_patches[fic_dest].append(pattern) 59 return bad_patches
60
61 -class Patches(Agent):
62
63 - def __init__(self, name, 64 **params):
65 Agent.__init__(self, name, **params) 66 self.status = status.OK() 67 self.table = TableData([ 68 ('patch', 'Nom du patch', {'align':'left'}, None), 69 ('dest', 'Fichier modifié', {'align':'left'}, None), 70 ('etat', 'Etat', {'align':'center'}, status_to_img), 71 ('pattern', 'Chaine non trouvée', {'align':'left'}, None)]) 72 self.data = [self.table]
73
74 - def measure(self):
75 patchs = glob('/etc/eole/patch/*.patch') 76 patchs.extend(glob('/etc/eole/patch/variante/*.patch')) 77 results = [] 78 meas_data = {} 79 self.status = status.OK() 80 for patch in patchs: 81 patch_name = patch 82 bad_patches = verify_patch(patch) 83 for dest, pattern in bad_patches.items(): 84 if pattern == []: 85 etat = 'On' 86 else: 87 etat = 'Off' 88 self.status = status.Error() 89 results.append({'patch':patch_name, 'dest':dest, 'etat':etat, 'pattern':escape('<br>'.join(pattern))}) 90 patch_name = '' 91 meas_data[patch] = bad_patches 92 self.measure_data = meas_data 93 return {'statistics':results}
94
95 - def check_status(self):
96 return self.status
97
98 - def write_data(self):
99 Agent.write_data(self) 100 if self.last_measure is not None: 101 self.table.table_data = self.last_measure.value['statistics']
102