Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / disk / quota2percent_ @ d24215d0

Historique | Voir | Annoter | Télécharger (7,64 ko)

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
Systems with multiple users and individual storage space limitations administered via 'quota'
13

    
14
=head1 CONFIGURATION
15

    
16
The following is the default configuration
17

    
18
  [quota2percent_*]
19
  user root
20

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

    
23
  [quota2percent_*]
24
  env.warning   [value]        (default: 90)
25
  env.critical  [value]        (default: 95)
26
  env.language  [en|de|es]     (default: en)
27
  env.humanuid  [value]        (default: 1000, only need if there is an other value define for UID_MIN in /etc/login.defs)
28

    
29
=head1 DESCRIPTION
30

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

    
38
=over  
39

    
40
I<<<  ln -s /<path to file>/quota2percent_  quota2percent_sdb1 >>>
41

    
42
=back
43

    
44
=head1 MAGIC MARKERS
45

    
46
  #%# family=auto
47
  #%# capabilities=autoconf
48

    
49
=head1 VERSION
50

    
51
17.0210
52

    
53
=head1 HISTORY
54

    
55
V17.0210
56

    
57
  add    env.humanid
58
  add    check if device exist
59
  add    if no limitations administered via 'quota' for the device the total line is shown only
60
  fix    some nitpicking details
61
  add    some comments
62

    
63
V17.0131
64

    
65
  add    POD documentation
66
  add    env.language
67
  add    example graph for Munin Plugin Gallery
68
  remove German comments  
69

    
70
V17.0124
71

    
72
  first version, not munin rules conform
73

    
74
=head1 AUTHOR
75

    
76
Jo Hartmann
77

    
78
=head1 LICENSE
79
 
80
GPLv2 (L<http://www.gnu.org/licenses/gpl-2.0.html>)
81

    
82
=cut
83

    
84
###################################################
85
# Autoconf section                                #
86
###################################################
87

    
88
  if [ "$1" = "autoconf" ]; then
89
     if ! repquota -V &> /dev/null ; then
90
        echo "no ('requota' executable is missing)"
91
        exit 127
92
     fi
93

    
94
     if ! df "/dev/${0##*_}" &> /dev/null; then
95
        echo "no (device /dev/${0##*_} does not exist!)" >&2
96
        exit 128
97
     fi
98

    
99
     echo yes
100
     exit 0
101
  fi
102

    
103
###################################################
104
# Preparation section                             #
105
###################################################
106

    
107
# Load munin's shell libary
108
  . "$MUNIN_LIBDIR/plugins/plugin.sh"
109

    
110
# if any fetch from munin-node file
111
     Warning=${warning:-90}
112
     Critical=${critical:-95}
113
     Language=${language:-en}
114
     Min_UID=${humanuid:-1000}
115

    
116
# Ensure that the 'root' path is valid
117
  PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
118

    
119
# Checking if repquota installed and on the path
120
  if ! repquota -V &> /dev/null ; then
121
     echo "The script 'repquota' is not installed or on the path" >&2
122
     # Send the exit code FATAL ERROR happens
123
     exit 127
124
  fi
125

    
126
# get tehe wild card text
127
  Id=${0##*_}
128

    
129
# Check if device exist
130
  if ! df "/dev/$Id" &> /dev/null; then
131
     echo "The device /dev/$Id does not exist!" >&2
132
     exit 128
133
  fi
134

    
135
###################################################
136
# Data reading sections                           #
137
###################################################
138

    
139
# Reading the quotes for the selected device, using repquota
140
  if repquota "/dev/$Id" &> /dev/null; then     
141
     readarray Quotas < <( repquota "/dev/$Id" | grep " -- " )
142
  else
143
     echo "No limitations administered via 'quota' for $Id" >&2
144
     # If no limitatitons administered: create a dummy
145
     Quotas[0]="root -- 1 1 1 1 1 1"
146
  fi
147

    
148
  readarray Totals < <( df "/dev/$Id" )
149

    
150
# Get the count of Users 
151
   Users=${#Quotas[@]}
152

    
153

    
154
###################################################
155
# Munin Configuration Section                     #
156
###################################################
157

    
158
  if [ "$1" = "config" ]; then
159

    
160
     # Localisation of the graphic texts 
161
     case $Language in
162
          de)
163
            echo graph_title  "Quota-Hard-Limit von $Id"
164
            echo graph_vlabel "Nutzung in % Hardlimit"
165
            echo graph_info   "Die Grafik zeigt die Belegung des durch Quota reglementierten Speicherplatzes für alle regulären Nutzer (UID >= $Min_UID) in Prozent des Hardlimits."
166
            Total_txt="Su. aller Nutzer"
167
            Total_info="Inklusive Systemnutzer (UID < $Min_UID)"
168
            ;;
169
          es) 
170
            echo graph_title  "Cuota de límite absoluto de $Id" 
171
            echo graph_vlabel "el % de uso del límite duro" 
172
            echo graph_info   "El gráfico muestra la disponibilidad de espacio regulado por cuotas para todos los usuarios regulares (UID >= $Min_UID) como porcentaje de límites duros."
173
            Total_txt="Suma de todos los usuarios "
174
            Total_info="La inclusión de usuario del sistema (UID < $Min_UID) "
175
            ;;
176
           *)
177
            echo graph_title  "quota hard limit of $Id"
178
            echo graph_vlabel "Usage in %"
179
            echo graph_info   "The graphic shows the allocation of the quota-regulated storage space for all regular users (UID >= $Min_UID) as a percentage of the hard limit ."
180
            Total_txt="all users"
181
            Total_info="system users (UID < $Min_UID) included" 
182
            ;;
183
     esac
184

    
185
     # Defaults configuration 
186
       echo    graph_category disk
187
       echo    graph_args --lower-limit 0 --upper-limit 100
188
       echo    graph_printf %5.2lf %%
189
       echo    graph_scale  no
190

    
191
     # For each quota user fetch his real name, solve the root problem,  Output the configuration data 
192
       for((i=0; i<"$Users"; i++));do
193
         Quota=( ${Quotas[$i]} )
194
         UserName=${Quota[0]}
195
         Passwd=$(grep "$UserName" /etc/passwd)
196
         OLDIFS=$IFS 
197
         IFS=':' Infos=($Passwd) 
198
         IFS=$OLDIFS
199
         UserInfo=${Infos[4]}
200
         UserInfo=${UserInfo%%,*}
201

    
202
         UserName="$(clean_fieldname "$UserName")"
203
         
204
         # I hate the underlines in place of blanks!
205
         [ "$(echo "$UserName"|cut -c 1)" = "_" ] && UserInfo="$(clean_fieldname "$UserInfo")"
206

    
207
         # If no UserInfo found
208
         [ ! -n "$UserInfo"  ] && UserInfo="$UserName"
209

    
210
         # No graph for none human uid
211
         [ "$(id -u "${Quota[0]}")" -lt "$Min_UID" ] && echo "$UserName.graph no"
212

    
213
         # configure the user lines
214
         echo "$UserName.label    $UserInfo"
215
         echo "$UserName.warning  $Warning"
216
         echo "$UserName.critical $Critical"
217
       done
218

    
219
     # configure the total line and send exit code NO ERROR happens
220
       echo total.label    "$Total_txt"
221
       echo total.warning  "$Warning"
222
       echo total.critical "$Critical"
223
       echo total.info     "$Total_info"
224
       exit 0
225
  fi
226

    
227
###################################################
228
# Munin value section                             #
229
###################################################
230

    
231
# fetch the needed values (used and hard limit) for each user, work around the root problem, calculate the percent value
232
  for((i=0; i<"$Users"; i++));do
233
    Quota=( ${Quotas[$i]} )
234
    UserName="$(clean_fieldname "${Quota[0]}")"
235
    echo "${Quota[2]} ${Quota[4]} $UserName.value" | awk '{printf "%s %f\n",$3,$1*100/$2}'
236
  done
237

    
238
# the value for the total line 
239
  Total=( ${Totals[1]} )
240
  echo "${Total[2]} ${Total[1]} total.value" | awk '{printf "%s %f\n",$3,$1*100/$2}'
241

    
242
# send the exit code NO ERROR happens
243
  exit 0
244

    
245
###################################################
246
# Script end                                      #
247
###################################################