Skip to content

Commit cce3892

Browse files
author
Konstantin Wolff
committed
Merge branch 'development'
2 parents 39445ce + 9757f72 commit cce3892

10 files changed

Lines changed: 2014 additions & 832 deletions

File tree

miniprobe/probe.py

100644100755
File mode changed.

miniprobe/sensors/__init__.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,24 @@
1-
__all__ = ['Ping', 'HTTP', 'Port', 'SNMPCustom', 'CPULoad', 'Memory', 'Diskspace', 'SNMPTraffic', 'CPUTemp', 'Probehealth', 'ExternalIP', 'ADNS', 'APT', 'NMAP', 'MDADM']
1+
# Copyright (c) 2014, Paessler AG <support@paessler.com>
2+
# All rights reserved.
3+
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
4+
# following conditions are met:
5+
# 1. Redistributions of source code must retain the above copyright notice, this list of conditions
6+
# and the following disclaimer.
7+
# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
8+
# and the following disclaimer in the documentation and/or other materials provided with the distribution.
9+
# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse
10+
# or promote products derived from this software without specific prior written permission.
11+
12+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
13+
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
14+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
15+
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
16+
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
17+
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
18+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
19+
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
20+
21+
# Announce modules available in this package
22+
# Just extend this list for your modules and they will be automatically imported during runtime and
23+
# are announced to the PRTG Core
24+
__all__ = ['Ping', 'HTTP', 'Port', 'SNMPCustom', 'SNMPCustomString', 'SNMPLoad', 'SNMPMemory', 'SNMPDisk', 'SNMPProcess', 'CPULoad', 'Memory', 'Diskspace', 'SNMPTraffic', 'CPUTemp', 'Probehealth', 'ExternalIP', 'ADNS', 'APT', 'NMAP', 'MDADM', 'Postfix']

miniprobe/sensors/diskspace.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,31 +83,31 @@ def get_data(data, out_queue):
8383
def read_disk(self):
8484
disks = []
8585
channel_list = []
86-
for line in os.popen("df -k"):
87-
if line.startswith("/"):
86+
for line in os.popen("df -k -xtmpfs -xdevtmpfs"):
87+
if not line.startswith("Filesystem"):
8888
disks.append(line.rstrip().split())
8989
for line in disks:
90-
channel1 = {"name": "Total Bytes " + str(line[0]),
90+
channel1 = {"name": "Total Bytes " + str(line[5]),
9191
"mode": "integer",
9292
"kind": "BytesDisk",
9393
"value": int(line[1]) * 1024}
94-
channel2 = {"name": "Used Bytes" + str(line[0]),
94+
channel2 = {"name": "Used Bytes " + str(line[5]),
9595
"mode": "integer",
9696
"kind": "BytesDisk",
9797
"value": int(line[2]) * 1024}
98-
channel3 = {"name": "Free Bytes " + str(line[0]),
98+
channel3 = {"name": "Free Bytes " + str(line[5]),
9999
"mode": "integer",
100100
"kind": "BytesDisk",
101101
"value": int(line[3]) * 1024}
102102
total = float(line[2]) + float(line[3])
103103
used = float(line[2]) / total
104104
free = float(line[3]) / total
105105

106-
channel4 = {"name": "Free Space " + str(line[0]),
106+
channel4 = {"name": "Free Space " + str(line[5]),
107107
"mode": "float",
108108
"kind": "Percent",
109109
"value": free * 100}
110-
channel5 = {"name": "Used Space" + str(line[0]),
110+
channel5 = {"name": "Used Space " + str(line[5]),
111111
"mode": "float",
112112
"kind": "Percent",
113113
"value": used * 100}

miniprobe/sensors/postfix.py

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
#!/usr/bin/env python
2+
# Copyright (c) 2014, Paessler AG <support@paessler.com>
3+
# All rights reserved.
4+
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
5+
# following conditions are met:
6+
# 1. Redistributions of source code must retain the above copyright notice, this list of conditions
7+
# and the following disclaimer.
8+
# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
9+
# and the following disclaimer in the documentation and/or other materials provided with the distribution.
10+
# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse
11+
# or promote products derived from this software without specific prior written permission.
12+
13+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
14+
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
15+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
16+
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
17+
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
18+
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
19+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
20+
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
21+
22+
import os
23+
import gc
24+
import logging
25+
26+
27+
class Postfix(object):
28+
def __init__(self):
29+
gc.enable()
30+
31+
@staticmethod
32+
def get_kind():
33+
"""
34+
return sensor kind
35+
"""
36+
return "mppostfix"
37+
38+
@staticmethod
39+
def get_sensordef():
40+
"""
41+
Definition of the sensor and data to be shown in the PRTG WebGUI
42+
"""
43+
sensordefinition = {
44+
"kind": Postfix.get_kind(),
45+
"name": "Postfix Mailqueue",
46+
"description": "Monitors the mailqueue of a postfix server",
47+
"help": "Monitors the mailqueue of a postfix server for active, deferred, hold or corrupt mail",
48+
"tag": "mppostfixsensor",
49+
"fields": [],
50+
"groups": []
51+
}
52+
return sensordefinition
53+
54+
def check(self):
55+
spoolcmd = os.popen("postconf -h queue_directory")
56+
spooldir = spoolcmd.readline().replace('\n', '')
57+
spoolcmd.close()
58+
deferredcmd = os.popen("test -d %s/deferred && find %s/deferred -type f | wc -l" % (spooldir, spooldir))
59+
deferredcnt = deferredcmd.readline().replace('\n', '')
60+
deferredcmd.close()
61+
activecmd = os.popen("test -d %s/active && find %s/active -type f | wc -l" % (spooldir, spooldir))
62+
activecnt = activecmd.readline().replace('\n', '')
63+
activecmd.close()
64+
holdcmd = os.popen("test -d %s/hold && find %s/hold -type f | wc -l" % (spooldir, spooldir))
65+
holdcnt = holdcmd.readline().replace('\n', '')
66+
holdcmd.close()
67+
corruptcmd = os.popen("test -d %s/corrupt && find %s/corrupt -type f | wc -l" % (spooldir, spooldir))
68+
corruptcnt = corruptcmd.readline().replace('\n', '')
69+
corruptcmd.close()
70+
channel_list = [
71+
{
72+
"name": "Deferred mails",
73+
"mode": "integer",
74+
"unit": "Count",
75+
"limitmaxwarning": 40,
76+
"limitmaxerror": 50,
77+
"limitmode": 1,
78+
"value": deferredcnt
79+
},
80+
{
81+
"name": "Active mails",
82+
"mode": "integer",
83+
"unit": "Count",
84+
"value": activecnt
85+
},
86+
{
87+
"name": "Hold mails",
88+
"mode": "integer",
89+
"unit": "Count",
90+
"value": holdcnt
91+
},
92+
{
93+
"name": "Corrupt mails",
94+
"mode": "integer",
95+
"unit": "Count",
96+
"value": corruptcnt
97+
},
98+
]
99+
return channel_list
100+
101+
@staticmethod
102+
def get_data(data, out_queue):
103+
postfix = Postfix()
104+
try:
105+
postfixdata = postfix.check()
106+
data_r = {
107+
"sensorid": int(data['sensorid']),
108+
"message": "OK",
109+
"channel": postfixdata
110+
}
111+
logging.debug("Running sensor: %s" % postfix.get_kind())
112+
except Exception as e:
113+
logging.error("Ooops Something went wrong with '%s' sensor %s. Error: %s" % (postfix.get_kind(),
114+
data['sensorid'], e))
115+
data_r = {
116+
"sensorid": int(data['sensorid']),
117+
"error": "Exception",
118+
"code": 1,
119+
"message": "Postfix failed. %s" % e
120+
}
121+
out_queue.put(data_r)
122+
return 1
123+
del postfix
124+
gc.collect()
125+
out_queue.put(data_r)
126+
return 0

0 commit comments

Comments
 (0)