Librenms/weathermap Créez des gifs animés

Simples scripts pour creer des gifs animés des maps weathermap pour Librenms. 

La combinaison Librenms/weathermap, une fois bien maitrisé peut s'avérer trés puissante, ici nous allons ajouter un peu d'animation en creant un gif animé journalier qui vous permetra de suivre l'évolution de votre réseau au fil du temps.

Nous allons y ajouter une petite interface avec un simple sélecteur de date pour afficher la map du jour choisi.

Prerequis : 

  • Commande "convert" (yum install ImageMagick et sur Ubuntu apt install imagemagick) - utilisée pour convertir des png en gif
  • Commande "pngquant" (yum install pngquant , apt install pngquant) - Optimisation PNG
  • Commande "gifsicle" (yum install gifsicle, apt install gifsicle) - Optimisation GIF qui montre une réduction de la taille du fichier GIF de 87 %

Nous supposons que votre chemin librenms est /opt/librenms (sinon vous devrez modifier les scripts).

Création du répertoire :

mkdir -p /opt/weathermap-history/history
cd /opt/weathermap-historique

Script de backup des images

nano getweather.sh
#!/bin/bash
DATE=`date '+%y%m%d%H%M'`
cp /opt/librenms/html/plugins/Weathermap/output/MAPNAME.png /opt/weathermap-history/history/MAPNAME_$DATE.png

Dans ce fichier vous aurez à modifier le nom de la map (la votre)

chmod +x getweather.sh

 

Script de de creation du .gif

nano makeGIF.sh
#!/bin/bash

DATE=$(date "+%Y-%m-%d" -d "yesterday")
mkdir -p /opt/librenms/html/plugins/Weathermap/output/history/$DATE
cd /opt/weathermap-history/history/
pngquant --force --quality=60-70 *.png -f --ext .png
convert  -delay 30 -loop 0 *.png /opt/librenms/html/plugins/Weathermap/output/history/$DATE/$DATE.gif
gifsicle -O3 /opt/librenms/html/plugins/Weathermap/output/history/$DATE/$DATE.gif -o /opt/librenms/html/plugins/Weathermap/output/history/$DATE/$DATE.gif
rm /opt/weathermap-history/history/*
chmod +x makeGIF.sh

Creation des cron

crontab -e
  • La première ligne créera des fichiers PNG à intervalles de 5 minutes entre 18h00 et 23h55, remplacez-le par vos périodes les plus chargées, mais je conserverais jusqu'à une période de 6 heures, sinon vous vous retrouveriez avec des GIF de grande taille)
  • La deuxième ligne crée le GIF à 3 heures du matin, je laisserais cela car nous avons explicitement défini -d hier pour compenser la date)
*/5 18-23 * * * /opt/weathermap-history/getweather.sh >> /dev/null 2>&1
0 3 * * * /opt/weathermap-history/makeGIF.sh >> /dev/null 2>&1

Selecteur de date

cd /opt/librenms/html/plugins/Weathermap/output
git clone https://github.com/h2tp/Weathermap-History.git

Dans 24 heures, vous devriez avoir le dossier de date et le GIF créés dans ce dossier opt/librenms/html/plugins/Weathermap/output/history/

Vous pouvez accéder au front-end Web ici : http://librenms-url/plugins/Weathermap/output/history/index.html

Opimisation d'image magick

Si il y a beaucoup de .png à traiter, il se peut que le script plante ! 

Dans ce cas vous pouvez adapter les valeur dans le fichier /etc/ImageMagick-6/policy.xml paragraphe <policymap>

Notamment les valeurs : "memory" et "map"

<policymap>
  <!-- <policy domain="resource" name="temporary-path" value="/tmp"/> -->
  <policy domain="resource" name="memory" value="2GiB"/>
  <policy domain="resource" name="map" value="4GiB"/>
  <policy domain="resource" name="width" value="16KP"/>
  <policy domain="resource" name="height" value="16KP"/>
  <!-- <policy domain="resource" name="list-length" value="128"/> -->
  <policy domain="resource" name="area" value="128MP"/>
  <policy domain="resource" name="disk" value="1GiB"/>
  <!-- <policy domain="resource" name="file" value="768"/> -->
  <!-- <policy domain="resource" name="thread" value="4"/> -->
  <!-- <policy domain="resource" name="throttle" value="0"/> -->
  <!-- <policy domain="resource" name="time" value="3600"/> -->
  <!-- <policy domain="coder" rights="none" pattern="MVG" /> -->
  <!-- <policy domain="module" rights="none" pattern="{PS,PDF,XPS}" /> -->
  <!-- <policy domain="path" rights="none" pattern="@*" /> -->
  <!-- <policy domain="cache" name="memory-map" value="anonymous"/> -->
  <!-- <policy domain="cache" name="synchronize" value="True"/> -->
  <!-- <policy domain="cache" name="shared-secret" value="passphrase" stealth="true"/>
  <!-- <policy domain="system" name="max-memory-request" value="256MiB"/> -->
  <!-- <policy domain="system" name="shred" value="2"/> -->
  <!-- <policy domain="system" name="precision" value="6"/> -->
  <!-- <policy domain="system" name="font" value="/path/to/font.ttf"/> -->
  <!-- <policy domain="system" name="pixel-cache-memory" value="anonymous"/> -->
  <!-- <policy domain="system" name="shred" value="2"/> -->
  <!-- <policy domain="system" name="precision" value="6"/> -->
  <!-- not needed due to the need to use explicitly by mvg: -->
  <!-- <policy domain="delegate" rights="none" pattern="MVG" /> -->
  <!-- use curl -->
  <policy domain="delegate" rights="none" pattern="URL" />
  <policy domain="delegate" rights="none" pattern="HTTPS" />
  <policy domain="delegate" rights="none" pattern="HTTP" />
  <!-- in order to avoid to get image with password text -->
  <policy domain="path" rights="none" pattern="@*"/>
  <!-- disable ghostscript format types -->
  <policy domain="coder" rights="none" pattern="PS" />
  <policy domain="coder" rights="none" pattern="PS2" />
  <policy domain="coder" rights="none" pattern="PS3" />
  <policy domain="coder" rights="none" pattern="EPS" />
  <policy domain="coder" rights="none" pattern="PDF" />
  <policy domain="coder" rights="none" pattern="XPS" />
</policymap>

 

 

Écrire un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec une *

Quelle est le cinquième caractère du mot 0h1vkar ? :