Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions 21 miniprobe/miniprobe.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#!/usr/bin/env python
#Copyright (c) 2014, Paessler AG <support@paessler.com>
#All rights reserved.
#Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
# Copyright (c) 2014, Paessler AG <support@paessler.com>
# All rights reserved.
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
# following conditions are met:
#1. Redistributions of source code must retain the above copyright notice, this list of conditions
# 1. Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
#2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
# and the following disclaimer in the documentation and/or other materials provided with the distribution.
#3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse
# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse
# or promote products derived from this software without specific prior written permission.

#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
Expand All @@ -20,9 +20,9 @@
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


### PRTG Python Miniprobe
### Miniprobe needs at least Python 2.7 because of "importlib"
### If older python version is used you will have to install "importlib"
# PRTG Python Miniprobe
# Miniprobe needs at least Python 2.7 because of "importlib"
# If older python version is used you will have to install "importlib"

# import general modules
import sys
Expand Down Expand Up @@ -149,4 +149,3 @@ def clean_mem():
os.popen("sysctl vm.drop_caches=1")
os.popen("sysctl vm.drop_caches=2")
os.popen("sysctl vm.drop_caches=3")

41 changes: 19 additions & 22 deletions 41 miniprobe/probe.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#!/usr/bin/env python
#Copyright (c) 2014, Paessler AG <support@paessler.com>
#All rights reserved.
#Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
# Copyright (c) 2014, Paessler AG <support@paessler.com>
# All rights reserved.
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
# following conditions are met:
#1. Redistributions of source code must retain the above copyright notice, this list of conditions
# 1. Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
#2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
# and the following disclaimer in the documentation and/or other materials provided with the distribution.
#3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse
# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse
# or promote products derived from this software without specific prior written permission.

#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
Expand All @@ -20,9 +20,9 @@
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


### PRTG Python Miniprobe
### Miniprobe needs at least Python 2.7 because of "importlib"
### If older python version is used you will have to install "importlib"
# PRTG Python Miniprobe
# Miniprobe needs at least Python 2.7 because of "importlib"
# If older python version is used you will have to install "importlib"

# import general modules
import sys
Expand All @@ -46,7 +46,6 @@
import multiprocessing
except Exception as e:
print e
#sys.exit()

# Implemented for internal testing only. Not for public usage!
http = False
Expand Down Expand Up @@ -94,8 +93,6 @@ def main():
data_announce = mini_probe.create_parameters(config, announce_json, 'announce')
logging.debug("Announce Data: %s" % data_announce)
json_history = []
timeout = False

while not announce:
try:
# announcing the probe and all sensors
Expand All @@ -107,8 +104,7 @@ def main():
logging.info("ANNOUNCE request successfully sent to PRTG Core Server at %s:%s."
% (config["server"], config["port"]))
logging.debug("Connecting to %s:%s" % (config["server"], config["port"]))
logging.debug("Status Code: %s | Message: %s" % (request_announce.status_code,
request_announce.text))
logging.debug("Status Code: %s | Message: %s" % (request_announce.status_code, request_announce.text))
request_announce.close()
except requests.exceptions.Timeout:
logging.error("ANNOUNCE Timeout: " + str(data_announce))
Expand Down Expand Up @@ -137,8 +133,8 @@ def main():
logging.debug(request_task.text)
try:
json_response = request_task.json()
except Exception as e:
logging.info("Error: %s! Server returned: %s" % (e, request_task.text))
except Exception as ex:
logging.info("Error: %s! Server returned: %s" % (ex, request_task.text))
request_task.close()
gc.collect()
task = True
Expand All @@ -147,8 +143,8 @@ def main():
logging.debug("task_url: " + url_task + "\ntask_data: " + str(task_data))
except requests.exceptions.Timeout:
logging.error("TASK Timeout: " + str(task_data))
logging.debug("Timeout encountered. Need to write more code to handle timeoutzzzzz: %s" % json_history)
timeout = True
logging.debug("Timeout encountered. Need to write more code to handle timeoutzzzzz: %s"
% json_history)
except Exception as announce_error:
logging.error(announce_error)
time.sleep(int(config['baseinterval']) / 2)
Expand Down Expand Up @@ -178,13 +174,14 @@ def main():
while len(json_payload_data) < len(element):
out = out_queue.get()
json_payload_data.append(out)
except Exception as e:
logging.error(e)
except Exception as ex:
logging.error(ex)
pass

url_data = mini_probe.create_url(config, 'data', http)
try:
request_data = requests.post(url_data, data=json.dumps(json_payload_data), verify=False, timeout=30)
request_data = requests.post(url_data, data=json.dumps(json_payload_data),
verify=False, timeout=30)
logging.info("DATA request successfully sent to PRTG Core Server at %s:%s. Status: %s"
% (config["server"], config["port"], request_data.status_code))
logging.debug("data_url: " + url_data + "\ndata_data: " + str(json_payload_data))
Expand Down
32 changes: 17 additions & 15 deletions 32 miniprobe/sensors/adns.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
pass


class aDNS(object):
class ADNS(object):
def __init__(self):
gc.enable()

Expand All @@ -49,10 +49,12 @@ def get_sensordef():
Definition of the sensor and data to be shown in the PRTG WebGUI
"""
sensordefinition = {
"kind": aDNS.get_kind(),
"kind": ADNS.get_kind(),
"name": "DNS",
"description": "Monitors a DNS server (Domain Name Service), resolves a domain name, and compares it to an IP address",
"help": "The DNS sensor monitors a Domain Name Service (DNS) server. It resolves a domain name and compares it to a given IP address.",
"description": "Monitors a DNS server (Domain Name Service), "
"resolves a domain name, and compares it to an IP address",
"help": "The DNS sensor monitors a Domain Name Service (DNS) server. "
"It resolves a domain name and compares it to a given IP address.",
"tag": "mpdnssensor",
"groups": [
{
Expand Down Expand Up @@ -114,18 +116,16 @@ def get_sensordef():

@staticmethod
def get_data(data, out_queue):
adns = aDNS()
result = ""
timed = 0
adns = ADNS()
logging.debug("Running sensor: %s" % adns.get_kind())
try:
start_time = timeit.default_timer()
result = adns.get_record(data['timeout'],data['port'],data['domain'],data['type'],data['host'])
result = adns.get_record(data['timeout'], data['port'], data['domain'], data['type'], data['host'])
timed = timeit.default_timer() - start_time
logging.debug("DNS: %s" % result)
except Exception as e:
except Exception as ex:
logging.error("Ooops Something went wrong with '%s' sensor %s. Error: %s" % (adns.get_kind(),
data['sensorid'], e))
data['sensorid'], ex))
data_r = {
"sensorid": int(data['sensorid']),
"error": "Exception",
Expand All @@ -134,7 +134,7 @@ def get_data(data, out_queue):
}
out_queue.put(data_r)
return 1
dns_channel = adns.get_dns(int(timed*1000))
dns_channel = adns.get_dns(int(timed * 1000))
addressdata = []
for element in dns_channel:
addressdata.append(element)
Expand Down Expand Up @@ -176,9 +176,9 @@ def get_record(timeout, port, domain, type, host):
resolver.port = port
if type == 'PTR':
addr = dns.reversename.from_address(domain)
answers = dns.resolver.query(addr,type)
answers = dns.resolver.query(addr, type)
else:
answers = dns.resolver.query(domain,type)
answers = dns.resolver.query(domain, type)
if (type == 'A') or (type == 'AAAA'):
for rdata in answers:
result = result + str(rdata.address) + ", "
Expand All @@ -187,10 +187,12 @@ def get_record(timeout, port, domain, type, host):
result = result + rdata.preference + ": " + rdata.exchange + ", "
elif type == 'SOA':
for rdata in answers:
result = result + "NS: " + str(rdata.mname) + ", TECH: " + str(rdata.rname) + ", S/N: " + str(rdata.serial) + ", Refresh: " + str(rdata.refresh/60) + " min, Expire: " + str(rdata.expire/60) + " min "
result = result + "NS: " + str(rdata.mname) + ", TECH: " + str(rdata.rname) + ", S/N: " + str(rdata.serial) + ", Refresh: " + str(rdata.refresh / 60) + " min, Expire: " \
+ str(rdata.expire / 60) + " min "
elif (type == 'CNAME') or (type == 'NS') or (type == 'PTR'):
for rdata in answers:
result = result + str(rdata.target) + ", "
except dns.resolver.NoAnswer:
result = "DNS Error while getting %s record. This could be the result of a misconfiguration in the sensor settings" % type
result = "DNS Error while getting %s record. " \
"This could be the result of a misconfiguration in the sensor settings" % type
return result[:-2]
17 changes: 8 additions & 9 deletions 17 miniprobe/sensors/apt.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#!/usr/bin/env python
#Copyright (c) 2014, Paessler AG <support@paessler.com>
#All rights reserved.
#Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
# Copyright (c) 2014, Paessler AG <support@paessler.com>
# All rights reserved.
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
# following conditions are met:
#1. Redistributions of source code must retain the above copyright notice, this list of conditions
# 1. Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
#2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
# and the following disclaimer in the documentation and/or other materials provided with the distribution.
#3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse
# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse
# or promote products derived from this software without specific prior written permission.

#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
Expand All @@ -22,7 +22,7 @@
import os
import gc
import logging
import sys


class APT(object):
def __init__(self):
Expand Down Expand Up @@ -55,7 +55,6 @@ def check(self):
upgrade = 0
install = 0
remove = 0
total = 0
ret = os.popen("apt-get -s dist-upgrade | grep 'newly inst'")
updatedata = ret.readlines()
ret.close()
Expand Down
51 changes: 29 additions & 22 deletions 51 miniprobe/sensors/cpuload.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#!/usr/bin/env python
#Copyright (c) 2014, Paessler AG <support@paessler.com>
#All rights reserved.
#Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
# Copyright (c) 2014, Paessler AG <support@paessler.com>
# All rights reserved.
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
# following conditions are met:
#1. Redistributions of source code must retain the above copyright notice, this list of conditions
# 1. Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
#2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
# and the following disclaimer in the documentation and/or other materials provided with the distribution.
#3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse
# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse
# or promote products derived from this software without specific prior written permission.

#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
Expand Down Expand Up @@ -88,20 +88,27 @@ def read_cpu(path):
for line in cpu:
for element in line.split(" "):
data.append(element)
channel_list = [{"name": "Load Average 1min",
"mode": "float",
"kind": "Custom",
"customunit": "",
"value": float(data[0])},
{"name": "Load Average 5min",
"mode": "float",
"kind": "Custom",
"customunit": "",
"value": float(data[1])},
{"name": "Load Average 10min",
"mode": "float",
"kind": "Custom",
"customunit": "",
"value": float(data[2])}]
channel_list = [
{
"name": "Load Average 1min",
"mode": "float",
"kind": "Custom",
"customunit": "",
"value": float(data[0])
},
{
"name": "Load Average 5min",
"mode": "float",
"kind": "Custom",
"customunit": "",
"value": float(data[1])
},
{
"name": "Load Average 10min",
"mode": "float",
"kind": "Custom",
"customunit": "",
"value": float(data[2])
}]
cpu.close()
return channel_list
11 changes: 6 additions & 5 deletions 11 miniprobe/sensors/cputemp.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
if not os.path.exists("/sys/class/thermal/thermal_zone0/temp"):
temp = False


class CPUTemp(object):
def __init__(self):
gc.enable()
Expand Down Expand Up @@ -78,7 +79,7 @@ def get_data(data, out_queue):
temperature = CPUTemp()
logging.debug("Running sensor: %s" % temperature.get_kind())
try:
temp = temperature.read_temp(data)
tmp = temperature.read_temp(data)
except Exception as e:
logging.error("Ooops Something went wrong with '%s' sensor %s. Error: %s" % (temperature.get_kind(),
data['sensorid'], e))
Expand All @@ -91,7 +92,7 @@ def get_data(data, out_queue):
out_queue.put(data)
return 1
tempdata = []
for element in temp:
for element in tmp:
tempdata.append(element)
data = {
"sensorid": int(data['sensorid']),
Expand All @@ -107,9 +108,9 @@ def get_data(data, out_queue):
def read_temp(config):
data = []
chandata = []
temp = open("/sys/class/thermal/thermal_zone0/temp", "r")
lines = temp.readlines()
temp.close()
tmp = open("/sys/class/thermal/thermal_zone0/temp", "r")
lines = tmp.readlines()
tmp.close()
temp_string = lines[0]
logging.debug("CPUTemp Debug message: Temperature from file: %s" % temp_string)
temp_c = float(temp_string) / 1000.0
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.