Created
December 13, 2018 14:36
-
-
Save Programie/d645ff19e5f4277c573df0c3d841c906 to your computer and use it in GitHub Desktop.
Increase number of data sources in RRD files created by PNP4Nagios (and possible other tools)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
set -e | |
file_owner="nagios" | |
rrd_file="$1" | |
required_ds="$2" | |
if [[ -z ${rrd_file} ]] || [[ -z ${required_ds} ]]; then | |
echo "Usage: $0 <rrd file> <no required data sources>" | |
exit 1 | |
fi | |
rm -f ${rrd_file}.chg | |
current_ds=$(rrdtool info ${rrd_file} | grep ^ds | cut -d "[" -f 2 | cut -d "]" -f 1 | sort -n | tail -n 1) | |
additional_ds=$((required_ds - current_ds)) | |
new_ds=$((current_ds + additional_ds)) | |
if [[ ${additional_ds} -lt 1 ]]; then | |
echo "Error: RRD file already has ${current_ds} data sources" | |
exit 1 | |
fi | |
start_ds=$((current_ds + 1)) | |
echo "Increasing data sources from ${current_ds} to ${new_ds} data sources" | |
cp -p ${rrd_file} ${rrd_file}.bak | |
/usr/lib/pnp4nagios/libexec/rrd_modify.pl ${rrd_file} insert ${start_ds},${additional_ds} && chown ${file_owner}: ${rrd_file} && mv ${rrd_file}.chg ${rrd_file} | |
if [[ $(rrdtool info ${rrd_file} | grep ^ds | cut -d "[" -f 2 | cut -d "]" -f 1 | tail -n 1) != ${new_ds} ]]; then | |
echo "Error: Last data source index in RRD file does not match expected data source index! Reverting..." | |
mv ${rrd_file}.bak ${rrd_file} | |
exit 1 | |
fi | |
echo "RRD file successfully updated" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment