detabification
darcs-hash:20051008142154-4ec08-7996c0fc50b2714b57f4cd4b1ecee5336b690b8e.gz
This commit is contained in:
parent
1ea8baa225
commit
9bfdf242c0
1 changed files with 94 additions and 94 deletions
|
@ -24,8 +24,8 @@ def NotRunningHosts() :
|
|||
"""
|
||||
hosts = []
|
||||
for host in os.listdir(statusfolder) :
|
||||
if os.path.getmtime('/usr/scripts/monit/status/%s' % host) < time.time() - 180 :
|
||||
hosts.append(host)
|
||||
if os.path.getmtime('/usr/scripts/monit/status/%s' % host) < time.time() - 180 :
|
||||
hosts.append(host)
|
||||
return hosts
|
||||
|
||||
def HostStatus (host) :
|
||||
|
@ -40,27 +40,27 @@ def HostStatus (host) :
|
|||
s = None
|
||||
|
||||
for line in f.readlines()[2:] :
|
||||
line = line.strip()
|
||||
if not line :
|
||||
# ligne vide, on passe au service suivant
|
||||
s = None
|
||||
elif not s :
|
||||
# création d'un nouveau service
|
||||
s = line.split(' ')[1][1:-1]
|
||||
t = line.split(' ')[0]
|
||||
# ajout du type s'il n'est pas dedans
|
||||
if not status.has_key(t) :
|
||||
status[t] = {}
|
||||
status[t][s] = {}
|
||||
else :
|
||||
# on ajoute les données
|
||||
status[t][s][line[:34].strip()] = line[34:].strip()
|
||||
line = line.strip()
|
||||
if not line :
|
||||
# ligne vide, on passe au service suivant
|
||||
s = None
|
||||
elif not s :
|
||||
# création d'un nouveau service
|
||||
s = line.split(' ')[1][1:-1]
|
||||
t = line.split(' ')[0]
|
||||
# ajout du type s'il n'est pas dedans
|
||||
if not status.has_key(t) :
|
||||
status[t] = {}
|
||||
status[t][s] = {}
|
||||
else :
|
||||
# on ajoute les données
|
||||
status[t][s][line[:34].strip()] = line[34:].strip()
|
||||
|
||||
# on supprime les données system
|
||||
try :
|
||||
status.pop('System')
|
||||
status.pop('System')
|
||||
except :
|
||||
pass
|
||||
pass
|
||||
|
||||
return status
|
||||
|
||||
|
@ -70,7 +70,7 @@ def AllStatus () :
|
|||
"""
|
||||
status = {}
|
||||
for host in os.listdir(statusfolder) :
|
||||
status[host] = HostStatus(host)
|
||||
status[host] = HostStatus(host)
|
||||
return status
|
||||
|
||||
def AllStatusOff () :
|
||||
|
@ -82,26 +82,26 @@ def AllStatusOff () :
|
|||
|
||||
for h in status.keys() :
|
||||
|
||||
# si c'est un host qui est down, on le laisse tel quel pour éviter qu'il le supprime
|
||||
if h in NotRunningHosts() :
|
||||
continue
|
||||
# si c'est un host qui est down, on le laisse tel quel pour éviter qu'il le supprime
|
||||
if h in NotRunningHosts() :
|
||||
continue
|
||||
|
||||
# on supprime les types
|
||||
for t in status[h].keys() :
|
||||
# on supprime les types
|
||||
for t in status[h].keys() :
|
||||
|
||||
for s in status[h][t].keys() :
|
||||
for s in status[h][t].keys() :
|
||||
|
||||
# on supprime un status s'il est Up
|
||||
if status[h][t][s]['status'] in ['running','accessible'] :
|
||||
status[h][t].pop(s)
|
||||
# on supprime un status s'il est Up
|
||||
if status[h][t][s]['status'] in ['running','accessible'] :
|
||||
status[h][t].pop(s)
|
||||
|
||||
# reste-t-il des services dans le groupe
|
||||
if not status[h][t] :
|
||||
status[h].pop(t)
|
||||
# reste-t-il des services dans le groupe
|
||||
if not status[h][t] :
|
||||
status[h].pop(t)
|
||||
|
||||
# reste-t-il des groupes dans l'hote
|
||||
if not status[h] :
|
||||
status.pop(h)
|
||||
# reste-t-il des groupes dans l'hote
|
||||
if not status[h] :
|
||||
status.pop(h)
|
||||
|
||||
return status
|
||||
|
||||
|
@ -118,17 +118,17 @@ def FormatService(Type, Service, Data, f) :
|
|||
result += f.table_row(1)
|
||||
result += f.table_cell(1,{'style':'background-color:silver'})
|
||||
if Type == 'Device' :
|
||||
Service = Service[2:]
|
||||
Service = Service[2:]
|
||||
elif Type == 'File' :
|
||||
Service = Service[4:]
|
||||
Service = Service[4:]
|
||||
result += f.strong(1)
|
||||
result += f.text(Service)
|
||||
result += f.strong(0)
|
||||
result += f.table_cell(0)
|
||||
if Data['status'] in ['running','accessible'] :
|
||||
result += f.table_cell(1,{'style':'background-color:lime'})
|
||||
result += f.table_cell(1,{'style':'background-color:lime'})
|
||||
else :
|
||||
result += f.table_cell(1,{'style':'background-color:red'})
|
||||
result += f.table_cell(1,{'style':'background-color:red'})
|
||||
result += f.text(Data['status'])
|
||||
result += f.table_cell(0)
|
||||
result += f.table_row(0)
|
||||
|
@ -152,7 +152,7 @@ def FormatType(Type, Data, f) :
|
|||
# les services
|
||||
result += f.table(1)
|
||||
for s in Data.keys() :
|
||||
result += FormatService(Type,s,Data[s],f)
|
||||
result += FormatService(Type,s,Data[s],f)
|
||||
result += f.table(0)
|
||||
|
||||
return result
|
||||
|
@ -174,14 +174,14 @@ def FormatHost (Host, Data, f) :
|
|||
|
||||
# si monit ne tourne pas
|
||||
if Host in NotRunningHosts() :
|
||||
return result + Cellule('Monit ne semble pas tourner sur %s' % Host,'yellow',f)
|
||||
return result + Cellule('Monit ne semble pas tourner sur %s' % Host,'yellow',f)
|
||||
|
||||
result += f.table(1)
|
||||
result += f.table_row(1)
|
||||
for t in Data.keys() :
|
||||
result += f.table_cell(1,{'valign':'top'})
|
||||
result += FormatType(t,Data[t],f)
|
||||
result += f.table_cell(0)
|
||||
result += f.table_cell(1,{'valign':'top'})
|
||||
result += FormatType(t,Data[t],f)
|
||||
result += f.table_cell(0)
|
||||
|
||||
result += f.table_row(0)
|
||||
result += f.table(0)
|
||||
|
@ -198,7 +198,7 @@ def FormatHosts(Data, f) :
|
|||
result = ''
|
||||
|
||||
for h in Data.keys() :
|
||||
result += FormatHost(h,Data[h],f)
|
||||
result += FormatHost(h,Data[h],f)
|
||||
|
||||
return result
|
||||
|
||||
|
@ -223,52 +223,52 @@ def execute(macro, filtre) :
|
|||
|
||||
# on met en forme le filtre
|
||||
if not filtre :
|
||||
filtre = 'all'
|
||||
filtre = 'all'
|
||||
else :
|
||||
filtre = filtre.lower()
|
||||
filtre = filtre.lower()
|
||||
|
||||
if filtre == 'off' :
|
||||
# tous les services off
|
||||
status = AllStatusOff()
|
||||
if status :
|
||||
return FormatHosts(status, f)
|
||||
else :
|
||||
# aucun service off, on affiche OK
|
||||
return Cellule(u'Tous les services semblent opérationels.','lime',f)
|
||||
# tous les services off
|
||||
status = AllStatusOff()
|
||||
if status :
|
||||
return FormatHosts(status, f)
|
||||
else :
|
||||
# aucun service off, on affiche OK
|
||||
return Cellule(u'Tous les services semblent opérationels.','lime',f)
|
||||
|
||||
elif filtre == 'all' :
|
||||
# tous les services
|
||||
status = AllStatus()
|
||||
return FormatHosts(status, f)
|
||||
# tous les services
|
||||
status = AllStatus()
|
||||
return FormatHosts(status, f)
|
||||
|
||||
elif '@' in filtre :
|
||||
# affichage d'un service simple
|
||||
# affichage d'un service simple
|
||||
|
||||
host = filtre.split('@')[1]
|
||||
service = filtre.split('@')[0]
|
||||
status = HostStatus(host)
|
||||
host = filtre.split('@')[1]
|
||||
service = filtre.split('@')[0]
|
||||
status = HostStatus(host)
|
||||
|
||||
# recherche du service dans la config
|
||||
s = {}
|
||||
for t in status.keys() :
|
||||
if service in status[t].keys() :
|
||||
s = status[t][service]
|
||||
# recherche du service dans la config
|
||||
s = {}
|
||||
for t in status.keys() :
|
||||
if service in status[t].keys() :
|
||||
s = status[t][service]
|
||||
|
||||
if not s :
|
||||
# service non trouvé
|
||||
code = f.table_cell(0)
|
||||
code += f.table_cell(1,{'style':'background-color:yellow'})
|
||||
code += f.text(u'Service introuvable')
|
||||
return code
|
||||
if not s :
|
||||
# service non trouvé
|
||||
code = f.table_cell(0)
|
||||
code += f.table_cell(1,{'style':'background-color:yellow'})
|
||||
code += f.text(u'Service introuvable')
|
||||
return code
|
||||
|
||||
# création de la chaine de retour
|
||||
code = f.table_cell(0)
|
||||
if s['status'] in ['running','accessible'] :
|
||||
code += f.table_cell(1,{'style':'background-color:lime'})
|
||||
else :
|
||||
code += f.table_cell(1,{'style':'background-color:red'})
|
||||
code += f.text(s['status'])
|
||||
return code
|
||||
# création de la chaine de retour
|
||||
code = f.table_cell(0)
|
||||
if s['status'] in ['running','accessible'] :
|
||||
code += f.table_cell(1,{'style':'background-color:lime'})
|
||||
else :
|
||||
code += f.table_cell(1,{'style':'background-color:red'})
|
||||
code += f.text(s['status'])
|
||||
return code
|
||||
|
||||
else :
|
||||
return Cellule('Erreur de filtre','yellow',f)
|
||||
return Cellule('Erreur de filtre','yellow',f)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue