Skip to content
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
2 changes: 2 additions & 0 deletions miniprobe/sensors/adns.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ def get_data(data, out_queue):
"message": "DNS sensor failed. See log for details"
}
out_queue.put(data_r)
return 1
dns_channel = adns.get_dns(int(timed*1000))
addressdata = []
for element in dns_channel:
Expand All @@ -153,6 +154,7 @@ def get_data(data, out_queue):
del result
gc.collect()
out_queue.put(data)
return 0

@staticmethod
def get_dns(time):
Expand Down
2 changes: 2 additions & 0 deletions miniprobe/sensors/apt.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ def get_data(data, out_queue):
"message": "APT failed. %s" % e
}
out_queue.put(data_r)
return 1
del apt
gc.collect()
out_queue.put(data_r)
return 0
2 changes: 2 additions & 0 deletions miniprobe/sensors/cpuload.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def get_data(data, out_queue):
"message": "CPU load sensor failed. See log for details"
}
out_queue.put(data)
return 1
cpudata = []
for element in cpu:
cpudata.append(element)
Expand All @@ -78,6 +79,7 @@ def get_data(data, out_queue):
del cpuload
gc.collect()
out_queue.put(data)
return 0

@staticmethod
def read_cpu(path):
Expand Down
4 changes: 3 additions & 1 deletion miniprobe/sensors/cputemp.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ def get_data(data, out_queue):
"code": 1,
"message": "CPUTemp sensor failed. See log for details"
}
return out_queue.put(data)
out_queue.put(data)
return 1
tempdata = []
for element in temp:
tempdata.append(element)
Expand All @@ -100,6 +101,7 @@ def get_data(data, out_queue):
del temperature
gc.collect()
out_queue.put(data)
return 1

@staticmethod
def read_temp(config):
Expand Down
2 changes: 2 additions & 0 deletions miniprobe/sensors/diskspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def get_data(data, out_queue):
"message": "Disk Space Sensor failed. See log for details"
}
out_queue.put(data)
return 1
channels = disk
data = {
"sensorid": int(data['sensorid']),
Expand All @@ -77,6 +78,7 @@ def get_data(data, out_queue):
del diskspace
gc.collect()
out_queue.put(data)
return 0

def read_disk(self):
disks = []
Expand Down
2 changes: 2 additions & 0 deletions miniprobe/sensors/ds18b20.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def get_data(data, out_queue):
"message": "DS18B20 sensor failed. See log for details"
}
out_queue.put(data)
return 1
tempdata = []
for element in temp:
tempdata.append(element)
Expand All @@ -106,6 +107,7 @@ def get_data(data, out_queue):
del temperature
gc.collect()
out_queue.put(data)
return 0

@staticmethod
def read_temp(config):
Expand Down
2 changes: 2 additions & 0 deletions miniprobe/sensors/external_ip.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def get_data(data, out_queue):
"message": "External IP sensor failed. See log for details"
}
out_queue.put(data)
return 1
addressdata = []
for element in address:
addressdata.append(element)
Expand All @@ -84,6 +85,7 @@ def get_data(data, out_queue):
del address
gc.collect()
out_queue.put(data)
return 0

@staticmethod
def get_ip(url):
Expand Down
2 changes: 2 additions & 0 deletions miniprobe/sensors/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ def get_data(data, out_queue):
"message": "HTTP Request failed. See log for details"
}
out_queue.put(data)
return 1

data = {
"sensorid": int(data['sensorid']),
Expand All @@ -205,3 +206,4 @@ def get_data(data, out_queue):
del http
gc.collect()
out_queue.put(data)
return 0
2 changes: 2 additions & 0 deletions miniprobe/sensors/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def get_data(data, out_queue):
"message": "Memory sensor failed. See log for details"
}
out_queue.put(data)
return 1
memorydata = []
for element in mem:
memorydata.append(element)
Expand All @@ -78,6 +79,7 @@ def get_data(data, out_queue):
del memory
gc.collect()
out_queue.put(data)
return 0

def read_memory(self, path):
mem = open(path, "r")
Expand Down
3 changes: 2 additions & 1 deletion miniprobe/sensors/nmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def get_data(data, out_queue):
"message": "Port check failed or ports closed. See log for details"
}
out_queue.put(sensor_data)
return
return 1
sensor_data = {
"sensorid": int(data['sensorid']),
"message": alive_str[:-2],
Expand All @@ -133,6 +133,7 @@ def get_data(data, out_queue):
del nmap
gc.collect()
out_queue.put(sensor_data)
return 0

def ip2bin(self,ip):
b = ""
Expand Down
4 changes: 3 additions & 1 deletion miniprobe/sensors/ping.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,11 @@ def get_data(data, out_queue):
"sensorid": int(data['sensorid']),
"error": "Exception",
"code": 1,
"message": "Ping failed. %s" % e
"message": "Ping failed." #%s" % e
}
out_queue.put(data_r)
return 1
del ping
gc.collect()
out_queue.put(data_r)
return 0
2 changes: 2 additions & 0 deletions miniprobe/sensors/port.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ def get_data(data, out_queue):
"message": "Port check failed. See log for details"
}
out_queue.put(data)
return 1
data = {
"sensorid": int(data['sensorid']),
"message": "OK Port %s available" % data['targetport'],
Expand All @@ -135,3 +136,4 @@ def get_data(data, out_queue):
del port
gc.collect()
out_queue.put(data)
return 0
2 changes: 2 additions & 0 deletions miniprobe/sensors/probehealth.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def get_data(data, out_queue):
"message": "Probe Health sensor failed. See log for details"
}
out_queue.put(data)
return 1
probedata = []
for element in health:
probedata.append(element)
Expand All @@ -115,6 +116,7 @@ def get_data(data, out_queue):
"channel": probedata
}
out_queue.put(data)
return 0

def read_memory(self, path):
mem = open(path, "r")
Expand Down
3 changes: 3 additions & 0 deletions miniprobe/sensors/snmpcustom.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ def snmp_get(self, oid, target, snmp_type, community, port, unit, multiplication
@staticmethod
def get_data(data, out_queue):
snmpcustom = SNMPCustom()
snmp_data = []
try:
snmp_data = snmpcustom.snmp_get(str(data['oid']), data['host'], data['value_type'],
data['community'], int(data['port']), data['unit'],
Expand All @@ -192,6 +193,7 @@ def get_data(data, out_queue):
"message": "SNMP Request failed. See log for details"
}
out_queue.put(data)
return 1

data = {
"sensorid": int(data['sensorid']),
Expand All @@ -201,3 +203,4 @@ def get_data(data, out_queue):
del snmpcustom
gc.collect()
out_queue.put(data)
return 0
3 changes: 3 additions & 0 deletions miniprobe/sensors/snmptraffic.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ def snmp_get(self, target, countertype, community, port, ifindex):
@staticmethod
def get_data(data, out_queue):
snmptraffic = SNMPTraffic()
snmp_data = []
try:
snmp_data = snmptraffic.snmp_get(data['host'], data['snmp_counter'],
data['community'], int(data['port']), data['ifindex'])
Expand All @@ -185,6 +186,7 @@ def get_data(data, out_queue):
"message": "SNMP Request failed. See log for details"
}
out_queue.put(data)
return 1

data = {
"sensorid": int(data['sensorid']),
Expand All @@ -194,3 +196,4 @@ def get_data(data, out_queue):
del snmptraffic
gc.collect()
out_queue.put(data)
return 0
47 changes: 47 additions & 0 deletions miniprobe/tests/test_sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from nose.tools import *
from miniprobe.sensors import adns,apt,cpuload,cputemp,diskspace,ds18b20,external_ip,http,memory,nmap,ping,port,portrange,probehealth,snmpcustom,snmptraffic
import multiprocessing

class TestSensors:
@classmethod
Expand All @@ -23,6 +24,8 @@ def setup_class(cls):
cls.test_port = port.Port()
cls.test_portrange = portrange.Portrange()
cls.test_probehealth = probehealth.Probehealth()
cls.test_out_queue = multiprocessing.Queue()
cls.test_sens_data = {'sensorid': '4567'}

# NMAP
def test_nmap_get_kind(self):
Expand Down Expand Up @@ -255,6 +258,17 @@ def test_cputemp_get_sensordef(self):
}
assert_equal(self.test_cputemp.get_sensordef(testing=True), test_sensordef)

def test_cputemp_get_data_error(self):
"""cputemp returns error data in expected format"""
test_sensor_error_data = {
"sensorid": int(self.test_sens_data['sensorid']),
"error": "Exception",
"code": 1,
"message": "CPUTemp sensor failed. See log for details"
}
self.test_cputemp.get_data(self.test_sens_data, self.test_out_queue)
assert_equal(self.test_out_queue.get(), test_sensor_error_data)

# SNMP Traffic
def test_snmptraffic_get_kind(self):
"""snmptraffic returns the correct kind"""
Expand Down Expand Up @@ -334,6 +348,17 @@ def test_snmptraffic_get_sensordef(self):
}
assert_equal(self.test_snmptraffic.get_sensordef(), test_sensordef)

def test_snmptraffic_get_data_error(self):
"""snmptraffic returns error data in expected format"""
test_sensor_error_data = {
"sensorid": int(self.test_sens_data['sensorid']),
"error": "Exception",
"code": 1,
"message": "SNMP Request failed. See log for details"
}
self.test_snmptraffic.get_data(self.test_sens_data, self.test_out_queue)
assert_equal(self.test_out_queue.get(), test_sensor_error_data)

# SNMP Custom
def test_snmpcustom_get_kind(self):
"""snmpcustom returns the correct kind"""
Expand Down Expand Up @@ -431,6 +456,17 @@ def test_snmpcustom_get_sensordef(self):
}
assert_equal(self.test_snmpcustom.get_sensordef(), test_sensordef)

def test_snmptcustom_get_data_error(self):
"""snmpcustom returns error data in expected format"""
test_sensor_error_data = {
"sensorid": int(self.test_sens_data['sensorid']),
"error": "Exception",
"code": 1,
"message": "SNMP Request failed. See log for details"
}
self.test_snmpcustom.get_data(self.test_sens_data, self.test_out_queue)
assert_equal(self.test_out_queue.get(), test_sensor_error_data)

# Diskspace
def test_diskspace_get_kind(self):
"""diskspace returns the correct kind"""
Expand Down Expand Up @@ -673,6 +709,17 @@ def test_ping_get_sensordef(self):
}
assert_equal(self.test_ping.get_sensordef(), test_sensordef)

def test_ping_get_data_error(self):
"""ping returns error data in expected format"""
test_sensor_error_data = {
"sensorid": int(self.test_sens_data['sensorid']),
"error": "Exception",
"code": 1,
"message": "Ping failed."
}
self.test_ping.get_data(self.test_sens_data, self.test_out_queue)
assert_equal(self.test_out_queue.get(), test_sensor_error_data)

# Port
def test_port_get_kind(self):
"""port returns the correct kind"""
Expand Down