Proyecto

General

Perfil

« Anterior | Siguiente » 

Revisión 334

Añadido por Manu Mora Gordillo hace casi 13 años

Añado portatiles de profesores, workstations y desconocidos

Ver diferencias:

puppetlastgroups
# -*- coding: utf-8 -*-
# Project:
# Module: puppetlastgroups
# Purpose: Gets info about last sinchronization date via puppet (grouped by classroom) from /var/lib/puppet/yaml/facts certs
# Purpose: Gets info about last sinchronization date via puppet (grouped) from /var/lib/puppet/yaml/facts certs
# Language: Python 2.5
# Date: 27-Abr-2012.
# Ver: 27-Abr-2012.
......
from datetime import datetime, timedelta
total_count=0
all_hosts=[]
all_certs=[]
def humanize(delta):
days = delta.days
hours = delta.seconds / 3600
......
# Obtiene lista nombres de maquinas a partir de los certificados almacenados en el servidor, en /var/lib/puppet/yaml/facts
# asi como informacion del periodo que llevan sin sincronizar via puppet.
def gettimes(search):
def gettimes():
times = []
global all_certs
out = ''
import pdb
for f in glob.glob("/var/lib/puppet/yaml/facts/*"):
host = f.split('/')[-1].replace('.yaml', '')
all_certs.append(host)
last = datetime.now() - datetime.fromtimestamp(os.stat(f)[9])
times.append((humanize(last), host, last))
return times
# Muestra en pantalla la info de la sincronizacion con codigo de colores
def printtimes(times):
global all_hosts
RED = '\033[91m'
GREEN = '\033[92m'
ORANGE = '\033[93m'
RESET = '\033[0m'
for time in reversed(sorted(times, key=lambda x: x[2])):
all_hosts.append(time[1])
if time[2] < timedelta(hours=24):
print GREEN, "%10s ago: %s" % (time[0], time[1]), RESET
elif time[2] < timedelta(hours=239):
......
tmp=sorted(data, key=itemgetter(0))
return tmp
def formatListLTSP(search):
def formatOtherList(search,head):
from operator import itemgetter, attrgetter
data=[]
tmp=[]
......
for s in servers:
tmp.append(s.replace("(","").replace(",-,-)",""))
tuple = ("LTSP-Servers",tmp)
tuple = (head,tmp)
data.append(tuple)
tmp=sorted(data, key=itemgetter(1))
return tmp
......
# Rutina principal
def puppetlast(times,search):
import pdb
global total_count
for c in search:
if c[0]:
times_temp=[]
......
if len(times_temp)>1:
print "\n- "+curso+" ("+str(len(alumnos))+" elementos) ("+str(len(times_temp))+" certificados)"
total_count=total_count+len(times_temp)
printtimes(times_temp)
......
print e
def cmpLists(list1, list2):
onlyInList1 = set(list1).difference(set(list2))
onlyInList2 = set(list2).difference(set(list1))
inTwoLists = set(list1) & set(list2)
return { 'onlyInList1':onlyInList1, 'onlyInList2':onlyInList2, 'inTwoLists':inTwoLists }
grupo=""
t=gettimes()
if len (sys.argv)==2:
grupo=sys.argv[1]
filter="(&(groupType=school_class)(cn="+grupo+"))"
......
search = ldapSearch("ou=Group",filter,["memberUid"])
data = formatList(search)
t=gettimes(data)
puppetlast(t,data)
if grupo=="":
# Servidores de aula
search = ldapSearch("cn=ltsp-server-hosts, ou=Netgroup","cn=*",["nisNetgroupTriple"])
data = formatListLTSP(search)
t=gettimes(data)
data = formatOtherList(search,"LTSP-Servers")
puppetlast(t,data)
# Portatiles de profesores. Debera tener la rama Netgroup->laptop-hosts
try:
search = ldapSearch("cn=workstation-hosts, ou=Netgroup","cn=*",["nisNetgroupTriple"])
data = formatOtherList(search,"Workstations")
puppetlast(t,data)
except:
pass
# Portatiles de profesores. Debera tener la rama Netgroup->laptop-hosts
try:
search = ldapSearch("cn=laptop-hosts, ou=Netgroup","cn=*",["nisNetgroupTriple"])
data = formatOtherList(search,"Portatiles profesores")
puppetlast(t,data)
except:
pass
# Equipos desconocidos
cmp=cmpLists(all_hosts, all_certs)
unknown=[]
unknown.append(("Desconocidos",cmp["onlyInList2"]))
puppetlast(t,unknown)
print "\nTotal certificados: "+str(total_count)

Exportar a: Unified diff