Projet

Général

Profil

Révision f21a2fe4

IDf21a2fe4325161a9214a478961cb27be7314d910
Parent dab96a61
Enfant 5efef7ca

Ajouté par JoHartmann il y a presque 9 ans

Update quota2percent_

add       POD documentation
add env.language
add example graph for Munin Plugin Gallery
remove German comments

Voir les différences:

plugins/disk/quota2percent_
1 1
#!/bin/bash
2
# -*- sh -*-
3
: <<=cut
4

  
5
=head1 NAME
6

  
7
quota2percent - Plugin to show disk usage in percent of quota hard limit.
8

  
9
=head1 APPLICABLE SYSTEMS
10

  
11
All systems with "bash", "quota", "repquota" and "munin"
12

  
13
=head1 CONFIGURATION
14

  
15
The following is the default configuration
16

  
17
  [quota2percent_*]
18
  user root
19

  
20
You could define two alert levels and the graph language
21

  
22
  [quota2percent_*]
23
  env.warning   [value]        (default: 90)
24
  env.critical  [value]        (default: 95)
25
  env.language  [en|de|es]     (default: en)   
26

  
27
=head1 DESCRIPTION
28

  
29
Wild card Plugin for monitoring the utilization of devices with quota rules. 
30
A graph is drawn for each user, which shows the usage as a percentage of his hard limit. System accounts (UID <1000) are suppressed. 
31
In addition, a graph is displayed which indicates the ratio device size to device coverage. 
32
The script repqutoa, usually part of the package quota, is needed. 
33
The plugin itself can be stored in any directory. For example, the device sdb1 shell be monitored, a symbolic link must be created
34
in the /etc/munin/plugins/ directory as follows: 
35

  
36
=over  
37

  
38
I<<<  ln -s /<path to file>/quota2percent_  quota2percent_sdb1 >>>
39

  
40
=back
41

  
42
=head1 MAGIC MARKERS
43

  
44
  #%# family=auto
45
  #%# capabilities=autoconf
46

  
47
=head1 VERSION
48

  
49
17.0131
50

  
51
=head1 HISTORY
52

  
53
V17.0131
54

  
55
  add    POD documentation
56
  add    env.language
57
  add    example graph for Munin Plugin Gallery
58
  remove German comments  
59

  
60
V17.0124
61

  
62
  first version, not munin rules conform
63

  
64
=head1 AUTHOR
65

  
66
Jo Hartmann
67

  
68
=head1 LICENSE
69
 
70
GPLv2 (L<http://www.gnu.org/licenses/gpl-2.0.html>)
71

  
72
=cut
73

  
74
###################################################
75
# Preparation section                             #
76
###################################################
77

  
78
# Load munin's shell libary
79
  . "$MUNIN_LIBDIR/plugins/plugin.sh"
80

  
81
# if any fetch from munin-node file
82
     Warning=${warning:-90}
83
     Critical=${critical:-95}
84
     Language=${language:-en}
85

  
86
# Ensure that the 'root' path is valid
87
  PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
88

  
89
# Checking if repquota installed and on the path
90
  repquota -V &> /dev/null
91
  if ! repquota -V &> /dev/null ; then
92
     echo "The script 'repquota' is not installed or on the path"
93
     # Send the exit code FATAL ERROR happens
94
     exit 127
95
  fi
2 96

  
3
# Das Plugin zeigt die Festplattenbelegung in Prozent des Quota-Hard-Limits.
4
# Munin plugin to show the disk usage in percent of the quota hard limit.
5
# The base frame is copied from the proftp plugin
6

  
7
##########################################################################################
8
# Folgende Eintraege in der Datei  /etc/munin/plugin-conf.d/munin-node nicht vergessen ! # 
9
# Don't forget to add following lines to the file /etc/munin/plugin-conf.d/munin-node    #
10
# [quota2percent_*]                                                                      #
11
# user root                                                                              #
12
#                                                                                        #
13
# Weiterhin sind folgende Environment-Variablen erlaubt:                                 #
14
# Following environment variables are allowed:                                           #
15
# env.warning   [value]                                                                  #
16
# env.critical  [value]                                                                  #
17
#                                                                 V17.0124  Jo Hartmann  #
18
##########################################################################################
19

  
20
# Spachauswahl 
21
# Language selection
22
  Language="de"
23

  
24

  
25
# Wildcard-Text erkennen
26 97
# get tehe wild card text
27
  Id=$0
28
  Id=${Id##*_}
98
  Id=${0##*_}
99

  
100
###################################################
101
# Data reading sections                           #
102
###################################################
29 103

  
30
# Einlesen der Quoten für das entsprechende Laufwerk mit repquota 
31 104
# Reading the quotes for the selected device, using repquota 
32
   readarray Quotas < <( repquota /dev/$Id | grep " -- " )
33
   readarray Totals < <(  df /dev/$Id )
105
  readarray Quotas < <( repquota "/dev/$Id" | grep " -- " )
106
  readarray Totals < <( df "/dev/$Id" )
34 107

  
35
# Anzahl der Nutzer ermitteln 
36 108
# Get the count of Users 
37 109
   Users=${#Quotas[@]}
38 110

  
39 111

  
40 112
###################################################
41
# Beginn der Standard-Konfigurationsbereiches     #
42
# Standard Config Section Begin                   #
113
# Munin Configuration Section                     #
43 114
###################################################
44 115

  
45 116
  if [ "$1" = "autoconf" ]; then
......
47 118
       exit 0
48 119
  fi
49 120

  
50
. $MUNIN_LIBDIR/plugins/plugin.sh
51 121

  
52 122
  if [ "$1" = "config" ]; then
53 123

  
54
     # Anpassung der Texte in der Grafik 
55 124
     # Localisation of the graphic texts 
56 125
     case $Language in
57 126
          de)
58
            echo graph_title  Quota-Hard-Limit von $Id
59
            echo graph_vlabel Nutzung in % Hardlimit
127
            echo graph_title  "Quota-Hard-Limit von $Id"
128
            echo graph_vlabel "Nutzung in % Hardlimit"
60 129
            echo graph_info   "Die Grafik zeigt die Belegung des durch Quota reglementierten Speicherplatzes für alle regulären Nutzer (UID >=1000) in Prozent des Hardlimits."
61 130
            Total_txt="Su. aller Nutzer"
62 131
            Total_info="Inklusive Systemnutzer (UID < 1000)"
63 132
            ;;
64 133
          es) 
65
            echo graph_title  Cuota de límite absoluto de $ Id 
66
            echo graph_vlabel el % de uso del límite duro 
134
            echo graph_title  "Cuota de límite absoluto de $Id" 
135
            echo graph_vlabel "el % de uso del límite duro" 
67 136
            echo graph_info   "El gráfico muestra la disponibilidad de espacio regulado por cuotas para todos los usuarios regulares (UID> = 1000) como porcentaje de límites duros."
68 137
            Total_txt="Suma de todos los usuarios "
69 138
            Total_info="La inclusión de usuario del sistema (UID <1000) "
70 139
            ;;
71 140
           *)
72
            echo graph_title  quota hard limit of %Id
73
            echo graph_vlabel Usage in %
74
            Total_txt="all users"
141
            echo graph_title  "quota hard limit of $Id"
142
            echo graph_vlabel "Usage in %"
75 143
            echo graph_info   "The graphic shows the allocation of the quota-regulated storage space for all regular users (UID> = 1000) as a percentage of the hard limit ."
144
            Total_txt="all users"
76 145
            Total_info="system users (UID < 1000) included" 
77 146
            ;;
78 147
     esac
79 148

  
80
     # Standard Konfiguration 
81 149
     # Defaults configuration 
82 150
       echo    graph_category disk
83 151
       echo    graph_args --lower-limit 0 --upper-limit 100
84 152
       echo    graph_printf %5.2lf %%
85 153
       echo    graph_scale  no
86 154

  
87
     # Ggf. Werte aus der Datei munin-node uebernehmen
88
     # if any fetch from munin-node file
89
       Warning=${warning:-90}
90
       Critical=${critical:-95}
91

  
92
     # Die Quota-Nutzer und deren Real-Namen ermitteln, das Root-Problem beheben, die Kondfigurationsdaten ausgeben
93 155
     # For each quota user fetch his real name, solve the root problem,  Output the configuration data 
94
       for((i=0; i<$Users; i++));do
156
       for((i=0; i<"$Users"; i++));do
95 157
         Quota=( ${Quotas[$i]} )
96
         User=${Quota[0]}
97
         Passwd=$(cat /etc/passwd | grep $User)
158
         UserName=${Quota[0]}
159
         #Passwd=$(cat /etc/passwd | grep $UserName)
160
         Passwd=$(grep "$UserName" /etc/passwd)
98 161
         OLDIFS=$IFS 
99 162
         IFS=':' Infos=($Passwd) 
100 163
         IFS=$OLDIFS
101
         Name=${Infos[4]}
102
         Name=${Name%%,*}
103

  
104
         [ $User == "root" ] && { User="__root"; Name="__root";}
105
         [ ! -n "$Name"  ] && Name=$User
106
         [ $(id -u ${Quota[0]}) -lt 1000 ] && echo $User.graph no
107
         echo $User.label $Name
108
         echo $User.warning  $warning
109
         echo $User.critical $critical
164
         UserInfo=${Infos[4]}
165
         UserInfo=${UserInfo%%,*}
166

  
167
         UserName="$(clean_fieldname "$UserName")"
168
         UserInfo="$(clean_fieldname "$UserInfo")"
169

  
170
         [ ! -n "$UserInfo"  ] && UserInfo="$UserName"
171
         [ "$(id -u "${Quota[0]}")" -lt 1000 ] && echo "$UserName.graph no"
172
         echo "$UserName.label $UserInfo"
173
         echo "$UserName.warning  $Warning"
174
         echo "$UserName.critical $Critical"
110 175
       done
111 176

  
112
     # Die Summenzeile konfigurieren
113
     # configure the total line 
114
       echo total.label    $Total_txt
115
       echo total.warning  $Warning
116
       echo total.critical $Critical
117
       echo total.info     $Total_info
118
     exit 0
177
     # configure the total line and send exit code NO ERROR happens
178
       echo total.label    "$Total_txt"
179
       echo total.warning  "$Warning"
180
       echo total.critical "$Critical"
181
       echo total.info     "$Total_info"
182
       exit 0
119 183
  fi
120 184

  
121 185
###################################################
122
# Ende der Standard-Konfigurationsbereiches       #
123
# Standard Config Section End                     #
186
# Munin value section                             #
124 187
###################################################
125 188

  
126
# Die Werte (Belegung und Hardlimit) je Nutzer ermitteln, das Root-Problem umgehen, die Prozente berechnen
127 189
# fetch the needed values (used and hard limit) for each user, work around the root problem, calculate the percent value
128
  for((i=0; i<$Users; i++));do
190
  for((i=0; i<"$Users"; i++));do
129 191
    Quota=( ${Quotas[$i]} )
130
    User=${Quota[0]}
131
    [ $User == "root" ] && User="__root"
132
    Prozent=`echo "scale=2 ; ${Quota[2]}*100/${Quota[4]}" | bc`
133

  
134
    echo $User.value $Prozent
192
    UserName="$(clean_fieldname "${Quota[0]}")"
193
    echo "${Quota[2]} ${Quota[4]} $UserName.value" | awk '{printf "%s %.2f\n", $3 ,$1*100/$2}'
135 194
  done
136 195

  
137
# Die Summenwerte
138 196
# the value for the total line 
139 197
  Total=( ${Totals[1]} )
140
  Summe=`echo "scale=2;${Total[2]}*100/${Total[1]}" | bc`
141
  echo total.value $Summe
198
  echo "${Total[2]} ${Total[1]} total.value" | awk '{printf "%s %.2f\n", $3, $1*100/$2}'
142 199

  
200
# send the exit code NO ERROR happens
143 201
  exit 0
202

  
203
###################################################
204
# Script end                                      #
205
###################################################

Formats disponibles : Unified diff