Guest User

Untitled

a guest
Dec 13th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #! /bin/bash
  2.  
  3. set -e
  4.  
  5. file_owner="nagios"
  6. rrd_file="$1"
  7. required_ds="$2"
  8.  
  9. if [[ -z ${rrd_file} ]] || [[ -z ${required_ds} ]]; then
  10. echo "Usage: $0 <rrd file> <no required data sources>"
  11. exit 1
  12. fi
  13.  
  14. rm -f ${rrd_file}.chg
  15.  
  16. current_ds=$(rrdtool info ${rrd_file} | grep ^ds | cut -d "[" -f 2 | cut -d "]" -f 1 | sort -n | tail -n 1)
  17.  
  18. additional_ds=$((required_ds - current_ds))
  19. new_ds=$((current_ds + additional_ds))
  20.  
  21. if [[ ${additional_ds} -lt 1 ]]; then
  22. echo "Error: RRD file already has ${current_ds} data sources"
  23. exit 1
  24. fi
  25.  
  26. start_ds=$((current_ds + 1))
  27.  
  28. echo "Increasing data sources from ${current_ds} to ${new_ds} data sources"
  29.  
  30. cp -p ${rrd_file} ${rrd_file}.bak
  31.  
  32. /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}
  33.  
  34. if [[ $(rrdtool info ${rrd_file} | grep ^ds | cut -d "[" -f 2 | cut -d "]" -f 1 | tail -n 1) != ${new_ds} ]]; then
  35. echo "Error: Last data source index in RRD file does not match expected data source index! Reverting..."
  36. mv ${rrd_file}.bak ${rrd_file}
  37. exit 1
  38. fi
  39.  
  40. echo "RRD file successfully updated"
Add Comment
Please, Sign In to add comment