Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /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"
Add Comment
Please, Sign In to add comment