Clean up migration scripts by doing a chown on destination folders and files to the LibreNMS user and group, remove leftover XML files from source directories, and allow user to specify the SNMP version string in the 'settings' section of . (#4792)

This commit is contained in:
Scott Armitage
2016-10-14 16:48:04 -07:00
committed by Neil Lathwood
parent 5b96c67ec5
commit 075c94d2eb
3 changed files with 30 additions and 16 deletions

View File

@@ -6,11 +6,11 @@
###################################################################
########################### DIRECTIONS ############################
# Enter values for ADDHOST, SNMPSTRING, and NODELIST. The default #
# Enter values for ADDHOST, SNMPSTRING, and NODELIST. The default #
# should work if you put the files in the same location. #
###################################################################
############################# CREDITS #############################
############################# CREDITS #############################
# LibreNMS work is done by a great group - http://librenms.org #
# Script Written by - Dan Brown - http://vlan50.com #
###################################################################
@@ -19,10 +19,16 @@
ADDHOST=/opt/librenms/addhost.php
# Enter your unique SNMP String
SNMPSTRING=cisconetwork
# Enter SNMP version of all clients in nodelist text file
SNMPVERSION=v2c
# Enter path to nodelist text file
NODELIST=/tmp/nodelist.txt
# Enter user and group of LibreNMS installation
L_USRGRP=librenms
while read line
while read line
# Change ownership to LibreNMS user and group
chown -R $L_USRGRP:$L_USRGRP .;
# Add each host from the node list file to LibreNMS
do php $ADDHOST "${line%/*}" $SNMPSTRING v2c;
done < $NODELIST
do php $ADDHOST "${line%/*}" $SNMPSTRING $SNMPVERSION;
done < $NODELIST

View File

@@ -17,7 +17,7 @@
# the same location. #
###################################################################
############################# CREDITS #############################
############################# CREDITS #############################
# LibreNMS work is done by a great group - http://librenms.org #
# Script Written by - Dan Brown - http://vlan50.com #
###################################################################
@@ -38,17 +38,19 @@ NODELIST=/tmp/nodelist.txt
# This line SSHs to LibreNMS server and makes directories based on node list text file
ssh root@$DEST 'bash -s' < $MKDIR
# Conversion and transfer loop
while read line;
# Conversion and transfer loop
while read line;
# Enter RRD Directory
do cd $O_RRDPATH"${line%/*}"
do cd $O_RRDPATH"${line%/*}"
# Convert each RRD to XML
for f in *.rrd; do rrdtool dump ${f} > ${f}.xml; done
# Transfer XML file to LibreNMS Server
scp *.xml root@$DEST:$L_RRDPATH"${line%/*}"/
scp *.xml root@$DEST:$L_RRDPATH"${line%/*}"/
# Remove leftover XML files
rm *.xml
# Exit to parent dir
cd ..
done < $NODELIST
# This line SSHs to LibreNMS server and runs the destwork script to finish conversion
ssh root@$DEST 'bash -s' < $DESTSCRIPT
ssh root@$DEST 'bash -s' < $DESTSCRIPT

View File

@@ -12,7 +12,7 @@
#The default should work if you put the files in the same location#
###################################################################
############################# CREDITS #############################
############################# CREDITS #############################
# LibreNMS work is done by a great group - http://librenms.org #
# Script Written by - Dan Brown - http://vlan50.com #
###################################################################
@@ -23,19 +23,25 @@ L_RRDPATH=/opt/librenms/rrd/
ADDHOST=/opt/librenms/addhost.php
# Enter your unique SNMP String
SNMPSTRING=cisconetwork
# Enter SNMP version of all clients in nodelist text file
SNMPVERSION=v2c
# Enter path to nodelist text file
NODELIST=/tmp/nodelist.txt
# Enter user and group of LibreNMS installation
L_USRGRP=librenms
# Loop enters RRD directory and then each folder based on contents of node list text file
while read line
while read line
# Enter the directory
do cd $L_RRDPATH"${line%/*}"
# Convert from XML back to RRD
for f in *.xml; do rrdtool restore ${f} `echo ${f} | cut -f1 -d .`.rrd; done;
# Remove leftover XML files
rm *.xml;
# Change ownership to LibreNMS user and group
chown -R $L_USRGRP:$L_USRGRP .;
# Add the host to LibreNMS
php $ADDHOST "${line%/*}" $SNMPSTRING v2c;
php $ADDHOST "${line%/*}" $SNMPSTRING $SNMPVERSION;
# Change back to parent directory
cd ..;
done < $NODELIST
cd ..;
done < $NODELIST