Avertissement
Dernière modification de cet article le 2012-03-06, le contenu pourrait être dépassé/obsolète.
Il arrive suite à migration ou erreur, de vouloir renommer une machine et, ce, sans perdre son historique de monitoring
Munin. Je vous propose donc le script suivant, librement inspiré de celui de
Yannick Warnier sur le blog BeezNest.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
| #! /bin/bash
# Moves RRD files from /var/lib/munin/$OLD_DOMAIN/ to /var/lib/munin/$NEW_DOMAIN/ by renaming files as required by munin.
# (Also does the same move operation for HTML files in /var/www/munin)
#
# @author DUVERGIER Claude
# @version 2012-03-06
# @see http://blog.claude.duvergier.fr/2012/03/renommer-un-noeud-munin-sans-perdre-son-historique
# Move operation config (will obviously be changed anytime a move is required):
OLD_DOMAIN='localdomain'
OLD_HOSTFQDN='localhost.localdomain'
NEW_DOMAIN='subdom.company.com'
NEW_HOSTFQDN='mailserver.subdom.company.com'
# System config (shouldn't often be changed):
MUNIN_USER='munin'
MUNIN_GROUP='munin'
MUNIN_RRDDIR='/var/lib/munin'
MUNIN_HTMLDIR='/var/www/munin'
# DEBUG:
#for file in $MUNIN_RRDDIR/$OLD_DOMAIN/$OLD_HOSTFQDN-*.rrd; do echo `echo $file | sed "s,$OLD_HOSTFQDN,$NEW_HOSTFQDN," | sed "s,$MUNIN_RRDDIR/$OLD_DOMAIN/,$MUNIN_RRDDIR/$NEW_DOMAIN/,"`; done
#for file in $MUNIN_HTMLDIR/$OLD_DOMAIN/$OLD_HOSTFQDN*; do echo `echo $file | sed "s,$OLD_HOSTFQDN/$NEW_HOSTFQDN," | sed "s,$MUNIN_HTMLDIR/$OLD_DOMAIN/,$MUNIN_HTMLDIR/$NEW_DOMAIN/,"`; done
# RRD files :
mkdir -p "$MUNIN_RRDDIR/$NEW_DOMAIN"
chown $MUNIN_USER:$MUNIN_GROUP "$MUNIN_RRDDIR/$NEW_DOMAIN"
for file in $MUNIN_RRDDIR/$OLD_DOMAIN/$OLD_HOSTFQDN-*.rrd; do mv $file `echo $file | sed "s,$OLD_HOSTFQDN,$NEW_HOSTFQDN," | sed "s,$MUNIN_RRDDIR/$OLD_DOMAIN/,$MUNIN_RRDDIR/$NEW_DOMAIN/,"`; done
# HTML files :
mkdir -p "$MUNIN_HTMLDIR/$NEW_DOMAIN"
chown $MUNIN_USER:$MUNIN_GROUP "$MUNIN_HTMLDIR/$NEW_DOMAIN"
if [ -d "$MUNIN_HTMLDIR/$OLD_DOMAIN/$OLD_HOSTFQDN" ]; then # Each host has it's own sub-directory ($MUNIN_HTMLDIR/domain/host.domain/...)
mv "$MUNIN_HTMLDIR/$OLD_DOMAIN/$OLD_HOSTFQDN" "$MUNIN_HTMLDIR/$NEW_DOMAIN/$NEW_HOSTFQDN"
else # Files of different hosts are stored in the same domain directory ($MUNIN_HTMLDIR/domain/host.domain-...)
for file in $MUNIN_HTMLDIR/$OLD_DOMAIN/$OLD_HOSTFQDN-*; do mv $file `echo $file | sed "s,$OLD_HOSTFQDN,$NEW_HOSTFQDN," | sed "s,$MUNIN_HTMLDIR/$OLD_DOMAIN/,$MUNIN_HTMLDIR/$NEW_DOMAIN/,"`; done
fi
|
Penser à couper/désactiver le cron et le daemon Munin avant d’exécuter le script. Il faut aussi bien entendu modifier le
fichier de configuration déclarant les noeud Munin pour y mettre le nouveau nom/FQDN du noeud.
Il a été testé sur Debian 5.0 et 6.0 mais est suffisamment générique/configurable pour fonctionner sur d’autres
distributions Linux.