Revisión 377
Añadido por Esteban M. Navas Martín hace casi 13 años
limpiar-puppet/puppetlast | ||
---|---|---|
#!/usr/bin/env python
|
||
|
||
import glob
|
||
import os
|
||
|
||
from datetime import datetime, timedelta
|
||
|
||
|
||
def humanize(delta):
|
||
days = delta.days
|
||
hours = delta.seconds / 3600
|
||
minutes = delta.seconds % 3600 / 60
|
||
seconds = delta.seconds % 3600 % 60
|
||
|
||
str = ""
|
||
tStr = ""
|
||
if days > 0:
|
||
if days == 1: tStr = "day"
|
||
else: tStr = "days"
|
||
str = str + "%s %s" %(days, tStr)
|
||
elif hours > 0:
|
||
if hours == 1: tStr = "hour"
|
||
else: tStr = "hours"
|
||
str = str + "%s %s" %(hours, tStr)
|
||
elif minutes > 0:
|
||
if minutes == 1: tStr = "min"
|
||
else: tStr = "mins"
|
||
str = str + "%s %s" %(minutes, tStr)
|
||
elif seconds > 0:
|
||
if seconds == 1: tStr = "sec"
|
||
else: tStr = "secs"
|
||
str = str + "%s %s" %(seconds, tStr)
|
||
return str
|
||
|
||
|
||
times = []
|
||
for f in glob.glob("/var/lib/puppet/yaml/facts/*"):
|
||
host = f.split('/')[-1].replace('.yaml', '')
|
||
last = datetime.now() - datetime.fromtimestamp(os.stat(f)[9])
|
||
times.append((humanize(last), host, last))
|
||
|
||
RED = '\033[91m'
|
||
GREEN = '\033[92m'
|
||
RESET = '\033[0m'
|
||
|
||
for time in sorted(times, key=lambda x: x[2]):
|
||
if time[2] < timedelta(hours=0.5):
|
||
print GREEN, "%10s ago: %s" % (time[0], time[1]), RESET
|
||
else:
|
||
print RED, "%10s ago: %s" % (time[0], time[1]), RESET
|
||
limpiar-puppet/limpia-puppet | ||
---|---|---|
#!/bin/bash
|
||
# ------------------------------------------------------------
|
||
# script: limpia-puppet
|
||
# Author: Esteban M. Navas Martín
|
||
# Date: 21-06-2012
|
||
# Ver: 21-06-2012
|
||
# Requisito: Tener instalado puppetlast
|
||
#
|
||
# Purpose: This program cleans the following puppet node info: facts, node and certificate
|
||
#
|
||
# Copyright (c) 2012 Esteban M. Navas Martín <adminies.valledeljerte@edu.juntaextremadura.net>. All rights reserved.
|
||
|
||
# This program 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.
|
||
|
||
# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||
|
||
|
||
# Comprobamos si se han introducido la antiguedad como parámetro
|
||
if [ $# -lt 1 ]; then
|
||
ANTIGUEDADMAX="100"
|
||
else
|
||
ANTIGUEDADMAX=$1
|
||
fi
|
||
|
||
/usr/local/sbin/puppetlast > /tmp/puppetlast.tmp
|
||
|
||
while read LINEA; do
|
||
LINEACOMPLETA=$LINEA
|
||
set -- $LINEACOMPLETA
|
||
ANTIGUEDAD=$2
|
||
DIAS=$3
|
||
HOST=$5
|
||
ARCHIVO=$HOST".yaml"
|
||
|
||
if [ "$ANTIGUEDAD" -ge "$ANTIGUEDADMAX" ] && [ "$DIAS"="days" ]; then
|
||
echo $DIAS
|
||
echo "Borrando certificado puppet $ARCHIVO"
|
||
puppetca --clean $HOST
|
||
if [ -f /var/lib/puppet/yaml/facts/$ARCHIVO ]; then
|
||
rm /var/lib/puppet/yaml/facts/$ARCHIVO
|
||
echo "Borrando /var/lib/puppet/yaml/facts/$ARCHIVO con $ANTIGUEDAD días de antiguedad."
|
||
fi
|
||
if [ -f /var/lib/puppet/yaml/node/$ARCHIVO ]; then
|
||
rm /var/lib/puppet/yaml/node/$ARCHIVO
|
||
echo "Borrando /var/lib/puppet/yaml/node/$ARCHIVO con $ANTIGUEDAD días de antiguedad."
|
||
fi
|
||
fi
|
||
done < /tmp/puppetlast.tmp
|
||
|
||
rm -f /tmp/puppetlast.tmp
|
||
Exportar a: Unified diff
Import inicial del proyecto