Projet

Général

Profil

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

root / plugins / bsd / df_bsd @ 17f78427

Historique | Voir | Annoter | Télécharger (2,73 ko)

1 e96ba6dc 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 percentage of disk usage 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, self.parsed_data[item][0])
40
        return thisdata
41
42
    def config(self):
43
        thisdata = """graph_title Filesystem usage (in %)
44
graph_args --lower-limit 0
45
graph_vlabel %
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 92\n%s.critical 98\n" % (thisdata, item, self.parsed_data[item][1], item, item)
51
        return thisdata
52
53
    def get_data(self):
54
        rawdata = os.popen('df -P -l').readlines()
55
        for i in range(1,len(rawdata)):
56
            dataline=rawdata[i].split()
57
            self.parsed_data[re.sub('/', '_', dataline[0])] = (re.sub('%', '', dataline[4]), dataline[5])
58 17f78427 Lars Kruse
59 e96ba6dc Net Easy, Inc
if __name__ == "__main__":
60
    processor = checker()
61
    processor.get_data()
62
    if len(argv) > 1 and argv[1] == 'config':
63
        print processor.config()
64
    else:
65
        print processor