Registrieren  •  Login 
  
 
im Forum


 News  •  Information  •  Pastebin  •  Fotos  •  Downloads  •  Online-Tools  •  Fun-Ecke  •  Links  •  Kontakt 


Pastebin
Dieser Code wurde am 29.10.2015, 16:22 von killerbees19 hochgeladen und 1 mal geändert.

Direktlink zu diesem Code: https://www.happytec.at/pastebin/view.php?id=278

Bash
  1. #!/bin/bash
  2. ########################################################################
  3. # #
  4. # repquota___ plugin for Munin #
  5. # ------------------------------ #
  6. # Version 1.0.0 (2015-10-29) #
  7. # #
  8. # Extended quota usage plugin for Munin-Node. #
  9. # Tested with Debian Jessie and Munin 2.0.25. #
  10. # #
  11. # Author: Christian Schroetter (Killerbees19) <scripts@happytec.at> #
  12. # https://www.blog.happytec.at/index.php?mode=view&id=403 #
  13. # #
  14. # License: GNU GENERAL PUBLIC LICENSE - Version 3 #
  15. # https://www.gnu.org/licenses/gpl-3.0.en.html #
  16. # #
  17. # -------------------------------------------------------------------- #
  18. # SYMLINK FORMAT #
  19. # -------------------------------------------------------------------- #
  20. # #
  21. # repquota_<DEV>_{users|groups}_{bytes|inodes} #
  22. # #
  23. # -------------------------------------------------------------------- #
  24. # PLUGIN CONF #
  25. # -------------------------------------------------------------------- #
  26. # #
  27. # [repquota_<DEV>_*] #
  28. # #env.path /mount/point #
  29. # user root #
  30. # #
  31. # -------------------------------------------------------------------- #
  32. # TODO #
  33. # -------------------------------------------------------------------- #
  34. # #
  35. # * Error checks. #
  36. # * ... #
  37. # #
  38. # -------------------------------------------------------------------- #
  39. # CHANGELOG #
  40. # -------------------------------------------------------------------- #
  41. # #
  42. # v1.0.0 (2015-10-29) #
  43. # * Initial release. #
  44. # #
  45. ########################################################################
  46.  
  47. if [[ "$1" == "autoconf" ]]
  48. then echo "no"; exit; fi
  49.  
  50. IFS='_' read -a array <<< "$0"
  51. DEVICE="${path:-/dev/${array[1]}}"
  52. MODE="${array[2]}"
  53. TYPE="${array[3]}"
  54.  
  55. if [[ "$MODE" != "users" && "$MODE" != "groups" ]]
  56. then echo "Invalid symlink: MODE" 1>&2; exit 1; fi
  57. if [[ "$TYPE" != "bytes" && "$TYPE" != "inodes" ]]
  58. then echo "Invalid symlink: TYPE" 1>&2; exit 1; fi
  59.  
  60. if [[ "$MODE" == "users" ]]
  61. then output=`LANG=C /usr/sbin/repquota --verbose --no-names --raw-grace --user "${DEVICE}" | egrep '(^#[0-9]+ |;)'`
  62. else output=`LANG=C /usr/sbin/repquota --verbose --no-names --raw-grace --group "${DEVICE}" | egrep '(^#[0-9]+ |;)'`
  63. fi
  64.  
  65. if [[ "$1" == "config" ]]
  66. then
  67. if [[ "$TYPE" == "bytes" ]]
  68. then
  69. info=`head -n 1 <<< "${output}" | cut -d ';' -f 1 | sed -e 's/^[[:space:]]*//'`
  70. vlabel="Bytes"
  71. else
  72. info=`head -n 1 <<< "${output}" | cut -d ';' -f 2 | sed -e 's/^[[:space:]]*//'`
  73. vlabel="Inodes"
  74. fi
  75.  
  76. echo "graph_title Quota usage for ${DEVICE} (${MODE})"
  77. echo "graph_vlabel ${vlabel}"
  78. echo "graph_info ${info}"
  79. echo "graph_category disk"
  80.  
  81. if [[ "$MODE" == "users" ]]
  82. then id="passwd"
  83. else id="group";
  84. fi
  85.  
  86. if [[ "$TYPE" == "bytes" ]]
  87. then tail -n +2 <<< "${output}" | cut -b 2- | sort -k 1 -h | awk '{cmd="getent '${id}' \""$1"\" | cut -d: -f1"; cmd | getline name; if(name == "") printf "_%d.label #%d\n", $1, $1; else printf "_%d.label %s\n", $1, name; if($4 > 0) printf "_%d.warning %d\n", $1, $4 * 1024; if($5 > 0) printf "_%d.critical %d\n", $1, $5 * 1024; printf "_%d.cdef _%d,1024,*\n", $1, $1;}' 2>/dev/null
  88. else tail -n +2 <<< "${output}" | cut -b 2- | sort -k 1 -h | awk '{cmd="getent '${id}' \""$1"\" | cut -d: -f1"; cmd | getline name; if(name == "") printf "_%d.label #%d\n", $1, $1; else printf "_%d.label %s\n", $1, name; if($8 > 0) printf "_%d.warning %d\n", $1, $8; if($9 > 0) printf "_%d.critical %d\n", $1, $9;}' 2>/dev/null
  89. fi
  90. else
  91. if [[ "$TYPE" == "bytes" ]]
  92. then tail -n +2 <<< "${output}" | cut -b 2- | sort -k 1 -h | awk '{cmd="date -d @"$6" +%Y-%m-%d"; cmd | getline date; printf "_%d.value %d\n", $1, $3; if($6 > 0) printf "_%d.extinfo End of grace period: %s\n", $1, date;}'
  93. else tail -n +2 <<< "${output}" | cut -b 2- | sort -k 1 -h | awk '{cmd="date -d @"$10" +%Y-%m-%d"; cmd | getline date; printf "_%d.value %d\n", $1, $7; if($10 > 0) printf "_%d.extinfo End of grace period: %s\n", $1, date;}'
  94. fi
  95. fi
Dieser Code wurde in 0.0800 Sekunden mit GeSHi farblich hervorgehoben.

 

Alle Zeiten sind GMT + 1 Stunde
Aktuelles Datum und Uhrzeit: 16.11.2019, 02:04
Nach oben
Valid HTML 4.01 Transitional
Valid CSS!

netcup - Internetdienstleistungen
 
 
[ happytec.at | forum.happytec.at | blog.happytec.at | esports.happytec.at | event.happytec.at ]