Projet

Général

Profil

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

root / plugins / bsd / df_abs_bsd @ b0b39b01

Historique | Voir | Annoter | Télécharger (3,02 ko)

1 4f119f79 Net Easy, Inc
#!/usr/bin/env python
2
3
# Copyright (c) 2008, Net Easy, Inc.
4
# All rights reserved.
5
#
6
# Redistribution and use in source and binary forms, with or without
7
# modification, are permitted provided that the following conditions are met:
8
#     * Redistributions of source code must retain the above copyright
9
#       notice, this list of conditions and the following disclaimer.
10
#     * Redistributions in binary form must reproduce the above copyright
11
#       notice, this list of conditions and the following disclaimer in the
12
#       documentation and/or other materials provided with the distribution.
13
#     * Neither the name of Net Easy, Inc. nor the
14
#       names of its contributors may be used to endorse or promote products
15
#       derived from this software without specific prior written permission.
16
#
17
# THIS SOFTWARE IS PROVIDED BY Net Easy, Inc. ''AS IS'' AND ANY
18
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
# DISCLAIMED. IN NO EVENT SHALL Net Easy, Inc. BE LIABLE FOR ANY
21
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28
import re, os
29
from sys import argv
30
31
class checker(object):
32
    def __init__(self):
33
        'parsed_data will have a tuple of the disk capacity and usage (in kbytes) and the mount point for each disk partition'
34
        self.parsed_data = {}
35
36
    def __repr__(self):
37
        thisdata = ''
38
        for item in self.parsed_data.keys():
39
            thisdata = '%s%s.value %s\n' % (thisdata, item, int(self.parsed_data[item][1] * 1024))
40
        return thisdata
41
42
    def config(self):
43
        thisdata = """graph_title Filesystem usage (in bytes)
44
graph_args --base 1024 --lower-limit 0
45
graph_vlabel bytes
46
graph_category disk
47
graph_info Filesystem usage
48
"""
49
        for item in self.parsed_data.keys():
50
            thisdata = "%s%s.label %s\n%s.warning %s\n%s.critical %s\n" % (thisdata, item, self.parsed_data[item][2],
51
                                                                        item, int(self.parsed_data[item][0] * 1024 * 0.92),
52
                                                                        item, int(self.parsed_data[item][0] * 1024 * 0.98))
53
        return thisdata
54
55
    def get_data(self):
56
        rawdata = os.popen('df -P -l -k').readlines()
57
        for i in range(1,len(rawdata)):
58
            dataline=rawdata[i].split()
59
            self.parsed_data[re.sub('/', '_', dataline[0])] = (int(dataline[1]), int(dataline[2]), dataline[5])
60 17f78427 Lars Kruse
61 4f119f79 Net Easy, Inc
if __name__ == "__main__":
62
    processor = checker()
63
    processor.get_data()
64
    if len(argv) > 1 and argv[1] == 'config':
65
        print processor.config()
66
    else:
67
        print processor